@Test void verifyMigrationNonApplicableFileIDs() throws Exception { byte[] mediumAddressBookBytes = addressBook(5).toByteArray(); int mediumIndex = mediumAddressBookBytes.length / 2; byte[] mediumAddressBookBytes1 = Arrays.copyOfRange(mediumAddressBookBytes, 0, mediumIndex); byte[] mediumAddressBookBytes2 = Arrays .copyOfRange(mediumAddressBookBytes, mediumIndex, mediumAddressBookBytes.length); byte[] largeAddressBookBytes = addressBook(10).toByteArray(); int largeIndex = largeAddressBookBytes.length / 3; byte[] largeAddressBookBytes1 = Arrays.copyOfRange(largeAddressBookBytes, 0, largeIndex); byte[] largeAddressBookBytes2 = Arrays.copyOfRange(largeAddressBookBytes, largeIndex, largeIndex * 2); byte[] largeAddressBookBytes3 = Arrays .copyOfRange(largeAddressBookBytes, largeIndex * 2, largeAddressBookBytes.length); List<FileData> fileDataList = new ArrayList<>(); fileDataList.add(fileData(1L, 3, 100, TransactionTypeEnum.FILECREATE.getProtoId())); fileDataList.add(fileData(2L, mediumAddressBookBytes1, 103, TransactionTypeEnum.FILEUPDATE.getProtoId())); fileDataList.add(fileData(3L, mediumAddressBookBytes2, 103, TransactionTypeEnum.FILEAPPEND.getProtoId())); fileDataList.add(fileData(4L, largeAddressBookBytes1, 104, TransactionTypeEnum.FILEUPDATE.getProtoId())); fileDataList.add(fileData(5L, largeAddressBookBytes2, 104, TransactionTypeEnum.FILEAPPEND.getProtoId())); fileDataList.add(fileData(6L, largeAddressBookBytes3, 104, TransactionTypeEnum.FILEAPPEND.getProtoId())); fileDataRepository.saveAll(fileDataList); migration.migrate(new FlywayContext()); assertEquals(6, fileDataRepository.count()); assertEquals(1, addressBookRepository.count()); assertEquals(4, addressBookEntryRepository.count()); }
@Override public void migrate(Context context) throws Exception { jdbcTemplate = new JdbcTemplate(dataSource); Stopwatch stopwatch = Stopwatch.createStarted(); AtomicLong currentConsensusTimestamp = new AtomicLong(0); AtomicLong fileDataEntries = new AtomicLong(0); byte[] addressBookBytes; try { Path initialAddressBook = mirrorProperties.getInitialAddressBook(); if (initialAddressBook != null) { addressBookBytes = Files.readAllBytes(initialAddressBook); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, initialAddressBook); } else { MirrorProperties.HederaNetwork hederaNetwork = mirrorProperties.getNetwork(); String resourcePath = String.format("/addressbook/%s", hederaNetwork.name().toLowerCase()); Resource resource = new ClassPathResource(resourcePath, getClass()); addressBookBytes = IOUtils.toByteArray(resource.getInputStream()); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, resource); } } catch (Exception e) { throw new IllegalStateException("Unable to load bootstrap address book", e); } FileData bootStrapFileData = new FileData(0L, addressBookBytes, AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, TransactionTypeEnum.FILECREATE.getProtoId()); addressBookService.update(bootStrapFileData); fileDataEntries.incrementAndGet(); int pageSize = 1000; List<FileData> fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); while (!CollectionUtils.isEmpty(fileDataList)) { fileDataList.forEach(fileData -> { addressBookService.update(fileData); fileDataEntries.incrementAndGet(); currentConsensusTimestamp.set(fileData.getConsensusTimestamp()); }); fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); } log.info("Migration processed {} in {} ms", fileDataEntries.get(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); }
V1_28_1__Address_Book extends BaseJavaMigration { @Override public void migrate(Context context) throws Exception { jdbcTemplate = new JdbcTemplate(dataSource); Stopwatch stopwatch = Stopwatch.createStarted(); AtomicLong currentConsensusTimestamp = new AtomicLong(0); AtomicLong fileDataEntries = new AtomicLong(0); byte[] addressBookBytes; try { Path initialAddressBook = mirrorProperties.getInitialAddressBook(); if (initialAddressBook != null) { addressBookBytes = Files.readAllBytes(initialAddressBook); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, initialAddressBook); } else { MirrorProperties.HederaNetwork hederaNetwork = mirrorProperties.getNetwork(); String resourcePath = String.format("/addressbook/%s", hederaNetwork.name().toLowerCase()); Resource resource = new ClassPathResource(resourcePath, getClass()); addressBookBytes = IOUtils.toByteArray(resource.getInputStream()); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, resource); } } catch (Exception e) { throw new IllegalStateException("Unable to load bootstrap address book", e); } FileData bootStrapFileData = new FileData(0L, addressBookBytes, AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, TransactionTypeEnum.FILECREATE.getProtoId()); addressBookService.update(bootStrapFileData); fileDataEntries.incrementAndGet(); int pageSize = 1000; List<FileData> fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); while (!CollectionUtils.isEmpty(fileDataList)) { fileDataList.forEach(fileData -> { addressBookService.update(fileData); fileDataEntries.incrementAndGet(); currentConsensusTimestamp.set(fileData.getConsensusTimestamp()); }); fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); } log.info("Migration processed {} in {} ms", fileDataEntries.get(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); } }
V1_28_1__Address_Book extends BaseJavaMigration { @Override public void migrate(Context context) throws Exception { jdbcTemplate = new JdbcTemplate(dataSource); Stopwatch stopwatch = Stopwatch.createStarted(); AtomicLong currentConsensusTimestamp = new AtomicLong(0); AtomicLong fileDataEntries = new AtomicLong(0); byte[] addressBookBytes; try { Path initialAddressBook = mirrorProperties.getInitialAddressBook(); if (initialAddressBook != null) { addressBookBytes = Files.readAllBytes(initialAddressBook); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, initialAddressBook); } else { MirrorProperties.HederaNetwork hederaNetwork = mirrorProperties.getNetwork(); String resourcePath = String.format("/addressbook/%s", hederaNetwork.name().toLowerCase()); Resource resource = new ClassPathResource(resourcePath, getClass()); addressBookBytes = IOUtils.toByteArray(resource.getInputStream()); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, resource); } } catch (Exception e) { throw new IllegalStateException("Unable to load bootstrap address book", e); } FileData bootStrapFileData = new FileData(0L, addressBookBytes, AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, TransactionTypeEnum.FILECREATE.getProtoId()); addressBookService.update(bootStrapFileData); fileDataEntries.incrementAndGet(); int pageSize = 1000; List<FileData> fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); while (!CollectionUtils.isEmpty(fileDataList)) { fileDataList.forEach(fileData -> { addressBookService.update(fileData); fileDataEntries.incrementAndGet(); currentConsensusTimestamp.set(fileData.getConsensusTimestamp()); }); fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); } log.info("Migration processed {} in {} ms", fileDataEntries.get(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); } V1_28_1__Address_Book(MirrorProperties mirrorProperties, @Lazy AddressBookService addressBookService,
                                 DataSource dataSource); }
