Btree { public Database getDb() { return db; } Btree(Database db, boolean uniqueKeys); WriteTransaction beginReadWrite(); ReadOnlyTransaction beginReadOnly(); boolean isUniqueKeys(); Database getDb(); String writeSnapshot(ReadOnlyTransaction txn, SnapshotStorage snapshotDest);  }
@Test public void testSpaceReclamation() throws Exception { byte[] keyBytes = randomBytes(16); Btree btree = buildBtree(keyBytes); byte[] key = "A".getBytes(); byte[] bytes = TestUtils.buildBytes(30000); for (int i = 1; i <= 10000; i++) { put(btree, key, bytes); } System.out.println(btree.getDb().getPageStore().debugDump()); Assert.assertTrue(btree.getDb().getPageStore().debugIsIdle().or(true)); }
@Test public void testPageSplit() throws Exception { byte[] keyBytes = randomBytes(16); Btree btree = buildBtree(keyBytes); int n = 30; for (int i = 1; i <= n; i++) { byte[] key = Integer.toString(i).getBytes(); byte[] value = buildBytes(i * 1000); put(btree, key, value); } for (int i = 1; i <= n; i++) { byte[] key = Integer.toString(i).getBytes(); byte[] actual = get(btree, key); byte[] expected = buildBytes(i * 1000); Assert.assertArrayEquals(expected, actual); } System.out.println(btree.getDb().getPageStore().debugDump()); Assert.assertTrue(btree.getDb().getPageStore().debugIsIdle().or(true)); }
@Test public void testHugeValues() throws Exception { byte[] keyBytes = randomBytes(16); Btree btree = buildBtree(keyBytes); int n = 30; for (int i = 1; i <= n; i++) { byte[] key = Integer.toString(i).getBytes(); byte[] value = buildBytes(i * 10000); put(btree, key, value); } for (int i = 1; i <= n; i++) { byte[] key = Integer.toString(i).getBytes(); byte[] actual = get(btree, key); byte[] expected = buildBytes(i * 10000); Assert.assertArrayEquals(expected, actual); } System.out.println(btree.getDb().getPageStore().debugDump()); Assert.assertTrue(btree.getDb().getPageStore().debugIsIdle().or(true)); }
@Test(expected = IOException.class) public void testWrongKey() throws Exception { byte[] keyBytes = randomBytes(16); File file = new File(folder.getRoot(), UUID.randomUUID().toString()); { Database db = Database.build(file, keyBytes, null, null); boolean uniqueKeys = true; Btree btree = new Btree(db, uniqueKeys); simplePut(btree, 100); simpleRead(btree, 100); Assert.assertTrue(btree.getDb().getPageStore().debugIsIdle().or(true)); db.close(); } keyBytes = randomBytes(16); { Database db = Database.build(file, keyBytes, null, null); boolean uniqueKeys = true; Btree btree = new Btree(db, uniqueKeys); simpleRead(btree, 100); Assert.assertTrue(btree.getDb().getPageStore().debugIsIdle().or(true)); db.close(); } }
@Test public void testSimple() throws Exception { byte[] keyBytes = randomBytes(16); File file = new File(folder.getRoot(), UUID.randomUUID().toString()); Database db = Database.build(file, keyBytes, null, null); boolean uniqueKeys = true; Btree btree = new Btree(db, uniqueKeys); simplePut(btree, 100); simpleRead(btree, 100); Assert.assertTrue(btree.getDb().getPageStore().debugIsIdle().or(true)); db.close(); }
@Test public void testOpenAndClose() throws Exception { byte[] keyBytes = randomBytes(16); File file = new File(folder.getRoot(), UUID.randomUUID().toString()); for (int i = 0; i < 3; i++) { Database db = Database.build(file, keyBytes, null, null); boolean uniqueKeys = true; Btree btree = new Btree(db, uniqueKeys); if (i == 0) { simplePut(btree, 100); } simpleRead(btree, 100); System.out.println(btree.getDb().getPageStore().debugDump()); System.out.flush(); Assert.assertTrue(btree.getDb().getPageStore().debugIsIdle().or(true)); db.close(); } }