io.reactivex.processors.ReplayProcessor Java Examples

The following examples show how to use io.reactivex.processors.ReplayProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HarvesterTest.java    From RxShell with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessors_errors() {
    String uuid = UUID.randomUUID().toString();
    when(cmd.getMarker()).thenReturn(uuid);
    ReplayProcessor<String> processor = ReplayProcessor.create();
    when(cmd.getErrorProcessor()).thenReturn(processor);

    TestSubscriber<Harvester.Crop> testSubscriber = publisher.compose(harvesterFactory.forError(publisher, cmd)).test();

    publisher.onNext("some-errors");
    publisher.onNext(uuid);

    processor.test().awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().assertValueCount(1).assertValue("some-errors");
    Harvester.Crop crop = testSubscriber.awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().assertValueCount(1).values().get(0);
    assertThat(crop.buffer, is(nullValue()));
}
 
Example #2
Source File: ElementsStream.java    From redisson with Apache License 2.0 6 votes vote down vote up
private static <V> void take(Supplier<RFuture<V>> factory, ReplayProcessor<V> p, AtomicLong counter, AtomicReference<RFuture<V>> futureRef) {
    RFuture<V> future = factory.get();
    futureRef.set(future);
    future.onComplete((res, e) -> {
        if (e != null) {
            p.onError(e);
            return;
        }
        
        p.onNext(res);
        if (counter.decrementAndGet() == 0) {
            p.onComplete();
        }
        
        take(factory, p, counter, futureRef);
    });
}
 
Example #3
Source File: ElementsStream.java    From redisson with Apache License 2.0 6 votes vote down vote up
public static <V> Flowable<V> takeElements(Supplier<RFuture<V>> callable) {
    ReplayProcessor<V> p = ReplayProcessor.create();
    return p.doOnRequest(new LongConsumer() {
        @Override
        public void accept(long n) throws Exception {
            AtomicLong counter = new AtomicLong(n);
            AtomicReference<RFuture<V>> futureRef = new AtomicReference<RFuture<V>>();
            
            take(callable, p, counter, futureRef);

            p.doOnCancel(new Action() {
                @Override
                public void run() throws Exception {
                    futureRef.get().cancel(true);
                }
            });
        }
    });
}
 
Example #4
Source File: TwoPSetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandleRemoveCommandArrivesBeforeAddCommand() {
    // given:
    final Processor<TwoPSet.TwoPSetCommand<String>, TwoPSet.TwoPSetCommand<String>> inputStream = ReplayProcessor.create();
    final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
    final TwoPSet<String> set = new TwoPSet<>("ID_1");
    set.subscribeTo(inputStream);
    set.subscribe(subscriber);

    final TwoPSet.RemoveCommand<String> command1 = new TwoPSet.RemoveCommand<>(set.getCrdtId(), "1");
    final TwoPSet.AddCommand<String> command2 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
    final TwoPSet.AddCommand<String> command3 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");

    // when:
    inputStream.onNext(command1);
    inputStream.onNext(command2);
    inputStream.onNext(command3);

    // then:
    assertThat(set, empty());
    assertThat(subscriber.valueCount(), is(1));
    subscriber.assertNotComplete();
    subscriber.assertNoErrors();
}
 
Example #5
Source File: TwoPSetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandleRemoveCommands() {
    // given:
    final Processor<TwoPSet.TwoPSetCommand<String>, TwoPSet.TwoPSetCommand<String>> inputStream = ReplayProcessor.create();
    final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
    final TwoPSet<String> set = new TwoPSet<>("ID_1");
    set.subscribeTo(inputStream);
    set.subscribe(subscriber);

    final TwoPSet.AddCommand<String> command1 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
    final TwoPSet.AddCommand<String> command2 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
    final TwoPSet.RemoveCommand<String> command3 = new TwoPSet.RemoveCommand<>(set.getCrdtId(), "1");

    // when:
    inputStream.onNext(command1);
    inputStream.onNext(command2);
    inputStream.onNext(command3);

    // then:
    assertThat(set, empty());
    assertThat(subscriber.valueCount(), is(2));
    subscriber.assertNotComplete();
    subscriber.assertNoErrors();
}
 
Example #6
Source File: TwoPSetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandleAddCommands() {
    // given:
    final Processor<TwoPSet.TwoPSetCommand<String>, TwoPSet.TwoPSetCommand<String>> inputStream = ReplayProcessor.create();
    final TestSubscriber<CrdtCommand> subscriber = TestSubscriber.create();
    final TwoPSet<String> set = new TwoPSet<>("ID_1");
    set.subscribeTo(inputStream);
    set.subscribe(subscriber);

    final TwoPSet.AddCommand<String> command1 = new TwoPSet.AddCommand<>(set.getCrdtId(), "1");
    final TwoPSet.AddCommand<String> command2 = new TwoPSet.AddCommand<>(set.getCrdtId(), "2");
    final TwoPSet.AddCommand<String> command3 = new TwoPSet.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();
}
 