V1_28_1__Address_Book extends BaseJavaMigration { @Override public void migrate(Context context) throws Exception { jdbcTemplate = new JdbcTemplate(dataSource); Stopwatch stopwatch = Stopwatch.createStarted(); AtomicLong currentConsensusTimestamp = new AtomicLong(0); AtomicLong fileDataEntries = new AtomicLong(0); byte[] addressBookBytes; try { Path initialAddressBook = mirrorProperties.getInitialAddressBook(); if (initialAddressBook != null) { addressBookBytes = Files.readAllBytes(initialAddressBook); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, initialAddressBook); } else { MirrorProperties.HederaNetwork hederaNetwork = mirrorProperties.getNetwork(); String resourcePath = String.format("/addressbook/%s", hederaNetwork.name().toLowerCase()); Resource resource = new ClassPathResource(resourcePath, getClass()); addressBookBytes = IOUtils.toByteArray(resource.getInputStream()); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, resource); } } catch (Exception e) { throw new IllegalStateException("Unable to load bootstrap address book", e); } FileData bootStrapFileData = new FileData(0L, addressBookBytes, AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, TransactionTypeEnum.FILECREATE.getProtoId()); addressBookService.update(bootStrapFileData); fileDataEntries.incrementAndGet(); int pageSize = 1000; List<FileData> fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); while (!CollectionUtils.isEmpty(fileDataList)) { fileDataList.forEach(fileData -> { addressBookService.update(fileData); fileDataEntries.incrementAndGet(); currentConsensusTimestamp.set(fileData.getConsensusTimestamp()); }); fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); } log.info("Migration processed {} in {} ms", fileDataEntries.get(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); } V1_28_1__Address_Book(MirrorProperties mirrorProperties, @Lazy AddressBookService addressBookService,
                                 DataSource dataSource); @Override void migrate(Context context); }
V1_28_1__Address_Book extends BaseJavaMigration { @Override public void migrate(Context context) throws Exception { jdbcTemplate = new JdbcTemplate(dataSource); Stopwatch stopwatch = Stopwatch.createStarted(); AtomicLong currentConsensusTimestamp = new AtomicLong(0); AtomicLong fileDataEntries = new AtomicLong(0); byte[] addressBookBytes; try { Path initialAddressBook = mirrorProperties.getInitialAddressBook(); if (initialAddressBook != null) { addressBookBytes = Files.readAllBytes(initialAddressBook); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, initialAddressBook); } else { MirrorProperties.HederaNetwork hederaNetwork = mirrorProperties.getNetwork(); String resourcePath = String.format("/addressbook/%s", hederaNetwork.name().toLowerCase()); Resource resource = new ClassPathResource(resourcePath, getClass()); addressBookBytes = IOUtils.toByteArray(resource.getInputStream()); log.info("Loading bootstrap address book of {} B from {}", addressBookBytes.length, resource); } } catch (Exception e) { throw new IllegalStateException("Unable to load bootstrap address book", e); } FileData bootStrapFileData = new FileData(0L, addressBookBytes, AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, TransactionTypeEnum.FILECREATE.getProtoId()); addressBookService.update(bootStrapFileData); fileDataEntries.incrementAndGet(); int pageSize = 1000; List<FileData> fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); while (!CollectionUtils.isEmpty(fileDataList)) { fileDataList.forEach(fileData -> { addressBookService.update(fileData); fileDataEntries.incrementAndGet(); currentConsensusTimestamp.set(fileData.getConsensusTimestamp()); }); fileDataList = getLatestFileData(currentConsensusTimestamp.get(), pageSize); } log.info("Migration processed {} in {} ms", fileDataEntries.get(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); } V1_28_1__Address_Book(MirrorProperties mirrorProperties, @Lazy AddressBookService addressBookService,
                                 DataSource dataSource); @Override void migrate(Context context);  }