reactor.core.publisher.Flux.hasElements()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(287)

本文整理了Java中reactor.core.publisher.Flux.hasElements()方法的一些代码示例,展示了Flux.hasElements()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flux.hasElements()方法的具体详情如下:
包路径:reactor.core.publisher.Flux
类名称:Flux
方法名:hasElements

Flux.hasElements介绍

[英]Emit a single boolean true if this Flux sequence has at least one element.

The implementation uses short-circuit logic and completes with true on onNext.
[中]如果此通量序列至少有一个元素,则发出一个布尔值true。
该实现使用短路逻辑,并在onNext上以true完成。

代码示例

代码示例来源:origin: spring-projects/spring-data-mongodb

public Mono<Boolean> exists(Query query, @Nullable Class<?> entityClass, String collectionName) {
  if (query == null) {
    throw new InvalidDataAccessApiUsageException("Query passed in to exist can't be null");
  }
  return createFlux(collectionName, collection -> {
    Document filter = queryMapper.getMappedObject(query.getQueryObject(), getPersistentEntity(entityClass));
    FindPublisher<Document> findPublisher = collection.find(filter, Document.class)
        .projection(new Document("_id", 1));
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("exists: {} in collection: {}", serializeToJsonSafely(filter), collectionName);
    }
    findPublisher = query.getCollation().map(Collation::toMongoCollation).map(findPublisher::collation)
        .orElse(findPublisher);
    return findPublisher.limit(1);
  }).hasElements();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void hasElementsCancel() throws InterruptedException {
  AtomicBoolean cancelled = new AtomicBoolean();
  Flux.just("foo", "bar").hide()
    .doOnCancel(() -> cancelled.set(true))
    .hasElements()
    .subscribe(v -> {}, e -> {}, () -> {},
        Subscription::cancel);
  assertThat(cancelled.get()).isTrue();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void fluxSourceIsCancelled() {
  AtomicLong cancelCount = new AtomicLong();
  StepVerifier.create(Flux.range(1, 10)
              .doOnCancel(cancelCount::incrementAndGet)
              .hasElements())
        .expectNext(true)
        .verifyComplete();
  assertThat(cancelCount.get()).isEqualTo(1);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void testHasElementsUpstream() throws InterruptedException {
  AtomicReference<Subscription> sub = new AtomicReference<>();
  Flux.just("foo", "bar").hide()
    .hasElements()
    .subscribe(v -> {}, e -> {}, () -> {},
        s -> {
          sub.set(s);
          s.request(Long.MAX_VALUE);
        });
  assertThat(sub.get()).isInstanceOf(MonoHasElements.HasElementsSubscriber.class);
  Scannable.from(sub.get())
       .parents()
       .findFirst()
       .ifPresent(s -> assertThat(s).isInstanceOf(FluxHide.HideSubscriber
           .class));
}

代码示例来源:origin: reactor/reactor-core

@Test
public void emptySource() {
  AssertSubscriber<Boolean> ts = AssertSubscriber.create();
  Flux.empty().hasElements().subscribe(ts);
  ts.assertValues(false)
   .assertComplete()
   .assertNoError();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void nonEmptySource() {
  AssertSubscriber<Boolean> ts = AssertSubscriber.create();
  Flux.range(1, 10).hasElements().subscribe(ts);
  ts.assertValues(true)
   .assertComplete()
   .assertNoError();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void nonEmptySourceBackpressured() {
  AssertSubscriber<Boolean> ts = AssertSubscriber.create(0);
  Flux.range(1, 10).hasElements().subscribe(ts);
  ts.assertNoValues()
   .assertNotComplete()
   .assertNoError();
  ts.request(1);
  ts.assertValues(true)
   .assertComplete()
   .assertNoError();
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

public Mono<Boolean> exists(Query query, @Nullable Class<?> entityClass, String collectionName) {
  if (query == null) {
    throw new InvalidDataAccessApiUsageException("Query passed in to exist can't be null");
  }
  return createFlux(collectionName, collection -> {
    Document filter = queryMapper.getMappedObject(query.getQueryObject(), getPersistentEntity(entityClass));
    FindPublisher<Document> findPublisher = collection.find(filter, Document.class)
        .projection(new Document("_id", 1));
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("exists: {} in collection: {}", serializeToJsonSafely(filter), collectionName);
    }
    findPublisher = query.getCollation().map(Collation::toMongoCollation).map(findPublisher::collation)
        .orElse(findPublisher);
    return findPublisher.limit(1);
  }).hasElements();
}

代码示例来源:origin: com.aol.cyclops/cyclops-reactor

/**
 * @return
 * @see reactor.core.publisher.Flux#hasElements()
 */
public final Mono<Boolean> hasElements() {
  return boxed.hasElements();
}
/**

代码示例来源:origin: rsocket/rsocket-java

@Test(timeout = 5_000L)
public void testCompleteWithoutNext() {
 handler =
   new AbstractRSocket() {
    @Override
    public Flux<Payload> requestStream(Payload payload) {
     return Flux.empty();
    }
   };
 RSocket client = buildClient();
 Boolean hasElements =
   client.requestStream(DefaultPayload.create("REQUEST", "META")).log().hasElements().block();
 assertFalse(hasElements);
}

代码示例来源:origin: org.springframework.data/spring-data-cassandra

@Override
public Mono<Boolean> exists(Object id, Class<?> entityClass) {
  Assert.notNull(id, "Id must not be null");
  Assert.notNull(entityClass, "Entity type must not be null");
  CassandraPersistentEntity<?> entity = getRequiredPersistentEntity(entityClass);
  Select select = QueryBuilder.select().from(entity.getTableName().toCql());
  getConverter().write(id, select.where(), entity);
  return getReactiveCqlOperations().queryForRows(select).hasElements();
}

代码示例来源:origin: org.springframework.data/spring-data-cassandra

Mono<Boolean> doExists(Query query, Class<?> entityClass, CqlIdentifier tableName) {
  RegularStatement select = getStatementFactory().select(query.limit(1), getRequiredPersistentEntity(entityClass),
      tableName);
  return getReactiveCqlOperations().queryForRows(select).hasElements();
}

相关文章

Flux类方法