use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.
the class AddressBookEntryRepositoryTest method findByConsensusTimestampAndNodeId.
@Test
void findByConsensusTimestampAndNodeId() {
long consensusTimestamp = 1L;
int limit = 2;
AddressBookEntry addressBookEntry1 = addressBookEntry(consensusTimestamp, 0L);
AddressBookEntry addressBookEntry2 = addressBookEntry(consensusTimestamp, 1L);
AddressBookEntry addressBookEntry3 = addressBookEntry(consensusTimestamp, 2L);
addressBookEntry(consensusTimestamp + 1, 0L);
assertThat(addressBookEntryRepository.findByConsensusTimestampAndNodeId(consensusTimestamp, 0L, limit)).as("First page has a length equal to limit").hasSize(limit).containsExactly(addressBookEntry1, addressBookEntry2);
assertThat(addressBookEntryRepository.findByConsensusTimestampAndNodeId(consensusTimestamp, limit, limit)).as("Second page has less than limit").containsExactly(addressBookEntry3);
}
use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.
the class AddressBookEntryRepositoryTest method serviceEndpoints.
@Test
void serviceEndpoints() {
AddressBookEntry addressBookEntry = domainBuilder.addressBookEntry(3).persist();
assertThat(addressBookEntryRepository.findById(addressBookEntry.getId())).get().extracting(AddressBookEntry::getServiceEndpoints).asInstanceOf(InstanceOfAssertFactories.COLLECTION).containsExactlyInAnyOrderElementsOf(addressBookEntry.getServiceEndpoints());
}
use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.
the class NetworkControllerTest method nullFields.
@Test
void nullFields() {
AddressBook addressBook = addressBook();
AddressBookEntry addressBookEntry = domainBuilder.addressBookEntry().customize(a -> a.consensusTimestamp(CONSENSUS_TIMESTAMP).description(null).memo(null).nodeCertHash(null).publicKey(null).stake(null)).persist();
AddressBookQuery query = AddressBookQuery.newBuilder().setFileId(FileID.newBuilder().setFileNum(addressBook.getFileId().getEntityNum()).build()).build();
reactiveService.getNodes(Mono.just(query)).as(StepVerifier::create).thenAwait(Duration.ofMillis(50)).consumeNextWith(n -> assertThat(n).isNotNull().returns("", NodeAddress::getDescription).returns(ByteString.EMPTY, NodeAddress::getMemo).returns(addressBookEntry.getNodeAccountId(), t -> EntityId.of(n.getNodeAccountId())).returns(ByteString.EMPTY, NodeAddress::getNodeCertHash).returns(addressBookEntry.getNodeId(), NodeAddress::getNodeId).returns("", NodeAddress::getRSAPubKey).returns(0L, NodeAddress::getStake)).expectComplete().verify(Duration.ofSeconds(1L));
}
use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.
the class NetworkControllerTest method noLimit.
@Test
void noLimit() {
AddressBook addressBook = addressBook();
AddressBookEntry addressBookEntry1 = addressBookEntry();
AddressBookEntry addressBookEntry2 = addressBookEntry();
AddressBookQuery query = AddressBookQuery.newBuilder().setFileId(FileID.newBuilder().setFileNum(addressBook.getFileId().getEntityNum()).build()).build();
reactiveService.getNodes(Mono.just(query)).as(StepVerifier::create).thenAwait(Duration.ofMillis(50)).consumeNextWith(n -> assertEntry(addressBookEntry1, n)).consumeNextWith(n -> assertEntry(addressBookEntry2, n)).expectComplete().verify(Duration.ofSeconds(1L));
}
use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry 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