Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ apply plugin: 'kotlin-android'
apply from: 'spec.gradle'

ext {
splitVersion = '5.1.1'
splitVersion = '5.1.2-rc1'
}

android {
compileSdk 33
targetCompatibility = '1.8'
sourceCompatibility = '1.8'

buildFeatures {
buildConfig true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ private static String[] getDbList(Context context) {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return Arrays.stream(context.databaseList()).filter(db -> !db.endsWith("-journal")).toArray(String[]::new);
return Arrays.stream(context.databaseList())
.filter(db -> !db.endsWith("-journal") && !db.endsWith("-wal") && !db.endsWith("-shm"))
.toArray(String[]::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ private void test(long timestampDaysAgo, RolloutCacheConfiguration.Builder confi

private void verify(SplitFactory factory, CountDownLatch readyLatch, List<SplitEntity> initialFlags, List<MySegmentEntity> initialSegments, List<MyLargeSegmentEntity> initialLargeSegments, long initialChangeNumber) throws InterruptedException {
// Track final values
Thread.sleep(10000);

List<SplitEntity> finalFlags = mRoomDb.splitDao().getAll();
List<MySegmentEntity> finalSegments = mRoomDb.mySegmentDao().getAll();
List<MyLargeSegmentEntity> finalLargeSegments = mRoomDb.myLargeSegmentDao().getAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void testCleanUp() throws IOException, InterruptedException {
mClient.on(SplitEvent.SDK_READY, readyTask);

latch.await(40, TimeUnit.SECONDS);
Thread.sleep(1000);
Thread.sleep(8000);

// Load all records again after cleanup
List<UniqueKeyEntity> remainingKeys = mUniqueKeysDao.getBy(0, StorageRecordStatus.ACTIVE, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import helper.DatabaseHelper;
import io.split.android.client.dtos.Split;
Expand All @@ -32,6 +33,8 @@ public class PersistentSplitsStorageTest {
SplitRoomDatabase mRoomDb;
Context mContext;
PersistentSplitsStorage mPersistentSplitsStorage;
private final Map<String, Set<String>> mFlagSets = new HashMap<>();
private final Map<String, Integer> mTrafficTypes = new HashMap<>();

@Before
public void setUp() {
Expand Down Expand Up @@ -94,7 +97,7 @@ public void addSplits() {
split.status = Status.ACTIVE;
splits.add(split);
}
mPersistentSplitsStorage.update(new ProcessedSplitChange(splits, new ArrayList<>(), 1L, 0L));
mPersistentSplitsStorage.update(new ProcessedSplitChange(splits, new ArrayList<>(), 1L, 0L), mTrafficTypes, mFlagSets);

SplitsSnapshot snapshot = mPersistentSplitsStorage.getSnapshot();
Map<String, Split> splitMap = listToMap(snapshot.getSplits());
Expand All @@ -114,7 +117,7 @@ public void addSplits() {
@Test
public void updateEmptySplit() {
List<Split> splits = new ArrayList<>();
mPersistentSplitsStorage.update(new ProcessedSplitChange(splits, splits, 1L, 0L));
mPersistentSplitsStorage.update(new ProcessedSplitChange(splits, splits, 1L, 0L), mTrafficTypes, mFlagSets);

SplitsSnapshot snapshot = mPersistentSplitsStorage.getSnapshot();
Map<String, Split> splitMap = listToMap(snapshot.getSplits());
Expand All @@ -134,7 +137,7 @@ public void updateEmptySplit() {
@Test
public void addNullSplitList() {
List<Split> splits = new ArrayList<>();
boolean res = mPersistentSplitsStorage.update(new ProcessedSplitChange(null, splits,1L, 0L));
boolean res = mPersistentSplitsStorage.update(new ProcessedSplitChange(null, splits,1L, 0L), mTrafficTypes, mFlagSets);

SplitsSnapshot snapshot = mPersistentSplitsStorage.getSnapshot();
Map<String, Split> splitMap = listToMap(snapshot.getSplits());
Expand All @@ -155,7 +158,7 @@ public void addNullSplitList() {
@Test
public void deleteNullSplitList() {
List<Split> splits = new ArrayList<>();
boolean res = mPersistentSplitsStorage.update(new ProcessedSplitChange(splits, null,1L, 0L));
boolean res = mPersistentSplitsStorage.update(new ProcessedSplitChange(splits, null,1L, 0L), mTrafficTypes, mFlagSets);

SplitsSnapshot snapshot = mPersistentSplitsStorage.getSnapshot();
Map<String, Split> splitMap = listToMap(snapshot.getSplits());
Expand Down Expand Up @@ -183,7 +186,7 @@ public void deleteSplits() {
split.status = Status.ARCHIVED;
splits.add(split);
}
mPersistentSplitsStorage.update(new ProcessedSplitChange(null, splits, 1L, 0L));
mPersistentSplitsStorage.update(new ProcessedSplitChange(null, splits, 1L, 0L), mTrafficTypes, mFlagSets);

SplitsSnapshot snapshot = mPersistentSplitsStorage.getSnapshot();
Map<String, Split> splitMap = listToMap(snapshot.getSplits());
Expand Down Expand Up @@ -220,7 +223,7 @@ public void deleteAllSplits() {
split.status = Status.ARCHIVED;
splits.add(split);
}
mPersistentSplitsStorage.update(new ProcessedSplitChange(null, splits, 1L, 0L));
mPersistentSplitsStorage.update(new ProcessedSplitChange(null, splits, 1L, 0L), mTrafficTypes, mFlagSets);

SplitsSnapshot snapshot = mPersistentSplitsStorage.getSnapshot();
List<Split> loadedSlits = snapshot.getSplits();
Expand Down
32 changes: 32 additions & 0 deletions src/androidTest/java/tests/storage/SplitsStorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -35,6 +36,7 @@
import io.split.android.client.storage.splits.SplitsStorage;
import io.split.android.client.storage.splits.SplitsStorageImpl;
import io.split.android.client.storage.splits.SqLitePersistentSplitsStorage;
import io.split.android.client.utils.Json;

public class SplitsStorageTest {

Expand Down Expand Up @@ -334,6 +336,11 @@ public void trafficTypesAreLoadedInMemoryWhenLoadingLocalSplits() {
mRoomDb.clearAllTables();
mRoomDb.splitDao().insert(Arrays.asList(newSplitEntity("split_test", "test_type"), newSplitEntity("split_test_2", "test_type_2")));

Map<String, Integer> trafficTypes = new HashMap<>();
trafficTypes.put("test_type", 1);
trafficTypes.put("test_type_2", 1);
mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.TRAFFIC_TYPES_MAP, Json.toJson(trafficTypes)));

mSplitsStorage.loadLocal();

assertTrue(mSplitsStorage.isValidTrafficType("test_type"));
Expand All @@ -346,6 +353,11 @@ public void loadedFromStorageTrafficTypesAreCorrectlyUpdated() {
mRoomDb.clearAllTables();
mRoomDb.splitDao().insert(Arrays.asList(newSplitEntity("split_test", "test_type"), newSplitEntity("split_test_2", "test_type_2")));

Map<String, Integer> trafficTypes = new HashMap<>();
trafficTypes.put("test_type", 1);
trafficTypes.put("test_type_2", 1);
mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.TRAFFIC_TYPES_MAP, Json.toJson(trafficTypes)));

mSplitsStorage.loadLocal();

Split updatedSplit = newSplit("split_test", Status.ACTIVE, "new_type");
Expand All @@ -365,6 +377,12 @@ public void flagSetsAreUpdatedWhenCallingLoadLocal() {
newSplitEntity("split_test_3", "test_type_2", Collections.singleton("set_2")),
newSplitEntity("split_test_4", "test_type_2", Collections.singleton("set_1"))));

Map<String, Set<String>> flagSets = new HashMap<>();
flagSets.put("set_1", new HashSet<>(Arrays.asList("split_test", "split_test_4")));
flagSets.put("set_2", new HashSet<>(Arrays.asList("split_test_2", "split_test_3")));

mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.FLAG_SETS_MAP, Json.toJson(flagSets)));

mSplitsStorage.loadLocal();

Assert.assertEquals(new HashSet<>(Arrays.asList("split_test", "split_test_4")), mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1")));
Expand All @@ -378,6 +396,13 @@ public void flagSetsAreRemovedWhenUpdating() {
newSplitEntity("split_test", "test_type", Collections.singleton("set_1")),
newSplitEntity("split_test_2", "test_type_2", Collections.singleton("set_2")),
newSplitEntity("split_test_3", "test_type_2", Collections.singleton("set_2"))));

Map<String, Set<String>> flagSets = new HashMap<>();
flagSets.put("set_1", new HashSet<>(Arrays.asList("split_test")));
flagSets.put("set_2", new HashSet<>(Arrays.asList("split_test_2", "split_test_3")));

mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.FLAG_SETS_MAP, Json.toJson(flagSets)));

mSplitsStorage.loadLocal();

Set<String> initialSet1 = mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"));
Expand All @@ -396,6 +421,13 @@ public void flagSetsAreRemovedWhenUpdating() {
public void updateWithoutChecksRemovesFromFlagSet() {
mRoomDb.clearAllTables();
mRoomDb.splitDao().insert(Arrays.asList(newSplitEntity("split_test", "test_type", Collections.singleton("set_1")), newSplitEntity("split_test_2", "test_type_2", Collections.singleton("set_2"))));

Map<String, Set<String>> flagSets = new HashMap<>();
flagSets.put("set_1", new HashSet<>(Arrays.asList("split_test")));
flagSets.put("set_2", new HashSet<>(Arrays.asList("split_test_2")));

mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.FLAG_SETS_MAP, Json.toJson(flagSets)));

mSplitsStorage.loadLocal();

Set<String> initialSet1 = mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class SplitClientFactoryImpl implements SplitClientFactory {
private final TreatmentManagerFactory mTreatmentManagerFactory;
private final ImpressionListener.FederatedImpressionListener mCustomerImpressionListener;
private final SplitValidatorImpl mSplitValidator;
private final EventsTracker mEventsTracker;
private final SplitFactoryImpl.EventsTrackerProvider mEventsTrackerProvider;

public SplitClientFactoryImpl(@NonNull SplitFactory splitFactory,
@NonNull SplitClientContainer clientContainer,
Expand All @@ -56,7 +56,7 @@ public SplitClientFactoryImpl(@NonNull SplitFactory splitFactory,
@NonNull SplitTaskExecutor splitTaskExecutor,
@NonNull ValidationMessageLogger validationLogger,
@NonNull KeyValidator keyValidator,
@NonNull EventsTracker eventsTracker,
@NonNull SplitFactoryImpl.EventsTrackerProvider eventsTrackerProvider,
@NonNull ImpressionListener.FederatedImpressionListener customerImpressionListener,
@Nullable FlagSetsFilter flagSetsFilter) {
mSplitFactory = checkNotNull(splitFactory);
Expand All @@ -67,7 +67,7 @@ public SplitClientFactoryImpl(@NonNull SplitFactory splitFactory,
mStorageContainer = checkNotNull(storageContainer);
mTelemetrySynchronizer = checkNotNull(telemetrySynchronizer);
mCustomerImpressionListener = checkNotNull(customerImpressionListener);
mEventsTracker = checkNotNull(eventsTracker);
mEventsTrackerProvider = checkNotNull(eventsTrackerProvider);

mAttributesManagerFactory = getAttributesManagerFactory(config.persistentAttributesEnabled(),
validationLogger,
Expand Down Expand Up @@ -106,7 +106,7 @@ public SplitClient getClient(@NonNull Key key,
mCustomerImpressionListener,
mConfig,
eventsManager,
mEventsTracker,
mEventsTrackerProvider.getEventsTracker(),
mAttributesManagerFactory.getManager(key.matchingKey(), attributesStorage),
mSplitValidator,
mTreatmentManagerFactory.getTreatmentManager(key,
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/io/split/android/client/SplitFactoryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class SplitFactoryHelper {
private static final int DB_MAGIC_CHARS_COUNT = 4;

String getDatabaseName(SplitClientConfig config, String apiToken, Context context) {

String dbName = buildDatabaseName(config, apiToken);
File dbPath = context.getDatabasePath(dbName);
if (dbPath.exists()) {
Expand Down Expand Up @@ -162,15 +161,16 @@ SplitStorageContainer buildStorageContainer(UserConsent userConsentStatus,
SplitCipher splitCipher,
TelemetryStorage telemetryStorage,
long observerCacheExpirationPeriod,
ScheduledThreadPoolExecutor impressionsObserverExecutor) {
ScheduledThreadPoolExecutor impressionsObserverExecutor,
SplitsStorage splitsStorage) {

boolean isPersistenceEnabled = userConsentStatus == UserConsent.GRANTED;
PersistentEventsStorage persistentEventsStorage =
StorageFactory.getPersistentEventsStorage(splitRoomDatabase, splitCipher);
PersistentImpressionsStorage persistentImpressionsStorage =
StorageFactory.getPersistentImpressionsStorage(splitRoomDatabase, splitCipher);
return new SplitStorageContainer(
StorageFactory.getSplitsStorage(splitRoomDatabase, splitCipher),
splitsStorage,
StorageFactory.getMySegmentsStorage(splitRoomDatabase, splitCipher),
StorageFactory.getMyLargeSegmentsStorage(splitRoomDatabase, splitCipher),
StorageFactory.getPersistentSplitsStorage(splitRoomDatabase, splitCipher),
Expand Down Expand Up @@ -504,7 +504,6 @@ static class Initializer implements Runnable {

this(new RolloutCacheManagerImpl(config,
storageContainer,
splitTaskFactory.createCleanUpDatabaseTask(System.currentTimeMillis() / 1000),
splitTaskFactory.createEncryptionMigrationTask(apiToken, splitDatabase, config.encryptionEnabled(), splitCipher)),
new Listener(eventsManagerCoordinator, splitTaskExecutor, splitSingleThreadTaskExecutor, syncManager, lifecycleManager, initLock),
initLock);
Expand Down Expand Up @@ -550,13 +549,13 @@ static class Listener implements SplitTaskExecutionListener {
@Override
public void taskExecuted(@NonNull SplitTaskExecutionInfo taskInfo) {
try {
mEventsManagerCoordinator.notifyInternalEvent(SplitInternalEvent.ENCRYPTION_MIGRATION_DONE);

mSplitTaskExecutor.resume();
mSplitSingleThreadTaskExecutor.resume();
mEventsManagerCoordinator.notifyInternalEvent(SplitInternalEvent.ENCRYPTION_MIGRATION_DONE);

mSyncManager.start();
mLifecycleManager.register(mSyncManager);

Logger.i("Android SDK initialized!");
} catch (Exception e) {
Logger.e("Error initializing Android SDK", e);
Expand Down
Loading
Loading