Package rx.schedulers

Examples of rx.schedulers.TestScheduler


        ts.assertReceivedOnNext(Arrays.asList("{\"false\":1}", "{\"false\":1}", "{\"true\":1}"));
    }

    @Test
    public void testStringValue_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 ((AggregateString) data.get("isCircuitBreakerOpen")).toJson();
            });
        }).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


        ts.assertReceivedOnNext(Arrays.asList("{\"false\":1}", "{\"false\":2}", "{\"false\":2}", "{\"false\":2}", "{\"false\":1,\"true\":1}", "{\"true\":2}"));
    }

    @Test
    public void testFields() {
        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 -> {
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                validateNumber(data, "reportingHosts");
                validateAggregateString(data, "type");
                validateString(data, "name");
                validateAggregateString(data, "group");
                validateNull(data, "currentTime");
                validateAggregateString(data, "isCircuitBreakerOpen");
                validateNumber(data, "errorPercentage");
                validateNumber(data, "errorCount");
                validateNumber(data, "requestCount");
                validateNumber(data, "rollingCountCollapsedRequests");
                validateNumber(data, "rollingCountExceptionsThrown");
                validateNumber(data, "rollingCountFailure");
                validateNumber(data, "rollingCountFallbackFailure");
                validateNumber(data, "rollingCountFallbackRejection");
                validateNumber(data, "rollingCountFallbackSuccess");
                validateNumber(data, "rollingCountResponsesFromCache");
                validateNumber(data, "rollingCountSemaphoreRejected");
                validateNumber(data, "rollingCountShortCircuited");
                validateNumber(data, "rollingCountSuccess");
                validateNumber(data, "rollingCountThreadPoolRejected");
                validateNumber(data, "rollingCountTimeout");
                validateNumber(data, "currentConcurrentExecutionCount");
                validateNumber(data, "latencyExecute_mean");
                validateNumberList(data, "latencyExecute");
                validateNumber(data, "latencyTotal_mean");
                validateNumberList(data, "latencyTotal");
                validateAggregateString(data, "propertyValue_circuitBreakerRequestVolumeThreshold");
                validateAggregateString(data, "propertyValue_circuitBreakerSleepWindowInMilliseconds");
                validateAggregateString(data, "propertyValue_circuitBreakerErrorThresholdPercentage");
                validateAggregateString(data, "propertyValue_circuitBreakerForceOpen");
                validateAggregateString(data, "propertyValue_executionIsolationStrategy");
                validateAggregateString(data, "propertyValue_executionIsolationThreadTimeoutInMilliseconds");
                validateAggregateString(data, "propertyValue_executionIsolationThreadInterruptOnTimeout");
                validateAggregateString(data, "propertyValue_executionIsolationSemaphoreMaxConcurrentRequests");
                validateAggregateString(data, "propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests");
                validateAggregateString(data, "propertyValue_requestCacheEnabled");
                validateAggregateString(data, "propertyValue_requestLogEnabled");
                validateAggregateString(data, "propertyValue_metricsRollingStatisticalWindowInMilliseconds");
                return data.get("name");
            });
        }).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

        ts.assertReceivedOnNext(Arrays.asList("CinematchGetPredictions", "CinematchGetPredictions", "CinematchGetPredictions", "CinematchGetPredictions", "CinematchGetPredictions", "CinematchGetPredictions"));
    }

    @Test
    public void testFieldReportingHosts() {
        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 -> {
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return data.get("reportingHosts");
            });
        }).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

        ts.assertReceivedOnNext(Arrays.asList(1L, 2L, 2L, 2L, 2L, 2L));
    }

    @Test
    public void testField_propertyValue_circuitBreakerForceOpen() {
        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 -> {
            numGroups.incrementAndGet();
            return commandGroup.map(data -> {
                return String.valueOf(data.get("propertyValue_circuitBreakerForceOpen"));
            });
        }).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

        ts.assertReceivedOnNext(Arrays.asList("AggregateString => false [1]", "AggregateString => false [2]", "AggregateString => false [2]", "AggregateString => false [2]", "AggregateString => false [2]", "AggregateString => false [2]"));
    }

    @Test
    public void testFieldOnStream() {
        TestScheduler scheduler = new TestScheduler();
        TestSubscriber<Object> ts = new TestSubscriber<>();
        // 20 events per instance, 10 per group
        // 80 events total
        GroupedObservable<InstanceKey, Map<String, Object>> hystrixStreamA = HystrixStreamSource.getHystrixStreamFromFileEachLineScheduledEvery10Milliseconds(HystrixStreamSource.STREAM_SUBSCRIBER_CINEMATCH_1, 12345, scheduler, 200);
        GroupedObservable<InstanceKey, Map<String, Object>> hystrixStreamB = HystrixStreamSource.getHystrixStreamFromFileEachLineScheduledEvery10Milliseconds(HystrixStreamSource.STREAM_SUBSCRIBER_CINEMATCH_1, 23456, scheduler, 200);
        GroupedObservable<InstanceKey, Map<String, Object>> hystrixStreamC = HystrixStreamSource.getHystrixStreamFromFileEachLineScheduledEvery10Milliseconds(HystrixStreamSource.STREAM_SUBSCRIBER_CINEMATCH_1, 67890, scheduler, 200);
        GroupedObservable<InstanceKey, Map<String, Object>> hystrixStreamD = HystrixStreamSource.getHystrixStreamFromFileEachLineScheduledEvery10Milliseconds(HystrixStreamSource.STREAM_SUBSCRIBER_CINEMATCH_1, 63543, scheduler, 200);

        Observable<GroupedObservable<InstanceKey, Map<String, Object>>> fullStream = Observable.just(hystrixStreamA, hystrixStreamB, hystrixStreamC, hystrixStreamD);
        StreamAggregator.aggregateGroupedStreams(fullStream).flatMap(commandGroup -> {
            System.out.println("======> Got group for command: " + commandGroup.getKey());
            return commandGroup;
        }).doOnNext(data -> {
            System.out.println("data => " + data.get("propertyValue_circuitBreakerForceOpen") + " " + data.get("name"));
        }).skip(8).doOnNext(v -> {
            // assert the count is always 4 (4 instances) on AggregateString values
                AggregateString as = (AggregateString) (v.get("propertyValue_circuitBreakerForceOpen"));
                if (!"AggregateString => false [4]".equals(as.toString())) {
                    // after the initial 1, 2, 3, 4 counting on each instance we should receive 4 always thereafter
                    // and we skip the first 8 to get past those
                    throw new IllegalStateException("Expect the count to always be 4");
                }
            }).subscribe(ts);

        scheduler.advanceTimeBy(200, 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.