Skip to content

Commit

Permalink
test: add additional test for dist 100.
Browse files Browse the repository at this point in the history
  • Loading branch information
credmond-git committed Nov 17, 2024
1 parent b48fb58 commit ca3c5b5
Showing 1 changed file with 65 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void testSubstitution() throws GestaltException {

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

Expand All @@ -40,8 +40,8 @@ public void testRunTimeSubstitution() throws GestaltException {

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

Expand All @@ -59,8 +59,8 @@ public void testRunTimeSubstitutionMultiRun() throws GestaltException {

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

Expand All @@ -82,8 +82,8 @@ public void testNestedSubstitution() throws GestaltException {

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

Expand All @@ -102,8 +102,8 @@ public void testNestedRunTimeSubstitution() throws GestaltException {

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

Expand All @@ -121,8 +121,8 @@ public void testEscapedSubstitution() throws GestaltException {

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

Expand All @@ -140,8 +140,8 @@ public void testEscapedRunTimeSubstitution() throws GestaltException {

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

Expand All @@ -160,8 +160,8 @@ public void testMixedNestedSubstitution() throws GestaltException {

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

Expand All @@ -186,10 +186,58 @@ public void testDist100RunTimeSubstitution() throws GestaltException {

boolean different = false;
int passes = 10;
while(!different && passes-- > 0) {
while (!different && passes-- > 0) {
String message2 = gestalt.getConfig("message", TypeCapture.of(String.class));

different = !message2.equals(message1);
}
}

@Test
public void testRedistributions() throws GestaltException {
Map<String, String> customMap = new HashMap<>();
// we want 10% of traffic to be true
customMap.put("color", "#{dist100:10:red,30:green,70:blue,75:pink,yellow}");


GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(customMap).build())
.build();

gestalt.loadConfigs();

int red = 0;
int green = 0;
int blue = 0;
int yellow = 0;
int pink = 0;
int passes = 1000;
while (passes-- > 0) {
String color = gestalt.getConfig("color", TypeCapture.of(String.class));

if ("red".equals(color)) {
red++;
} else if ("green".equals(color)) {
green++;
} else if ("blue".equals(color)) {
blue++;
} else if ("pink".equals(color)) {
pink++;
} else if ("yellow".equals(color)) {
yellow++;
}
}
red = red / 10;
green = green / 10;
blue = blue / 10;
yellow = yellow / 10;
pink = pink / 10;

Assertions.assertTrue(red > 5 && red < 15);
Assertions.assertTrue(green > 15 && green < 25);
Assertions.assertTrue(blue > 35 && blue < 45);
Assertions.assertTrue(pink > 3 && pink < 7);
Assertions.assertTrue(yellow > 20 && yellow < 30);
}
}

0 comments on commit ca3c5b5

Please sign in to comment.