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