Search in sources :

Example 21 with RecordFile

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;
        }
    });
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) TestFactory(org.junit.jupiter.api.TestFactory) SneakyThrows(lombok.SneakyThrows)

Example 22 with RecordFile

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;
        }
    });
}
Also used : Path(java.nio.file.Path) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) TestFactory(org.junit.jupiter.api.TestFactory) SneakyThrows(lombok.SneakyThrows)

Example 23 with RecordFile

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();
    });
}
Also used : Path(java.nio.file.Path) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) TestFactory(org.junit.jupiter.api.TestFactory)

Example 24 with RecordFile

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);
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Test(org.junit.jupiter.api.Test)

Example 25 with RecordFile

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);
    }
}
Also used : ImporterException(com.hedera.mirror.importer.exception.ImporterException) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ValidatedDataInputStream(com.hedera.mirror.importer.reader.ValidatedDataInputStream) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ImporterException(com.hedera.mirror.importer.exception.ImporterException)

Aggregations

RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)33 Test (org.junit.jupiter.api.Test)9 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)8 Instant (java.time.Instant)5 ByteString (com.google.protobuf.ByteString)4 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 StreamFileData (com.hedera.mirror.importer.domain.StreamFileData)3 StreamFileReaderException (com.hedera.mirror.importer.exception.StreamFileReaderException)3 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 RequiredArgsConstructor (lombok.RequiredArgsConstructor)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 TestFactory (org.junit.jupiter.api.TestFactory)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MirrorProperties (com.hedera.mirror.importer.MirrorProperties)2 PREVIEWNET (com.hedera.mirror.importer.MirrorProperties.HederaNetwork.PREVIEWNET)2 TESTNET (com.hedera.mirror.importer.MirrorProperties.HederaNetwork.TESTNET)2