@Override protected BoxStore createBoxStore() { return MyObjectBox.builder().directory(boxStoreDir).build(); } }
protected BoxStore createBoxStore() { return MyObjectBox.builder().directory(boxStoreDir).build(); }
@Test public void testOpenTwoBoxStoreTwoFiles() { File boxStoreDir2 = new File(boxStoreDir.getAbsolutePath() + "-2"); BoxStoreBuilder builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir2); builder.entity(new TestEntity_()); }
@Test public void testDeleteAllFiles_staticDir() { closeStoreForTest(); File boxStoreDir2 = new File(boxStoreDir.getAbsolutePath() + "-2"); BoxStoreBuilder builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir2); BoxStore store2 = builder.build(); store2.close(); assertTrue(boxStoreDir2.exists()); assertTrue(BoxStore.deleteAllFiles(boxStoreDir2)); assertFalse(boxStoreDir2.exists()); }
@Before public void setUpBox() { BoxStore.clearDefaultStore(); builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir); }
protected BoxStoreBuilder createBoxStoreBuilder(boolean withIndex) { BoxStoreBuilder builder = new BoxStoreBuilder(createTestModel(withIndex)).directory(boxStoreDir); builder.debugFlags(DebugFlags.LOG_TRANSACTIONS_READ | DebugFlags.LOG_TRANSACTIONS_WRITE); builder.entity(new TestEntity_()); return builder; }
@Test public void testDebugCursor_seekOrNext_get_withoutModel() { TestEntity entity1 = putTestEntity("foo", 23); TestEntity entity2 = putTestEntity("bar", 42); store.close(); store = BoxStoreBuilder.createDebugWithoutModel().directory(boxStoreDir).build(); runTest(entity1, entity2); }
protected BoxStoreBuilder createBoxStoreBuilderWithTwoEntities(boolean withIndex) { BoxStoreBuilder builder = new BoxStoreBuilder(createTestModelWithTwoEntities(withIndex)).directory(boxStoreDir); builder.debugFlags(DebugFlags.LOG_TRANSACTIONS_READ | DebugFlags.LOG_TRANSACTIONS_WRITE); builder.entity(new TestEntity_()); builder.entity(new TestEntityMinimal_()); return builder; }
@Test public void testCallInReadTxWithRetry_callback() { closeStoreForTest(); final int[] countHolder = {0}; final int[] countHolderCallback = {0}; BoxStoreBuilder builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir) .failedReadTxAttemptCallback(new TxCallback() { @Override public void txFinished(@Nullable Object result, @Nullable Throwable error) { assertNotNull(error); countHolderCallback[0]++; } }); store = builder.build(); String value = store.callInReadTxWithRetry(createTestCallable(countHolder), 5, 0, true); assertEquals("42", value); assertEquals(5, countHolder[0]); assertEquals(4, countHolderCallback[0]); }
@Test // TODO can we improve? More than just "still works"? public void testQueryAttempts() { store.close(); BoxStoreBuilder builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir) .queryAttempts(5) .failedReadTxAttemptCallback(new TxCallback() { @Override public void txFinished(@Nullable Object result, @Nullable Throwable error) { error.printStackTrace(); } }); builder.entity(new TestEntity_()); store = builder.build(); putTestEntitiesScalars(); Query<TestEntity> query = store.boxFor(TestEntity.class).query().equal(simpleInt, 2007).build(); assertEquals(2007, query.findFirst().getSimpleInt()); }
@Before public void setUp() throws IOException { // store the database in the systems temporary files folder File tempFile = File.createTempFile("object-store-test", ""); // ensure file does not exist so builder creates a directory instead tempFile.delete(); boxStoreDir = tempFile; store = MyObjectBox.builder().directory(boxStoreDir).build(); }
@Before public void setUp() throws Exception { // delete database files before each test to start with a clean database BoxStore.deleteAllFiles(TEST_DIRECTORY); store = MyObjectBox.builder() // add directory flag to change where ObjectBox puts its database files .directory(TEST_DIRECTORY) // optional: add debug flags for more detailed ObjectBox log output .debugFlags(DebugFlags.LOG_QUERIES | DebugFlags.LOG_QUERY_PARAMETERS) .build(); }