Search in sources :

Example 21 with AddressBook

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

the class Fix102AddressBookMigrationTest method addressBook.

private AddressBook addressBook(long fileId, long startConsensusTimestamp, Long endConsensusTimestamp) {
    AddressBook addressBook = new AddressBook();
    addressBook.setEndConsensusTimestamp(endConsensusTimestamp);
    addressBook.setFileData(new byte[] {});
    addressBook.setFileId(EntityId.of(0, 0, fileId, EntityType.FILE));
    addressBook.setStartConsensusTimestamp(startConsensusTimestamp);
    return addressBookRepository.save(addressBook);
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook)

Example 22 with AddressBook

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

the class Fix102AddressBookMigrationTest method previous102WithIncorrectTimestamp.

@Test
void previous102WithIncorrectTimestamp() throws IOException {
    AddressBook addressBook1 = addressBook(102, 1, 200L);
    AddressBook addressBook2 = addressBook(102, 101, 300L);
    AddressBook addressBook3 = addressBook(101, 201, null);
    AddressBook addressBook4 = addressBook(101, 301, null);
    runMigration();
    assertEndTimestamp(addressBook1, 100L);
    assertEndTimestamp(addressBook2, null);
    assertEndTimestamp(addressBook3, 300L);
    assertEndTimestamp(addressBook4, null);
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 23 with AddressBook

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

the class MissingAddressBooksMigrationTest method verifyAddressBookMigrationWithNewFileDataAfterCurrentAddressBook.

@Test
void verifyAddressBookMigrationWithNewFileDataAfterCurrentAddressBook() {
    // store initial address books
    addressBookRepository.save(addressBook(ab -> ab.fileId(AddressBookServiceImpl.ADDRESS_BOOK_101_ENTITY_ID), 1, 4));
    addressBookRepository.save(addressBook(ab -> ab.fileId(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID), 2, 4));
    addressBookRepository.save(addressBook(ab -> ab.fileId(AddressBookServiceImpl.ADDRESS_BOOK_101_ENTITY_ID), 11, 8));
    addressBookRepository.save(addressBook(ab -> ab.fileId(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID), 12, 8));
    assertEquals(4, addressBookRepository.count());
    // un-parsed file_data
    // file 101 update contents to be split over 1 update and 1 append operation
    byte[] addressBook101Bytes = FINAL.toByteArray();
    int index101 = addressBook101Bytes.length / 2;
    byte[] addressBook101Bytes1 = Arrays.copyOfRange(addressBook101Bytes, 0, index101);
    byte[] addressBook101Bytes2 = Arrays.copyOfRange(addressBook101Bytes, index101, addressBook101Bytes.length);
    createAndStoreFileData(addressBook101Bytes1, 101, false, TransactionType.FILEUPDATE);
    createAndStoreFileData(addressBook101Bytes2, 102, false, TransactionType.FILEAPPEND);
    // file 102 update contents to be split over 1 update and 1 append operation
    byte[] addressBook102Bytes = FINAL.toByteArray();
    int index = addressBook102Bytes.length / 2;
    byte[] addressBook102Bytes1 = Arrays.copyOfRange(addressBook102Bytes, 0, index);
    byte[] addressBook102Bytes2 = Arrays.copyOfRange(addressBook102Bytes, index, addressBook102Bytes.length);
    createAndStoreFileData(addressBook102Bytes1, 201, true, TransactionType.FILEUPDATE);
    createAndStoreFileData(addressBook102Bytes2, 202, true, TransactionType.FILEAPPEND);
    assertEquals(4, fileDataRepository.count());
    // migration on startup
    missingAddressBooksMigration.doMigrate();
    assertEquals(6, addressBookRepository.count());
    AddressBook newAddressBook = addressBookRepository.findLatestAddressBook(205, AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID.getId()).get();
    assertThat(newAddressBook.getStartConsensusTimestamp()).isEqualTo(203L);
    assertAddressBook(newAddressBook, FINAL);
}
Also used : CsvSource(org.junit.jupiter.params.provider.CsvSource) Arrays(java.util.Arrays) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookRepository(com.hedera.mirror.importer.repository.AddressBookRepository) EntityId(com.hedera.mirror.common.domain.entity.EntityId) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) EntityType(com.hedera.mirror.common.domain.entity.EntityType) ClassicConfiguration(org.flywaydb.core.api.configuration.ClassicConfiguration) ArrayList(java.util.ArrayList) TransactionType(com.hedera.mirror.common.domain.transaction.TransactionType) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) AccountID(com.hederahashgraph.api.proto.java.AccountID) FileDataRepository(com.hedera.mirror.importer.repository.FileDataRepository) AddressBookServiceEndpointRepository(com.hedera.mirror.importer.repository.AddressBookServiceEndpointRepository) Resource(javax.annotation.Resource) AddressBookServiceImpl(com.hedera.mirror.importer.addressbook.AddressBookServiceImpl) Instant(java.time.Instant) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) FileData(com.hedera.mirror.common.domain.file.FileData) DisplayName(org.junit.jupiter.api.DisplayName) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EntityProperties(com.hedera.mirror.importer.parser.record.entity.EntityProperties) Assertions(org.junit.jupiter.api.Assertions) ListAssert(org.assertj.core.api.ListAssert) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with AddressBook

use of com.hedera.mirror.common.domain.addressbook.AddressBook 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 25 with AddressBook

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

the class AddAddressBookServiceEndpointsMigrationTest method insertAddressBook.

/**
 * Insert address book object using only columns supported before V_1_37.1
 *
 * @param fileEntityId
 * @param startConsensusTimestamp
 * @param nodeCount
 */
private void insertAddressBook(EntityId fileEntityId, long startConsensusTimestamp, int nodeCount) {
    AddressBook addressBook = new AddressBook();
    addressBook.setFileData(new byte[] {});
    addressBook.setFileId(fileEntityId);
    addressBook.setStartConsensusTimestamp(startConsensusTimestamp);
    addressBook.setNodeCount(nodeCount);
    jdbcOperations.update("insert into address_book (start_consensus_timestamp, end_consensus_timestamp, file_id, " + "node_count, file_data) values" + " (?, ?, ?, ?, ?)", addressBook.getStartConsensusTimestamp(), addressBook.getEndConsensusTimestamp(), addressBook.getFileId().getId(), addressBook.getNodeCount(), addressBook.getFileData());
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook)

Aggregations

AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)43 Test (org.junit.jupiter.api.Test)33 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)17 NodeAddressBook (com.hederahashgraph.api.proto.java.NodeAddressBook)17 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)12 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)11 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)10 AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)9 EntityId (com.hedera.mirror.common.domain.entity.EntityId)6 AddressBookFilter (com.hedera.mirror.grpc.domain.AddressBookFilter)6 Resource (javax.annotation.Resource)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ByteString (com.google.protobuf.ByteString)4 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)4 NodeAddress (com.hederahashgraph.api.proto.java.NodeAddress)4 StepVerifier (reactor.test.StepVerifier)4 AddressBookQuery (com.hedera.mirror.api.proto.AddressBookQuery)3 EntityType (com.hedera.mirror.common.domain.entity.EntityType)3 SignatureVerificationException (com.hedera.mirror.importer.exception.SignatureVerificationException)3