Skip to content

Commit

Permalink
General info storage (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Nov 26, 2024
1 parent f39d3fc commit a5a56c9
Show file tree
Hide file tree
Showing 17 changed files with 402 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply plugin: 'kotlin-android'
apply from: 'spec.gradle'

ext {
splitVersion = '5.0.1'
splitVersion = '5.1.0-alpha.1'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public void firstRequestChangeNumber() throws Exception {
String apiKey = apiKeyAndDb.first;
SplitRoomDatabase splitRoomDatabase = DatabaseHelper.getTestDatabase(mContext);
splitRoomDatabase.clearAllTables();
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, INITIAL_CHANGE_NUMBER));
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.SPLITS_UPDATE_TIMESTAMP, System.currentTimeMillis()));

Expand Down
3 changes: 0 additions & 3 deletions src/androidTest/java/tests/integration/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public void testAll() throws Exception {

SplitRoomDatabase splitRoomDatabase = DatabaseHelper.getTestDatabase(mContext);
splitRoomDatabase.clearAllTables();
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, 2));
SplitClient client;
SplitManager manager;
Expand Down Expand Up @@ -249,7 +248,6 @@ public void testNoReadyFromCache() throws Exception {

SplitRoomDatabase splitRoomDatabase = DatabaseHelper.getTestDatabase(mContext);
splitRoomDatabase.clearAllTables();
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, -1));
SplitClient client;
SplitManager manager;
Expand Down Expand Up @@ -304,7 +302,6 @@ public void testGetTreatmentFromCache() throws Exception {
mContext = InstrumentationRegistry.getInstrumentation().getContext();
mRoomDb = DatabaseHelper.getTestDatabase(mContext);
mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, 10));
mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, 1));

SplitChange change = Json.fromJson(mJsonChanges.get(0), SplitChange.class);
List<SplitEntity> entities = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public void test() throws Exception {

SplitRoomDatabase splitRoomDatabase = DatabaseHelper.getTestDatabase(mContext);
splitRoomDatabase.clearAllTables();
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, -1));

ImpressionListenerHelper impListener = new ImpressionListenerHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public void testAll() throws Exception {
SplitRoomDatabase.class)
.build();
splitRoomDatabase.clearAllTables();
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, 2));
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.SPLITS_FILTER_QUERY_STRING, expectedQs));
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.SPLITS_UPDATE_TIMESTAMP, System.currentTimeMillis()));
Expand Down
3 changes: 0 additions & 3 deletions src/androidTest/java/tests/integration/TrackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.split.android.client.dtos.Event;
import io.split.android.client.events.SplitEvent;
import io.split.android.client.exceptions.SplitInstantiationException;
import io.split.android.client.storage.db.GeneralInfoEntity;
import io.split.android.client.storage.db.SplitRoomDatabase;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
Expand Down Expand Up @@ -120,7 +119,6 @@ public void test() throws Exception {
String apiKey = IntegrationHelper.dummyApiKey();
SplitRoomDatabase splitRoomDatabase = DatabaseHelper.getTestDatabase(mContext);
splitRoomDatabase.clearAllTables();
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));

ImpressionListenerHelper impListener = new ImpressionListenerHelper();

Expand Down Expand Up @@ -220,7 +218,6 @@ public void largeNumberInPropertiesTest() throws InterruptedException, SplitInst
String apiKey = IntegrationHelper.dummyApiKey();
SplitRoomDatabase splitRoomDatabase = DatabaseHelper.getTestDatabase(mContext);
splitRoomDatabase.clearAllTables();
splitRoomDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));

final String url = mWebServer.url("/").url().toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ private void insertSplitsFromFileIntoDB() {
return result;
}).collect(Collectors.toList());

mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));
mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, 1));

mRoomDb.splitDao().insert(entities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void setUp() {
}
insertSplitsIntoDb();
mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, 10));
mRoomDb.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, 1));

ServerMock mWebServer = new ServerMock(mJsonChanges);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ private void insertSplitsFromFileIntoDB() {
return result;
}).collect(Collectors.toList());

testDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.DATBASE_MIGRATION_STATUS, GeneralInfoEntity.DATBASE_MIGRATION_STATUS_DONE));
testDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, 1));
testDatabase.generalInfoDao().update(new GeneralInfoEntity(GeneralInfoEntity.SPLITS_UPDATE_TIMESTAMP, System.currentTimeMillis()));

Expand Down
92 changes: 92 additions & 0 deletions src/androidTest/java/tests/storage/GeneralInfoStorageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package tests.storage;

import static org.junit.Assert.assertEquals;

