Skip to content

Commit

Permalink
fix:extended a unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Peterson <[email protected]>
  • Loading branch information
mattp-swirldslabs committed Jul 29, 2024
1 parent d20db18 commit 3385041
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,42 @@ public void testConstructorWithInvalidPath() {

@Test
public void testPartialBlockRemoval() throws IOException {
final List<BlockItem> blockItems = PersistTestUtils.generateBlockItems(1);
final List<BlockItem> blockItems = PersistTestUtils.generateBlockItems(3);
final BlockRemover blockRemover =
new BlockAsDirRemover(
Path.of(testConfig.get(JUNIT).asString().get()), Util.defaultPerms);
final BlockWriter<BlockItem> blockWriter =
new TestIOExceptionBlockAsDirWriter(
JUNIT, testConfig, blockRemover, Util.defaultPerms, 3);
JUNIT, testConfig, blockRemover, Util.defaultPerms, 23);

// Write a few block items
blockWriter.write(blockItems.get(0));
blockWriter.write(blockItems.get(1));
blockWriter.write(blockItems.get(2));
// Write all the block items for 2 blocks
for (int i = 0;i < 20;i++) {
blockWriter.write(blockItems.get(i));
}

// Write a few block items for the 3rd block
blockWriter.write(blockItems.get(20));
blockWriter.write(blockItems.get(21));
blockWriter.write(blockItems.get(22));

// Attempt to write the next block should fail
assertThrows(IOException.class, () -> blockWriter.write(blockItems.get(3)));
assertThrows(IOException.class, () -> blockWriter.write(blockItems.get(23)));

// Verify the partially written block was removed
final BlockReader<Block> blockReader = new BlockAsDirReader(JUNIT, testConfig);
final Optional<Block> blockOpt = blockReader.read(1);
Optional<Block> blockOpt = blockReader.read(3);
assertTrue(blockOpt.isEmpty());

// Confirm blocks 1 and 2 still exist
blockOpt = blockReader.read(1);
assertFalse(blockOpt.isEmpty());
assertEquals(10, blockOpt.get().getBlockItemsList().size());
assertEquals(1, blockOpt.get().getBlockItems(0).getHeader().getBlockNumber());

blockOpt = blockReader.read(2);
assertFalse(blockOpt.isEmpty());
assertEquals(10, blockOpt.get().getBlockItemsList().size());
assertEquals(2, blockOpt.get().getBlockItems(0).getHeader().getBlockNumber());
}

private void removeBlockReadPerms(int blockNumber, final Config config) throws IOException {
Expand Down

0 comments on commit 3385041

Please sign in to comment.