Package rx.schedulers

Examples of rx.schedulers.TestScheduler


*/
public class UnicastContentSubjectTest {

    @Test(expected = IllegalStateException.class)
    public void testNoSubscriptions() throws Exception {
        TestScheduler testScheduler = Schedulers.test();
        UnicastContentSubject<String> subject = UnicastContentSubject.create(1, TimeUnit.DAYS, testScheduler);
        subject.onNext("Start the timeout now."); // Since the timeout is scheduled only after content arrival.
        testScheduler.advanceTimeBy(1, TimeUnit.DAYS);
        subject.toBlocking().last(); // Should immediately throw an error.
    }
View Full Code Here


        subject.toBlocking().last(); // Should immediately throw an error.
    }

    @Test(expected = IllegalStateException.class)
    public void testNoSubscriptionsWithOnUnsubscribeAction() throws Exception {
        TestScheduler testScheduler = Schedulers.test();
        OnUnsubscribeAction onUnsub = new OnUnsubscribeAction();
        UnicastContentSubject<String> subject = UnicastContentSubject.create(1, TimeUnit.DAYS, testScheduler,
                                                                             onUnsub);
        subject.onNext("Start the timeout now."); // Since the timeout is scheduled only after content arrival.
        testScheduler.advanceTimeBy(1, TimeUnit.DAYS);
        Assert.assertTrue("On unsubscribe action not called on dispose.", onUnsub.isCalled());
        subject.toBlocking().last(); // Should immediately throw an error.
    }
View Full Code Here

        subject.toBlocking().last();
    }

    @Test
    public void testNoTimeoutPostSubscription() throws Exception {
        TestScheduler testScheduler = Schedulers.test();
        UnicastContentSubject<String> subject = UnicastContentSubject.create(1, TimeUnit.DAYS, testScheduler);
        subject.onNext("Start the timeout now."); // Since the timeout is scheduled only after content arrival.
        final AtomicReference<Throwable> errorOnSubscribe = new AtomicReference<Throwable>();
        final CountDownLatch latch = new CountDownLatch(1);
        subject.subscribe(Actions.empty(), new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                errorOnSubscribe.set(throwable);
                latch.countDown();
            }
        }, new Action0() {
            @Override
            public void call() {
                latch.countDown();
            }
        });

        testScheduler.advanceTimeBy(1, TimeUnit.DAYS);
        subject.onCompleted();

        latch.await(1, TimeUnit.MINUTES);

        Assert.assertNull("Subscription got an error.", errorOnSubscribe.get());
