コード例 #1
0
ファイル: HTreeMap2Test.java プロジェクト: albedium/JDBM4
  @Test
  public void test_delete() {
    HTreeMap m =
        new HTreeMap(recman, true) {
          @Override
          protected int hash(Object key) {
            return 0;
          }
        };

    for (long i = 0; i < 20; i++) {
      m.put(i, i + 100);
    }

    for (long i = 0; i < 20; i++) {
      assertTrue(m.containsKey(i));
      assertEquals(i + 100, m.get(i));
    }

    for (long i = 0; i < 20; i++) {
      m.remove(i);
    }

    for (long i = 0; i < 20; i++) {
      assertTrue(!m.containsKey(i));
      assertEquals(null, m.get(i));
    }
  }
コード例 #2
0
ファイル: Issue400Test.java プロジェクト: dave68/mapdb
  @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);
    }
  }
コード例 #3
0
ファイル: HTreeMap2Test.java プロジェクト: albedium/JDBM4
  @Test
  public void test_simple_put() {

    HTreeMap m = new HTreeMap(recman, true);

    m.put(111L, 222L);
    m.put(333L, 444L);
    assertTrue(m.containsKey(111L));
    assertTrue(!m.containsKey(222L));
    assertTrue(m.containsKey(333L));
    assertTrue(!m.containsKey(444L));

    assertEquals(222L, m.get(111L));
    assertEquals(null, m.get(222L));
    assertEquals(444l, m.get(333L));
  }
コード例 #4
0
ファイル: HTreeMap2Test.java プロジェクト: albedium/JDBM4
  @Test
  public void test_hash_collision() {
    HTreeMap m =
        new HTreeMap(recman, true) {
          @Override
          protected int hash(Object key) {
            return 0;
          }
        };

    for (long i = 0; i < 20; i++) {
      m.put(i, i + 100);
    }

    for (long i = 0; i < 20; i++) {
      assertTrue(m.containsKey(i));
      assertEquals(i + 100, m.get(i));
    }

    m.put(11L, 1111L);
    assertEquals(1111L, m.get(11L));
  }
コード例 #5
0
ファイル: Issue400Test.java プロジェクト: dave68/mapdb
  @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);
    }
  }