use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.
the class RecordFileReaderImplV5Test method verifyRecordItemLinksInEthTransactionValidFile.
@SneakyThrows
@TestFactory
Stream<DynamicTest> verifyRecordItemLinksInEthTransactionValidFile() {
String template = "read file %s containing eth transactions";
var resourceResolver = new PathMatchingResourcePatternResolver();
return DynamicTest.stream(Arrays.stream(resourceResolver.getResources("classpath:data/recordstreams/eth-0.26.0/record0.0.3/*" + ".rcd")), (recordFile) -> String.format(template, recordFile.getFilename()), (recordFile) -> {
// given
StreamFileData streamFileData = StreamFileData.from(recordFile.getFile());
// when
RecordFile actual = recordFileReader.read(streamFileData);
// then
RecordItem previousItem = null;
RecordItem lastParentItem = null;
for (var item : actual.getItems().collectList().block()) {
// assert previous link points to previous item
assertThat(item.getPrevious()).isEqualTo(previousItem);
// confirm if child that parent is populated
if (item.isChild()) {
assertThat(item.getParent()).isEqualTo(lastParentItem);
} else {
lastParentItem = item;
}
previousItem = item;
}
});
}
use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.
the class RecordFileReaderTest method verifyRecordItemLinksInValidFile.
@SneakyThrows
@TestFactory
Stream<DynamicTest> verifyRecordItemLinksInValidFile() {
String template = "read file %s containing eth transactions";
var resourceResolver = new PathMatchingResourcePatternResolver();
return DynamicTest.stream(getFilteredFiles(false), (recordFile) -> String.format(template, recordFile.getVersion(), recordFile.getName()), (recordFile) -> {
// given
Path testFile = getTestFile(recordFile);
StreamFileData streamFileData = StreamFileData.from(testFile.toFile());
// when
RecordFile actual = recordFileReader.read(streamFileData);
// then
RecordItem previousItem = null;
for (var item : actual.getItems().collectList().block()) {
// assert previous link points to previous item
assertThat(item.getPrevious()).isEqualTo(previousItem);
previousItem = item;
}
});
}
use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.
the class RecordFileReaderTest method readValidFile.
@TestFactory
Stream<DynamicTest> readValidFile() {
String template = "read valid version %d file %s";
return DynamicTest.stream(getFilteredFiles(false), (recordFile) -> String.format(template, recordFile.getVersion(), recordFile.getName()), (recordFile) -> {
// given
Path testFile = getTestFile(recordFile);
StreamFileData streamFileData = StreamFileData.from(testFile.toFile());
// when
RecordFile actual = recordFileReader.read(streamFileData);
// then
assertThat(actual).usingRecursiveComparison().ignoringFields("bytes", "items", "loadStart", "logsBloomAggregator").isEqualTo(recordFile);
assertThat(actual.getBytes()).isNotEmpty().isEqualTo(streamFileData.getBytes());
assertThat(actual.getLoadStart()).isNotNull().isPositive();
List<Long> timestamps = actual.getItems().map(RecordItem::getConsensusTimestamp).collectList().block();
assertThat(timestamps).first().isEqualTo(recordFile.getConsensusStart());
assertThat(timestamps).last().isEqualTo(recordFile.getConsensusEnd());
assertThat(timestamps).doesNotHaveDuplicates().isSorted();
List<Integer> transactionIndexes = actual.getItems().map(RecordItem::getTransactionIndex).collectList().block();
assertThat(transactionIndexes).first().isEqualTo(0);
assertThat(transactionIndexes).isEqualTo(IntStream.range(0, recordFile.getCount().intValue()).boxed().collect(Collectors.toList()));
assertThat(transactionIndexes).doesNotHaveDuplicates().isSorted();
});
}
use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.
the class RecordFileRepositoryTest method findLatest.
@Test
void findLatest() {
RecordFile recordFile1 = recordFile();
RecordFile recordFile2 = recordFile();
RecordFile recordFile3 = recordFile();
recordFileRepository.saveAll(List.of(recordFile1, recordFile2, recordFile3));
assertThat(recordFileRepository.findLatest()).get().isEqualTo(recordFile3);
}
use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.
the class AbstractPreV5RecordFileReader method read.
@Override
public RecordFile read(@NonNull StreamFileData streamFileData) {
String filename = streamFileData.getFilename();
try (RecordFileDigest digest = getRecordFileDigest(streamFileData.getInputStream());
ValidatedDataInputStream vdis = new ValidatedDataInputStream(digest.getDigestInputStream(), filename)) {
RecordFile recordFile = new RecordFile();
recordFile.setBytes(streamFileData.getBytes());
recordFile.setLoadStart(Instant.now().getEpochSecond());
recordFile.setName(filename);
recordFile.setDigestAlgorithm(DIGEST_ALGORITHM);
readHeader(vdis, recordFile);
readBody(vdis, digest, recordFile);
return recordFile;
} catch (ImporterException e) {
throw e;
} catch (Exception e) {
throw new StreamFileReaderException("Error reading record file " + filename, e);
}
}
Aggregations