本文整理匯總了Java中io.reactivex.subscribers.TestSubscriber.create方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.create方法的具體用法?Java TestSubscriber.create怎麽用?Java TestSubscriber.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.subscribers.TestSubscriber
的用法示例。
在下文中一共展示了TestSubscriber.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void test() throws InterruptedException {
// We use the test subscriber of RxJava 2
TestSubscriber<LiveDeviceReading> subscriber = TestSubscriber.create();
// Any stream discovered using streaming pool is a Publisher, thus can
// be used with any reactive stream technology, like RxJava 2
Flowable.fromPublisher(discovery.discover(LIVE_DEVICE_ID)).take(2).subscribe(subscriber);
subscriber.await(5, TimeUnit.SECONDS);
List<LiveDeviceReading> values = subscriber.values();
List<LiveDeviceReading> expectedValues = Arrays.asList(new LiveDeviceReading(0L), new LiveDeviceReading(1L));
assertThat(values).containsExactlyElementsOf(expectedValues);
}
示例2: test
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void test() throws InterruptedException {
// The stream id specify which stream we want to obtain
IntegerRangeId streamId = new IntegerRangeId(0, 10);
// Using the RxJava 2 test subscriber
TestSubscriber<Integer> subscriber = TestSubscriber.create();
// The stream id will be discovered (and created by the factory)
discovery.discover(streamId).subscribe(subscriber);
// Wait for the end of the stream
subscriber.await();
List<Integer> values = subscriber.values();
List<Integer> expectedValues = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertThat(values).containsExactlyElementsOf(expectedValues);
}
示例3: shouldHandleDuplicateCommands
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void shouldHandleDuplicateCommands() {
// given:
final Processor<ORSet.ORSetCommand<String>, ORSet.ORSetCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final ORSet<String> set = new ORSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final ORSet.AddCommand<String> command = new ORSet.AddCommand<>(set.getCrdtId(), new ORSet.Element<>("1", UUID.randomUUID()));
// when:
inputStream.onNext(command);
inputStream.onNext(command);
// then:
assertThat(set, hasSize(1));
assertThat(subscriber.valueCount(), is(1));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例4: testDelayedStreamWithCorrectValues
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testDelayedStreamWithCorrectValues() throws InterruptedException {
final long delay = 2000;
final long deltaDelay = 500;
StreamId<Integer> sourceStreamId = provide(Flowable.<Integer> just(1)).withUniqueStreamId();
StreamId<Integer> delayedStreamId = ComposedStreams.delayedStream(sourceStreamId, Duration.ofMillis(delay));
TestSubscriber<Integer> subscriber = TestSubscriber.create();
discover(delayedStreamId).subscribe(subscriber);
Instant before = Instant.now();
subscriber.await();
Instant after = Instant.now();
assertThat(subscriber.values()).hasSize(1).containsExactly(1);
assertThat(Duration.between(before, after).toMillis()).isBetween(delay - deltaDelay, delay + deltaDelay);
}
示例5: itShouldSendCommandsOnUpdates
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void itShouldSendCommandsOnUpdates() {
// given
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final PNCounter counter = new PNCounter(NODE_ID_1, CRDT_ID);
counter.subscribe(subscriber);
// when
counter.increment();
counter.decrement();
counter.increment(3L);
counter.decrement(5L);
// then
subscriber.assertNotComplete();
subscriber.assertNoErrors();
assertThat(subscriber.values(), contains(
new UpdateCommandMatcher(CRDT_ID, HashMap.of(NODE_ID_1, 1L), HashMap.empty()),
new UpdateCommandMatcher(CRDT_ID, HashMap.of(NODE_ID_1, 1L), HashMap.of(NODE_ID_1, 1L)),
new UpdateCommandMatcher(CRDT_ID, HashMap.of(NODE_ID_1, 4L), HashMap.of(NODE_ID_1, 1L)),
new UpdateCommandMatcher(CRDT_ID, HashMap.of(NODE_ID_1, 4L), HashMap.of(NODE_ID_1, 6L))
));
}
示例6: shouldHandleAddCommands
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void shouldHandleAddCommands() {
// given:
final Processor<GSet.AddCommand<String>, GSet.AddCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final GSet<String> set = new GSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final GSet.AddCommand<String> command1 = new GSet.AddCommand<>(set.getCrdtId(), "1");
final GSet.AddCommand<String> command2 = new GSet.AddCommand<>(set.getCrdtId(), "2");
final GSet.AddCommand<String> command3 = new GSet.AddCommand<>(set.getCrdtId(), "1");
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
inputStream.onNext(command3);
// then:
assertThat(set, hasSize(2));
assertThat(subscriber.valueCount(), is(2));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例7: testUpdatesChecked
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUpdatesChecked() throws Exception {
RxPaperBook book = RxPaperBook.with("UPDATES_CH", Schedulers.trampoline());
final String key = "hello";
final ComplexObject value = ComplexObject.random();
final TestSubscriber<ComplexObject> updatesSubscriber = TestSubscriber.create();
book.observe(key, ComplexObject.class, BackpressureStrategy.MISSING).subscribe(updatesSubscriber);
updatesSubscriber.assertValueCount(0);
book.write(key, value).subscribe();
updatesSubscriber.assertValueCount(1);
updatesSubscriber.assertValues(value);
final ComplexObject newValue = ComplexObject.random();
book.write(key, newValue).subscribe();
updatesSubscriber.assertValueCount(2);
updatesSubscriber.assertValues(value, newValue);
// Error value
final int wrongValue = 3;
book.write(key, wrongValue).test().assertComplete().assertNoErrors();
updatesSubscriber.assertValueCount(2);
updatesSubscriber.assertValues(value, newValue);
updatesSubscriber.assertNoErrors();
}
示例8: shouldSendNotificationForAdds
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void shouldSendNotificationForAdds() {
// given:
final UUID uuid1 = UUID.randomUUID();
final UUID uuid2 = UUID.randomUUID();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final USet<UUID> set = new USet<>("ID_1");
set.subscribe(subscriber);
// when:
set.add(uuid1);
set.add(uuid2);
// then:
subscriber.assertNotComplete();
subscriber.assertNoErrors();
assertThat(subscriber.values(), contains(
new AddCommandMatcher<>(set.getCrdtId(), uuid1),
new AddCommandMatcher<>(set.getCrdtId(), uuid2)
));
}
示例9: shouldHandleAddCommands
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void shouldHandleAddCommands() {
// given:
final UUID uuid1 = UUID.randomUUID();
final UUID uuid2 = UUID.randomUUID();
final Processor<USet.USetCommand<UUID>, USet.USetCommand<UUID>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final USet<UUID> set = new USet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final USet.AddCommand<UUID> command1 = new USet.AddCommand<>(set.getCrdtId(), uuid1);
final USet.AddCommand<UUID> command2 = new USet.AddCommand<>(set.getCrdtId(), uuid2);
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
// then:
assertThat(set, hasSize(2));
assertThat(subscriber.valueCount(), is(2));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例10: shouldHandleRemoveCommands
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void shouldHandleRemoveCommands() {
// given:
final UUID uuid1 = UUID.randomUUID();
final Processor<USet.USetCommand<UUID>, USet.USetCommand<UUID>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final USet<UUID> set = new USet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final USet.AddCommand<UUID> command1 = new USet.AddCommand<>(set.getCrdtId(), uuid1);
final USet.RemoveCommand<UUID> command2 = new USet.RemoveCommand<>(set.getCrdtId(), uuid1);
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
// then:
assertThat(set, empty());
assertThat(subscriber.valueCount(), is(2));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}
示例11: shouldSendNotificationForAdds
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void shouldSendNotificationForAdds() {
// given:
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final TwoPSet<String> set = new TwoPSet<>("ID_1");
set.subscribe(subscriber);
// when:
set.add("1");
set.add("2");
set.add("1");
// then:
subscriber.assertNotComplete();
subscriber.assertNoErrors();
assertThat(subscriber.values(), contains(
new AddCommandMatcher<>(set.getCrdtId(), "1"),
new AddCommandMatcher<>(set.getCrdtId(), "2")
));
}
示例12: shouldSendNotificationForAdds
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void shouldSendNotificationForAdds() {
// given:
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final GSet<String> set = new GSet<>("ID_1");
set.subscribe(subscriber);
// when:
set.add("1");
set.add("2");
set.add("1");
// then:
subscriber.assertNotComplete();
subscriber.assertNoErrors();
assertThat(subscriber.values(), contains(
new AddCommandMatcher<>(set.getCrdtId(), "1"),
new AddCommandMatcher<>(set.getCrdtId(), "2"),
new AddCommandMatcher<>(set.getCrdtId(), "1")
));
}
示例13: itShouldIgnoreOlderValueFromReceivedCommands
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void itShouldIgnoreOlderValueFromReceivedCommands() {
// given
final TestSubscriber<LWWRegister.SetCommand<String>> outCommands1 = TestSubscriber.create();
final TestSubscriber<LWWRegister.SetCommand<String>> outCommands2 = TestSubscriber.create();
final Processor<LWWRegister.SetCommand<String>, LWWRegister.SetCommand<String>> inCommands3 = ReplayProcessor.create();
final LWWRegister<String> register1 = new LWWRegister<>(NODE_ID_1, CRDT_ID);
register1.subscribe(outCommands1);
final LWWRegister<String> register2 = new LWWRegister<>(NODE_ID_2, CRDT_ID);
register2.subscribe(outCommands2);
register1.subscribeTo(register2);
register2.subscribeTo(register1);
final LWWRegister<String> register3 = new LWWRegister<>(NODE_ID_3, CRDT_ID);
register3.subscribeTo(inCommands3);
// when
register1.set("Hello World");
register2.set("Goodbye World");
final LWWRegister.SetCommand<String> oldCommand = outCommands1.values().get(0);
final LWWRegister.SetCommand<String> newCommand = outCommands2.values().get(1);
inCommands3.onNext(newCommand);
inCommands3.onNext(oldCommand);
// then
assertThat(register3.get(), is("Goodbye World"));
}
示例14: createSubscriberAndWait
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
private TestSubscriber<Integer> createSubscriberAndWait(StreamId<Integer> sourceStreamId) {
TestSubscriber<Integer> subscriber = TestSubscriber.create();
discover(sourceStreamId).subscribe(subscriber);
try {
subscriber.await();
} catch (InterruptedException e) {
fail("Interrupted wait", e);
}
return subscriber;
}
示例15: shouldHandleRemoveCommands
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void shouldHandleRemoveCommands() {
// given:
final Processor<ORSet.ORSetCommand<String>, ORSet.ORSetCommand<String>> inputStream = ReplayProcessor.create();
final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
final ORSet<String> set = new ORSet<>("ID_1");
set.subscribeTo(inputStream);
set.subscribe(subscriber);
final ORSet.Element<String> elem1 = new ORSet.Element<>("1", UUID.randomUUID());
final ORSet.Element<String> elem2 = new ORSet.Element<>("1", UUID.randomUUID());
final Set<ORSet.Element<String>> elements = new HashSet<>(Arrays.asList(elem1, elem2));
final ORSet.AddCommand<String> command1 = new ORSet.AddCommand<>(set.getCrdtId(), elem1);
final ORSet.AddCommand<String> command2 = new ORSet.AddCommand<>(set.getCrdtId(), elem2);
final ORSet.RemoveCommand<String> command3 = new ORSet.RemoveCommand<>(set.getCrdtId(), elements);
// when:
inputStream.onNext(command1);
inputStream.onNext(command2);
inputStream.onNext(command3);
// then:
assertThat(set, empty());
assertThat(subscriber.valueCount(), is(3));
subscriber.assertNotComplete();
subscriber.assertNoErrors();
}