Search in sources :

Example 26 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class CompositeRecordFileReader method read.

@Override
public RecordFile read(@NonNull StreamFileData streamFileData) {
    long count = 0;
    Stopwatch stopwatch = Stopwatch.createStarted();
    String filename = streamFileData.getFilename();
    int version = 0;
    try (DataInputStream dis = new DataInputStream(streamFileData.getInputStream())) {
        RecordFileReader reader;
        version = dis.readInt();
        switch(version) {
            case 1:
                reader = version1Reader;
                break;
            case 2:
                reader = version2Reader;
                break;
            case 5:
                reader = version5Reader;
                break;
            default:
                throw new InvalidStreamFileException(String.format("Unsupported record file version %d in file %s", version, filename));
        }
        RecordFile recordFile = reader.read(streamFileData);
        count = recordFile.getCount();
        return recordFile;
    } catch (IOException e) {
        throw new StreamFileReaderException("Error reading record file " + filename, e);
    } finally {
        log.info("Read {} items {}successfully from v{} record file {} in {}", count, count != 0 ? "" : "un", version, filename, stopwatch);
    }
}
Also used : InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Stopwatch(com.google.common.base.Stopwatch) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 27 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class RecordFileParserTest method getStreamFile.

@Override
protected StreamFile getStreamFile() {
    long id = ++count;
    Instant instant = Instant.ofEpochSecond(0L, id);
    String filename = StreamFilename.getFilename(parserProperties.getStreamType(), DATA, instant);
    recordItem = recordItem(id);
    RecordFile recordFile = new RecordFile();
    recordFile.setBytes(new byte[] { 0, 1, 2 });
    recordFile.setConsensusEnd(id);
    recordFile.setConsensusStart(id);
    recordFile.setConsensusEnd(id);
    recordFile.setCount(id);
    recordFile.setDigestAlgorithm(DigestAlgorithm.SHA384);
    recordFile.setFileHash("fileHash" + id);
    recordFile.setHapiVersionMajor(0);
    recordFile.setHapiVersionMinor(23);
    recordFile.setHapiVersionPatch(0);
    recordFile.setHash("hash" + id);
    recordFile.setLoadEnd(id);
    recordFile.setLoadStart(id);
    recordFile.setName(filename);
    recordFile.setNodeAccountId(EntityId.of("0.0.3", EntityType.ACCOUNT));
    recordFile.setPreviousHash("previousHash" + (id - 1));
    recordFile.setVersion(1);
    recordFile.setItems(Flux.just(recordItem));
    return recordFile;
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Instant(java.time.Instant)

Example 28 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class RecordFileParserIntegrationTest method recordFile.

RecordFile recordFile(File file, long index) {
    RecordFile recordFile = recordFileReader.read(StreamFileData.from(file));
    recordFile.setIndex(index);
    recordFile.setNodeAccountId(NODE_ACCOUNT_ID);
    return recordFile;
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile)

Example 29 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class RecordFileParserIntegrationTest method rollback.

@Test
void rollback() {
    // when
    RecordFile recordFile = recordFileDescriptor1.getRecordFile();
    recordFileParser.parse(recordFile);
    // then
    verifyFinalDatabaseState(recordFileDescriptor1);
    // when
    Assertions.assertThrows(ParserException.class, () -> recordFileParser.parse(recordFile));
    // then
    verifyFinalDatabaseState(recordFileDescriptor1);
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 30 with RecordFile

use of com.hedera.mirror.common.domain.transaction.RecordFile in project hedera-mirror-node by hashgraph.

the class RecordFileParserPerformanceTest method setup.

@BeforeAll
void setup() throws Exception {
    EntityId nodeAccountId = EntityId.of(0L, 0L, 3L, EntityType.ACCOUNT);
    for (int index = 0; index < testFiles.length; index++) {
        RecordFile recordFile = recordFileReader.read(StreamFileData.from(testFiles[index].getFile()));
        recordFile.setIndex((long) index);
        recordFile.setNodeAccountId(nodeAccountId);
        recordFiles.add(recordFile);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) BeforeAll(org.junit.jupiter.api.BeforeAll)

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