|
20 | 20 | import com.google.common.base.Charsets;
|
21 | 21 | import com.google.common.io.Resources;
|
22 | 22 | import com.optimizely.ab.bucketing.FeatureDecision;
|
| 23 | +import com.optimizely.ab.bucketing.UserProfile; |
23 | 24 | import com.optimizely.ab.bucketing.UserProfileService;
|
| 25 | +import com.optimizely.ab.bucketing.UserProfileUtils; |
24 | 26 | import com.optimizely.ab.config.*;
|
25 | 27 | import com.optimizely.ab.config.parser.ConfigParseException;
|
26 | 28 | import com.optimizely.ab.event.EventHandler;
|
@@ -369,7 +371,7 @@ public void decideAll_allFlags() {
|
369 | 371 |
|
370 | 372 | OptimizelyUserContext user = optimizely.createUserContext(userId, attributes);
|
371 | 373 | Map<String, OptimizelyDecision> decisions = user.decideAll();
|
372 |
| - assertTrue(decisions.size() == 3); |
| 374 | + assertEquals(decisions.size(), 3); |
373 | 375 |
|
374 | 376 | assertEquals(
|
375 | 377 | decisions.get(flagKey1),
|
@@ -421,6 +423,39 @@ public void decideAll_allFlags() {
|
421 | 423 | assertEquals(sentEvents.get(2).getUserContext().getUserId(), userId);
|
422 | 424 | }
|
423 | 425 |
|
| 426 | + @Test |
| 427 | + public void decideForKeys_ups_batching() throws Exception { |
| 428 | + UserProfileService ups = mock(UserProfileService.class); |
| 429 | + |
| 430 | + optimizely = new Optimizely.Builder() |
| 431 | + .withDatafile(datafile) |
| 432 | + .withUserProfileService(ups) |
| 433 | + .build(); |
| 434 | + |
| 435 | + String flagKey1 = "feature_1"; |
| 436 | + String flagKey2 = "feature_2"; |
| 437 | + String flagKey3 = "feature_3"; |
| 438 | + Map<String, Object> attributes = Collections.singletonMap("gender", "f"); |
| 439 | + |
| 440 | + OptimizelyUserContext user = optimizely.createUserContext(userId, attributes); |
| 441 | + Map<String, OptimizelyDecision> decisions = user.decideForKeys(Arrays.asList( |
| 442 | + flagKey1, flagKey2, flagKey3 |
| 443 | + )); |
| 444 | + |
| 445 | + assertEquals(decisions.size(), 3); |
| 446 | + |
| 447 | + ArgumentCaptor<Map> argumentCaptor = ArgumentCaptor.forClass(Map.class); |
| 448 | + |
| 449 | + |
| 450 | + verify(ups, times(1)).lookup(userId); |
| 451 | + verify(ups, times(1)).save(argumentCaptor.capture()); |
| 452 | + |
| 453 | + Map<String, Object> savedUps = argumentCaptor.getValue(); |
| 454 | + UserProfile savedProfile = UserProfileUtils.convertMapToUserProfile(savedUps); |
| 455 | + |
| 456 | + assertEquals(savedProfile.userId, userId); |
| 457 | + } |
| 458 | + |
424 | 459 | @Test
|
425 | 460 | public void decideAll_allFlags_enabledFlagsOnly() {
|
426 | 461 | String flagKey1 = "feature_1";
|
|
0 commit comments