Beispiel #1
0
  @Test
  @org.junit.Ignore
  public void large_node_size() {
    for (int i : new int[] {10, 200, 6000}) {

      int max = i * 100;
      File f = TT.tempDbFile();
      DB db = DBMaker.fileDB(f).transactionDisable().make();
      Map m =
          db.treeMapCreate("map")
              .nodeSize(i)
              .keySerializer(BTreeKeySerializer.INTEGER)
              .valueSerializer(Serializer.INTEGER)
              .make();

      for (int j = 0; j < max; j++) {
        m.put(j, j);
      }

      db.close();
      db = DBMaker.fileDB(f).deleteFilesAfterClose().transactionDisable().make();
      m = db.treeMap("map");

      for (Integer j = 0; j < max; j++) {
        assertEquals(j, m.get(j));
      }
      db.close();
    }
  }
Beispiel #2
0
  @Test
  public void WriteDBInt_lastKey_middle() {
    int numberOfRecords = 1000;

    /* Creates connections to MapDB */
    DB db1 = DBMaker.memoryDB().transactionDisable().make();

    /* Creates maps */
    ConcurrentNavigableMap<Integer, Integer> map1 = db1.treeMap("column1");

    /* Inserts initial values in maps */
    for (int i = 0; i < numberOfRecords; i++) {
      map1.put(i, i);
    }

    assertEquals((Object) (numberOfRecords - 1), map1.lastKey());

    map1.clear();

    /* Inserts some values in maps */
    for (int i = 100; i < 110; i++) {
      map1.put(i, i);
    }

    assertEquals(10, map1.size());
    assertFalse(map1.isEmpty());
    assertEquals((Object) 109, map1.lastKey());
    assertEquals((Object) 109, map1.lastEntry().getValue());
    assertEquals((Object) 100, map1.firstKey());
    assertEquals((Object) 100, map1.firstEntry().getValue());
  }
Beispiel #3
0
  @Test
  public void concurrent_first_key() {
    DB db = DBMaker.memoryDB().transactionDisable().make();
    final BTreeMap m = db.treeMap("name");

    // fill
    final int c = 1000000 * TT.scale();
    for (int i = 0; i <= c; i++) {
      m.put(i, i);
    }

    Thread t =
        new Thread() {
          @Override
          public void run() {
            for (int i = 0; i <= c; i++) {
              m.remove(c);
            }
          }
        };
    t.run();
    while (t.isAlive()) {
      assertNotNull(m.firstKey());
    }
  }
Beispiel #4
0
  @Test
  public void mod_listener_lock() {
    DB db = DBMaker.memoryDB().transactionDisable().make();
    final BTreeMap m = db.treeMap("name");

    final long rootRecid = db.getEngine().get(m.rootRecidRef, Serializer.RECID);
    final AtomicInteger counter = new AtomicInteger();

    m.modificationListenerAdd(
        new Bind.MapListener() {
          @Override
          public void update(Object key, Object oldVal, Object newVal) {
            assertTrue(m.nodeLocks.get(rootRecid) == Thread.currentThread());
            assertEquals(1, m.nodeLocks.size());
            counter.incrementAndGet();
          }
        });

    m.put("aa", "aa");
    m.put("aa", "bb");
    m.remove("aa");

    m.put("aa", "aa");
    m.remove("aa", "aa");
    m.putIfAbsent("aa", "bb");
    m.replace("aa", "bb", "cc");
    m.replace("aa", "cc");

    assertEquals(8, counter.get());
  }
  @Test
  public void testLong() {
    DB db = DBMaker.memoryDB().make();
    Map m = db.treeMap("test").keySerializer(Serializer.LONG).createOrOpen();

    for (long i = 0; i < 1000; i++) {
      m.put(i * i, i * i + 1);
    }

    for (long i = 0; i < 1000; i++) {
      assertEquals(i * i + 1, m.get(i * i));
    }
  }
Beispiel #6
0
  @Test
  public void NoSuchElem_After_Clear() {
    //      bug reported by :	Lazaros Tsochatzidis
    //        But after clearing the tree using:
    //
    //        public void Delete() {
    //            db.getTreeMap("Names").clear();
    //            db.compact();
    //        }
    //
    //        every next call of getLastKey() leads to the exception "NoSuchElement". Not
    //        only the first one...

    DB db = DBMaker.memoryDB().transactionDisable().make();
    NavigableMap m = db.treeMap("name");
    try {
      m.lastKey();
      fail();
    } catch (NoSuchElementException e) {
    }
    m.put("aa", "aa");
    assertEquals("aa", m.lastKey());
    m.put("bb", "bb");
    assertEquals("bb", m.lastKey());
    db.treeMap("name").clear();
    db.compact();
    try {
      Object key = m.lastKey();
      fail(key.toString());
    } catch (NoSuchElementException e) {
    }
    m.put("aa", "aa");
    assertEquals("aa", m.lastKey());
    m.put("bb", "bb");
    assertEquals("bb", m.lastKey());
  }
  @Test
  public void testString() {

    DB db = DBMaker.memoryDB().make();
    Map m = db.treeMap("test").keySerializer(Serializer.STRING).createOrOpen();

    List<String> list = new ArrayList<String>();
    for (long i = 0; i < 1000; i++) {
      String s = "" + Math.random() + (i * i * i);
      m.put(s, s + "aa");
    }

    for (String s : list) {
      assertEquals(s + "aa", m.get(s));
    }
  }
 public static void initializeDB() {
   db = DBMaker.fileDB(new File("testdb")).closeOnJvmShutdown().make();
   treeMap = db.treeMap("map");
 }