Skip to content

Commit b5e4d99

Browse files
DbFullException: test max size when opening, clarify in docs
In response to #1199
1 parent f3fd1a5 commit b5e4d99

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,13 @@ BoxStoreBuilder modelUpdate(ModelUpdate modelUpdate) {
369369

370370
/**
371371
* Sets the maximum size the database file can grow to.
372-
* When applying a transaction (e.g. putting an object) would exceed it a {@link DbFullException} is thrown.
373372
* <p>
374-
* By default, this is 1 GB, which should be sufficient for most applications.
375-
* In general, a maximum size prevents the database from growing indefinitely when something goes wrong
376-
* (for example data is put in an infinite loop).
373+
* The Store will throw when the file size is about to be exceeded, see {@link DbFullException} for details.
377374
* <p>
378-
* This value can be changed, so increased or also decreased, each time when opening a store.
375+
* By default, this is 1 GB, which should be sufficient for most applications. In general, a maximum size prevents
376+
* the database from growing indefinitely when something goes wrong (for example data is put in an infinite loop).
377+
* <p>
378+
* This can be set to a value different, so higher or also lower, from when last building the Store.
379379
*/
380380
public BoxStoreBuilder maxSizeInKByte(long maxSizeInKByte) {
381381
if (maxSizeInKByte <= maxDataSizeInKByte) {

objectbox-java/src/main/java/io/objectbox/exception/DbFullException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* {@link io.objectbox.BoxStoreBuilder#maxSizeInKByte(long) maxSizeInKByte} configured for the Store.
2222
* <p>
2323
* This can occur for operations like when an Object is {@link io.objectbox.Box#put(Object) put}, at the point when the
24-
* (internal) transaction is committed. Or when the Store is opened with a max size smaller than the existing database.
24+
* (internal) transaction is committed. Or when the Store is opened with a max size too small for the existing database.
2525
*/
2626
public class DbFullException extends DbException {
2727
public DbFullException(String message) {

tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreBuilderTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ public void maxFileSize() {
262262
assumeFalse(IN_MEMORY); // no max size support for in-memory
263263

264264
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+
265273
builder.maxSizeInKByte(30); // Empty file is around 12 KB, object below adds about 8 KB each.
266274
store = builder.build();
267275
putTestEntity(LONG_STRING, 1);

0 commit comments

Comments
 (0)