Search in sources :

Example 11 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method verifyMigrateWhenOnlyAddressBookServiceEndpointsAreSet.

@Test
void verifyMigrateWhenOnlyAddressBookServiceEndpointsAreSet() throws IOException {
    long consensusTimestamp = 1;
    int nodeIdCount = 3;
    int endPointPerNode = 3;
    int numEndPoints = nodeIdCount * endPointPerNode;
    insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, consensusTimestamp, nodeIdCount);
    getAndSaveAddressBookEntries(false, consensusTimestamp, nodeIdCount, endPointPerNode);
    assertThat(addressBookEntryRepository.count()).isEqualTo(numEndPoints);
    runMigration();
    assertThat(addressBookEntryRepository.findAll()).isNotEmpty().hasSize(nodeIdCount).extracting(AddressBookEntry::getId).extracting(AddressBookEntry.Id::getNodeId).containsExactlyInAnyOrder(0L, 1L, 2L);
    assertThat(addressBookServiceEndpointRepository.findAll()).isNotEmpty().hasSize(numEndPoints).extracting(AddressBookServiceEndpoint::getId).extracting(AddressBookServiceEndpoint.Id::getPort).containsExactlyInAnyOrder(443, 444, 445, 446, 447, 448, 449, 450, 451);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 12 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method getAndSaveAddressBookEntry.

private List<AddressBookEntry> getAndSaveAddressBookEntry(boolean deprecatedIp, long id, long consensusTimestamp, long nodeId, int endPointCount) {
    long accountIdNum = nodeAccountOffset + nodeId;
    String accountId = baseAccountId + accountIdNum;
    List<AddressBookEntry> addressBookEntries = new ArrayList<>();
    AddressBookEntry.AddressBookEntryBuilder builder = AddressBookEntry.builder().consensusTimestamp(consensusTimestamp).nodeId(nodeId).memo(accountId).nodeCertHash("nodeCertHash".getBytes()).nodeAccountId(EntityId.of(accountId, EntityType.ACCOUNT)).publicKey("rsa+public/key");
    AtomicLong idCount = new AtomicLong(id);
    AddressBookEntry addressBookEntry = builder.build();
    if (deprecatedIp) {
        insertAddressBookEntry(addressBookEntry, baseIp + idCount.get(), basePort + (int) idCount.get());
        idCount.getAndIncrement();
        addressBookEntries.add(addressBookEntry);
    }
    for (int i = 1; i <= endPointCount; i++) {
        insertAddressBookEntry(addressBookEntry, baseIp + idCount.get(), basePort + (int) idCount.get());
        idCount.getAndIncrement();
        addressBookEntries.add(addressBookEntry);
    }
    // handle no endpoints case
    if (!deprecatedIp && endPointCount == 0) {
        insertAddressBookEntry(addressBookEntry, "", 0);
        addressBookEntries.add(addressBookEntry);
    }
    return addressBookEntries;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

Example 13 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method verifyMigrateWhenOnlyDeprecatedIpIsSet.

@Test
void verifyMigrateWhenOnlyDeprecatedIpIsSet() throws IOException {
    long consensusTimestamp = 1;
    int nodeIdCount = 3;
    int endPointPerNode = 0;
    int numEndPoints = nodeIdCount;
    insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, consensusTimestamp, nodeIdCount);
    getAndSaveAddressBookEntries(true, consensusTimestamp, nodeIdCount, endPointPerNode);
    assertThat(addressBookEntryRepository.count()).isEqualTo(numEndPoints);
    runMigration();
    assertThat(addressBookEntryRepository.findAll()).isNotEmpty().hasSize(nodeIdCount).extracting(AddressBookEntry::getId).extracting(AddressBookEntry.Id::getNodeId).containsExactlyInAnyOrder(0L, 1L, 2L);
    assertThat(addressBookServiceEndpointRepository.findAll()).isNotEmpty().hasSize(numEndPoints).extracting(AddressBookServiceEndpoint::getId).extracting(AddressBookServiceEndpoint.Id::getPort).containsExactlyInAnyOrder(443, 444, 445);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 14 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method verifyAddressBookEntryDuplicatesRemoved.

@Test
void verifyAddressBookEntryDuplicatesRemoved() throws IOException {
    long consensusTimestamp = 1;
    int nodeIdCount = 3;
    AddressBookEntry.AddressBookEntryBuilder builder = AddressBookEntry.builder().consensusTimestamp(consensusTimestamp).nodeCertHash("nodeCertHash".getBytes()).nodeId(0L).publicKey("rsa+public/key");
    List<Long> nodeIds = List.of(0L, 1L, 2L);
    List<Integer> ports = List.of(80, 443, 5600);
    int numEndPoints = nodeIds.size() * ports.size();
    // populate address_book and address_book_entry
    insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, consensusTimestamp, nodeIdCount);
    nodeIds.forEach(nodeId -> {
        ports.forEach(port -> {
            insertAddressBookEntry(builder.memo(baseAccountId + (nodeId + nodeAccountOffset)).build(), // duplicate ip per nodeId
            baseIp + nodeId, port);
        });
    });
    assertThat(addressBookEntryRepository.count()).isEqualTo(numEndPoints);
    runMigration();
    assertThat(addressBookEntryRepository.findAll()).isNotEmpty().hasSize(nodeIds.size()).extracting(AddressBookEntry::getId).extracting(AddressBookEntry.Id::getNodeId).containsExactlyInAnyOrderElementsOf(nodeIds);
    IterableAssert<AddressBookServiceEndpoint> listAssert = assertThat(addressBookServiceEndpointRepository.findAll()).isNotEmpty().hasSize(numEndPoints);
    List<Integer> allPorts = new ArrayList<>();
    allPorts.addAll(ports);
    allPorts.addAll(ports);
    allPorts.addAll(ports);
    listAssert.extracting(AddressBookServiceEndpoint::getId).extracting(AddressBookServiceEndpoint.Id::getPort).containsExactlyInAnyOrderElementsOf(allPorts);
    // verify address_book counts are updated
    assertThat(addressBookRepository.findById(consensusTimestamp)).get().returns(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, AddressBook::getFileId).returns(nodeIds.size(), AddressBook::getNodeCount).returns(null, AddressBook::getEndConsensusTimestamp);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 15 with AddressBookEntry

use of com.hedera.mirror.common.domain.addressbook.AddressBookEntry in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method getAndSaveAddressBookEntries.

private List<AddressBookEntry> getAndSaveAddressBookEntries(boolean deprecatedIp, long consensusTimestamp, int nodeCount, int endPointCount) {
    List<AddressBookEntry> addressBookEntries = new ArrayList<>();
    int numEndpointsPerNode = deprecatedIp ? endPointCount + 1 : endPointCount;
    for (int id = 0; id < nodeCount; id++) {
        addressBookEntries.addAll(getAndSaveAddressBookEntry(deprecatedIp, numEndpointsPerNode * id, consensusTimestamp, id, endPointCount));
    }
    return addressBookEntries;
}
Also used : ArrayList(java.util.ArrayList) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

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