本文整理了Java中reactor.core.publisher.Mono.hasElement()
方法的一些代码示例,展示了Mono.hasElement()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.hasElement()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:hasElement
[英]Emit a single boolean true if this Mono has an element.
[中]如果此Mono有元素,则发出一个布尔值true。
代码示例来源:origin: reactor/reactor-core
@Test
public void hasElementCancel() throws InterruptedException {
AtomicBoolean cancelled = new AtomicBoolean();
Mono.just("foo").hide()
.doOnCancel(() -> cancelled.set(true))
.log()
.hasElement()
.subscribe(v -> {}, e -> {}, () -> {},
Subscription::cancel);
assertThat(cancelled.get()).isTrue();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testHasElementUpstream() throws InterruptedException {
AtomicReference<Subscription> sub = new AtomicReference<>();
Mono.just("foo").hide()
.hasElement()
.subscribe(v -> {}, e -> {}, () -> {},
s -> {
sub.set(s);
s.request(Long.MAX_VALUE);
});
assertThat(sub.get()).isInstanceOf(MonoHasElement.HasElementSubscriber.class);
assertThat(Scannable.from(sub.get()).scan(Scannable.Attr.PARENT).getClass()).isEqualTo(FluxHide.HideSubscriber.class);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void monoSourceIsNotCancelled() {
AtomicLong cancelCount = new AtomicLong();
StepVerifier.create(Mono.just(1)
.doOnCancel(cancelCount::incrementAndGet)
.hasElement())
.expectNext(true)
.verifyComplete();
assertThat(cancelCount.get()).isEqualTo(0);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void emptyMonoSource() {
AssertSubscriber<Boolean> ts = AssertSubscriber.create();
Mono.empty().hasElement().subscribe(ts);
ts.assertValues(false)
.assertComplete()
.assertNoError();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void emptySourceBackpressured() {
AssertSubscriber<Boolean> ts = AssertSubscriber.create(0);
Mono.empty().hasElement().subscribe(ts);
ts.assertNoValues()
.assertNotComplete()
.assertNoError();
ts.request(1);
ts.assertValues(false)
.assertComplete()
.assertNoError();
}
代码示例来源:origin: com.aol.cyclops/cyclops-reactor
/**
* @return
* @see reactor.core.publisher.Mono#hasElement()
*/
public final Mono<Boolean> hasElement() {
return boxed.hasElement();
}
/**
代码示例来源:origin: apache/james-project
public Mono<Boolean> executeReturnExists(Statement statement) {
return executeSingleRowReactor(statement)
.hasElement();
}
}
代码示例来源:origin: spring-projects/spring-data-r2dbc
@Override
public Mono<Boolean> existsById(Publisher<ID> publisher) {
return Mono.from(publisher).flatMap(this::findById).hasElement();
}
代码示例来源:origin: org.springframework.data/spring-data-r2dbc
@Override
public Mono<Boolean> existsById(Publisher<ID> publisher) {
return Mono.from(publisher).flatMap(this::findById).hasElement();
}
代码示例来源:origin: apache/james-project
@Test
void shouldExecuteTheRunnableAndReturnEmpty() {
Counter counter = new Counter(1);
Mono<?> reactor = Mono.empty()
.switchIfEmpty(ReactorUtils.executeAndEmpty(() -> counter.increment(2)))
.map(FunctionalUtils.toFunction(any -> counter.increment(4)));
assertThat(reactor.hasElement().block()).isFalse();
assertThat(counter.getCounter()).isEqualTo(3);
}
代码示例来源:origin: apache/james-project
@Test
void shouldNotExecuteTheRunnableAndReturnTheValue() {
Counter counter = new Counter(1);
Mono<?> reactor = Mono.just(42)
.switchIfEmpty(ReactorUtils.executeAndEmpty(() -> counter.increment(2)))
.map(FunctionalUtils.toFunction(any -> counter.increment(4)));
assertThat(reactor.hasElement().block()).isTrue();
assertThat(counter.getCounter()).isEqualTo(5);
}
代码示例来源:origin: org.springframework.data/spring-data-r2dbc
@Override
public Mono<Boolean> existsById(ID id) {
Assert.notNull(id, "Id must not be null!");
String idColumnName = getIdColumnName();
BindIdOperation select = accessStrategy.selectById(entity.getTableName(), Collections.singleton(idColumnName),
idColumnName, 10);
GenericExecuteSpec sql = databaseClient.execute().sql(select);
BindSpecAdapter<GenericExecuteSpec> wrapper = BindSpecAdapter.create(sql);
select.bindId(wrapper, id);
return wrapper.getBoundOperation().as(entity.getJavaType()) //
.map((r, md) -> r) //
.first() //
.hasElement();
}
代码示例来源:origin: spring-projects/spring-data-r2dbc
@Override
public Mono<Boolean> existsById(ID id) {
Assert.notNull(id, "Id must not be null!");
String idColumnName = getIdColumnName();
BindIdOperation select = accessStrategy.selectById(entity.getTableName(), Collections.singleton(idColumnName),
idColumnName, 10);
GenericExecuteSpec sql = databaseClient.execute().sql(select);
BindSpecAdapter<GenericExecuteSpec> wrapper = BindSpecAdapter.create(sql);
select.bindId(wrapper, id);
return wrapper.getBoundOperation().as(entity.getJavaType()) //
.map((r, md) -> r) //
.first() //
.hasElement();
}
内容来源于网络,如有侵权,请联系作者删除!