Example #7
Source File: GSetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandleDuplicateCommands() {
    // 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> command = new GSet.AddCommand<>(set.getCrdtId(), "1");

    // when:
    inputStream.onNext(command);
    inputStream.onNext(command);

    // then:
    assertThat(set, hasSize(1));
    assertThat(subscriber.valueCount(), is(1));
    subscriber.assertNotComplete();
    subscriber.assertNoErrors();
}
 
Example #8
Source File: GSetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #9
Source File: ORSetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #10
Source File: ORSetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandleAddCommands() {
    // 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> command1 = new ORSet.AddCommand<>(set.getCrdtId(), new ORSet.Element<>("1", UUID.randomUUID()));
    final ORSet.AddCommand<String> command2 = new ORSet.AddCommand<>(set.getCrdtId(), new ORSet.Element<>("2", UUID.randomUUID()));
    final ORSet.AddCommand<String> command3 = new ORSet.AddCommand<>(set.getCrdtId(), new ORSet.Element<>("1", UUID.randomUUID()));

    // when:
    inputStream.onNext(command1);
    inputStream.onNext(command2);
    inputStream.onNext(command3);

    // then:
    assertThat(set, hasSize(2));
    assertThat(subscriber.valueCount(), is(3));
    subscriber.assertNotComplete();
    subscriber.assertNoErrors();
}
 
Example #11
Source File: HarvesterTest.java    From RxShell with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessors_output() {
    String uuid = UUID.randomUUID().toString();
    when(cmd.getMarker()).thenReturn(uuid);
    ReplayProcessor<String> processor = ReplayProcessor.create();
    when(cmd.getOutputProcessor()).thenReturn(processor);

    TestSubscriber<OutputHarvester.Crop> testSubscriber = publisher.compose(harvesterFactory.forOutput(publisher, cmd)).test();

    publisher.onNext("some-output");
    publisher.onNext(uuid + " 255");

    processor.test().awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().assertValueCount(1).assertValue("some-output");
    OutputHarvester.Crop crop = testSubscriber.awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().assertValueCount(1).values().get(0);
    assertThat(crop.exitCode, is(255));
    assertThat(crop.buffer, is(nullValue()));
}
 
Example #12
Source File: USetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #13
Source File: USetTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #14
Source File: MVRegisterTest.java    From wurmloch-crdt with Apache License 2.0 6 votes vote down vote up
@Test
public void itShouldOverwriteOnlyPartialCommandsFromReceivedCommand() {
    // given
    final TestSubscriber<MVRegister.SetCommand<String>> outCommands1 = TestSubscriber.create();
    final Processor<MVRegister.SetCommand<String>, MVRegister.SetCommand<String>> inCommands2 = ReplayProcessor.create();
    final MVRegister<String> register1 = new MVRegister<>(NODE_ID_1, CRDT_ID);
    register1.subscribe(outCommands1);
    final MVRegister<String> register2 = new MVRegister<>(NODE_ID_2, CRDT_ID);
    register2.subscribeTo(inCommands2);

    register1.set("Hello World");
    register2.set("Goodbye World");
    inCommands2.onNext(outCommands1.values().get(0));

    // when
    register1.set("42");
    inCommands2.onNext(outCommands1.values().get(1));

    // then
    assertThat(register1.get(), containsInAnyOrder("42"));
    assertThat(register2.get(), containsInAnyOrder("42", "Goodbye World"));
}
 
Example #15
Source File: ORSetTest.java    From wurmloch-crdt with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #16
Source File: MVRegisterTest.java    From wurmloch-crdt with Apache License 2.0 5 votes vote down vote up
@Test
public void itShouldIgnoreOlderValueFromReceivedCommands() {
    // given
    final TestSubscriber<MVRegister.SetCommand<String>> outCommands1 = TestSubscriber.create();
    final TestSubscriber<MVRegister.SetCommand<String>> outCommands2 = TestSubscriber.create();
    final Processor<MVRegister.SetCommand<String>, MVRegister.SetCommand<String>> inCommands3 = ReplayProcessor.create();
    final MVRegister<String> register1 = new MVRegister<>(NODE_ID_1, CRDT_ID);
    register1.subscribe(outCommands1);
    final MVRegister<String> register2 = new MVRegister<>(NODE_ID_2, CRDT_ID);
    register2.subscribe(outCommands2);
    register1.subscribeTo(register2);
    register2.subscribeTo(register1);
    final MVRegister<String> register3 = new MVRegister<>(NODE_ID_3, CRDT_ID);
    register3.subscribeTo(inCommands3);


    // when
    register1.set("Hello World");
    register2.set("Goodbye World");
    final MVRegister.SetCommand<String> oldCommand = outCommands1.values().get(0);
    final MVRegister.SetCommand<String> newCommand = outCommands2.values().get(1);
    inCommands3.onNext(newCommand);
    inCommands3.onNext(oldCommand);

    // then
    assertThat(register3.get(), contains("Goodbye World"));
}
 
