|
28 | 28 | import org.apache.commons.lang3.RandomStringUtils; |
29 | 29 | import org.junit.Assert; |
30 | 30 | import org.junit.Test; |
| 31 | +import org.junit.rules.ExpectedException; |
31 | 32 | import org.mockito.ArgumentCaptor; |
32 | 33 | import org.mockito.Mockito; |
33 | 34 |
|
@@ -234,9 +235,10 @@ public void worksAndHasConfig() { |
234 | 235 |
|
235 | 236 | int numKeys = 5; |
236 | 237 | for (int i = 0; i < numKeys; i++) { |
| 238 | + Map<String, Object> attributes = new HashMap<>(); |
237 | 239 | String randomKey = RandomStringUtils.random(10); |
238 | 240 | assertThat(client.getTreatment(randomKey, test), is(equalTo("on"))); |
239 | | - assertThat(client.getTreatmentWithConfig(randomKey, test).config(), is(equalTo(configurations.get("on")))); |
| 241 | + assertThat(client.getTreatmentWithConfig(randomKey, test, attributes).config(), is(equalTo(configurations.get("on")))); |
240 | 242 | } |
241 | 243 |
|
242 | 244 | // Times 2 because we are calling getTreatment twice. Once for getTreatment and one for getTreatmentWithConfig |
@@ -972,7 +974,7 @@ public void track_with_valid_parameters() { |
972 | 974 |
|
973 | 975 | String validEventSize = new String(new char[80]).replace('\0', 'a'); |
974 | 976 | String validKeySize = new String(new char[250]).replace('\0', 'a'); |
975 | | - Assert.assertThat(client.track(validKeySize, "valid_traffic_type", validEventSize), |
| 977 | + Assert.assertThat(client.track(validKeySize, "valid_traffic_type", validEventSize, 10), |
976 | 978 | org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(true))); |
977 | 979 |
|
978 | 980 | } |
@@ -1286,4 +1288,72 @@ public void client_cannot_perform_actions_when_destroyed() throws InterruptedExc |
1286 | 1288 | Assert.assertThat(client.track("validKey", "valid_traffic_type", "valid_event"), |
1287 | 1289 | org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false))); |
1288 | 1290 | } |
| 1291 | + |
| 1292 | + @Test |
| 1293 | + public void worksAndHasConfigTryKetTreatmentWithKey() { |
| 1294 | + String test = "test1"; |
| 1295 | + |
| 1296 | + ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100))); |
| 1297 | + List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone); |
| 1298 | + |
| 1299 | + // Add config for only one treatment |
| 1300 | + Map<String, String> configurations = new HashMap<>(); |
| 1301 | + configurations.put(Treatments.ON, "{\"size\" : 30}"); |
| 1302 | + |
| 1303 | + ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1, configurations); |
| 1304 | + |
| 1305 | + SDKReadinessGates gates = mock(SDKReadinessGates.class); |
| 1306 | + SplitCache splitCache = mock(InMemoryCacheImp.class); |
| 1307 | + when(splitCache.get(test)).thenReturn(parsedSplit); |
| 1308 | + |
| 1309 | + SplitClientImpl client = new SplitClientImpl( |
| 1310 | + mock(SplitFactory.class), |
| 1311 | + splitCache, |
| 1312 | + new ImpressionsManager.NoOpImpressionsManager(), |
| 1313 | + new Metrics.NoopMetrics(), |
| 1314 | + NoopEventClient.create(), |
| 1315 | + config, |
| 1316 | + gates, |
| 1317 | + new EvaluatorImp(splitCache) |
| 1318 | + ); |
| 1319 | + |
| 1320 | + int numKeys = 5; |
| 1321 | + for (int i = 0; i < numKeys; i++) { |
| 1322 | + Map<String, Object> attributes = new HashMap<>(); |
| 1323 | + String randomKey = RandomStringUtils.random(10); |
| 1324 | + Key key = new Key(randomKey, "BucketingKey"); |
| 1325 | + assertThat(client.getTreatment(randomKey, test), is(equalTo("on"))); |
| 1326 | + assertThat(client.getTreatmentWithConfig(key, test, attributes).config(), is(equalTo(configurations.get("on")))); |
| 1327 | + } |
| 1328 | + |
| 1329 | + // Times 2 because we are calling getTreatment twice. Once for getTreatment and one for getTreatmentWithConfig |
| 1330 | + verify(splitCache, times(numKeys * 2)).get(test); |
| 1331 | + } |
| 1332 | + |
| 1333 | + @Test(expected = IllegalArgumentException.class) |
| 1334 | + public void blockUntilReadyException() throws TimeoutException, InterruptedException { |
| 1335 | + String test = "test1"; |
| 1336 | + |
| 1337 | + ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100))); |
| 1338 | + List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone); |
| 1339 | + ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1); |
| 1340 | + |
| 1341 | + SDKReadinessGates gates = mock(SDKReadinessGates.class); |
| 1342 | + SplitCache splitCache = mock(InMemoryCacheImp.class); |
| 1343 | + when(splitCache.get(test)).thenReturn(parsedSplit); |
| 1344 | + |
| 1345 | + SplitClientConfig config = SplitClientConfig.builder().setBlockUntilReadyTimeout(-100).build(); |
| 1346 | + SplitClientImpl client = new SplitClientImpl( |
| 1347 | + mock(SplitFactory.class), |
| 1348 | + splitCache, |
| 1349 | + new ImpressionsManager.NoOpImpressionsManager(), |
| 1350 | + new Metrics.NoopMetrics(), |
| 1351 | + NoopEventClient.create(), |
| 1352 | + config, |
| 1353 | + gates, |
| 1354 | + new EvaluatorImp(splitCache) |
| 1355 | + ); |
| 1356 | + |
| 1357 | + client.blockUntilReady(); |
| 1358 | + } |
1289 | 1359 | } |
0 commit comments