Skip to content

Commit

Permalink
change to log and error and throwing an exception instead of just ign…
Browse files Browse the repository at this point in the history
…oring an illegal state.

Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Jan 9, 2025
1 parent 080a30a commit 928e0bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
package com.hedera.block.server.verification.service;

import static java.lang.System.Logger.Level.ERROR;
import static java.lang.System.Logger.Level.WARNING;
import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -76,10 +77,10 @@ public void onBlockItemsReceived(@NonNull List<BlockItemUnparsed> blockItems) th
currentSession = sessionFactory.createSession(blockHeader);
currentSession.appendBlockItems(blockItems);

} else { // If we don't have a block header, we should have a current session, otherwise ignore
} else {
if (currentSession == null) {
LOGGER.log(WARNING, "Received block items before a block header. Ignoring.");
return;
LOGGER.log(ERROR, "Received block items before a block header.");
throw new IllegalStateException("Received block items before a block header.");
}
// Append to current session
currentSession.appendBlockItems(blockItems);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
package com.hedera.block.server.verification;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -138,12 +140,12 @@ void testOnBlockItemsReceivedNoBlockHeaderNoCurrentSession() throws ParseExcepti
BlockVerificationService service = new BlockVerificationServiceImpl(metricsService, sessionFactory);

// When
service.onBlockItemsReceived(blockItems);
IllegalStateException exception = assertThrows(IllegalStateException.class, () -> service.onBlockItemsReceived(blockItems));

// Then
// Just logs a warning. No increments or sessions created.
verifyNoInteractions(sessionFactory);
verifyNoInteractions(verificationBlocksReceived, verificationBlocksFailed);
assertEquals("Received block items before a block header.", exception.getMessage());
}

@Test
Expand Down

0 comments on commit 928e0bd

Please sign in to comment.