use of com.amplifyframework.datastore.syncengine.LastSyncMetadata in project amplify-android by aws-amplify.
the class SyncStatusTest method syncStatusGetReturnSyncedStatus.
/**
* Get returns sync status.
*/
@Test
public void syncStatusGetReturnSyncedStatus() {
final LastSyncMetadata lastSyncMetadata = LastSyncMetadata.baseSyncedAt(BlogOwner.class.getName(), Time.now());
List<LastSyncMetadata> resultList = new ArrayList<>();
resultList.add(lastSyncMetadata);
Consumer<DataStoreException> onObservationError = value -> {
};
SqlQueryProcessor mockSqlQueryProcessor = mock(SqlQueryProcessor.class);
when(mockSqlQueryProcessor.queryOfflineData(eq(LastSyncMetadata.class), any(), any())).thenReturn(resultList);
DataStoreConfiguration mockDataStoreConfig = mock(DataStoreConfiguration.class);
when(mockDataStoreConfig.getSyncIntervalInMinutes()).thenReturn(5L);
SyncStatus subject = new SyncStatus(mockSqlQueryProcessor, mockDataStoreConfig);
boolean result = subject.get(LastSyncMetadata.class.getName(), onObservationError);
Assert.assertTrue(result);
}
use of com.amplifyframework.datastore.syncengine.LastSyncMetadata in project amplify-android by aws-amplify.
the class SyncStatusTest method syncStatusGetReturnNotSyncedStatus.
/**
* Get returns false for sync status.
*/
@Test
public void syncStatusGetReturnNotSyncedStatus() {
final LastSyncMetadata lastSyncMetadata = LastSyncMetadata.baseSyncedAt(BlogOwner.class.getName(), Time.now());
List<LastSyncMetadata> resultList = new ArrayList<>();
resultList.add(lastSyncMetadata);
Consumer<DataStoreException> onObservationError = value -> {
};
SqlQueryProcessor mockSqlQueryProcessor = mock(SqlQueryProcessor.class);
when(mockSqlQueryProcessor.queryOfflineData(eq(LastSyncMetadata.class), any(), any())).thenReturn(resultList);
DataStoreConfiguration mockDataStoreConfig = mock(DataStoreConfiguration.class);
when(mockDataStoreConfig.getSyncIntervalInMinutes()).thenReturn(0L);
SyncStatus subject = new SyncStatus(mockSqlQueryProcessor, mockDataStoreConfig);
boolean result = subject.get(LastSyncMetadata.class.getName(), onObservationError);
Assert.assertFalse(result);
}
use of com.amplifyframework.datastore.syncengine.LastSyncMetadata in project amplify-android by aws-amplify.
the class SyncStatus method get.
/**
* Method returns sync status.
* @param modelClassName model class name.
* @param onObservationError invoked on error.
* @return returns the sync status of true or false.
*/
public boolean get(@NonNull String modelClassName, @NonNull Consumer<DataStoreException> onObservationError) {
LastSyncMetadata lastSyncMetadata;
boolean syncStatus = false;
try {
lastSyncMetadata = getLastSyncMetaData(modelClassName, onObservationError);
if (lastSyncMetadata.getLastSyncTime() != null) {
syncStatus = (Time.now() - lastSyncMetadata.getLastSyncTime()) < TimeUnit.MINUTES.toMillis(dataStoreConfiguration.getSyncIntervalInMinutes());
}
} catch (DataStoreException exception) {
onObservationError.accept(exception);
}
return syncStatus;
}
use of com.amplifyframework.datastore.syncengine.LastSyncMetadata in project amplify-android by aws-amplify.
the class SyncStatus method getLastSyncMetaData.
private LastSyncMetadata getLastSyncMetaData(@NonNull String modelClassName, @NonNull Consumer<DataStoreException> onObservationError) throws DataStoreException {
QueryPredicate hasMatchingModelClassName = QueryField.field("modelClassName").eq(modelClassName);
List<LastSyncMetadata> syncedList = sqlQueryProcessor.queryOfflineData(LastSyncMetadata.class, Where.matches(hasMatchingModelClassName), onObservationError);
return extractSingleResult(modelClassName, syncedList);
}
Aggregations