use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class NotifyAboutChangesTest method shouldReceiveOneNotificationWithAllAffectedTablesInTransactionWithMultipleThreads.
@Test
@Repeat(times = 20)
public void shouldReceiveOneNotificationWithAllAffectedTablesInTransactionWithMultipleThreads() throws InterruptedException {
final String table1 = "test_table1";
final String table2 = "test_table2";
final int numberOfThreads = ConcurrencyTesting.optimalTestThreadsCount();
final TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
storIOSQLite.observeChanges(LATEST).subscribe(testSubscriber);
final StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
lowLevel.beginTransaction();
final CountDownLatch startAllThreadsLock = new CountDownLatch(1);
final CountDownLatch allThreadsFinishedLock = new CountDownLatch(numberOfThreads);
for (int i = 0; i < numberOfThreads; i++) {
new Thread(new Runnable() {
@Override
public void run() {
try {
// All threads should start "simultaneously".
startAllThreadsLock.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
lowLevel.notifyAboutChanges(Changes.newInstance(table1));
lowLevel.notifyAboutChanges(Changes.newInstance(table2));
allThreadsFinishedLock.countDown();
}
}).start();
}
// Ready!
// Steady!
// Go!
startAllThreadsLock.countDown();
assertThat(allThreadsFinishedLock.await(25, SECONDS)).isTrue();
// While we in transaction, no changes should be sent.
testSubscriber.assertValueCount(0);
lowLevel.endTransaction();
testSubscriber.assertNoErrors();
List<Changes> actualChanges = testSubscriber.values();
assertThat(actualChanges).hasSize(1);
assertThat(actualChanges.get(0).affectedTables()).containsOnly("test_table1", "test_table2");
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class ChangesFilterTest method applyForTags_shouldFilterRequiredTagWhichIsPartOfSomeChanges.
@Test
public void applyForTags_shouldFilterRequiredTagWhichIsPartOfSomeChanges() {
final TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
Changes changes = Changes.newInstance(new HashSet<String>() {
{
add("table1");
}
}, new HashSet<String>() {
{
add("tag1");
add("tag2");
}
});
ChangesFilter.applyForTags(Flowable.just(changes, Changes.newInstance("table3", "tag3"), Changes.newInstance("table4")), singleton("tag1")).subscribe(testSubscriber);
// All other tags should be filtered
testSubscriber.assertValue(changes);
testSubscriber.dispose();
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class ObserveChangesOfTagTest method insertEmission.
@Test
public void insertEmission() {
final List<User> users = TestFactory.newUsers(10);
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();
putUsersBlocking(users);
// Should receive changes of Users table
emissionChecker.awaitNextExpectedValue();
emissionChecker.assertThatNoExpectedValuesLeft();
disposable.dispose();
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class ObserveChangesOfTagTest method deleteEmission.
@Test
public void deleteEmission() {
final List<User> users = putUsersBlocking(10);
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();
deleteUsersBlocking(users);
// Should receive changes of Users table
emissionChecker.awaitNextExpectedValue();
emissionChecker.assertThatNoExpectedValuesLeft();
disposable.dispose();
}
use of com.pushtorefresh.storio3.contentresolver.Changes in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method observeChangesOfTags_shouldReceiveIfObservedTagExistInChanges.
@Test
public void observeChangesOfTags_shouldReceiveIfObservedTagExistInChanges() {
TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
String tag1 = "tag1";
String tag2 = "tag2";
Set<String> tags = new HashSet<String>(2);
tags.add(tag1);
tags.add(tag2);
storIOSQLite.observeChangesOfTags(tags, LATEST).subscribe(testSubscriber);
testSubscriber.assertNoValues();
Changes changes = Changes.newInstance("table1", tag1);
storIOSQLite.lowLevel().notifyAboutChanges(changes);
testSubscriber.assertValues(changes);
testSubscriber.assertNoErrors();
testSubscriber.dispose();
}
Aggregations