示例#1
0
 @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();
   }
 }
示例#2
0
 @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();
   }
 }
示例#3
0
  @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();
    }
  }