本文整理了Java中reactor.core.publisher.Flux.as()
方法的一些代码示例,展示了Flux.as()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flux.as()
方法的具体详情如下:
包路径:reactor.core.publisher.Flux
类名称:Flux
方法名:as
[英]Transform this Flux into a target type.
flux.as(Mono::from).subscribe()
[中]将此通量转换为目标类型
flux.as(Mono::from).subscribe()
代码示例来源:origin: spring-projects/spring-framework
@Test
public void writeMultipleItems() throws Exception {
List<String> items = Arrays.asList("one", "two", "three");
Mono<Void> completion = Flux.fromIterable(items).as(this::sendOperator);
Signal<Void> signal = completion.materialize().block();
assertNotNull(signal);
assertTrue("Unexpected signal: " + signal, signal.isOnComplete());
assertEquals(3, this.writer.items.size());
assertEquals("one", this.writer.items.get(0));
assertEquals("two", this.writer.items.get(1));
assertEquals("three", this.writer.items.get(2));
assertTrue(this.writer.completed);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void writeOneItem() throws Exception {
Mono<Void> completion = Flux.just("one").as(this::sendOperator);
Signal<Void> signal = completion.materialize().block();
assertNotNull(signal);
assertTrue("Unexpected signal: " + signal, signal.isOnComplete());
assertEquals(1, this.writer.items.size());
assertEquals("one", this.writer.items.get(0));
assertTrue(this.writer.completed);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void completionBeforeFirstItem() throws Exception {
Mono<Void> completion = Flux.<String>empty().as(this::sendOperator);
Signal<Void> signal = completion.materialize().block();
assertNotNull(signal);
assertTrue("Unexpected signal: " + signal, signal.isOnComplete());
assertEquals(0, this.writer.items.size());
assertTrue(this.writer.completed);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void windowWhileIntentionallyEmptyWindows() {
Flux.just("ALPHA", "#", "BETA", "#", "#")
.windowWhile(s -> !"#".equals(s))
.flatMap(Flux::collectList)
.as(StepVerifier::create)
.assertNext(w -> assertThat(w).containsExactly("ALPHA"))
.assertNext(w -> assertThat(w).containsExactly("BETA"))
.assertNext(w -> assertThat(w).isEmpty())
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void windowUntilCutBeforeIntentionallyEmptyWindows() {
Flux.just("ALPHA", "#", "BETA", "#", "#")
.windowUntil("#"::equals, true)
.flatMap(Flux::collectList)
.as(StepVerifier::create)
.assertNext(w -> assertThat(w).containsExactly("ALPHA"))
.assertNext(w -> assertThat(w).containsExactly("#", "BETA"))
.assertNext(w -> assertThat(w).containsExactly("#"))
.assertNext(w -> assertThat(w).containsExactly("#"))
.verifyComplete();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void errorAfterMultipleItems() throws Exception {
IllegalStateException error = new IllegalStateException("boo");
Flux<String> publisher = Flux.generate(() -> 0, (idx , subscriber) -> {
int i = ++idx;
subscriber.next(String.valueOf(i));
if (i == 3) {
subscriber.error(error);
}
return i;
});
Mono<Void> completion = publisher.as(this::sendOperator);
Signal<Void> signal = completion.materialize().block();
assertNotNull(signal);
assertSame("Unexpected signal: " + signal, error, signal.getThrowable());
assertEquals(3, this.writer.items.size());
assertEquals("1", this.writer.items.get(0));
assertEquals("2", this.writer.items.get(1));
assertEquals("3", this.writer.items.get(2));
assertSame(error, this.writer.error);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void windowWhileNoEmptyWindows() {
Flux.just("ALPHA", "#", "BETA", "#")
.windowWhile(s -> !"#".equals(s))
.flatMap(Flux::collectList)
.as(StepVerifier::create)
.assertNext(w -> assertThat(w).containsExactly("ALPHA"))
.assertNext(w -> assertThat(w).containsExactly("BETA"))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void windowUntilCutBeforeNoEmptyWindows() {
Flux.just("ALPHA", "#", "BETA", "#")
.windowUntil("#"::equals, true)
.flatMap(Flux::collectList)
.as(StepVerifier::create)
.assertNext(w -> assertThat(w).containsExactly("ALPHA"))
.assertNext(w -> assertThat(w).containsExactly("#", "BETA"))
.assertNext(w -> assertThat(w).containsExactly("#"))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void windowUntilIntentionallyEmptyWindows() {
Flux.just("ALPHA", "#", "BETA", "#", "#")
.windowUntil("#"::equals)
.flatMap(Flux::collectList)
.as(StepVerifier::create)
.assertNext(w -> assertThat(w).containsExactly("ALPHA", "#"))
.assertNext(w -> assertThat(w).containsExactly("BETA", "#"))
.assertNext(w -> assertThat(w).containsExactly("#"))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void windowUntilNoEmptyWindows() {
Flux.just("ALPHA", "#", "BETA", "#")
.windowUntil("#"::equals)
.flatMap(Flux::collectList)
.as(StepVerifier::create)
.assertNext(w -> assertThat(w).containsExactly("ALPHA", "#"))
.assertNext(w -> assertThat(w).containsExactly("BETA", "#"))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void monoDirect() {
StepVerifier.create(Flux.just(1).as(Mono::fromDirect))
.expectNext(1)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void asJustNext() {
StepVerifier.create(Flux.just(1, 2, 3).as(Mono::from))
.expectNext(1)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked") //safe varargs
public void take() {
new FluxMergeOrdered<>(2, Queues.small(), Comparator.naturalOrder(),
Flux.just(1, 3, 5, 7), Flux.just(2, 4, 6, 8))
.take(5)
.as(StepVerifier::create)
.expectNext(1, 2, 3, 4, 5)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked") //safe varargs
public void backpressure1() {
new FluxMergeOrdered<>(2, Queues.small(), Comparator.naturalOrder(),
Flux.just(1, 3, 5, 7), Flux.just(2, 4, 6, 8))
.limitRate(1)
.as(StepVerifier::create)
.expectNext(1, 2, 3, 4, 5, 6, 7, 8)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked") //safe varargs
public void backpressure3() {
new FluxMergeOrdered<>(1, Queues.small(), Comparator.naturalOrder(),
Flux.just(1, 3, 5, 7), Flux.just(2, 4, 6, 8))
.limitRate(1)
.as(StepVerifier::create)
.expectNext(1, 2, 3, 4, 5, 6, 7, 8)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked") //safe varargs
public void backpressure2() {
new FluxMergeOrdered<>(2, Queues.small(), Comparator.naturalOrder(),
Flux.just(1), Flux.just(2))
.limitRate(1)
.as(StepVerifier::create)
.expectNext(1, 2)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void monoDirectHidden() {
StepVerifier.create(Flux.just(1).hide().as(Mono::fromDirect))
.expectNext(1)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
final StepVerifier.Step<O> inputFusedSyncErrorOutputFusedSync(OperatorScenario<I, PI, O, PO> scenario) {
return StepVerifier.create(scenario.body()
.apply(Flux.just(item(0), item(1))
.as(f -> withFluxSource(new FluxFuseableExceptionOnPoll<>(
f,
exception())))))
.expectFusion(scenario.fusionMode() & SYNC);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void prematureCompleteFusedSync() {
StepVerifier.create(Flux.just("test")
.as(this::passThrough)
.filter(t -> true))
.expectFusion(Fuseable.SYNC)
.expectNext("test")
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void handleBackpressuredBothConditional() {
TestPublisher<String> ts = TestPublisher.create();
StepVerifier.create(ts.flux()
.as(this::filterTest2), 0)
.thenRequest(2)
.then(() -> ts.next("test0", "test1"))
.expectNext("test0", "test1")
.thenRequest(1)
.then(() -> ts.next("test2"))
.expectNext("test2")
.verifyComplete();
}
内容来源于网络,如有侵权,请联系作者删除!