use of com.amplifyframework.datastore.storage.LocalStorageAdapter in project amplify-android by aws-amplify.
the class MutationProcessorTest method setup.
/**
* A {@link MutationProcessor} is being tested. To do so, we arrange mutations into
* an {@link MutationOutbox}. Fake responses are returned from a mock {@link AppSync}.
* @throws AmplifyException When loading SchemaRegistry
*/
@Before
public void setup() throws AmplifyException {
ShadowLog.stream = System.out;
LocalStorageAdapter localStorageAdapter = InMemoryStorageAdapter.create();
this.synchronousStorageAdapter = SynchronousStorageAdapter.delegatingTo(localStorageAdapter);
this.mutationOutbox = new PersistentMutationOutbox(localStorageAdapter);
VersionRepository versionRepository = new VersionRepository(localStorageAdapter);
Merger merger = new Merger(mutationOutbox, versionRepository, localStorageAdapter);
this.appSync = mock(AppSync.class);
this.configurationProvider = mock(DataStoreConfigurationProvider.class);
ConflictResolver conflictResolver = new ConflictResolver(configurationProvider, appSync);
schemaRegistry = SchemaRegistry.instance();
schemaRegistry.register(Collections.singleton(BlogOwner.class));
this.mutationProcessor = MutationProcessor.builder().merger(merger).versionRepository(versionRepository).schemaRegistry(schemaRegistry).mutationOutbox(mutationOutbox).appSync(appSync).conflictResolver(conflictResolver).build();
}
use of com.amplifyframework.datastore.storage.LocalStorageAdapter in project amplify-android by aws-amplify.
the class MutationPersistenceInstrumentationTest method obtainLocalStorageAndValidateModelSchema.
/**
* Prepare an instance of {@link LocalStorageAdapter}. Evaluate its
* emitted collection of ModelSchema, to ensure that
* {@link PendingMutation.PersistentRecord} is among them.
*
* TODO: later, consider hiding system schema, such as the
* {@link PendingMutation.PersistentRecord}, from the callback. This schema might be
* an implementation detail, that is working as a leaky abstraction.
*
* @throws AmplifyException On failure to initialize the storage adapter,
* or on failure to load model schema into registry
*/
@Before
public void obtainLocalStorageAndValidateModelSchema() throws AmplifyException {
this.converter = new GsonPendingMutationConverter();
getApplicationContext().deleteDatabase(DATABASE_NAME);
ModelProvider modelProvider = SimpleModelProvider.withRandomVersion(BlogOwner.class);
schemaRegistry = SchemaRegistry.instance();
schemaRegistry.clear();
schemaRegistry.register(modelProvider.models());
LocalStorageAdapter localStorageAdapter = SQLiteStorageAdapter.forModels(schemaRegistry, modelProvider);
this.storage = SynchronousStorageAdapter.delegatingTo(localStorageAdapter);
List<ModelSchema> initializationResults = storage.initialize(getApplicationContext());
// Evaluate the returned set of ModelSchema. Ensure that there is one
// for the PendingMutation.PersistentRecord system class.
assertTrue(Observable.fromIterable(initializationResults).map(ModelSchema::getName).toList().blockingGet().contains(PendingMutation.PersistentRecord.class.getSimpleName()));
}
Aggregations