import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import helper.DatabaseHelper;
import io.split.android.client.storage.db.SplitRoomDatabase;
import io.split.android.client.storage.general.GeneralInfoStorage;
import io.split.android.client.storage.general.GeneralInfoStorageImpl;

public class GeneralInfoStorageTest {

private SplitRoomDatabase mDb;
private GeneralInfoStorage mGeneralInfoStorage;

@Before
public void setUp() {
mDb = DatabaseHelper.getTestDatabase(InstrumentationRegistry.getInstrumentation().getContext());
mGeneralInfoStorage = new GeneralInfoStorageImpl(mDb.generalInfoDao());
}

@After
public void tearDown() {
mDb.clearAllTables();
mDb.close();
}

@Test
public void setSplitsUpdateTimestamp() {
long initialValue = mGeneralInfoStorage.getSplitsUpdateTimestamp();
mGeneralInfoStorage.setSplitsUpdateTimestamp(100L);
long finalValue = mGeneralInfoStorage.getSplitsUpdateTimestamp();

assertEquals(0L, initialValue);
assertEquals(100L, finalValue);
}

@Test
public void setChangeNumber() {
long initialValue = mGeneralInfoStorage.getChangeNumber();
mGeneralInfoStorage.setChangeNumber(100L);
long finalValue = mGeneralInfoStorage.getChangeNumber();

assertEquals(-1L, initialValue);
assertEquals(100L, finalValue);
}

@Test
public void setSplitsFilterQueryString() {
String initialValue = mGeneralInfoStorage.getSplitsFilterQueryString();
mGeneralInfoStorage.setSplitsFilterQueryString("queryString");
String finalValue = mGeneralInfoStorage.getSplitsFilterQueryString();

assertEquals("", initialValue);
assertEquals("queryString", finalValue);
}

@Test
public void setDatabaseEncryptionMode() {
String initialValue = mGeneralInfoStorage.getDatabaseEncryptionMode();
mGeneralInfoStorage.setDatabaseEncryptionMode("MODE");
String finalValue = mGeneralInfoStorage.getDatabaseEncryptionMode();

assertEquals("", initialValue);
assertEquals("MODE", finalValue);
}

@Test
public void setFlagsSpec() {
String initialValue = mGeneralInfoStorage.getFlagsSpec();
mGeneralInfoStorage.setFlagsSpec("4.4");
String finalValue = mGeneralInfoStorage.getFlagsSpec();

assertEquals("", initialValue);
assertEquals("4.4", finalValue);
}

@Test
public void setRolloutCacheLastClearTimestamp() {
long initialValue = mGeneralInfoStorage.getRolloutCacheLastClearTimestamp();
mGeneralInfoStorage.setRolloutCacheLastClearTimestamp(100L);
long finalValue = mGeneralInfoStorage.getRolloutCacheLastClearTimestamp();

assertEquals(0L, initialValue);
assertEquals(100L, finalValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ SplitStorageContainer buildStorageContainer(UserConsent userConsentStatus,
StorageFactory.getAttributesStorage(),
StorageFactory.getPersistentAttributesStorage(splitRoomDatabase, splitCipher),
getTelemetryStorage(shouldRecordTelemetry, telemetryStorage),
StorageFactory.getImpressionsObserverCachePersistentStorage(splitRoomDatabase, observerCacheExpirationPeriod, impressionsObserverExecutor));
StorageFactory.getImpressionsObserverCachePersistentStorage(splitRoomDatabase, observerCacheExpirationPeriod, impressionsObserverExecutor),
StorageFactory.getGeneralInfoStorage(splitRoomDatabase));
}

SplitApiFacade buildApiFacade(SplitClientConfig splitClientConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.split.android.client.storage.common;

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

import androidx.annotation.NonNull;

import io.split.android.client.service.impressions.observer.PersistentImpressionsObserverCacheStorage;
Expand All @@ -8,6 +10,7 @@
import io.split.android.client.storage.attributes.PersistentAttributesStorage;
import io.split.android.client.storage.events.EventsStorage;
import io.split.android.client.storage.events.PersistentEventsStorage;
import io.split.android.client.storage.general.GeneralInfoStorage;
import io.split.android.client.storage.impressions.ImpressionsStorage;
import io.split.android.client.storage.impressions.PersistentImpressionsCountStorage;
import io.split.android.client.storage.impressions.PersistentImpressionsStorage;
Expand All @@ -18,8 +21,6 @@
import io.split.android.client.storage.splits.SplitsStorage;
import io.split.android.client.telemetry.storage.TelemetryStorage;

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

public class SplitStorageContainer {

private final SplitsStorage mSplitStorage;
Expand All @@ -36,6 +37,7 @@ public class SplitStorageContainer {
private final TelemetryStorage mTelemetryStorage;
private final PersistentImpressionsUniqueStorage mPersistentImpressionsUniqueStorage;
private final PersistentImpressionsObserverCacheStorage mPersistentImpressionsObserverCacheStorage;
private final GeneralInfoStorage mGeneralInfoStorage;

public SplitStorageContainer(@NonNull SplitsStorage splitStorage,
@NonNull MySegmentsStorageContainer mySegmentsStorageContainer,
Expand All @@ -50,7 +52,8 @@ public SplitStorageContainer(@NonNull SplitsStorage splitStorage,
@NonNull AttributesStorageContainer attributesStorageContainer,
@NonNull PersistentAttributesStorage persistentAttributesStorage,
@NonNull TelemetryStorage telemetryStorage,
@NonNull PersistentImpressionsObserverCacheStorage persistentImpressionsObserverCacheStorage) {
@NonNull PersistentImpressionsObserverCacheStorage persistentImpressionsObserverCacheStorage,
@NonNull GeneralInfoStorage generalInfoStorage) {

mSplitStorage = checkNotNull(splitStorage);
mMySegmentsStorageContainer = checkNotNull(mySegmentsStorageContainer);
Expand All @@ -66,6 +69,7 @@ public SplitStorageContainer(@NonNull SplitsStorage splitStorage,
mTelemetryStorage = checkNotNull(telemetryStorage);
mPersistentImpressionsUniqueStorage = checkNotNull(persistentImpressionsUniqueStorage);
mPersistentImpressionsObserverCacheStorage = checkNotNull(persistentImpressionsObserverCacheStorage);
mGeneralInfoStorage = checkNotNull(generalInfoStorage);
}

public SplitsStorage getSplitsStorage() {
Expand Down Expand Up @@ -135,4 +139,8 @@ public PersistentImpressionsUniqueStorage getPersistentImpressionsUniqueStorage(
public PersistentImpressionsObserverCacheStorage getImpressionsObserverCachePersistentStorage() {
return mPersistentImpressionsObserverCacheStorage;
}

public GeneralInfoStorage getGeneralInfoStorage() {
return mGeneralInfoStorage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class GeneralInfoEntity {
public static final String SPLITS_UPDATE_TIMESTAMP = "splitsUpdateTimestamp";
public static final String CHANGE_NUMBER_INFO = "splitChangesChangeNumber";
public static final String SPLITS_FILTER_QUERY_STRING = "splitsFilterQueryString";
public static final String DATBASE_MIGRATION_STATUS = "databaseMigrationStatus";
public static final int DATBASE_MIGRATION_STATUS_DONE = 1;
public static final String DATABASE_ENCRYPTION_MODE = "databaseEncryptionMode";
public static final String FLAGS_SPEC = "flagsSpec";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.split.android.client.storage.events.EventsStorage;
import io.split.android.client.storage.events.PersistentEventsStorage;
import io.split.android.client.storage.events.SqLitePersistentEventsStorage;
import io.split.android.client.storage.general.GeneralInfoStorage;
import io.split.android.client.storage.general.GeneralInfoStorageImpl;
import io.split.android.client.storage.impressions.ImpressionsStorage;
import io.split.android.client.storage.impressions.PersistentImpressionsCountStorage;
import io.split.android.client.storage.impressions.PersistentImpressionsStorage;
Expand Down Expand Up @@ -148,4 +150,8 @@ private static AttributesStorageContainer getAttributesStorageContainerInstance(
public static PersistentImpressionsObserverCacheStorage getImpressionsObserverCachePersistentStorage(SplitRoomDatabase splitRoomDatabase, long expirationPeriod, ScheduledThreadPoolExecutor executorService) {
return new SqlitePersistentImpressionsObserverCacheStorage(splitRoomDatabase.impressionsObserverCacheDao(), expirationPeriod, executorService);
}

public static GeneralInfoStorage getGeneralInfoStorage(SplitRoomDatabase splitRoomDatabase) {
return new GeneralInfoStorageImpl(splitRoomDatabase.generalInfoDao());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.split.android.client.storage.general;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public interface GeneralInfoStorage {

long getSplitsUpdateTimestamp();

void setSplitsUpdateTimestamp(long timestamp);

long getChangeNumber();

void setChangeNumber(long changeNumber);

@NonNull
String getSplitsFilterQueryString();

void setSplitsFilterQueryString(String queryString);

String getDatabaseEncryptionMode();

void setDatabaseEncryptionMode(String value);

@Nullable
String getFlagsSpec();

void setFlagsSpec(String value);

long getRolloutCacheLastClearTimestamp();

void setRolloutCacheLastClearTimestamp(long timestamp);
}
Loading

0 comments on commit a5a56c9

Please sign in to comment.