Search in sources :

Example 11 with AddressBook

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

the class AddressBookServiceImplTest method verifyAddressBookMigrationInitiatedByDownloader.

@Test
void verifyAddressBookMigrationInitiatedByDownloader() {
    byte[] addressBookBytes1 = UPDATED.toByteArray();
    store(addressBookBytes1, 2L, false);
    byte[] addressBookBytes2 = UPDATED.toByteArray();
    store(addressBookBytes2, 3L, true);
    byte[] addressBookBytes3 = FINAL.toByteArray();
    store(addressBookBytes3, 4L, false);
    byte[] addressBookBytes4 = FINAL.toByteArray();
    store(addressBookBytes4, 5L, true);
    // migration
    AddressBook addressBook = addressBookService.getCurrent();
    assertThat(addressBook.getStartConsensusTimestamp()).isEqualTo(6L);
    assertAddressBook(addressBook, FINAL);
    assertEquals(4, fileDataRepository.count());
    // initial plus 4 files
    assertEquals(5, addressBookRepository.count());
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + (UPDATED.getNodeAddressCount() * 2) + (FINAL.getNodeAddressCount() * 2), addressBookEntryRepository.count());
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 12 with AddressBook

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

the class AddressBookServiceImplTest method appendCompleteFile.

@Test
void appendCompleteFile() {
    byte[] addressBookBytes = UPDATED.toByteArray();
    int index = addressBookBytes.length / 3;
    byte[] addressBookBytes1 = Arrays.copyOfRange(addressBookBytes, 0, index);
    byte[] addressBookBytes2 = Arrays.copyOfRange(addressBookBytes, index, index * 2);
    byte[] addressBookBytes3 = Arrays.copyOfRange(addressBookBytes, index * 2, addressBookBytes.length);
    update(addressBookBytes1, 2L, true);
    assertArrayEquals(initialAddressBookBytes, addressBookService.getCurrent().getFileData());
    append(addressBookBytes2, 3L, true);
    assertArrayEquals(initialAddressBookBytes, addressBookService.getCurrent().getFileData());
    long addressBookConsensusTimeStamp = 5L;
    append(addressBookBytes3, addressBookConsensusTimeStamp, true);
    assertAddressBook(addressBookService.getCurrent(), UPDATED);
    assertAddressBookData(addressBookBytes, addressBookConsensusTimeStamp + 1);
    assertEquals(2, addressBookRepository.count());
    assertEquals(UPDATED.getNodeAddressCount() + TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT, addressBookEntryRepository.count());
    AddressBook addressBook = addressBookService.getCurrent();
    assertThat(addressBook.getStartConsensusTimestamp()).isEqualTo(6L);
    assertThat(addressBook.getEntries()).hasSize(UPDATED.getNodeAddressCount());
}
Also used : 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)

Example 13 with AddressBook

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

the class AddressBookServiceImplTest method verifyAddressBookUpdateAcrossSessions.

@Test
void verifyAddressBookUpdateAcrossSessions() {
    // create network book, perform an update and append
    byte[] addressBookBytes = FINAL.toByteArray();
    int index = addressBookBytes.length / 2;
    byte[] addressBookBytes1 = Arrays.copyOfRange(addressBookBytes, 0, index);
    byte[] addressBookBytes2 = Arrays.copyOfRange(addressBookBytes, index, addressBookBytes.length);
    update(addressBookBytes1, 2L, true);
    // create new address book and submit another append to complete file
    addressBookService.getCurrent();
    long addressBookConsensusTimeStamp = 3L;
    append(addressBookBytes2, addressBookConsensusTimeStamp, true);
    // verify valid address book and repository update
    AddressBook addressBook = addressBookService.getCurrent();
    assertAddressBook(addressBook, FINAL);
    assertAddressBookData(FINAL.toByteArray(), addressBookConsensusTimeStamp + 1);
    assertThat(addressBook.getStartConsensusTimestamp()).isEqualTo(addressBookConsensusTimeStamp + 1);
}
Also used : 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)

Example 14 with AddressBook

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

the class AddressBookServiceImplTest method updateCompleteFile.

@Test
void updateCompleteFile() {
    byte[] addressBookBytes = UPDATED.toByteArray();
    long addressBookConsensusTimeStamp = 5L;
    update(addressBookBytes, addressBookConsensusTimeStamp, true);
    // assert current addressBook is updated
    AddressBook addressBook = addressBookService.getCurrent();
    assertThat(addressBook.getStartConsensusTimestamp()).isEqualTo(addressBookConsensusTimeStamp + 1);
    assertAddressBook(addressBook, UPDATED);
    // assert repositories contain updates
    assertAddressBookData(UPDATED.toByteArray(), addressBookConsensusTimeStamp + 1);
    assertEquals(2, addressBookRepository.count());
    assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + UPDATED.getNodeAddressCount(), addressBookEntryRepository.count());
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 15 with AddressBook

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

the class AddressBookServiceImplTest method cacheAndEvictAddressBook.

@Test
void cacheAndEvictAddressBook() {
    byte[] addressBookBytes = UPDATED.toByteArray();
    long addressBookConsensusTimeStamp = 5L;
    update(addressBookBytes, addressBookConsensusTimeStamp, true);
    // verify cache is empty to start
    assertNull(cacheManager.getCache(AddressBookServiceImpl.ADDRESS_BOOK_102_CACHE_NAME).get(SimpleKey.EMPTY));
    // verify getCurrent() adds an entry to the cache
    AddressBook addressBookDb = addressBookService.getCurrent();
    AddressBook addressBookCache = (AddressBook) cacheManager.getCache(AddressBookServiceImpl.ADDRESS_BOOK_102_CACHE_NAME).get(SimpleKey.EMPTY).get();
    assertNotNull(addressBookCache);
    assertThat(addressBookCache).isEqualTo(addressBookDb);
    // verify updating the address book evicts the cache.
    update(addressBookBytes, addressBookConsensusTimeStamp + 1, true);
    assertNull(cacheManager.getCache(AddressBookServiceImpl.ADDRESS_BOOK_102_CACHE_NAME).get(SimpleKey.EMPTY));
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

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