Skip to content

Commit

Permalink
Fix sonar issues
Browse files Browse the repository at this point in the history
Signed-off-by: sdimitrov9 <[email protected]>
  • Loading branch information
sdimitrov9 committed Dec 11, 2024
1 parent d268e43 commit c249f7c
Show file tree
Hide file tree
Showing 72 changed files with 352 additions and 586 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

class TokenAccountTest {

private final EntityId FOO_COIN_ID = EntityId.of("0.0.101");
private final EntityId ACCOUNT_ID = EntityId.of("0.0.102");
private static final EntityId FOO_COIN_ID = EntityId.of("0.0.101");
private static final EntityId ACCOUNT_ID = EntityId.of("0.0.102");

@Test
void createValidTokenAccount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ class RecordItemTest {
.setTransactionHash(ByteString.copyFrom(nextBytes(32)))
.build();

private static final TransactionRecord TRANSACTION_RECORD_ETHEREUM_HASH = TransactionRecord.newBuilder()
.setReceipt(TransactionReceipt.newBuilder().setStatusValue(22).build())
.setMemo("memo")
.setTransactionHash(ByteString.copyFrom(nextBytes(32)))
.build();

private static final TransactionRecord TRANSACTION_RECORD_HEDERA_HASH = TransactionRecord.newBuilder()
.setReceipt(TransactionReceipt.newBuilder().setStatusValue(22).build())
.setMemo("memo")
.setTransactionHash(ByteString.copyFrom(nextBytes(48)))
.build();

@CsvSource({
", FEE_SCHEDULE_FILE_PART_UPLOADED, true",
", SUCCESS, true",
Expand Down Expand Up @@ -128,10 +140,10 @@ void isSuccessful(ResponseCodeEnum parentStatus, ResponseCodeEnum childStatus, b
void getTransactionHashEthereum() {
var recordItem = RecordItem.builder()
.transaction(DEFAULT_TRANSACTION)
.transactionRecord(TRANSACTION_RECORD)
.transactionRecord(TRANSACTION_RECORD_ETHEREUM_HASH)
.build();
assertThat(recordItem.getTransactionHash())
.isEqualTo(TRANSACTION_RECORD.getTransactionHash().toByteArray());
.isEqualTo(TRANSACTION_RECORD_ETHEREUM_HASH.getTransactionHash().toByteArray());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EntityServiceTest {

private final DomainBuilder domainBuilder = new DomainBuilder();
private final Base32 base32 = new Base32();
private final int EVM_ADDRESS_BYTE_LENGTH = 20;
private static final int EVM_ADDRESS_BYTE_LENGTH = 20;

@Mock
private EntityRepository entityRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class NotifyingTopicListenerTest extends AbstractSharedTopicListenerTest {
"valid_start_timestamp":1594401416000000000
}""";
private static final Duration WAIT = Duration.ofSeconds(1L);
private static boolean INITIALIZED = false;
private static boolean initialized = false;
private final NotifyingTopicListener topicListener;
private final JdbcTemplate jdbcTemplate;

Expand All @@ -58,7 +58,7 @@ protected ListenerProperties.ListenerType getType() {

@BeforeEach
void warmup() {
if (!INITIALIZED) {
if (!initialized) {
try {
// Warm up the database connection
var filter = TopicMessageFilter.builder().build();
Expand All @@ -68,7 +68,7 @@ void warmup() {
.expectNextCount(1)
.thenCancel()
.verify(WAIT);
INITIALIZED = true;
initialized = true;
} catch (AssertionError e) {
log.warn("Unable to warmup connection: {}", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,31 @@ void findAllByConsensusTimestamp() {
@Test
void findAllStakeByConsensusTimestamp() {
long consensusTimestamp = 0L;
var nodeStake0_0 = nodeStake(consensusTimestamp, 0L, 0L);
var nodeStake0_1 = nodeStake(consensusTimestamp, 1L, 1L);
var nodeStakeZeroZero = nodeStake(consensusTimestamp, 0L, 0L);
var nodeStakeZeroOne = nodeStake(consensusTimestamp, 1L, 1L);

assertThat(nodeStakeRepository.findAllStakeByConsensusTimestamp(consensusTimestamp))
.as("Latest timestamp 0 stakes")
.containsAllEntriesOf(Map.of(
nodeStake0_0.getNodeId(),
nodeStake0_0.getStake(),
nodeStake0_1.getNodeId(),
nodeStake0_1.getStake()));
nodeStakeZeroZero.getNodeId(),
nodeStakeZeroZero.getStake(),
nodeStakeZeroOne.getNodeId(),
nodeStakeZeroOne.getStake()));

// Clear cache and load the next day's node stake info
reset();

consensusTimestamp++;
var nodeStake1_0 = nodeStake(consensusTimestamp, 0L, 10L);
var nodeStake1_1 = nodeStake(consensusTimestamp, 1L, 11L);
var nodeStakeOneZero = nodeStake(consensusTimestamp, 0L, 10L);
var nodeStakeOneOne = nodeStake(consensusTimestamp, 1L, 11L);

assertThat(nodeStakeRepository.findAllStakeByConsensusTimestamp(consensusTimestamp))
.as("Latest timestamp 1 stakes")
.containsAllEntriesOf(Map.of(
nodeStake1_0.getNodeId(),
nodeStake1_0.getStake(),
nodeStake1_1.getNodeId(),
nodeStake1_1.getStake()));
nodeStakeOneZero.getNodeId(),
nodeStakeOneZero.getStake(),
nodeStakeOneOne.getNodeId(),
nodeStakeOneOne.getStake()));
}

private NodeStake nodeStake(long consensusTimestamp, long nodeId, long stake) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package com.hedera.mirror.importer.config;

import static org.hibernate.cfg.JdbcSettings.STATEMENT_INSPECTOR;

import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer;
Expand All @@ -32,7 +33,7 @@ class HibernateConfiguration implements HibernatePropertiesCustomizer {

@Override
public void customize(Map<String, Object> hibernateProperties) {
hibernateProperties.put(AvailableSettings.STATEMENT_INSPECTOR, statementInspector());
hibernateProperties.put(STATEMENT_INSPECTOR, statementInspector());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,22 @@ public void afterCompletion(int status) {

for (ThreadState threadState : threadConnections.values()) {
try (Connection connection = threadState.getConnection()) {
if (status == STATUS_COMMITTED) {
connection.commit();
successfulShards.addAll(threadState.getProcessedShards());
threadState.setStatus(STATUS_COMMITTED);
} else if (status == STATUS_ROLLED_BACK) {
connection.rollback();
successfulShards.addAll(threadState.getProcessedShards());
threadState.setStatus(STATUS_ROLLED_BACK);
} else {
connection.rollback();
failedShards.addAll(threadState.getProcessedShards());
threadState.setStatus(STATUS_UNKNOWN);
switch (status) {
case STATUS_COMMITTED -> {
connection.commit();
successfulShards.addAll(threadState.getProcessedShards());
threadState.setStatus(STATUS_COMMITTED);
}
case STATUS_ROLLED_BACK -> {
connection.rollback();
successfulShards.addAll(threadState.getProcessedShards());
threadState.setStatus(STATUS_ROLLED_BACK);
}
default -> {
connection.rollback();
failedShards.addAll(threadState.getProcessedShards());
threadState.setStatus(STATUS_UNKNOWN);
}
}
} catch (Exception e) {
log.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class TestRecordFiles {
public Map<String, RecordFile> getAll() {
var digestAlgorithm = DigestAlgorithm.SHA_384;

var recordFileV1_1 = RecordFile.builder()
var recordFileVersionOneOne = RecordFile.builder()
.consensusStart(1561990380317763000L)
.consensusEnd(1561990399074934000L)
.count(15L)
Expand All @@ -63,7 +63,7 @@ public Map<String, RecordFile> getAll() {
.size(4898)
.version(1)
.build();
var recordFileV1_2 = RecordFile.builder()
var recordFileVersionOneTwo = RecordFile.builder()
.consensusStart(1561991340302068000L)
.consensusEnd(1561991353226225001L)
.count(69L)
Expand All @@ -73,11 +73,11 @@ public Map<String, RecordFile> getAll() {
.hash(
"1faf198f8fdbefa59bde191f214d73acdc4f5c0f434677a7edf9591b129e21aea90a5b3119d2802cee522e7be6bc8830")
.name("2019-07-01T14_29_00.302068Z.rcd")
.previousHash(recordFileV1_1.getFileHash())
.previousHash(recordFileVersionOneOne.getFileHash())
.size(22347)
.version(1)
.build();
var recordFileV2_1 = RecordFile.builder()
var recordFileVersionTwoOne = RecordFile.builder()
.consensusStart(1567188600419072000L)
.consensusEnd(1567188604906443001L)
.count(19L)
Expand All @@ -91,7 +91,7 @@ public Map<String, RecordFile> getAll() {
.size(8515)
.version(2)
.build();
var recordFileV2_2 = RecordFile.builder()
var recordFileVersionTwoTwo = RecordFile.builder()
.consensusStart(1567188605249678000L)
.consensusEnd(1567188609705382001L)
.count(15L)
Expand All @@ -101,11 +101,11 @@ public Map<String, RecordFile> getAll() {
.hash(
"5ed51baeff204eb6a2a68b76bbaadcb9b6e7074676c1746b99681d075bef009e8d57699baaa6342feec4e83726582d36")
.name("2019-08-30T18_10_05.249678Z.rcd")
.previousHash(recordFileV2_1.getFileHash())
.previousHash(recordFileVersionTwoOne.getFileHash())
.size(6649)
.version(2)
.build();
var recordFileV5_1 = RecordFile.builder()
var recordFileVersionFiveOne = RecordFile.builder()
.consensusStart(1610402964063739000L)
.consensusEnd(1610402964063739000L)
.count(1L)
Expand All @@ -124,7 +124,7 @@ public Map<String, RecordFile> getAll() {
.size(498)
.version(5)
.build();
var recordFileV5_2 = RecordFile.builder()
var recordFileVersionFiveTwo = RecordFile.builder()
.consensusStart(1610402974097416003L)
.consensusEnd(1610402974097416003L)
.count(1L)
Expand All @@ -139,11 +139,11 @@ public Map<String, RecordFile> getAll() {
.metadataHash(
"912869b5204ffbb7e437aaa6e7a09e9d53da98ead27942fdf7017e850827e857fadb1167e8877cfb8175883adcd74f7d")
.name("2021-01-11T22_09_34.097416003Z.rcd")
.previousHash(recordFileV5_1.getHash())
.previousHash(recordFileVersionFiveOne.getHash())
.size(498)
.version(5)
.build();
var recordFileV6_1 = RecordFile.builder()
var recordFileVersionSixTwo = RecordFile.builder()
.consensusStart(1657701968041986003L)
.consensusEnd(1657701968041986003L)
.count(1L)
Expand Down Expand Up @@ -203,7 +203,7 @@ public Map<String, RecordFile> getAll() {
.metadataHash(
"b13a2b638c5688dbec43b97dbee8ad637d2d42376fc313c628a990ac65aefdbd39832cf5ece42b925a520ed2d2bf8eac")
.name("2022-07-13T08_46_11.304284003Z.rcd.gz")
.previousHash(recordFileV6_1.getHash())
.previousHash(recordFileVersionSixTwo.getHash())
.size(805)
.sidecarCount(1)
.sidecars(List.of(SidecarFile.builder()
Expand All @@ -222,13 +222,13 @@ public Map<String, RecordFile> getAll() {
.build();

var allFiles = List.of(
recordFileV1_1,
recordFileV1_2,
recordFileV2_1,
recordFileV2_2,
recordFileV5_1,
recordFileV5_2,
recordFileV6_1,
recordFileVersionOneOne,
recordFileVersionOneTwo,
recordFileVersionTwoOne,
recordFileVersionTwoTwo,
recordFileVersionFiveOne,
recordFileVersionFiveTwo,
recordFileVersionSixTwo,
recordFileV6_2);
return Collections.unmodifiableMap(allFiles.stream().collect(Collectors.toMap(RecordFile::getName, rf -> rf)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,8 @@ void getNodes(ConsensusMode mode, long stake, long expectedNodeStake, long expec
long timestamp = domainBuilder.timestamp();
var nodeId = new AtomicInteger(0);
for (int i = 0; i < TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT; i++) {
var nodeStake = domainBuilder
// node stake
domainBuilder
.nodeStake()
.customize(n -> n.consensusTimestamp(timestamp)
.nodeId(nodeId.getAndIncrement())
Expand Down Expand Up @@ -1033,7 +1034,8 @@ void getNodesWithNodeStakeCountMoreThanAddressBook(
var nodeId = new AtomicInteger(0);
final int nodeCount = 6; // regardless of mode, always have 4 nodes in address book and 6 nodes in nodeStakes.
for (int i = 0; i < nodeCount; i++) {
var nodeStake = domainBuilder
// node stake
domainBuilder
.nodeStake()
.customize(n -> n.consensusTimestamp(timestamp)
.nodeId(nodeId.getAndIncrement())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ void testPartialCollection() {
}

@Test
void testDownloadRatioSetTooLow() throws Exception {
void testDownloadRatioSetTooLow() {
BigDecimal problematicDownloadRatio = new BigDecimal("0.10");
commonDownloaderProperties.setDownloadRatio(problematicDownloadRatio);
assertThrows(IllegalArgumentException.class, () -> commonDownloaderProperties.init());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ public JavaMigration(MigrationVersion version, MigrationVersion minimumVersion)
}

@Override
protected void doMigrate() {}
protected void doMigrate() {
throw new UnsupportedOperationException("Missing implementation");
}

@Override
public MigrationVersion getVersion() {
Expand Down
Loading

0 comments on commit c249f7c

Please sign in to comment.