use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.
the class DomainBuilder method addressBookEntry.
public DomainWrapper<AddressBookEntry, AddressBookEntry.AddressBookEntryBuilder> addressBookEntry(int endpoints) {
long consensusTimestamp = timestamp();
long nodeId = id();
var builder = AddressBookEntry.builder().consensusTimestamp(consensusTimestamp).description(text(10)).memo(text(10)).nodeId(nodeId).nodeAccountId(EntityId.of(0L, 0L, nodeId + 3, ACCOUNT)).nodeCertHash(bytes(96)).publicKey(text(64)).stake(0L);
var serviceEndpoints = new HashSet<AddressBookServiceEndpoint>();
builder.serviceEndpoints(serviceEndpoints);
for (int i = 0; i < endpoints; ++i) {
var endpoint = addressBookServiceEndpoint().customize(a -> a.consensusTimestamp(consensusTimestamp).nodeId(nodeId)).get();
serviceEndpoints.add(endpoint);
}
return new DomainWrapperImpl<>(builder, builder::build);
}
use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImpl method getAddressBookServiceEndpoint.
private static AddressBookServiceEndpoint getAddressBookServiceEndpoint(ServiceEndpoint serviceEndpoint, long consensusTimestamp, long nodeId) throws UnknownHostException {
var ipAddressByteString = serviceEndpoint.getIpAddressV4();
if (ipAddressByteString == null || ipAddressByteString.size() != 4) {
throw new IllegalStateException(String.format("Invalid IpAddressV4: %s", ipAddressByteString));
}
var ip = InetAddress.getByAddress(ipAddressByteString.toByteArray()).getHostAddress();
AddressBookServiceEndpoint addressBookServiceEndpoint = new AddressBookServiceEndpoint();
addressBookServiceEndpoint.setConsensusTimestamp(consensusTimestamp);
addressBookServiceEndpoint.setIpAddressV4(ip);
addressBookServiceEndpoint.setPort(serviceEndpoint.getPort());
addressBookServiceEndpoint.setNodeId(nodeId);
return addressBookServiceEndpoint;
}
use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method assertAddressBookEndPoints.
private void assertAddressBookEndPoints(Set<AddressBookServiceEndpoint> actual, List<ServiceEndpoint> expected) {
if (expected.isEmpty()) {
return;
}
var listAssert = assertThat(actual).hasSize(expected.size());
for (ServiceEndpoint serviceEndpoint : expected) {
listAssert.anySatisfy(abe -> {
AtomicReference<String> ip = new AtomicReference<>("");
assertDoesNotThrow(() -> {
ip.set(InetAddress.getByAddress(serviceEndpoint.getIpAddressV4().toByteArray()).getHostAddress());
});
assertThat(abe.getId().getPort()).isEqualTo(serviceEndpoint.getPort());
assertThat(abe.getId().getIpAddressV4()).isEqualTo(ip.get());
});
}
}
use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.
the class AddAddressBookServiceEndpointsMigrationTest method verifyMigrateWhenBothDeprecatedIpAndAddressBookServiceEndpointsAreSet.
@Test
void verifyMigrateWhenBothDeprecatedIpAndAddressBookServiceEndpointsAreSet() throws IOException {
long consensusTimestamp = 1;
int nodeIdCount = 3;
int endPointPerNode = 3;
int numEndPoints = nodeIdCount * (endPointPerNode + 1);
insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_101_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, 446, 447, 448, 449, 450, 451, 452, 453, 454);
}
use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint 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);
}
Aggregations