use of io.reark.rxgithubapp.shared.pojo.GitHubRepository in project reark by reark.
the class GitHubRepositoryStoreCore method mergeValues.
@NonNull
@Override
protected GitHubRepository mergeValues(@NonNull final GitHubRepository v1, @NonNull final GitHubRepository v2) {
checkNotNull(v1);
checkNotNull(v2);
// Creating a new object to avoid overwriting the passed argument
GitHubRepository newValue = new GitHubRepository(v1);
return newValue.overwrite(v2);
}
use of io.reark.rxgithubapp.shared.pojo.GitHubRepository in project reark by reark.
the class GitHubRepositoryStoreTest method getOnceAndStream_ReturnsOnlyNewValues_AndDoesNotComplete.
@Test
public void getOnceAndStream_ReturnsOnlyNewValues_AndDoesNotComplete() throws InterruptedException {
final GitHubRepository value = create(100, "repository1");
// In the default store implementation identical values are filtered out.
gitHubRepositoryStore.getOnceAndStream(100).subscribe(testSubscriber);
Thread.sleep(Constants.Tests.PROVIDER_WAIT_TIME);
gitHubRepositoryStore.put(value);
gitHubRepositoryStore.put(value);
testSubscriber.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
testSubscriber.assertNotCompleted();
testSubscriber.assertNoErrors();
testSubscriber.assertReceivedOnNext(asList(none(), value));
}
use of io.reark.rxgithubapp.shared.pojo.GitHubRepository in project reark by reark.
the class GitHubRepositoryStoreTest method getOnceAndStream_WithInitialValue_WithDelayedSubscription_ReturnsFirstValue_AndDoesNotComplete.
@Test
public void getOnceAndStream_WithInitialValue_WithDelayedSubscription_ReturnsFirstValue_AndDoesNotComplete() throws InterruptedException {
final GitHubRepository value1 = create(100, "repository1");
final GitHubRepository value2 = create(100, "repository1");
// This behavior is a little surprising, but it is because we cannot guarantee that the
// observable that is produced as the stream will keep its first (cached) value up to date.
// The only ways to around this would be custom subscribe function or converting the
// source observable into a behavior, but these would significantly increase the
// complexity and are hard to implement in other kinds of store (such as content providers).
// Put initial value.
gitHubRepositoryStore.put(value1);
Thread.sleep(Constants.Tests.PROVIDER_WAIT_TIME);
// Create the stream observable but do not subscribe immediately.
Observable<GitHubRepository> stream = gitHubRepositoryStore.getOnceAndStream(100);
// Put new value into the store.
gitHubRepositoryStore.put(value2);
// Subscribe to stream that was created potentially a long time ago.
stream.subscribe(testSubscriber);
// Observe that the stream actually gives as the first item the cached value at the time of
// creating the stream observable.
testSubscriber.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
testSubscriber.assertNotCompleted();
testSubscriber.assertNoErrors();
testSubscriber.assertReceivedOnNext(singletonList(value1));
}
use of io.reark.rxgithubapp.shared.pojo.GitHubRepository in project reark by reark.
the class GitHubRepositoryStoreTest method getOnceAndStream_WithInitialValue_ReturnsInitialValues_AndDoesNotComplete.
@Test
public void getOnceAndStream_WithInitialValue_ReturnsInitialValues_AndDoesNotComplete() throws InterruptedException {
final GitHubRepository value = create(100, "repository1");
gitHubRepositoryStore.put(value);
Thread.sleep(Constants.Tests.PROVIDER_WAIT_TIME);
gitHubRepositoryStore.getOnceAndStream(100).subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
testSubscriber.assertNotCompleted();
testSubscriber.assertNoErrors();
testSubscriber.assertReceivedOnNext(singletonList(value));
}
use of io.reark.rxgithubapp.shared.pojo.GitHubRepository in project reark by reark.
the class GitHubRepositoryStoreCoreTest method getStream_EmitsValuesForId_AndDoesNotComplete.
// GET STREAM
@Test
public void getStream_EmitsValuesForId_AndDoesNotComplete() {
final GitHubRepository value1 = create(100, "test name 1");
final GitHubRepository value2 = create(200, "test name 2");
TestSubscriber<GitHubRepository> testSubscriber1 = new TestSubscriber<>();
TestSubscriber<GitHubRepository> testSubscriber2 = new TestSubscriber<>();
gitHubRepositoryStoreCore.getStream(100).subscribe(testSubscriber1);
gitHubRepositoryStoreCore.getStream(200).subscribe(testSubscriber2);
gitHubRepositoryStoreCore.put(100, value1);
gitHubRepositoryStoreCore.put(200, value2);
testSubscriber1.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
testSubscriber1.assertNotCompleted();
testSubscriber1.assertNoErrors();
testSubscriber1.assertValue(value1);
testSubscriber2.awaitTerminalEvent(Constants.Tests.PROVIDER_WAIT_TIME, TimeUnit.MILLISECONDS);
testSubscriber2.assertNotCompleted();
testSubscriber2.assertNoErrors();
testSubscriber2.assertValue(value2);
}
Aggregations