@Test(dataProvider = "versions") public void testVersion(String path) throws MdbmException { MdbmInterface mdbm = null; try { mdbm = MdbmProvider.open(path, Open.MDBM_O_RDONLY, 0755, 0, 0); } catch (java.lang.AssertionError ae) { dumpStats(path); throw ae; } finally { if (null != mdbm) mdbm.close(); } }
@Test public void testFetch() throws MdbmException, UnsupportedEncodingException { String key = "testkey"; MdbmDatum datum = new MdbmDatum(key.getBytes("UTF-8")); MdbmInterface mdbm = null; try { mdbm = MdbmProvider.open( fetchMdbmV3Path, Open.MDBM_CREATE_V3 | Open.MDBM_O_RDWR | Open.MDBM_O_CREAT, 0755, 0, 0); mdbm.plock(datum, 0); mdbm.store(datum, datum, Constants.MDBM_REPLACE, mdbm.iterator()); mdbm.punlock(datum, 0); System.err.println("Calling fetch"); MdbmDatum data = mdbm.fetch(datum, mdbm.iterator()); Assert.assertNotNull(data); Assert.assertNotNull(data.getData()); Assert.assertEquals(new String(data.getData()), key); } finally { if (null != mdbm) mdbm.close(); } }
@Test(expectedExceptions = {MdbmNoEntryException.class}) public void testFetchNoEntry() throws MdbmException, UnsupportedEncodingException { String key = "nothere"; MdbmDatum datum = new MdbmDatum(key.getBytes("UTF-8")); MdbmInterface mdbm = null; try { mdbm = MdbmProvider.open( fetchMdbmV3Path, Open.MDBM_CREATE_V3 | Open.MDBM_O_RDWR | Open.MDBM_O_CREAT, 0755, 0, 0); MdbmDatum data = mdbm.fetch(datum, mdbm.iterator()); } finally { if (null != mdbm) mdbm.close(); } }
@Test public void testEmptyFirst() throws MdbmException { MdbmInterface mdbm = null; MdbmIterator iter = null; try { mdbm = MdbmProvider.open(testMdbmV3Path, Open.MDBM_O_RDONLY, 0755, 0, 0); iter = mdbm.iterator(); Assert.assertNotNull(iter); MdbmKvPair kv = mdbm.first(iter); Assert.assertNull(kv); kv = mdbm.next(iter); Assert.assertNull(kv); } finally { if (null != mdbm) mdbm.close(); if (null != iter) iter.close(); } }
@Test(dataProvider = "createMdbms") public static MdbmInterface testCreate(String path, int flags, boolean close) throws MdbmException { MdbmInterface mdbm = null; String key = "abc"; String value = "def"; try { File f = new File(path); f.delete(); Assert.assertFalse(f.exists()); mdbm = MdbmProvider.open(path, flags, 0755, 0, 0); Assert.assertFalse(mdbm.isClosed()); mdbm.storeString(key, value, Store.MDBM_REPLACE); String ret = mdbm.fetchString(key); Assert.assertEquals(ret, value); try { ret = mdbm.fetchString("nothere"); } catch (MdbmNoEntryException e) { } return mdbm; } finally { if (close && null != mdbm) mdbm.close(); } }
@Test(dataProvider = "iterateMdbms") public static void testIterate(String path, int flags) throws MdbmException { MdbmInterface mdbm = null; try { mdbm = testCreate(path, flags, false); int max = 10; for (int i = 0; i < max; i++) { String s = Integer.toString(i); mdbm.storeString(s, s, 0); } for (int i = 0; i < max; i++) { String k = Integer.toString(i); String v = mdbm.fetchString(k); Assert.assertNotNull(v); } String k = Integer.toString(max); String v = mdbm.fetchString(k); Assert.assertNull(v); } finally { if (null != mdbm) mdbm.close(); } }
@Test public void testFetchString() throws MdbmException, UnsupportedEncodingException { String key = "testkey"; MdbmDatum datum = new MdbmDatum(key.getBytes("UTF-8")); MdbmInterface mdbm = null; try { mdbm = MdbmProvider.open( fetchMdbmV3Path, Open.MDBM_CREATE_V3 | Open.MDBM_O_RDWR | Open.MDBM_O_CREAT, 0755, 0, 0); mdbm.plock(datum, 0); mdbm.storeString(key, key, Constants.MDBM_REPLACE); mdbm.punlock(datum, 0); Assert.assertEquals(mdbm.fetchString(key), key); } finally { if (null != mdbm) mdbm.close(); } }