Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Dec 10, 2024
1 parent ed204a7 commit a041c52
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class UserConsentModeNoneTest {
mKeysLatch?.await(10, TimeUnit.SECONDS)
mCountLatch?.await(10, TimeUnit.SECONDS)

Assert.assertTrue(mKeysPosted)
Assert.assertTrue(mCountPosted)
Assert.assertTrue(mKeysPosted)
}

@Test
Expand Down Expand Up @@ -207,6 +207,7 @@ class UserConsentModeNoneTest {
.impressionsRefreshRate(3)
.eventFlushInterval(3)
.mtkRefreshRate(3)
.enableDebug()
.userConsent(userConsent)
.build()

Expand All @@ -228,7 +229,7 @@ class UserConsentModeNoneTest {
return HttpStreamResponseMock(200, null)
}

override fun getResponse(uri: URI, method: HttpMethod, body: String): HttpResponseMock {
override fun getResponse(uri: URI, method: HttpMethod, body: String?): HttpResponseMock {
println(uri.path)
return if (uri.path.contains("/" + IntegrationHelper.ServicePath.MEMBERSHIPS)) {
HttpResponseMock(200, IntegrationHelper.emptyAllSegments())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.split.android.client.service.impressions;

import static io.split.android.client.utils.Utils.checkNotNull;

import androidx.core.util.Pair;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import io.split.android.client.impressions.Impression;
Expand All @@ -14,16 +18,18 @@ public class StrategyImpressionManager implements ImpressionManager, PeriodicTra
private final AtomicBoolean isTrackingEnabled = new AtomicBoolean(true);
private final ProcessStrategy mProcessStrategy;
private final ProcessStrategy mNoneStrategy;
private final PeriodicTracker[] mPeriodicTracker;
private final Set<PeriodicTracker> mPeriodicTrackers;

public StrategyImpressionManager(Pair<ProcessStrategy, PeriodicTracker> noneComponents, Pair<ProcessStrategy, PeriodicTracker> strategy) {
this(noneComponents.first, noneComponents.second, strategy.first, strategy.second);
}

StrategyImpressionManager(ProcessStrategy noneStrategy, PeriodicTracker noneTracker, ProcessStrategy strategy, PeriodicTracker strategyTracker) {
mProcessStrategy = strategy;
mNoneStrategy = noneStrategy;
mPeriodicTracker = new PeriodicTracker[]{noneTracker, strategyTracker};
mProcessStrategy = checkNotNull(strategy);
mNoneStrategy = checkNotNull(noneStrategy);
mPeriodicTrackers = new HashSet<>();
mPeriodicTrackers.add(noneTracker);
mPeriodicTrackers.add(strategyTracker);
}

@Override
Expand All @@ -47,21 +53,21 @@ public void enableTracking(boolean enable) {

@Override
public void flush() {
for (PeriodicTracker tracker : mPeriodicTracker) {
for (PeriodicTracker tracker : mPeriodicTrackers) {
tracker.flush();
}
}

@Override
public void startPeriodicRecording() {
for (PeriodicTracker tracker : mPeriodicTracker) {
for (PeriodicTracker tracker : mPeriodicTrackers) {
tracker.startPeriodicRecording();
}
}

@Override
public void stopPeriodicRecording() {
for (PeriodicTracker tracker : mPeriodicTracker) {
for (PeriodicTracker tracker : mPeriodicTrackers) {
tracker.stopPeriodicRecording();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ImpressionStrategyProvider {
private final ImpressionStrategyConfig mImpressionStrategyConfig;
private final ImpressionsCounter mImpressionsCounter;
private final ImpressionManagerRetryTimerProviderImpl mImpressionManagerRetryTimerProvider;
private final NoneStrategy mNoneStrategy;
private final NoneTracker mNoneTracker;

public ImpressionStrategyProvider(SplitTaskExecutor splitTaskExecutor,
SplitStorageContainer storageContainer,
Expand All @@ -39,64 +41,15 @@ public ImpressionStrategyProvider(SplitTaskExecutor splitTaskExecutor,
mImpressionStrategyConfig = config;
mImpressionsCounter = new ImpressionsCounter(mImpressionStrategyConfig.getDedupeTimeIntervalInMs());
mImpressionManagerRetryTimerProvider = new ImpressionManagerRetryTimerProviderImpl(mSplitTaskExecutor);
}

public Pair<ProcessStrategy, PeriodicTracker> getStrategy(ImpressionsMode mode) {
ImpressionsObserverImpl impressionsObserver = new ImpressionsObserverImpl(mStorageContainer.getImpressionsObserverCachePersistentStorage(), ServiceConstants.LAST_SEEN_IMPRESSION_CACHE_SIZE);
RecorderSyncHelperImpl<KeyImpression> impressionsSyncHelper = new RecorderSyncHelperImpl<>(
SplitTaskType.IMPRESSIONS_RECORDER,
mStorageContainer.getImpressionsStorage(),
mImpressionStrategyConfig.getImpressionsQueueSize(),
mImpressionStrategyConfig.getImpressionsChunkSize(),
mSplitTaskExecutor);
if (mode == ImpressionsMode.DEBUG) {
DebugTracker tracker = new DebugTracker(
impressionsObserver,
impressionsSyncHelper,
mSplitTaskExecutor,
mSplitTaskFactory,
mImpressionManagerRetryTimerProvider.getImpressionsTimer(),
mImpressionStrategyConfig.getImpressionsRefreshRate());
DebugStrategy debugStrategy = new DebugStrategy(
impressionsObserver,
impressionsSyncHelper,
mSplitTaskExecutor,
mSplitTaskFactory,
mTelemetryStorage);
return new Pair<>(debugStrategy, tracker);
} else if (mode == ImpressionsMode.NONE) {
return new Pair<>(null, null);
} else {
OptimizedStrategy optimizedStrategy = new OptimizedStrategy(
impressionsObserver,
mImpressionsCounter,
impressionsSyncHelper,
mSplitTaskExecutor,
mSplitTaskFactory,
mTelemetryStorage,
mImpressionStrategyConfig.getDedupeTimeIntervalInMs());
OptimizedTracker optimizedTracker = new OptimizedTracker(
impressionsObserver,
impressionsSyncHelper,
mSplitTaskExecutor,
mSplitTaskFactory,
mImpressionManagerRetryTimerProvider.getImpressionsTimer(),
mImpressionStrategyConfig.getImpressionsRefreshRate(),
mImpressionStrategyConfig.isUserConsentGranted()
);
return new Pair<>(optimizedStrategy, optimizedTracker);
}
}

public Pair<ProcessStrategy, PeriodicTracker> getNoneComponents() {
UniqueKeysTracker uniqueKeysTracker = new UniqueKeysTrackerImpl();
NoneStrategy noneStrategy = new NoneStrategy(
mNoneStrategy = new NoneStrategy(
mSplitTaskExecutor,
mSplitTaskFactory,
mImpressionsCounter,
uniqueKeysTracker,
mImpressionStrategyConfig.isUserConsentGranted());
NoneTracker noneTracker = new NoneTracker(
mNoneTracker = new NoneTracker(
mSplitTaskExecutor,
mSplitTaskFactory,
mImpressionsCounter,
Expand All @@ -106,6 +59,57 @@ public Pair<ProcessStrategy, PeriodicTracker> getNoneComponents() {
mImpressionStrategyConfig.getImpressionsCounterRefreshRate(),
mImpressionStrategyConfig.getUniqueKeysRefreshRate(),
mImpressionStrategyConfig.isUserConsentGranted());
return new Pair<>(noneStrategy, noneTracker);
}

public Pair<ProcessStrategy, PeriodicTracker> getStrategy(ImpressionsMode mode) {
ImpressionsObserverImpl impressionsObserver = new ImpressionsObserverImpl(mStorageContainer.getImpressionsObserverCachePersistentStorage(), ServiceConstants.LAST_SEEN_IMPRESSION_CACHE_SIZE);
RecorderSyncHelperImpl<KeyImpression> impressionsSyncHelper = new RecorderSyncHelperImpl<>(
SplitTaskType.IMPRESSIONS_RECORDER,
mStorageContainer.getImpressionsStorage(),
mImpressionStrategyConfig.getImpressionsQueueSize(),
mImpressionStrategyConfig.getImpressionsChunkSize(),
mSplitTaskExecutor);
switch (mode) {
case DEBUG:
DebugTracker tracker = new DebugTracker(
impressionsObserver,
impressionsSyncHelper,
mSplitTaskExecutor,
mSplitTaskFactory,
mImpressionManagerRetryTimerProvider.getImpressionsTimer(),
mImpressionStrategyConfig.getImpressionsRefreshRate());
DebugStrategy debugStrategy = new DebugStrategy(
impressionsObserver,
impressionsSyncHelper,
mSplitTaskExecutor,
mSplitTaskFactory,
mTelemetryStorage);
return new Pair<>(debugStrategy, tracker);
case NONE:
return getNoneComponents();
default:
OptimizedStrategy optimizedStrategy = new OptimizedStrategy(
impressionsObserver,
mImpressionsCounter,
impressionsSyncHelper,
mSplitTaskExecutor,
mSplitTaskFactory,
mTelemetryStorage,
mImpressionStrategyConfig.getDedupeTimeIntervalInMs());
OptimizedTracker optimizedTracker = new OptimizedTracker(
impressionsObserver,
impressionsSyncHelper,
mSplitTaskExecutor,
mSplitTaskFactory,
mImpressionManagerRetryTimerProvider.getImpressionsTimer(),
mImpressionStrategyConfig.getImpressionsRefreshRate(),
mImpressionStrategyConfig.isUserConsentGranted()
);
return new Pair<>(optimizedStrategy, optimizedTracker);
}
}

public Pair<ProcessStrategy, PeriodicTracker> getNoneComponents() {
return new Pair<>(mNoneStrategy, mNoneTracker);
}
}

0 comments on commit a041c52

Please sign in to comment.