Skip to content

Commit

Permalink
Add some comments and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
centic9 committed Mar 28, 2024
1 parent bc54270 commit ed9447d
Showing 1 changed file with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,52 @@ public void testOffer() throws Exception {
File file = File.createTempFile("ProcessImplTest", ".tmp");
try {
assertTrue(file.delete());

try (BlockProcessor process = new ProcessImpl(file, false)) {
byte[] block = FileUtils.readFileToByteArray(new File("src/test/data/block1.bin"));

process.offer(block, 0);
}
} // this will flush the queue

// need to do this outside the block to let process.close() join the Thread
assertTrue(file.exists());
assertTrue(file.length() > 0);

final long length = file.length();
assertTrue("Failed for " + file,
file.exists());
assertTrue("Failed for " + file,
file.length() > 0);

final long length = file.length();

// with append=false
try (BlockProcessor process = new ProcessImpl(file, false)) {
byte[] block = FileUtils.readFileToByteArray(new File("src/test/data/block1.bin"));

process.offer(block, 0);
}
} // this will flush the queue

// need to do this outside the block to let process.close() join the Thread
assertTrue(file.exists());
assertTrue(file.length() > 0);

assertEquals("When re-creating the file the length should be the same as before",
length, file.length());
assertTrue("Failed for " + file,
file.exists());
assertTrue("Failed for " + file,
file.length() > 0);

assertEquals("When re-creating the file the length should be the same as before",
length, file.length());

// with append=false
try (BlockProcessor process = new ProcessImpl(file, true)) {
byte[] block = FileUtils.readFileToByteArray(new File("src/test/data/block1.bin"));

process.offer(block, 0);
}
} // this will flush the queue

// need to do this outside the block to let process.close() join the Thread
assertTrue(file.exists());
assertTrue(file.length() > 0);

assertEquals("When appending, the length should be double",
length*2, file.length());
assertTrue("Failed for " + file,
file.exists());
assertTrue("Failed for " + file,
file.length() > 0);

assertEquals("When appending, the length should be double",
length*2, file.length());
} finally {
assertTrue(file.delete());
}
Expand Down

0 comments on commit ed9447d

Please sign in to comment.