Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,6 @@ public ProjectConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializa
region = jsonObject.get("region").getAsString();
}

// Validate experiment types
Set<String> validExperimentTypes = new HashSet<>(Arrays.asList(
Experiment.TYPE_AB, Experiment.TYPE_MAB, Experiment.TYPE_CMAB,
Experiment.TYPE_TD, Experiment.TYPE_FR
));
for (Experiment experiment : experiments) {
if (experiment.getType() != null && !validExperimentTypes.contains(experiment.getType())) {
throw new JsonParseException(
String.format("Experiment \"%s\" has invalid type \"%s\". Valid types: %s.",
experiment.getKey(), experiment.getType(), validExperimentTypes));
}
}
for (Group group : groups) {
for (Experiment experiment : group.getExperiments()) {
if (experiment.getType() != null && !validExperimentTypes.contains(experiment.getType())) {
throw new JsonParseException(
String.format("Experiment \"%s\" has invalid type \"%s\". Valid types: %s.",
experiment.getKey(), experiment.getType(), validExperimentTypes));
}
}
}

return new DatafileProjectConfig(
accountId,
anonymizeIP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,6 @@ public DatafileProjectConfig deserialize(JsonParser parser, DeserializationConte
region = node.get("region").textValue();
}

// Validate experiment types
Set<String> validExperimentTypes = new HashSet<>(Arrays.asList(
Experiment.TYPE_AB, Experiment.TYPE_MAB, Experiment.TYPE_CMAB,
Experiment.TYPE_TD, Experiment.TYPE_FR
));
for (Experiment experiment : experiments) {
if (experiment.getType() != null && !validExperimentTypes.contains(experiment.getType())) {
throw new IOException(
String.format("Experiment \"%s\" has invalid type \"%s\". Valid types: %s.",
experiment.getKey(), experiment.getType(), validExperimentTypes));
}
}
for (Group group : groups) {
for (Experiment experiment : group.getExperiments()) {
if (experiment.getType() != null && !validExperimentTypes.contains(experiment.getType())) {
throw new IOException(
String.format("Experiment \"%s\" has invalid type \"%s\". Valid types: %s.",
experiment.getKey(), experiment.getType(), validExperimentTypes));
}
}
}

return new DatafileProjectConfig(
accountId,
anonymizeIP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,6 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
String regionString = rootObject.getString("region");
}

// Validate experiment types
Set<String> validExperimentTypes = new HashSet<>(Arrays.asList(
Experiment.TYPE_AB, Experiment.TYPE_MAB, Experiment.TYPE_CMAB,
Experiment.TYPE_TD, Experiment.TYPE_FR
));
for (Experiment experiment : experiments) {
if (experiment.getType() != null && !validExperimentTypes.contains(experiment.getType())) {
throw new ConfigParseException(
String.format("Experiment \"%s\" has invalid type \"%s\". Valid types: %s.",
experiment.getKey(), experiment.getType(), validExperimentTypes));
}
}
for (Group group : groups) {
for (Experiment experiment : group.getExperiments()) {
if (experiment.getType() != null && !validExperimentTypes.contains(experiment.getType())) {
throw new ConfigParseException(
String.format("Experiment \"%s\" has invalid type \"%s\". Valid types: %s.",
experiment.getKey(), experiment.getType(), validExperimentTypes));
}
}
}

return new DatafileProjectConfig(
accountId,
anonymizeIP,
Expand All @@ -149,8 +127,6 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
rollouts,
integrations
);
} catch (ConfigParseException e) {
throw e;
} catch (RuntimeException e) {
throw new ConfigParseException("Unable to parse datafile: " + json, e);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,6 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
String regionString = (String) rootObject.get("region");
}

// Validate experiment types
Set<String> validExperimentTypes = new HashSet<>(Arrays.asList(
Experiment.TYPE_AB, Experiment.TYPE_MAB, Experiment.TYPE_CMAB,
Experiment.TYPE_TD, Experiment.TYPE_FR
));
for (Experiment experiment : experiments) {
if (experiment.getType() != null && !validExperimentTypes.contains(experiment.getType())) {
throw new ConfigParseException(
String.format("Experiment \"%s\" has invalid type \"%s\". Valid types: %s.",
experiment.getKey(), experiment.getType(), validExperimentTypes));
}
}
for (Group group : groups) {
for (Experiment experiment : group.getExperiments()) {
if (experiment.getType() != null && !validExperimentTypes.contains(experiment.getType())) {
throw new ConfigParseException(
String.format("Experiment \"%s\" has invalid type \"%s\". Valid types: %s.",
experiment.getKey(), experiment.getType(), validExperimentTypes));
}
}
}

return new DatafileProjectConfig(
accountId,
anonymizeIP,
Expand All @@ -152,8 +130,6 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
rollouts,
integrations
);
} catch (ConfigParseException e) {
throw e;
} catch (RuntimeException ex) {
throw new ConfigParseException("Unable to parse datafile: " + json, ex);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,22 @@ public void featureRolloutWithEmptyRolloutIdDoesNotCrash() {
}

/**
* Test 6: Type field parsed - experiments with type field in the datafile
* Test 6: Unknown type accepted - experiment with type "new_unknown_type"
* does NOT cause error or rejection, and config parsing succeeds.
*/
@Test
public void unknownExperimentTypeAccepted() {
Experiment experiment = projectConfig.getExperimentKeyMapping().get("unknown_type_experiment");
assertNotNull("Experiment with unknown type should be parsed successfully", experiment);
assertEquals("new_unknown_type", experiment.getType());
assertEquals("exp_unknown_type", experiment.getId());
assertEquals("unknown_type_experiment", experiment.getKey());
assertEquals(1, experiment.getVariations().size());
assertEquals("unknown_variation", experiment.getVariations().get(0).getKey());
}

/**
* Test 7: Type field parsed - experiments with type field in the datafile
* have the value correctly preserved after config parsing.
*/
@Test
Expand Down
22 changes: 22 additions & 0 deletions core-api/src/test/resources/config/feature-rollout-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@
"endOfRange": 5000
}
]
},
{
"id": "exp_unknown_type",
"key": "unknown_type_experiment",
"status": "Running",
"layerId": "layer_5",
"audienceIds": [],
"forcedVariations": {},
"type": "new_unknown_type",
"variations": [
{
"id": "var_unknown_1",
"key": "unknown_variation",
"featureEnabled": true
}
],
"trafficAllocation": [
{
"entityId": "var_unknown_1",
"endOfRange": 10000
}
]
}
],
"featureFlags": [
Expand Down
Loading