Skip to content

Commit d5caeba

Browse files
committed
up version to "2.7.0-2020-07-30", add validateOnOpen() test
1 parent 684d31a commit d5caeba

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class BoxStore implements Closeable {
6666
/** Change so ReLinker will update native library when using workaround loading. */
6767
public static final String JNI_VERSION = "2.6.0";
6868

69-
private static final String VERSION = "2.6.1-2020-06-09";
69+
private static final String VERSION = "2.7.0-2020-07-30";
7070
private static BoxStore defaultStore;
7171

7272
/** Currently used DB dirs with values from {@link #getCanonicalPath(File)}. */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class BoxStoreBuilder {
102102
boolean readOnly;
103103
boolean usePreviousCommit;
104104

105-
int validateOnOpenMode;
105+
short validateOnOpenMode;
106106
long validateOnOpenPageLimit;
107107

108108
TxCallback<?> failedReadTxAttemptCallback;
@@ -357,7 +357,7 @@ public BoxStoreBuilder usePreviousCommit() {
357357
*
358358
* @param validateOnOpenMode One of {@link ValidateOnOpenMode}.
359359
*/
360-
public BoxStoreBuilder validateOnOpen(int validateOnOpenMode) {
360+
public BoxStoreBuilder validateOnOpen(short validateOnOpenMode) {
361361
if (validateOnOpenMode < ValidateOnOpenMode.None || validateOnOpenMode > ValidateOnOpenMode.Full) {
362362
throw new IllegalArgumentException("Must be one of ValidateOnOpenMode");
363363
}
@@ -366,7 +366,7 @@ public BoxStoreBuilder validateOnOpen(int validateOnOpenMode) {
366366
}
367367

368368
/**
369-
* To fine-tune {@link #validateOnOpen(int)}, you can specify a limit on how much data is looked at.
369+
* To fine-tune {@link #validateOnOpen(short)}, you can specify a limit on how much data is looked at.
370370
* This is measured in "pages" with a page typically holding 4000.
371371
* Usually a low number (e.g. 1-20) is sufficient and does not impact startup performance significantly.
372372
* <p>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void setUp() throws IOException {
5858

5959
// This works with Android without needing any context
6060
File tempFile = File.createTempFile("object-store-test", "");
61+
//noinspection ResultOfMethodCallIgnored
6162
tempFile.delete();
6263
boxStoreDir = tempFile;
6364

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2020 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,15 @@
1616

1717
package io.objectbox;
1818

19+
import io.objectbox.model.ValidateOnOpenMode;
1920
import org.junit.Before;
2021
import org.junit.Test;
2122

2223

2324
import static org.junit.Assert.assertSame;
2425
import static org.junit.Assert.assertTrue;
2526
import static org.junit.Assert.fail;
27+
import static org.junit.Assert.assertNotNull;
2628

2729
public class BoxStoreBuilderTest extends AbstractObjectBoxTest {
2830

@@ -35,7 +37,7 @@ protected BoxStore createBoxStore() {
3537
}
3638

3739
@Before
38-
public void setUpBox() {
40+
public void setUpBuilder() {
3941
BoxStore.clearDefaultStore();
4042
builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir);
4143
}
@@ -106,17 +108,39 @@ public void testMaxReaders() {
106108

107109
@Test
108110
public void readOnly() {
109-
// Create a database first.
111+
// Create a database first; we must create the model only once (ID/UID sequences would be different 2nd time)
110112
byte[] model = createTestModel(false);
111113
builder = new BoxStoreBuilder(model).directory(boxStoreDir);
112114
store = builder.build();
113115
store.close();
114116

115-
// Then open database with same model as read-only.
117+
// Then re-open database with same model as read-only.
116118
builder = new BoxStoreBuilder(model).directory(boxStoreDir);
117119
builder.readOnly();
118120
store = builder.build();
119121

120122
assertTrue(store.isReadOnly());
121123
}
124+
125+
@Test
126+
public void validateOnOpen() {
127+
// Create a database first; we must create the model only once (ID/UID sequences would be different 2nd time)
128+
byte[] model = createTestModel(false);
129+
builder = new BoxStoreBuilder(model).directory(boxStoreDir);
130+
builder.entity(new TestEntity_());
131+
store = builder.build();
132+
133+
TestEntity object = new TestEntity(0);
134+
object.setSimpleString("hello hello");
135+
long id = getTestEntityBox().put(object);
136+
store.close();
137+
138+
// Then re-open database with validation and ensure db is operational
139+
builder = new BoxStoreBuilder(model).directory(boxStoreDir);
140+
builder.entity(new TestEntity_());
141+
builder.validateOnOpen(ValidateOnOpenMode.Full);
142+
store = builder.build();
143+
assertNotNull(getTestEntityBox().get(id));
144+
getTestEntityBox().put(new TestEntity(0));
145+
}
122146
}

0 commit comments

Comments
 (0)