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