Search in sources :

Example 6 with AddressBookFilter

use of com.hedera.mirror.grpc.domain.AddressBookFilter in project hedera-mirror-node by hashgraph.

the class NetworkServiceTest method limitReached.

@Test
void limitReached() {
    AddressBook addressBook = addressBook();
    AddressBookEntry addressBookEntry1 = addressBookEntry();
    addressBookEntry();
    AddressBookFilter filter = AddressBookFilter.builder().fileId(addressBook.getFileId()).limit(1).build();
    assertThat(getNodes(filter)).containsExactly(addressBookEntry1);
}
Also used : AddressBookFilter(com.hedera.mirror.grpc.domain.AddressBookFilter) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with AddressBookFilter

use of com.hedera.mirror.grpc.domain.AddressBookFilter in project hedera-mirror-node by hashgraph.

the class NetworkServiceTest method addressBookNotFound.

@Test
void addressBookNotFound() {
    AddressBookFilter filter = AddressBookFilter.builder().fileId(EntityId.of(102L, EntityType.FILE)).build();
    assertThatThrownBy(() -> networkService.getNodes(filter)).isInstanceOf(EntityNotFoundException.class).hasMessage("File 0.0.102 does not exist");
}
Also used : AddressBookFilter(com.hedera.mirror.grpc.domain.AddressBookFilter) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 8 with AddressBookFilter

use of com.hedera.mirror.grpc.domain.AddressBookFilter in project hedera-mirror-node by hashgraph.

the class NetworkServiceTest method equalToPageSize.

@Test
void equalToPageSize() {
    addressBookProperties.setPageSize(2);
    AddressBook addressBook = addressBook();
    AddressBookEntry addressBookEntry1 = addressBookEntry();
    AddressBookEntry addressBookEntry2 = addressBookEntry();
    AddressBookFilter filter = AddressBookFilter.builder().fileId(addressBook.getFileId()).build();
    assertThat(getNodes(filter)).containsExactly(addressBookEntry1, addressBookEntry2);
}
Also used : AddressBookFilter(com.hedera.mirror.grpc.domain.AddressBookFilter) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with AddressBookFilter

use of com.hedera.mirror.grpc.domain.AddressBookFilter in project hedera-mirror-node by hashgraph.

the class NetworkServiceTest method noNodes.

@Test
void noNodes() {
    AddressBook addressBook = addressBook();
    AddressBookFilter filter = AddressBookFilter.builder().fileId(addressBook.getFileId()).build();
    networkService.getNodes(filter).as(StepVerifier::create).thenAwait(Duration.ofMillis(100)).expectNextCount(0L).expectComplete().verify(Duration.ofMillis(500));
}
Also used : AddressBookFilter(com.hedera.mirror.grpc.domain.AddressBookFilter) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with AddressBookFilter

use of com.hedera.mirror.grpc.domain.AddressBookFilter in project hedera-mirror-node by hashgraph.

the class NetworkServiceImpl method getNodes.

@Override
public Flux<AddressBookEntry> getNodes(AddressBookFilter filter) {
    var fileId = filter.getFileId();
    if (!VALID_FILE_IDS.contains(fileId)) {
        throw new IllegalArgumentException(INVALID_FILE_ID);
    }
    long timestamp = addressBookRepository.findLatestTimestamp(fileId.getId()).orElseThrow(() -> new EntityNotFoundException(fileId));
    var context = new AddressBookContext(timestamp);
    return Flux.defer(() -> page(context)).repeatWhen(Repeat.onlyIf(c -> !context.isComplete()).randomBackoff(addressBookProperties.getMinPageDelay(), addressBookProperties.getMaxPageDelay()).jitter(Jitter.random()).withBackoffScheduler(Schedulers.parallel())).take(filter.getLimit() > 0 ? filter.getLimit() : Long.MAX_VALUE).name("addressBook").metrics().doOnNext(context::onNext).doOnSubscribe(s -> log.info("Querying for address book: {}", filter)).doOnComplete(() -> log.info("Retrieved {} nodes from the address book", context.getCount()));
}
Also used : Validated(org.springframework.validation.annotation.Validated) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Jitter(reactor.retry.Jitter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Repeat(reactor.retry.Repeat) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) EntityType(com.hedera.mirror.common.domain.entity.EntityType) AddressBookEntryRepository(com.hedera.mirror.grpc.repository.AddressBookEntryRepository) Value(lombok.Value) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Flux(reactor.core.publisher.Flux) Log4j2(lombok.extern.log4j.Log4j2) AddressBookRepository(com.hedera.mirror.grpc.repository.AddressBookRepository) Schedulers(reactor.core.scheduler.Schedulers) Named(javax.inject.Named) AddressBookFilter(com.hedera.mirror.grpc.domain.AddressBookFilter) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException)

Aggregations

AddressBookFilter (com.hedera.mirror.grpc.domain.AddressBookFilter)10 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)9 Test (org.junit.jupiter.api.Test)9 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)6 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)6 EntityNotFoundException (com.hedera.mirror.grpc.exception.EntityNotFoundException)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 AddressBookEntryRepository (com.hedera.mirror.grpc.repository.AddressBookEntryRepository)1 AddressBookRepository (com.hedera.mirror.grpc.repository.AddressBookRepository)1 Collection (java.util.Collection)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Named (javax.inject.Named)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Value (lombok.Value)1 Log4j2 (lombok.extern.log4j.Log4j2)1 Validated (org.springframework.validation.annotation.Validated)1