View Full Code Here

     *
     * The inner values need to be summed.
     */
    @Test
    public void testArrayMapValue_OneInstanceOneGroup() {
        TestScheduler scheduler = new TestScheduler();
        TestSubject<GroupedObservable<InstanceKey, Map<String, Object>>> stream = TestSubject.create(scheduler);

        AtomicInteger numGroups = new AtomicInteger();
        TestSubscriber<Object> ts = new TestSubscriber<>();

        StreamAggregator.aggregateGroupedStreams(stream).flatMap(commandGroup -> {
            System.out.println("======> Got group for command: " + commandGroup.getKey());
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return ((NumberList) data.get("latencyTotal")).toJson();
            });
        }).subscribe(ts);

        stream.onNext(getCinematchCommandInstanceStream(12345, scheduler), 5);
        stream.onCompleted(100);

        scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

        ts.awaitTerminalEvent();

        System.out.println("---------> OnErrorEvents: " + ts.getOnErrorEvents());
        if (ts.getOnErrorEvents().size() > 0) {
View Full Code Here

     *
     * The inner values need to be summed.
     */
    @Test
    public void testArrayMapValue_TwoInstanceOneGroup() {
        TestScheduler scheduler = new TestScheduler();
        TestSubject<GroupedObservable<InstanceKey, Map<String, Object>>> stream = TestSubject.create(scheduler);

        AtomicInteger numGroups = new AtomicInteger();
        TestSubscriber<Object> ts = new TestSubscriber<>();

        StreamAggregator.aggregateGroupedStreams(stream).flatMap(commandGroup -> {
            System.out.println("======> Got group for command: " + commandGroup.getKey());
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return ((NumberList) data.get("latencyTotal")).toJson();
            });
        }).subscribe(ts);

        stream.onNext(getCinematchCommandInstanceStream(12345, scheduler), 0);
        stream.onNext(getCinematchCommandInstanceStream(23456, scheduler), 5);
        stream.onCompleted(100);

        scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

        ts.awaitTerminalEvent();

        System.out.println("---------> OnErrorEvents: " + ts.getOnErrorEvents());
        if (ts.getOnErrorEvents().size() > 0) {
View Full Code Here

     *
     * We should receive a GroupedObservable of key "CinematchGetPredictions" with deltas => 327, 43, -12
     */
    @Test
    public void testNumberValue_OneInstanceOneGroup() {
        TestScheduler scheduler = new TestScheduler();
        TestSubject<GroupedObservable<InstanceKey, Map<String, Object>>> stream = TestSubject.create(scheduler);

        AtomicInteger numGroups = new AtomicInteger();
        TestSubscriber<Object> ts = new TestSubscriber<>();

        StreamAggregator.aggregateGroupedStreams(stream).flatMap(commandGroup -> {
            System.out.println("======> Got group for command: " + commandGroup.getKey());
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return data.get("rollingCountSuccess");
            });
        }).subscribe(ts);

        stream.onNext(getCinematchCommandInstanceStream(12345, scheduler), 5);
        stream.onCompleted(100);

        scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

        ts.awaitTerminalEvent();

        System.out.println("---------> OnErrorEvents: " + ts.getOnErrorEvents());
        if (ts.getOnErrorEvents().size() > 0) {
View Full Code Here

     *
     *
     */
    @Test
    public void testNumberValue_OneInstanceTwoGroups() {
        TestScheduler scheduler = new TestScheduler();
        TestSubject<GroupedObservable<InstanceKey, Map<String, Object>>> stream = TestSubject.create(scheduler);

        AtomicInteger numGroups = new AtomicInteger();
        TestSubscriber<Object> ts = new TestSubscriber<>();

        StreamAggregator.aggregateGroupedStreams(stream).flatMap(commandGroup -> {
            System.out.println("======> Got group for command: " + commandGroup.getKey());
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return data.get("rollingCountSuccess");
            });
        }).subscribe(ts);

        stream.onNext(getSubscriberAndCinematchCommandInstanceStream(12345, scheduler), 0);
        stream.onCompleted(100);

        scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

        ts.awaitTerminalEvent();

        System.out.println("---------> OnErrorEvents: " + ts.getOnErrorEvents());
        if (ts.getOnErrorEvents().size() > 0) {
View Full Code Here

     * 728 - 12 = 716
     *
     */
    @Test
    public void testNumberValue_TwoInstancesOneGroup() {
        TestScheduler scheduler = new TestScheduler();
        TestSubject<GroupedObservable<InstanceKey, Map<String, Object>>> stream = TestSubject.create(scheduler);

        AtomicInteger numGroups = new AtomicInteger();
        TestSubscriber<Object> ts = new TestSubscriber<>();

        StreamAggregator.aggregateGroupedStreams(stream).flatMap(commandGroup -> {
            System.out.println("======> Got group for command: " + commandGroup.getKey());
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return data.get("rollingCountSuccess");
            });
        }).subscribe(ts);

        stream.onNext(getCinematchCommandInstanceStream(12345, scheduler), 0);
        stream.onNext(getCinematchCommandInstanceStream(23456, scheduler), 0);
        stream.onCompleted(100);

        scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

        ts.awaitTerminalEvent();

        System.out.println("---------> OnErrorEvents: " + ts.getOnErrorEvents());
        if (ts.getOnErrorEvents().size() > 0) {
View Full Code Here

     * 327, 654, 617, 1234, 697, 740, 1231, 1228, 728, 716, 1199, 1170
     *
     */
    @Test
    public void testNumberValue_TwoInstancesTwoGroups() {
        TestScheduler scheduler = new TestScheduler();
        TestSubject<GroupedObservable<InstanceKey, Map<String, Object>>> stream = TestSubject.create(scheduler);

        AtomicInteger numGroups = new AtomicInteger();
        TestSubscriber<Object> ts = new TestSubscriber<>();

        StreamAggregator.aggregateGroupedStreams(stream).flatMap(commandGroup -> {
            System.out.println("======> Got group for command: " + commandGroup.getKey());
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return data.get("rollingCountSuccess");
            });
        }).subscribe(ts);

        stream.onNext(getSubscriberAndCinematchCommandInstanceStream(12345, scheduler), 0);
        stream.onNext(getSubscriberAndCinematchCommandInstanceStream(23456, scheduler), 5);
        stream.onCompleted(100);

        scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

        ts.awaitTerminalEvent();

        System.out.println("---------> OnErrorEvents: " + ts.getOnErrorEvents());
        if (ts.getOnErrorEvents().size() > 0) {
View Full Code Here

        ts.assertReceivedOnNext(Arrays.asList(327L, 654L, 617L, 1234L, 697L, 740L, 1231L, 1228L, 728L, 716L, 1199L, 1170L));
    }

    @Test
    public void testStringValue_OneInstanceOneGroup() {
        TestScheduler scheduler = new TestScheduler();
        TestSubject<GroupedObservable<InstanceKey, Map<String, Object>>> stream = TestSubject.create(scheduler);

        AtomicInteger numGroups = new AtomicInteger();
        TestSubscriber<Object> ts = new TestSubscriber<>();

        StreamAggregator.aggregateGroupedStreams(stream).flatMap(commandGroup -> {
            System.out.println("======> Got group for command: " + commandGroup.getKey());
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return ((AggregateString) data.get("isCircuitBreakerOpen")).toJson();
            });
        }).subscribe(ts);

        stream.onNext(getCinematchCommandInstanceStream(12345, scheduler), 5);
        stream.onCompleted(100);

        scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

        ts.awaitTerminalEvent();

        System.out.println("---------> OnErrorEvents: " + ts.getOnErrorEvents());
        if (ts.getOnErrorEvents().size() > 0) {
View Full Code Here

TOP

Related Classes of rx.schedulers.TestScheduler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.