use of com.hedera.mirror.common.domain.balance.AccountBalance in project hedera-mirror-node by hashgraph.
the class AccountBalanceFileParser method doParse.
@Override
protected void doParse(AccountBalanceFile accountBalanceFile) {
log.info("Starting processing account balances file {}", accountBalanceFile.getName());
DateRangeFilter filter = mirrorDateRangePropertiesProcessor.getDateRangeFilter(StreamType.BALANCE);
int batchSize = ((BalanceParserProperties) parserProperties).getBatchSize();
long count = 0L;
if (filter.filter(accountBalanceFile.getConsensusTimestamp())) {
List<AccountBalance> accountBalances = new ArrayList<>(batchSize);
Map<TokenBalance.Id, TokenBalance> tokenBalances = new HashMap<>(batchSize);
count = accountBalanceFile.getItems().doOnNext(accountBalance -> {
accountBalances.add(accountBalance);
for (var tokenBalance : accountBalance.getTokenBalances()) {
if (tokenBalances.putIfAbsent(tokenBalance.getId(), tokenBalance) != null) {
log.warn("Skipping duplicate token balance: {}", tokenBalance);
}
}
if (accountBalances.size() >= batchSize) {
batchPersister.persist(accountBalances);
accountBalances.clear();
}
if (tokenBalances.size() >= batchSize) {
batchPersister.persist(tokenBalances.values());
tokenBalances.clear();
}
}).count().block();
batchPersister.persist(accountBalances);
batchPersister.persist(tokenBalances.values());
}
Instant loadEnd = Instant.now();
accountBalanceFile.setCount(count);
accountBalanceFile.setLoadEnd(loadEnd.getEpochSecond());
streamFileListener.onEnd(accountBalanceFile);
streamFileRepository.save(accountBalanceFile);
}
use of com.hedera.mirror.common.domain.balance.AccountBalance in project hedera-mirror-node by hashgraph.
the class AccountBalanceFileParserTest method duplicateFile.
@Test
void duplicateFile() {
// given
AccountBalanceFile accountBalanceFile = accountBalanceFile(1);
AccountBalanceFile duplicate = accountBalanceFile(1);
List<AccountBalance> items = accountBalanceFile.getItems().collectList().block();
// when
accountBalanceFileParser.parse(accountBalanceFile);
// Will be ignored
accountBalanceFileParser.parse(duplicate);
// then
assertThat(accountBalanceFileRepository.count()).isEqualTo(1L);
assertAccountBalanceFile(accountBalanceFile, items);
}
use of com.hedera.mirror.common.domain.balance.AccountBalance in project hedera-mirror-node by hashgraph.
the class AccountBalanceFileParserTest method errata.
@Test
void errata() {
// given
var network = mirrorProperties.getNetwork();
mirrorProperties.setNetwork(MirrorProperties.HederaNetwork.MAINNET);
AccountBalanceFile accountBalanceFile = accountBalanceFile(BAD_TIMESTAMP1);
List<AccountBalance> items = accountBalanceFile.getItems().collectList().block();
// when
accountBalanceFileParser.parse(accountBalanceFile);
// then
assertAccountBalanceFile(accountBalanceFile, items);
assertThat(accountBalanceFile.getTimeOffset()).isEqualTo(-1);
mirrorProperties.setNetwork(network);
}
Aggregations