Search in sources :

Example 6 with AccountBalanceFile

use of com.hedera.mirror.common.domain.balance.AccountBalanceFile in project hedera-mirror-node by hashgraph.

the class ProtoBalanceFileReader method read.

@Override
public AccountBalanceFile read(StreamFileData streamFileData) {
    Instant loadStart = Instant.now();
    Flux<AccountBalance> items = toFlux(streamFileData);
    long consensusTimestamp = items.map(AccountBalance::getId).map(AccountBalance.Id::getConsensusTimestamp).blockFirst();
    try (InputStream inputStream = streamFileData.getInputStream()) {
        AccountBalanceFile accountBalanceFile = new AccountBalanceFile();
        accountBalanceFile.setBytes(streamFileData.getBytes());
        accountBalanceFile.setConsensusTimestamp(consensusTimestamp);
        accountBalanceFile.setFileHash(DigestUtils.sha384Hex(inputStream));
        accountBalanceFile.setItems(items);
        accountBalanceFile.setLoadStart(loadStart.getEpochSecond());
        accountBalanceFile.setName(streamFileData.getFilename());
        return accountBalanceFile;
    } catch (IOException e) {
        throw new StreamFileReaderException(e);
    }
}
Also used : AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) CodedInputStream(com.google.protobuf.CodedInputStream) InputStream(java.io.InputStream) Instant(java.time.Instant) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) IOException(java.io.IOException)

Example 7 with AccountBalanceFile

use of com.hedera.mirror.common.domain.balance.AccountBalanceFile in project hedera-mirror-node by hashgraph.

the class AccountBalanceFileParserPerformanceTest method setup.

@BeforeAll
void setup() throws Exception {
    balanceParserProperties.setEnabled(true);
    EntityId nodeAccountId = EntityId.of(0L, 0L, 3L, EntityType.ACCOUNT);
    for (Resource resource : testFiles) {
        AccountBalanceFile accountBalanceFile = balanceFileReader.read(StreamFileData.from(resource.getFile()));
        accountBalanceFile.setNodeAccountId(nodeAccountId);
        accountBalanceFiles.add(accountBalanceFile);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) Resource(org.springframework.core.io.Resource) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 8 with AccountBalanceFile

use of com.hedera.mirror.common.domain.balance.AccountBalanceFile in project hedera-mirror-node by hashgraph.

the class AccountBalanceFileParserTest method multipleBatches.

@Test
void multipleBatches() {
    // given
    int batchSize = parserProperties.getBatchSize();
    parserProperties.setBatchSize(2);
    AccountBalanceFile accountBalanceFile = accountBalanceFile(1);
    List<AccountBalance> items = accountBalanceFile.getItems().collectList().block();
    // when
    accountBalanceFileParser.parse(accountBalanceFile);
    // then
    assertAccountBalanceFile(accountBalanceFile, items);
    parserProperties.setBatchSize(batchSize);
}
Also used : AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 9 with AccountBalanceFile

use of com.hedera.mirror.common.domain.balance.AccountBalanceFile in project hedera-mirror-node by hashgraph.

the class AccountBalanceFileParserTest method disabled.

@Test
void disabled() {
    // given
    parserProperties.setEnabled(false);
    AccountBalanceFile accountBalanceFile = accountBalanceFile(1);
    // when
    accountBalanceFileParser.parse(accountBalanceFile);
    // then
    assertAccountBalanceFile(accountBalanceFile, List.of());
}
Also used : AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 10 with AccountBalanceFile

use of com.hedera.mirror.common.domain.balance.AccountBalanceFile in project hedera-mirror-node by hashgraph.

the class AccountBalanceFileParserTest method success.

@Test
void success() {
    // given
    AccountBalanceFile accountBalanceFile = accountBalanceFile(1);
    List<AccountBalance> items = accountBalanceFile.getItems().collectList().block();
    // when
    accountBalanceFileParser.parse(accountBalanceFile);
    // then
    assertAccountBalanceFile(accountBalanceFile, items);
    assertThat(accountBalanceFile.getTimeOffset()).isZero();
}
Also used : AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)23 Test (org.junit.jupiter.api.Test)18 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)9 AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)8 StreamFileData (com.hedera.mirror.importer.domain.StreamFileData)7 Instant (java.time.Instant)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 UnknownFieldSet (com.google.protobuf.UnknownFieldSet)2 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)2 AllAccountBalances (com.hedera.services.stream.proto.AllAccountBalances)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Stopwatch (com.google.common.base.Stopwatch)1 CodedInputStream (com.google.protobuf.CodedInputStream)1 StreamType (com.hedera.mirror.common.domain.StreamType)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 DomainUtils (com.hedera.mirror.common.util.DomainUtils)1