mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(appconfigdata): honor requested poll interval (#3092)
This commit is contained in:
1 parent
64f06e090f
commit
8686651de1
6 files changed
+133
-14
No files matched your search
@@ -204,8 +204,8 @@ class AppConfigTest {
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
@DisplayName("Poll interval: requested 60s but emulator returns 15s (known deviation from AWS)")
|
||||
void requiredMinimumPollIntervalIsAcceptedButNotEnforced() {
|
||||
@DisplayName("Poll interval: requested minimum is returned to the client")
|
||||
void requiredMinimumPollIntervalIsReturned() {
|
||||
var sessionResponse = appConfigData.startConfigurationSession(StartConfigurationSessionRequest.builder()
|
||||
.applicationIdentifier(applicationId)
|
||||
.environmentIdentifier(environmentId)
|
||||
@@ -218,16 +218,14 @@ class AppConfigTest {
|
||||
.configurationToken(intervalSessionToken)
|
||||
.build());
|
||||
|
||||
// Emulator always returns 15s regardless of the requested interval.
|
||||
// AWS would return the requested 60s. Pinning current emulator behavior.
|
||||
assertThat(firstResponse.nextPollIntervalInSeconds()).isEqualTo(15);
|
||||
assertThat(firstResponse.nextPollIntervalInSeconds()).isEqualTo(60);
|
||||
assertThat(firstResponse.nextPollConfigurationToken()).isNotNull();
|
||||
|
||||
GetLatestConfigurationResponse secondResponse = appConfigData.getLatestConfiguration(GetLatestConfigurationRequest.builder()
|
||||
.configurationToken(firstResponse.nextPollConfigurationToken())
|
||||
.build());
|
||||
|
||||
assertThat(secondResponse.nextPollIntervalInSeconds()).isEqualTo(15);
|
||||
assertThat(secondResponse.nextPollIntervalInSeconds()).isEqualTo(60);
|
||||
assertThat(secondResponse.nextPollConfigurationToken()).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class AppConfigDataController {
|
||||
.header("Content-Type", data.contentType())
|
||||
.header("Version-Label", data.configurationVersion())
|
||||
.header("Next-Poll-Configuration-Token", data.nextPollConfigurationToken())
|
||||
.header("Next-Poll-Interval-In-Seconds", 15)
|
||||
.header("Next-Poll-Interval-In-Seconds", data.nextPollIntervalInSeconds())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+34
-3
@@ -10,6 +10,7 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -40,7 +41,8 @@ public class AppConfigDataService {
|
||||
session.setApplicationId(appId);
|
||||
session.setEnvironmentId(envId);
|
||||
session.setConfigurationProfileId(profileId);
|
||||
session.setRequiredMinimumPollIntervalInSeconds((Integer) request.getOrDefault("RequiredMinimumPollIntervalInSeconds", 15));
|
||||
int pollInterval = parsePollInterval(request.getOrDefault("RequiredMinimumPollIntervalInSeconds", 15));
|
||||
session.setRequiredMinimumPollIntervalInSeconds(pollInterval);
|
||||
session.setCurrentToken(UUID.randomUUID().toString());
|
||||
|
||||
sessionStore.put(session.getCurrentToken(), session);
|
||||
@@ -48,10 +50,33 @@ public class AppConfigDataService {
|
||||
return session.getCurrentToken();
|
||||
}
|
||||
|
||||
private static int parsePollInterval(Object value) {
|
||||
if (!(value instanceof Number)) {
|
||||
throw invalidPollInterval();
|
||||
}
|
||||
try {
|
||||
long interval = new BigDecimal(value.toString()).longValueExact();
|
||||
if (interval < 15 || interval > 86400) {
|
||||
throw invalidPollInterval();
|
||||
}
|
||||
return (int) interval;
|
||||
} catch (NumberFormatException | ArithmeticException e) {
|
||||
throw invalidPollInterval();
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException invalidPollInterval() {
|
||||
return new AwsException("BadRequestException",
|
||||
"RequiredMinimumPollIntervalInSeconds must be an integer between 15 and 86400", 400);
|
||||
}
|
||||
|
||||
public ConfigurationData getLatestConfiguration(String token) {
|
||||
ConfigurationSession session = sessionStore.get(token)
|
||||
.orElseThrow(() -> new AwsException("BadRequestException", "Invalid configuration token", 400));
|
||||
|
||||
int pollInterval = normalizePollInterval(session.getRequiredMinimumPollIntervalInSeconds());
|
||||
session.setRequiredMinimumPollIntervalInSeconds(pollInterval);
|
||||
|
||||
String activeVersion = appConfigService.getActiveVersion(session.getEnvironmentId(), session.getConfigurationProfileId());
|
||||
|
||||
HostedConfigurationVersion version = null;
|
||||
@@ -73,8 +98,14 @@ public class AppConfigDataService {
|
||||
String contentType = (version != null) ? version.getContentType() : "application/octet-stream";
|
||||
String versionLabel = (version != null) ? String.valueOf(version.getVersionNumber()) : "";
|
||||
|
||||
return new ConfigurationData(content, contentType, versionLabel, nextToken);
|
||||
return new ConfigurationData(content, contentType, versionLabel, nextToken,
|
||||
pollInterval);
|
||||
}
|
||||
|
||||
public record ConfigurationData(byte[] content, String contentType, String configurationVersion, String nextPollConfigurationToken) {}
|
||||
static int normalizePollInterval(int interval) {
|
||||
return interval >= 15 && interval <= 86400 ? interval : 15;
|
||||
}
|
||||
|
||||
public record ConfigurationData(byte[] content, String contentType, String configurationVersion,
|
||||
String nextPollConfigurationToken, int nextPollIntervalInSeconds) {}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ public class ConfigurationSession {
|
||||
private String applicationId;
|
||||
private String environmentId;
|
||||
private String configurationProfileId;
|
||||
private int requiredMinimumPollIntervalInSeconds;
|
||||
private int requiredMinimumPollIntervalInSeconds = 15;
|
||||
private String currentToken;
|
||||
private String lastConfigurationVersion;
|
||||
|
||||
|
||||
+69
-3
@@ -182,8 +182,8 @@ class AppConfigIntegrationTest {
|
||||
}
|
||||
|
||||
@Test @Order(12)
|
||||
@DisplayName("Poll interval: requested 60s but emulator returns 15s (known deviation from AWS)")
|
||||
void requiredMinimumPollIntervalIsStoredButNotEnforced() {
|
||||
@DisplayName("Poll interval: requested minimum is returned to the client")
|
||||
void requiredMinimumPollIntervalIsReturned() {
|
||||
intervalToken = given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 60}")
|
||||
@@ -199,7 +199,7 @@ class AppConfigIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Next-Poll-Configuration-Token", notNullValue())
|
||||
.header("Next-Poll-Interval-In-Seconds", equalTo("15"))
|
||||
.header("Next-Poll-Interval-In-Seconds", equalTo("60"))
|
||||
.extract().header("Next-Poll-Configuration-Token");
|
||||
|
||||
given()
|
||||
@@ -210,6 +210,72 @@ class AppConfigIntegrationTest {
|
||||
.header("Next-Poll-Configuration-Token", notNullValue());
|
||||
}
|
||||
|
||||
@Test @Order(32)
|
||||
void requiredMinimumPollIntervalMustBeWithinAwsLimits() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 14}")
|
||||
.when().post("/configurationsessions")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test @Order(33)
|
||||
void requiredMinimumPollIntervalAcceptsAwsUpperBoundary() {
|
||||
String token = startSessionWithInterval(86400);
|
||||
|
||||
given()
|
||||
.queryParam("configuration_token", token)
|
||||
.when().get("/configuration")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("Next-Poll-Interval-In-Seconds", equalTo("86400"));
|
||||
}
|
||||
|
||||
@Test @Order(34)
|
||||
void requiredMinimumPollIntervalRejectsValuesAboveAwsMaximum() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 86401}")
|
||||
.when().post("/configurationsessions")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test @Order(35)
|
||||
void requiredMinimumPollIntervalRejectsFractionalValues() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 60.5}")
|
||||
.when().post("/configurationsessions")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test @Order(36)
|
||||
void requiredMinimumPollIntervalRejectsOversizedValues() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": 4294967296}")
|
||||
.when().post("/configurationsessions")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
private String startSessionWithInterval(int interval) {
|
||||
return given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("{\"ApplicationIdentifier\": \"" + appId + "\", \"EnvironmentIdentifier\": \"" + envId + "\", \"ConfigurationProfileIdentifier\": \"" + profileId + "\", \"RequiredMinimumPollIntervalInSeconds\": " + interval + "}")
|
||||
.when().post("/configurationsessions")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.extract().path("InitialConfigurationToken");
|
||||
}
|
||||
|
||||
// ──────────────────────────── Hosted Configuration Version list ────────────────────────────
|
||||
|
||||
@Test @Order(13)
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationSession;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigurationSessionTest {
|
||||
@Test
|
||||
void legacySessionWithoutPollIntervalUsesAwsDefault() throws Exception {
|
||||
ConfigurationSession session = new ObjectMapper().readValue(
|
||||
"{\"id\":\"legacy\",\"applicationId\":\"app\",\"environmentId\":\"env\",\"configurationProfileId\":\"profile\"}",
|
||||
ConfigurationSession.class);
|
||||
|
||||
assertEquals(15, session.getRequiredMinimumPollIntervalInSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidPersistedPollIntervalUsesAwsDefault() {
|
||||
assertEquals(15, AppConfigDataService.normalizePollInterval(0));
|
||||
assertEquals(15, AppConfigDataService.normalizePollInterval(86401));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user