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);
}
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");
}
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);
}
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));
}
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()));
}
Aggregations