AudienceManager { @NonNull public List<TagGroupsMutation> getTagOverrides() { return getTagGroupOverrides(clock.currentTimeMillis() - getPreferLocalTagDataTime()); } AudienceManager(@NonNull AirshipRuntimeConfig runtimeConfig,
                           @NonNull AirshipChannel airshipChannel,
                           @NonNull NamedUser namedUser,
                           @NonNull PreferenceDataStore dataStore); @VisibleForTesting  AudienceManager(@NonNull TagGroupLookupApiClient client, @NonNull AirshipChannel airshipChannel,
                    @NonNull NamedUser namedUser, @NonNull AudienceHistorian historian,
                    @NonNull PreferenceDataStore dataStore, @NonNull Clock clock); void setEnabled(boolean enabled); boolean isEnabled(); void setCacheMaxAgeTime(@IntRange(from = 0) long duration, @NonNull TimeUnit unit); long getCacheMaxAgeTimeMilliseconds(); void setCacheStaleReadTime(@IntRange(from = MIN_CACHE_MAX_AGE_TIME_MS) long duration, @NonNull TimeUnit unit); long getCacheStaleReadTimeMilliseconds(); void setRequestTagsCallback(@Nullable RequestTagsCallback callback); long getPreferLocalTagDataTime(); void setPreferLocalTagDataTime(@IntRange(from = 0) long duration, @NonNull TimeUnit unit); @NonNull @WorkerThread synchronized TagGroupResult getTags(@NonNull Map<String, Set<String>> tags); @NonNull List<TagGroupsMutation> getTagOverrides(); @NonNull List<AttributeMutation> getAttributeOverrides(); static final long MIN_CACHE_MAX_AGE_TIME_MS; static final long DEFAULT_CACHE_MAX_AGE_TIME_MS; static final long DEFAULT_CACHE_STALE_READ_TIME_MS; static final long DEFAULT_PREFER_LOCAL_DATA_TIME_MS; }
@Test public void testGetTagOverrides() { clock.currentTimeMillis = System.currentTimeMillis(); when(mockNamedUser.getId()).thenReturn("named-user-id"); List<TagGroupsMutation> history = new ArrayList<>(); history.add(TagGroupsMutation.newRemoveTagsMutation("foo", tagSet("one", "two"))); history.add(TagGroupsMutation.newSetTagsMutation("bar", tagSet("a"))); history.add(TagGroupsMutation.newSetTagsMutation("baz", tagSet("1"))); when(mockHistorian.getTagGroupHistory(clock.currentTimeMillis - manager.getPreferLocalTagDataTime() )).thenReturn(history); pendingChannelMutations.add(TagGroupsMutation.newSetTagsMutation("baz", tagSet("2"))); pendingChannelMutations.add(TagGroupsMutation.newAddTagsMutation("bar", tagSet("b"))); pendingNamedUserMutations.add(TagGroupsMutation.newSetTagsMutation("baz", tagSet("3"))); pendingNamedUserMutations.add(TagGroupsMutation.newAddTagsMutation("foo", tagSet("one"))); List<TagGroupsMutation> expected = new ArrayList<>(); expected.addAll(history); expected.addAll(pendingNamedUserMutations); expected.addAll(pendingChannelMutations); assertEquals(TagGroupsMutation.collapseMutations(expected), manager.getTagOverrides()); }