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