Search in sources :

Example 21 with AddressBookEntry

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);
}
Also used : AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) Test(org.junit.jupiter.api.Test) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest)

Example 22 with AddressBookEntry

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());
}
Also used : AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) Test(org.junit.jupiter.api.Test) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest)

Example 23 with AddressBookEntry

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));
}
Also used : FileID(com.hederahashgraph.api.proto.java.FileID) AddressBookQuery(com.hedera.mirror.api.proto.AddressBookQuery) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) GrpcClient(net.devh.boot.grpc.client.inject.GrpcClient) StepVerifier(reactor.test.StepVerifier) EntityId(com.hedera.mirror.common.domain.entity.EntityId) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) ProtoUtil(com.hedera.mirror.grpc.util.ProtoUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Mono(reactor.core.publisher.Mono) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) InetAddress(java.net.InetAddress) Test(org.junit.jupiter.api.Test) ReactorNetworkServiceGrpc(com.hedera.mirror.api.proto.ReactorNetworkServiceGrpc) Duration(java.time.Duration) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Log4j2(lombok.extern.log4j.Log4j2) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) Status(io.grpc.Status) AddressBookQuery(com.hedera.mirror.api.proto.AddressBookQuery) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 24 with AddressBookEntry

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));
}
Also used : FileID(com.hederahashgraph.api.proto.java.FileID) AddressBookQuery(com.hedera.mirror.api.proto.AddressBookQuery) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) GrpcClient(net.devh.boot.grpc.client.inject.GrpcClient) StepVerifier(reactor.test.StepVerifier) EntityId(com.hedera.mirror.common.domain.entity.EntityId) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) ProtoUtil(com.hedera.mirror.grpc.util.ProtoUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Mono(reactor.core.publisher.Mono) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) InetAddress(java.net.InetAddress) Test(org.junit.jupiter.api.Test) ReactorNetworkServiceGrpc(com.hedera.mirror.api.proto.ReactorNetworkServiceGrpc) Duration(java.time.Duration) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Log4j2(lombok.extern.log4j.Log4j2) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) Status(io.grpc.Status) AddressBookQuery(com.hedera.mirror.api.proto.AddressBookQuery) 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 25 with AddressBookEntry

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

AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)26 Test (org.junit.jupiter.api.Test)18 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)12 AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)11 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)10 EntityId (com.hedera.mirror.common.domain.entity.EntityId)6 AddressBookFilter (com.hedera.mirror.grpc.domain.AddressBookFilter)6 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)6 NodeAddress (com.hederahashgraph.api.proto.java.NodeAddress)6 ByteString (com.google.protobuf.ByteString)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 AddressBookQuery (com.hedera.mirror.api.proto.AddressBookQuery)3 Log4j2 (lombok.extern.log4j.Log4j2)3 ReactorNetworkServiceGrpc (com.hedera.mirror.api.proto.ReactorNetworkServiceGrpc)2 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)2 EntityType (com.hedera.mirror.common.domain.entity.EntityType)2 ProtoUtil (com.hedera.mirror.grpc.util.ProtoUtil)2 FileID (com.hederahashgraph.api.proto.java.FileID)2 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)2 Status (io.grpc.Status)2