use of com.pushtorefresh.storio3.sqlite.Changes in project storio by pushtorefresh.
the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForFlowable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForFlowable() {
final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
Uri testUri = mock(Uri.class);
when(storIOContentResolver.observeChangesOfUri(eq(testUri), eq(BackpressureStrategy.MISSING))).thenReturn(Flowable.<Changes>empty());
// noinspection unchecked
final GetResolver<Integer> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
new PreparedGetNumberOfResults.Builder(storIOContentResolver).withQuery(Query.builder().uri(testUri).build()).withGetResolver(getResolver).prepare().asRxFlowable(BackpressureStrategy.MISSING).subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(60, SECONDS);
testSubscriber.assertError(StorIOException.class);
assertThat(testSubscriber.errors()).hasSize(1);
StorIOException storIOException = (StorIOException) testSubscriber.errors().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
testSubscriber.dispose();
}
use of com.pushtorefresh.storio3.sqlite.Changes in project storio by pushtorefresh.
the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForFlowable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForFlowable() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
when(storIOSQLite.observeChanges(any(BackpressureStrategy.class))).thenReturn(Flowable.<Changes>empty());
// noinspection unchecked
final GetResolver<Integer> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<Integer> testSubscriber = new TestSubscriber<Integer>();
new PreparedGetNumberOfResults.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").observesTags("test_tag").build()).withGetResolver(getResolver).prepare().asRxFlowable(LATEST).subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(60, SECONDS);
testSubscriber.assertError(StorIOException.class);
assertThat(testSubscriber.errorCount()).isEqualTo(1);
StorIOException storIOException = (StorIOException) testSubscriber.errors().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
testSubscriber.dispose();
}
use of com.pushtorefresh.storio3.sqlite.Changes in project storio by pushtorefresh.
the class PreparedGetCursorTest method shouldWrapExceptionIntoStorIOExceptionForFlowable.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForFlowable() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
when(storIOSQLite.observeChanges(any(BackpressureStrategy.class))).thenReturn(Flowable.<Changes>empty());
// noinspection unchecked
final GetResolver<Cursor> getResolver = mock(GetResolver.class);
when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
final TestSubscriber<Cursor> testSubscriber = new TestSubscriber<Cursor>();
new PreparedGetCursor.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").observesTags("test_tag").build()).withGetResolver(getResolver).prepare().asRxFlowable(LATEST).subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(60, SECONDS);
testSubscriber.assertError(StorIOException.class);
StorIOException storIOException = (StorIOException) testSubscriber.errors().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
testSubscriber.dispose();
}
use of com.pushtorefresh.storio3.sqlite.Changes in project storio by pushtorefresh.
the class RxQueryTest method concurrentPutWithoutGlobalTransaction.
@Test
@Repeat(times = 20)
public void concurrentPutWithoutGlobalTransaction() throws InterruptedException {
final int numberOfConcurrentPuts = ConcurrencyTesting.optimalTestThreadsCount();
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
storIOSQLite.observeChangesInTable(TweetTableMeta.TABLE, LATEST).subscribe(testSubscriber);
final CountDownLatch concurrentPutLatch = new CountDownLatch(1);
final CountDownLatch allPutsDoneLatch = new CountDownLatch(numberOfConcurrentPuts);
for (int i = 0; i < numberOfConcurrentPuts; i++) {
final int iCopy = i;
new Thread(new Runnable() {
@Override
public void run() {
try {
concurrentPutLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
storIOSQLite.put().object(Tweet.newInstance(null, 1L, "Some text: " + iCopy)).prepare().executeAsBlocking();
allPutsDoneLatch.countDown();
}
}).start();
}
// Start concurrent Put operations.
concurrentPutLatch.countDown();
assertThat(allPutsDoneLatch.await(25, SECONDS)).isTrue();
testSubscriber.assertNoErrors();
// Put operation creates short-term transaction which might result in merge of some notifications.
// So we have two extreme cases:
// - no merged notifications → isEqualTo(numberOfParallelPuts)
// - all notifications merged → isEqualTo(1)
// Obviously truth is somewhere between those (depends on CPU of machine that runs test).
assertThat(testSubscriber.valueCount()).isLessThanOrEqualTo(numberOfConcurrentPuts).isGreaterThanOrEqualTo(1);
}
use of com.pushtorefresh.storio3.sqlite.Changes in project storio by pushtorefresh.
the class ObserveChangesOfTagTest method updateEmission.
@Test
public void updateEmission() {
final List<User> users = putUsersBlocking(10);
final List<User> updated = new ArrayList<User>(users.size());
for (User user : users) {
updated.add(User.newInstance(user.id(), user.email()));
}
final Queue<Changes> expectedChanges = new LinkedList<Changes>();
expectedChanges.add(Changes.newInstance(UserTableMeta.TABLE, UserTableMeta.NOTIFICATION_TAG));
final EmissionChecker emissionChecker = new EmissionChecker(expectedChanges);
final Disposable disposable = emissionChecker.subscribe();
storIOSQLite.put().objects(updated).prepare().executeAsBlocking();
// Should receive changes of Users table
emissionChecker.awaitNextExpectedValue();
emissionChecker.assertThatNoExpectedValuesLeft();
disposable.dispose();
}
Aggregations