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