本文整理了Java中reactor.core.publisher.Mono.expand()
方法的一些代码示例,展示了Mono.expand()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.expand()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:expand
[英]Recursively expand elements into a graph and emit all the resulting element using a breadth-first traversal strategy.
That is: emit the value from this Mono first, then it each at a first level of recursion and emit all of the resulting values, then expand all of these at a second level and so on...
For example, given the hierarchical structure
A
- AA
- aa1
- AB
- ab1
- a1
Expands Mono.just(A) into
A
AA
AB
a1
aa1
ab1
[中]递归地将元素展开为一个图,并使用广度优先遍历策略发出所有生成的元素。
也就是说:首先从这个Mono中发出值,然后在递归的第一级对每个值进行处理,并发出所有结果值,然后在第二级展开所有这些值,以此类推。。。
例如,考虑到层次结构
A
- AA
- aa1
- AB
- ab1
- a1
扩展单声道。仅(A)进入<<1$>>
代码示例来源:origin: reactor/reactor-core
return expand(expander, Queues.SMALL_BUFFER_SIZE);
代码示例来源:origin: reactor/reactor-core
@Test
public void empty() {
StepVerifier.create(Mono.<Integer>empty()
.expand(countDown))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void expanderThrows() {
StepVerifier.create(Mono.just(10)
.expand(v -> {
throw new IllegalStateException("boom");
}))
.expectNext(10)
.verifyErrorMessage("boom");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void javadocExampleBreadthFirst() {
List<String> breadthFirstExpected = Arrays.asList(
"A",
"AA",
"AB",
"a1",
"aa1",
"ab1");
StepVerifier.create(
Mono.just(ROOT)
.expand(v -> Flux.fromIterable(v.children))
.map(n -> n.name))
.expectNextSequence(breadthFirstExpected)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void error() {
StepVerifier.create(Mono.<Integer>error(new IllegalStateException("boom"))
.expand(countDown))
.verifyErrorMessage("boom");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void recursiveCountdown() {
StepVerifier.create(Mono.just(10)
.expand(countDown))
.expectNext(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void expanderReturnsNull() {
StepVerifier.create(Mono.just(10)
.expand(v -> null))
.expectNext(10)
.verifyError(NullPointerException.class);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void recursiveCountdownTake() {
StepVerifier.create(Mono.just(10)
.expand(countDown)
.take(5)
)
.expectNext(10, 9, 8, 7, 6)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void recursiveCountdownLoop() {
for (int i = 0; i < 1000; i = (i < 100 ? i + 1 : i + 50)) {
String tag = "i = " + i + ", strategy = breadth";
List<Integer> list = new ArrayList<>();
StepVerifier.create(Mono.just(i)
.expand(countDown))
.expectSubscription()
.recordWith(() -> list)
.expectNextCount(i + 1)
.as(tag)
.verifyComplete();
for (int j = 0; j <= i; j++) {
assertThat(list.get(j).intValue())
.as(tag + ", " + list)
.isEqualTo(i - j);
}
}
}
代码示例来源:origin: reactor/reactor-core
@Test(timeout = 5000)
public void breadthFirst() {
FluxExpandTest.Node root = createTest();
StepVerifier.create(Mono.just(root)
.expand(v -> Flux.fromIterable(v.children))
.map(v -> v.name))
.expectNext(
"root",
"1", "2", "3", "4",
"11", "21", "22", "31", "32", "33", "41", "42", "43", "44",
"221", "321", "331", "332", "421", "431", "432", "441", "442", "443",
"3321", "4321", "4421", "4431", "4432"
)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void breadthFirstAsync() {
FluxExpandTest.Node root = createTest();
StepVerifier.create(Mono.just(root)
.expand(v -> Flux.fromIterable(v.children).subscribeOn(Schedulers.elastic()))
.map(v -> v.name))
.expectNext(
"root",
"1", "2", "3", "4",
"11", "21", "22", "31", "32", "33", "41", "42", "43", "44",
"221", "321", "331", "332", "421", "431", "432", "441", "442", "443",
"3321", "4321", "4421", "4431", "4432"
)
.expectComplete()
.verify(Duration.ofSeconds(5));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void recursiveCountdownBackpressure() {
StepVerifier.create(Mono.just(10)
.expand(countDown),
StepVerifierOptions.create()
.initialRequest(0)
.checkUnderRequesting(false))
.thenRequest(1)
.expectNext(10)
.thenRequest(3)
.expectNext(9, 8, 7)
.thenRequest(4)
.expectNext(6, 5, 4, 3)
.thenRequest(3)
.expectNext(2, 1, 0)
.verifyComplete();
}
代码示例来源:origin: io.projectreactor/reactor-core
return expand(expander, Queues.SMALL_BUFFER_SIZE);
内容来源于网络,如有侵权,请联系作者删除!