Java Code Examples for reactor.core.Scannable#scan()

The following examples show how to use reactor.core.Scannable#scan() . 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: FluxPublishOnTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void scanRunOn() {
	Scannable publishOnScannable = Scannable.from(
			Flux.just(1).hide()
			    .publishOn(Schedulers.boundedElastic())
	);
	Scannable runOnScannable = publishOnScannable.scan(Scannable.Attr.RUN_ON);

	assertThat(runOnScannable).isNotNull()
	                          .matches(Scannable::isScanAvailable, "isScanAvailable");

	System.out.println(runOnScannable + " isScannable " + runOnScannable.isScanAvailable());
	System.out.println(runOnScannable.scan(Scannable.Attr.NAME));
	runOnScannable.parents().forEach(System.out::println);
	System.out.println(runOnScannable.scan(Scannable.Attr.BUFFERED));
}
 
Example 2
Source File: BaseOperatorTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
final void touchInner(@Nullable Object t){
	if(t == null) return;
	Scannable o = Scannable.from(t);
	o.scan(Attr.ACTUAL);
	o.scan(Attr.BUFFERED);
	o.scan(Attr.CANCELLED);
	o.scan(Attr.CAPACITY);
	o.scan(Attr.DELAY_ERROR);
	o.scan(Attr.ERROR);
	o.scan(Attr.PREFETCH);
	o.scan(Attr.PARENT);
	o.scan(Attr.REQUESTED_FROM_DOWNSTREAM);
	o.scan(Attr.TERMINATED);
	o.inners();
}
 
Example 3
Source File: OnDiscardShouldNotLeakTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Test
public void ensureNoLeaksPopulatedQueueAndRacingCancelAndOnNext() {
	Assumptions.assumeThat(discardScenario.subscriptionsNumber).isOne();
	for (int i = 0; i < 10000; i++) {
		tracker.reset();
		TestPublisher<Tracked> testPublisher = TestPublisher.createNoncompliant(
				TestPublisher.Violation.DEFER_CANCELLATION,
				TestPublisher.Violation.REQUEST_OVERFLOW);
		Publisher<Tracked> source = discardScenario.producePublisherFromSources(testPublisher);

		if (conditional) {
			if (source instanceof Flux) {
				source = ((Flux<Tracked>) source).filter(t -> true);
			}
			else {
				source = ((Mono<Tracked>) source).filter(t -> true);
			}
		}

		Scannable scannable = Scannable.from(source);
		Integer prefetch = scannable.scan(Scannable.Attr.PREFETCH);

		Assumptions.assumeThat(prefetch).isNotZero();

		AssertSubscriber<Tracked> assertSubscriber = new AssertSubscriber<>(Operators.enableOnDiscard(null, Tracked::safeRelease), 0);
		if (fused) {
			assertSubscriber.requestedFusionMode(Fuseable.ANY);
		}
		source.subscribe(assertSubscriber);

		testPublisher.next(tracker.track(1));
		testPublisher.next(tracker.track(2));

		Tracked value3 = tracker.track(3);
		Tracked value4 = tracker.track(4);
		Tracked value5 = tracker.track(5);

		RaceTestUtils.race(assertSubscriber::cancel, () -> {
			testPublisher.next(value3);
			testPublisher.next(value4);
			testPublisher.next(value5);
		}, scheduler);

		List<Tracked> values = assertSubscriber.values();
		values.forEach(Tracked::release);

		tracker.assertNoLeaks();
	}
}
 
Example 4
Source File: OnDiscardShouldNotLeakTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Test
public void ensureNoLeaksPopulatedQueueAndRacingCancelAndOnComplete() {
	Assumptions.assumeThat(discardScenario.subscriptionsNumber).isOne();
	for (int i = 0; i < 10000; i++) {
		tracker.reset();
		TestPublisher<Tracked> testPublisher = TestPublisher.createNoncompliant(
				TestPublisher.Violation.DEFER_CANCELLATION,
				TestPublisher.Violation.REQUEST_OVERFLOW);
		Publisher<Tracked> source = discardScenario.producePublisherFromSources(testPublisher);

		if (conditional) {
			if (source instanceof Flux) {
				source = ((Flux<Tracked>) source).filter(t -> true);
			}
			else {
				source = ((Mono<Tracked>) source).filter(t -> true);
			}
		}

		Scannable scannable = Scannable.from(source);
		Integer prefetch = scannable.scan(Scannable.Attr.PREFETCH);

		Assumptions.assumeThat(prefetch).isNotZero();

		AssertSubscriber<Tracked> assertSubscriber = new AssertSubscriber<>(Operators.enableOnDiscard(null, Tracked::safeRelease), 0);
		if (fused) {
			assertSubscriber.requestedFusionMode(Fuseable.ANY);
		}
		source.subscribe(assertSubscriber);

		testPublisher.next(tracker.track(1));
		testPublisher.next(tracker.track(2));
		testPublisher.next(tracker.track(3));
		testPublisher.next(tracker.track(4));

		RaceTestUtils.race(
				assertSubscriber::cancel,
				() -> testPublisher.complete(),
				scheduler);

		List<Tracked> values = assertSubscriber.values();
		values.forEach(Tracked::release);

		tracker.assertNoLeaks();
	}
}
 
