@@ -219,26 +219,42 @@ public void testConstructorWithInvalidPath() {
219
219
220
220
@ Test
221
221
public void testPartialBlockRemoval () throws IOException {
222
- final List <BlockItem > blockItems = PersistTestUtils .generateBlockItems (1 );
222
+ final List <BlockItem > blockItems = PersistTestUtils .generateBlockItems (3 );
223
223
final BlockRemover blockRemover =
224
224
new BlockAsDirRemover (
225
225
Path .of (testConfig .get (JUNIT ).asString ().get ()), Util .defaultPerms );
226
226
final BlockWriter <BlockItem > blockWriter =
227
227
new TestIOExceptionBlockAsDirWriter (
228
- JUNIT , testConfig , blockRemover , Util .defaultPerms , 3 );
228
+ JUNIT , testConfig , blockRemover , Util .defaultPerms , 23 );
229
229
230
- // Write a few block items
231
- blockWriter .write (blockItems .get (0 ));
232
- blockWriter .write (blockItems .get (1 ));
233
- blockWriter .write (blockItems .get (2 ));
230
+ // Write all the block items for 2 blocks
231
+ for (int i = 0 ;i < 20 ;i ++) {
232
+ blockWriter .write (blockItems .get (i ));
233
+ }
234
+
235
+ // Write a few block items for the 3rd block
236
+ blockWriter .write (blockItems .get (20 ));
237
+ blockWriter .write (blockItems .get (21 ));
238
+ blockWriter .write (blockItems .get (22 ));
234
239
235
240
// Attempt to write the next block should fail
236
- assertThrows (IOException .class , () -> blockWriter .write (blockItems .get (3 )));
241
+ assertThrows (IOException .class , () -> blockWriter .write (blockItems .get (23 )));
237
242
238
243
// Verify the partially written block was removed
239
244
final BlockReader <Block > blockReader = new BlockAsDirReader (JUNIT , testConfig );
240
- final Optional <Block > blockOpt = blockReader .read (1 );
245
+ Optional <Block > blockOpt = blockReader .read (3 );
241
246
assertTrue (blockOpt .isEmpty ());
247
+
248
+ // Confirm blocks 1 and 2 still exist
249
+ blockOpt = blockReader .read (1 );
250
+ assertFalse (blockOpt .isEmpty ());
251
+ assertEquals (10 , blockOpt .get ().getBlockItemsList ().size ());
252
+ assertEquals (1 , blockOpt .get ().getBlockItems (0 ).getHeader ().getBlockNumber ());
253
+
254
+ blockOpt = blockReader .read (2 );
255
+ assertFalse (blockOpt .isEmpty ());
256
+ assertEquals (10 , blockOpt .get ().getBlockItemsList ().size ());
257
+ assertEquals (2 , blockOpt .get ().getBlockItems (0 ).getHeader ().getBlockNumber ());
242
258
}
243
259
244
260
private void removeBlockReadPerms (int blockNumber , final Config config ) throws IOException {
0 commit comments