@@ -261,31 +261,31 @@ public void maxSize_invalidValues_throw() {
261
261
public void maxFileSize () {
262
262
assumeFalse (IN_MEMORY ); // no max size support for in-memory
263
263
264
+ // To avoid frequently changing the limit choose one high enough to insert at least one object successfully,
265
+ // then keep inserting until the limit is hit.
264
266
builder = createBoxStoreBuilder (null );
265
- // The empty data.mdb file is around 12 KB, but creating will fail also if slightly above that
266
- builder .maxSizeInKByte (15 );
267
- DbFullException couldNotPut = assertThrows (
268
- DbFullException .class ,
269
- () -> builder .build ()
270
- );
271
- assertEquals ("Could not put" , couldNotPut .getMessage ());
272
-
273
- builder .maxSizeInKByte (30 ); // Empty file is around 12 KB, object below adds about 8 KB each.
267
+ builder .maxSizeInKByte (150 );
274
268
store = builder .build ();
275
- putTestEntity (LONG_STRING , 1 );
276
- TestEntity testEntity2 = createTestEntity (LONG_STRING , 2 );
277
- DbFullException dbFullException = assertThrows (
278
- DbFullException .class ,
279
- () -> getTestEntityBox ().put (testEntity2 )
280
- );
281
- assertEquals ("Could not commit tx" , dbFullException .getMessage ());
282
269
283
- // Re-open with larger size.
270
+ putTestEntity (LONG_STRING , 1 ); // Should work
271
+
272
+ boolean dbFullExceptionThrown = false ;
273
+ for (int i = 2 ; i < 1000 ; i ++) {
274
+ TestEntity testEntity = createTestEntity (LONG_STRING , i );
275
+ try {
276
+ getTestEntityBox ().put (testEntity );
277
+ } catch (DbFullException e ) {
278
+ dbFullExceptionThrown = true ;
279
+ break ;
280
+ }
281
+ }
282
+ assertTrue ("DbFullException was not thrown" , dbFullExceptionThrown );
283
+
284
+ // Check re-opening with larger size allows to insert again
284
285
store .close ();
285
- builder .maxSizeInKByte (40 );
286
+ builder .maxSizeInKByte (200 );
286
287
store = builder .build ();
287
- testEntity2 .setId (0 ); // Clear ID of object that failed to put.
288
- getTestEntityBox ().put (testEntity2 );
288
+ getTestEntityBox ().put (createTestEntity (LONG_STRING , 1000 ));
289
289
}
290
290
291
291
@ Test
0 commit comments