Example #17
Source File: RedissonTransferQueueRx.java    From redisson with Apache License 2.0 5 votes vote down vote up
public Publisher<V> iterator() {
    ReplayProcessor<V> p = ReplayProcessor.create();
    return p.doOnRequest(new LongConsumer() {

        private int currentIndex = 0;

        @Override
        public void accept(long n) throws Exception {
            queue.getValueAsync(currentIndex).onComplete((value, e) -> {
                if (e != null) {
                    p.onError(e);
                    return;
                }

                if (value != null) {
                    p.onNext(value);
                    currentIndex++;
                }

                if (value == null) {
                    p.onComplete();
                    return;
                }
                if (n-1 == 0) {
                    return;
                }
                try {
                    accept(n-1);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            });
        }

    });
}
 
Example #18
Source File: RedissonTopicRx.java    From redisson with Apache License 2.0 5 votes vote down vote up
public <M> Flowable<M> getMessages(Class<M> type) {
    ReplayProcessor<M> p = ReplayProcessor.create();
    return p.doOnRequest(new LongConsumer() {
        @Override
        public void accept(long n) throws Exception {
            AtomicLong counter = new AtomicLong(n);
            RFuture<Integer> t = topic.addListenerAsync(type, new MessageListener<M>() {
                @Override
                public void onMessage(CharSequence channel, M msg) {
                    p.onNext(msg);
                    if (counter.decrementAndGet() == 0) {
                        topic.removeListenerAsync(this);
                        p.onComplete();
                    }
                }
            });
            t.onComplete((id, e) -> {
                if (e != null) {
                    p.onError(e);
                    return;
                }
                
                p.doOnCancel(new Action() {
                    @Override
                    public void run() throws Exception {
                        topic.removeListenerAsync(id);
                    }
                });
            });
        }
    });
}
 
Example #19
Source File: RedissonListRx.java    From redisson with Apache License 2.0 5 votes vote down vote up
private Publisher<V> iterator(int startIndex, boolean forward) {
    ReplayProcessor<V> p = ReplayProcessor.create();
    return p.doOnRequest(new LongConsumer() {

        private int currentIndex = startIndex;
        
        @Override
        public void accept(long n) throws Exception {
            instance.getAsync(currentIndex).onComplete((value, e) -> {
                if (e != null) {
                    p.onError(e);
                    return;
                }
                
                if (value != null) {
                    p.onNext(value);
                    if (forward) {
                        currentIndex++;
                    } else {
                        currentIndex--;
                    }
                }
                
                if (value == null) {
                    p.onComplete();
                    return;
                }
                if (n-1 == 0) {
                    return;
                }
                try {
                    accept(n-1);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            });
        }
    });
}
 
Example #20
Source File: CommandRxService.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public <R> Flowable<R> flowable(Callable<RFuture<R>> supplier) {
    ReplayProcessor<R> p = ReplayProcessor.create();
    return p.doOnRequest(new LongConsumer() {
        @Override
        public void accept(long t) throws Exception {
            RFuture<R> future;
            try {
                future = supplier.call();
            } catch (Exception e) {
                p.onError(e);
                return;
            }
            p.doOnCancel(new Action() {
                @Override
                public void run() throws Exception {
                    future.cancel(true);
                }
            });
            
            future.onComplete((res, e) -> {
               if (e != null) {
                   p.onError(e);
                   return;
               }
               
               if (res != null) {
                   p.onNext(res);
               }
               p.onComplete();
            });
        }
    });
}
 
Example #21
Source File: LWWRegisterTest.java    From wurmloch-crdt with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example #22
Source File: GoogleApiProcessor.java    From eternity with Apache License 2.0 4 votes vote down vote up
private GoogleApiProcessor(ReplayProcessor<GoogleApiProcessor.Event> processor) {
  this.processor = processor;
}
 
Example #23
Source File: RxJava2Proxies.java    From RHub with Apache License 2.0 4 votes vote down vote up
public static RxJava2ProcProxy replayProcessorProxy() {
    return new RxJava2ProcProxy(ReplayProcessor.create(), Roxy.TePolicy.PASS);
}
 
Example #24
Source File: RxJava2Proxies.java    From RHub with Apache License 2.0 4 votes vote down vote up
public static RxJava2ProcProxy serializedReplayProcessorProxy() {
    return new RxJava2ProcProxy(ReplayProcessor.create().toSerialized(), Roxy.TePolicy.PASS);
}
 
Example #25
Source File: RxJava2Proxies.java    From RHub with Apache License 2.0 4 votes vote down vote up
public static RxJava2ProcProxy safeReplayProcessorProxy() {
    return new RxJava2ProcProxy(ReplayProcessor.create(), Roxy.TePolicy.WRAP);
}
 
Example #26
Source File: RxJava2Proxies.java    From RHub with Apache License 2.0 4 votes vote down vote up
public static RxJava2ProcProxy safeSerializedReplayProcessorProxy() {
    return new RxJava2ProcProxy(ReplayProcessor.create().toSerialized(), Roxy.TePolicy.WRAP);
}
 
Example #27
Source File: RedissonKeysRx.java    From redisson with Apache License 2.0 4 votes vote down vote up
private Publisher<String> createKeysIterator(MasterSlaveEntry entry, String pattern, int count) {
    ReplayProcessor<String> p = ReplayProcessor.create();
    return p.doOnRequest(new LongConsumer() {

        private RedisClient client;
        private List<String> firstValues;
        private long nextIterPos;
        
        private long currentIndex;
        
        @Override
        public void accept(long value) {
            currentIndex = value;
            nextValues();
        }
        
        protected void nextValues() {
            instance.scanIteratorAsync(client, entry, nextIterPos, pattern, count).onComplete((res, e) -> {
                if (e != null) {
                    p.onError(e);
                    return;
                }
                
                client = res.getRedisClient();
                long prevIterPos = nextIterPos;
                if (nextIterPos == 0 && firstValues == null) {
                    firstValues = (List<String>) (Object) res.getValues();
                } else if (res.getValues().equals(firstValues)) {
                    p.onComplete();
                    currentIndex = 0;
                    return;
                }

                nextIterPos = res.getPos();
                if (prevIterPos == nextIterPos) {
                    nextIterPos = -1;
                }
                for (Object val : res.getValues()) {
                    p.onNext((String) val);
                    currentIndex--;
                    if (currentIndex == 0) {
                        p.onComplete();
                        return;
                    }
                }
                if (nextIterPos == -1) {
                    p.onComplete();
                    currentIndex = 0;
                }
                
                if (currentIndex == 0) {
                    return;
                }
                nextValues();
            });
        }
    });
}
 
Example #28
Source File: GoogleApiProcessor.java    From eternity with Apache License 2.0 4 votes vote down vote up
protected GoogleApiProcessor() {
  this(ReplayProcessor.create());
}
 
Example #29
Source File: SimpleCrdt.java    From wurmloch-crdt with Apache License 2.0 4 votes vote down vote up
SimpleCrdt(String nodeId, String crdtId) {
    super(nodeId, crdtId, ReplayProcessor.create());
}
 
Example #30
Source File: RGATest.java    From wurmloch-crdt with Apache License 2.0 4 votes vote down vote up
@Test
public void itShouldAddAndRemoveSingleElementConcurrently() {
    int i1 = 0;

    // given
    final Processor<RGA.RGACommand<String>, RGA.RGACommand<String>> inCommands1 = ReplayProcessor.create();
    final TestSubscriber<RGA.RGACommand<String>> outCommands1 = TestSubscriber.create();
    final RGA<String> rga1 = new RGA<>(NODE_ID_1, CRDT_ID);
    rga1.subscribeTo(inCommands1);
    rga1.subscribe(outCommands1);

    final Processor<RGA.RGACommand<String>, RGA.RGACommand<String>> inCommands2 = ReplayProcessor.create();
    final TestSubscriber<RGA.RGACommand<String>> outCommands2 = TestSubscriber.create();
    final RGA<String> rga2 = new RGA<>(NODE_ID_2, CRDT_ID);
    rga2.subscribeTo(inCommands2);
    rga2.subscribe(outCommands2);

    rga1.add("A");
    inCommands2.onNext(outCommands1.values().get(i1));
    int i2 = i1;

    // when
    rga1.remove(0);
    rga2.add(0, "B");
    inCommands2.onNext(outCommands1.values().get(++i1));
    inCommands1.onNext(outCommands2.values().get(++i2));

    // then
    assertThat(rga1, contains("B"));
    assertThat(rga2, contains("B"));

    // when
    rga1.remove(0);
    rga2.add(1, "C");
    inCommands2.onNext(outCommands1.values().get(i1 + 2));
    inCommands1.onNext(outCommands2.values().get(i2 + 2));

    // then
    assertThat(rga1, contains("C"));
    assertThat(rga2, contains("C"));
}