Example 5
Source File: OnDiscardShouldNotLeakTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Test
public void ensureNoLeaksPopulatedQueueAndRacingCancelAndOnError() {
	Assumptions.assumeThat(discardScenario.subscriptionsNumber).isOne();
	for (int i = 0; i < 10000; i++) {
		tracker.reset();
		TestPublisher<Tracked> testPublisher = TestPublisher.createNoncompliant(
				TestPublisher.Violation.DEFER_CANCELLATION,
				TestPublisher.Violation.REQUEST_OVERFLOW);
		@SuppressWarnings("unchecked")
		Publisher<Tracked> source = discardScenario.producePublisherFromSources(testPublisher);

		if (conditional) {
			if (source instanceof Flux) {
				source = ((Flux<Tracked>) source).filter(t -> true);
			}
			else {
				source = ((Mono<Tracked>) source).filter(t -> true);
			}
		}

		Scannable scannable = Scannable.from(source);
		Integer prefetch = scannable.scan(Scannable.Attr.PREFETCH);

		Assumptions.assumeThat(prefetch).isNotZero();

		AssertSubscriber<Tracked> assertSubscriber = new AssertSubscriber<>(Operators.enableOnDiscard(null, Tracked::safeRelease), 0);
		if (fused) {
			assertSubscriber.requestedFusionMode(Fuseable.ANY);
		}
		source.subscribe(assertSubscriber);

		testPublisher.next(tracker.track(1));
		testPublisher.next(tracker.track(2));
		testPublisher.next(tracker.track(3));
		testPublisher.next(tracker.track(4));

		RaceTestUtils.race(
				assertSubscriber::cancel,
				() -> testPublisher.error(new RuntimeException("test")),
				scheduler);

		List<Tracked> values = assertSubscriber.values();
		values.forEach(Tracked::release);
		if (assertSubscriber.isTerminated()) {
			// has a chance to error with rejected exception
			assertSubscriber.assertError();
		}

		tracker.assertNoLeaks();
	}
}
 
Example 6
Source File: OnDiscardShouldNotLeakTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Test
public void ensureNoLeaksPopulatedQueueAndRacingCancelAndOverflowError() {
	Assumptions.assumeThat(discardScenario.subscriptionsNumber).isOne();
	for (int i = 0; i < 10000; i++) {
		tracker.reset();
		TestPublisher<Tracked> testPublisher = TestPublisher.createNoncompliant(
				TestPublisher.Violation.DEFER_CANCELLATION,
				TestPublisher.Violation.REQUEST_OVERFLOW);
		@SuppressWarnings("unchecked")
		Publisher<Tracked> source = discardScenario.producePublisherFromSources(testPublisher);

		if (conditional) {
			if (source instanceof Flux) {
				source = ((Flux<Tracked>) source).filter(t -> true);
			}
			else {
				source = ((Mono<Tracked>) source).filter(t -> true);
			}
		}

		Scannable scannable = Scannable.from(source);
		Integer capacity = scannable.scan(Scannable.Attr.CAPACITY);
		Integer prefetch = Math.min(scannable.scan(Scannable.Attr.PREFETCH),
				capacity == 0 ? Integer.MAX_VALUE : capacity);

		Assumptions.assumeThat(prefetch).isNotZero();
		Assumptions.assumeThat(prefetch).isNotEqualTo(Integer.MAX_VALUE);
		AssertSubscriber<Tracked> assertSubscriber = new AssertSubscriber<>(Operators.enableOnDiscard(null, Tracked::safeRelease), 0);
		if (fused) {
			assertSubscriber.requestedFusionMode(Fuseable.ANY);
		}
		source.subscribe(assertSubscriber);

		for (int j = 0; j < prefetch - 1; j++) {
			testPublisher.next(tracker.track(j));
		}

		Tracked lastValue = tracker.track(prefetch - 1);
		Tracked overflowValue1 = tracker.track(prefetch);
		Tracked overflowValue2 = tracker.track(prefetch + 1);

		RaceTestUtils.race(assertSubscriber::cancel, () -> {
			testPublisher.next(lastValue);
			testPublisher.next(overflowValue1);
			testPublisher.next(overflowValue2);
		});

		List<Tracked> values = assertSubscriber.values();
		values.forEach(Tracked::release);
		if (assertSubscriber.isTerminated()) {
			// has a chance to error with rejected exception
			assertSubscriber.assertError();
		}

		tracker.assertNoLeaks();
	}
}
 
Example 7
Source File: OnDiscardShouldNotLeakTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Test
public void ensureNoLeaksPopulatedQueueAndRacingCancelAndRequest() {
	Assumptions.assumeThat(discardScenario.subscriptionsNumber).isOne();
	for (int i = 0; i < 10000; i++) {
		tracker.reset();
		TestPublisher<Tracked> testPublisher = TestPublisher.createNoncompliant(
				TestPublisher.Violation.DEFER_CANCELLATION,
				TestPublisher.Violation.REQUEST_OVERFLOW);
		@SuppressWarnings("unchecked")
		Publisher<Tracked> source = discardScenario.producePublisherFromSources(testPublisher);

		if (conditional) {
			if (source instanceof Flux) {
				source = ((Flux<Tracked>) source).filter(t -> true);
			}
			else {
				source = ((Mono<Tracked>) source).filter(t -> true);
			}
		}

		Scannable scannable = Scannable.from(source);
		Integer prefetch = scannable.scan(Scannable.Attr.PREFETCH);

		Assumptions.assumeThat(prefetch).isNotZero();

		AssertSubscriber<Tracked> assertSubscriber = new AssertSubscriber<>(Operators.enableOnDiscard(null, Tracked::safeRelease), 0);
		if (fused) {
			assertSubscriber.requestedFusionMode(Fuseable.ANY);
		}
		source.subscribe(assertSubscriber);

		testPublisher.next(tracker.track(1));
		testPublisher.next(tracker.track(2));
		testPublisher.next(tracker.track(3));
		testPublisher.next(tracker.track(4));

		RaceTestUtils.race(
				assertSubscriber::cancel,
				() -> assertSubscriber.request(Long.MAX_VALUE),
				scheduler);

		List<Tracked> values = assertSubscriber.values();
		values.forEach(Tracked::release);

		tracker.assertNoLeaks();
	}
}