Skip to content

Commit

Permalink
failure during write
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Atanasov <[email protected]>
  • Loading branch information
ata-nas committed Feb 6, 2025
1 parent 491f1f3 commit 2a7ecd0
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.hedera.block.server.util.PersistTestUtils;
import com.hedera.hapi.block.BlockItemUnparsed;
import com.hedera.hapi.block.BlockUnparsed;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -118,6 +119,40 @@ void testSuccessfulWriteResponse(final long validBlockNumber) throws Exception {
.returns(BlockPersistenceStatus.SUCCESS, from(BlockPersistenceResult::status));
}

/**
* This test aims to verify that the {@link AsyncBlockAsLocalFileWriter#call()}
* correctly returns a failure during write status if the offered block is
* complete, but an exception is thrown during the write operation.
*
* @param validBlockNumber parameterized, valid block number
*/
@Timeout(value = TEST_TIMEOUT_MILLIS, unit = TimeUnit.MILLISECONDS)
@ParameterizedTest
@MethodSource("validBlockNumbers")
void testFailDuringWrite(final long validBlockNumber) throws Exception {
// setup
final List<BlockItemUnparsed> validBlock =
PersistTestUtils.generateBlockItemsUnparsedForWithBlockNumber(validBlockNumber);
final AsyncBlockWriter toTest = new AsyncBlockAsLocalFileWriter(
blockPathResolverMock, blockRemoverMock, compressionMock, validBlockNumber);
final TransferQueue<BlockItemUnparsed> q = toTest.getQueue();
validBlock.forEach(q::offer);

// when
final Path expectedWrittenBlockFile = testTempDir.resolve(validBlockNumber + Constants.BLOCK_FILE_EXTENSION);
when(blockPathResolverMock.resolveLiveRawPathToBlock(validBlockNumber)).thenReturn(expectedWrittenBlockFile);
when(blockPathResolverMock.existsVerifiedBlock(validBlockNumber)).thenReturn(false);
when(compressionMock.getCompressionFileExtension()).thenReturn("");
when(compressionMock.wrap(any(OutputStream.class))).thenThrow(IOException.class);

// then
final BlockPersistenceResult actual = toTest.call();
assertThat(actual)
.isNotNull()
.returns(validBlockNumber, from(BlockPersistenceResult::blockNumber))
.returns(BlockPersistenceStatus.FAILURE_DURING_WRITE, from(BlockPersistenceResult::status));
}

/**
* This test aims to verify that the {@link AsyncBlockAsLocalFileWriter#call()}
* correctly returns an incomplete block status if the offered block is
Expand Down

0 comments on commit 2a7ecd0

Please sign in to comment.