Esempio n. 1
0
  @Test
  public void run() throws IOException {
    File f = File.createTempFile("mapdbTest", "mapdb");
    DB db = DBMaker.fileDB(f).closeOnJvmShutdown().make();

    Map<Integer, String> testMap =
        db.hashMapCreate("testmap")
            .valueSerializer(VALUE_SERIALIZER)
            // .valueSerializer(new TestSerializer())
            .makeOrGet();

    testMap.put(1, problem);
    db.commit();
    db.close();

    db = null;
    testMap = null;

    // -------------------------
    db = DBMaker.fileDB(f).closeOnJvmShutdown().make();
    testMap = db.hashMapCreate("testmap").valueSerializer(VALUE_SERIALIZER).makeOrGet();
    String deserialized = testMap.get(1);

    db.close();
    assertEquals(problem, deserialized);
  }
Esempio n. 2
0
  @Test(timeout = 600000)
  public void expire_maxSize_with_TTL_get() throws InterruptedException {
    if (UtilsTest.scale() == 0) return;

    File f = UtilsTest.tempDbFile();
    for (int o = 0; o < 2; o++) {
      final DB db = DBMaker.fileDB(f).transactionDisable().make();
      final HTreeMap<Object, Object> map =
          db.hashMapCreate("foo")
              .expireMaxSize(1000)
              .expireAfterAccess(3, TimeUnit.SECONDS)
              .makeOrGet();

      map.put("foo", "bar");

      for (int i = 0; i < 10; i++) assertEquals("bar", map.get("foo"));

      Thread.sleep(6000);
      map.get("aa"); // so internal tasks have change to run
      assertEquals(null, map.get("foo"));

      db.commit();
      db.close();
      Thread.sleep(1100);
    }
  }
 public static void main(String[] args) {
   DB db = DBMaker.memoryDB().make();
   // a
   HTreeMap<String, Long> map =
       db.hashMapCreate("map")
           .valueCreator(
               new Fun.Function1<Long, String>() {
                 @Override
                 public Long run(String o) {
                   return 1111L;
                 }
               })
           .makeOrGet();
   // z
 }
Esempio n. 4
0
  @Test
  public void expire_maxSize_with_TTL() throws InterruptedException {
    if (UtilsTest.scale() == 0) return;
    File f = UtilsTest.tempDbFile();
    for (int o = 0; o < 2; o++) {
      final DB db = DBMaker.fileDB(f).transactionDisable().make();
      final HTreeMap<Object, Object> map =
          db.hashMapCreate("foo")
              .expireMaxSize(1000)
              .expireAfterWrite(1, TimeUnit.DAYS)
              .makeOrGet();

      map.put("foo", "bar");

      assertEquals("bar", map.get("foo"));

      Thread.sleep(1100);
      assertEquals("bar", map.get("foo"));

      db.commit();
      db.close();
      Thread.sleep(1100);
    }
  }