Esempio n. 1
0
  @Test
  public void WriteDBInt_lastKey_set_middle() {
    int numberOfRecords = 1000;

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

    /* Creates maps */
    NavigableSet<Integer> map1 = db1.treeSet("column1");

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

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

    map1.clear();

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

    assertEquals(10, map1.size());
    assertFalse(map1.isEmpty());
    assertEquals((Object) 109, map1.last());
    assertEquals((Object) 100, map1.first());
  }
Esempio n. 2
0
  @Test
  public void WriteDBInt_lastKey() {
    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 = 0; i < 10; i++) {
      map1.put(i, i);
    }

    assertEquals(10, map1.size());
    assertFalse(map1.isEmpty());
    assertEquals((Object) 9, map1.lastKey());
    assertEquals((Object) 9, map1.lastEntry().getValue());
    assertEquals((Object) 0, map1.firstKey());
    assertEquals((Object) 0, map1.firstEntry().getValue());
  }
Esempio n. 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());
    }
  }
Esempio n. 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());
  }
Esempio n. 5
0
  @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));
    }
  }
Esempio n. 6
0
  @Test
  public void issue_38() {
    int max = 50000 * TT.scale();
    Map<Integer, String[]> map = DBMaker.memoryDB().transactionDisable().make().treeMap("test");

    for (int i = 0; i < max; i++) {
      map.put(i, new String[5]);
    }

    for (int i = 0; i < max; i = i + 1000) {
      assertTrue(Arrays.equals(new String[5], map.get(i)));
      assertTrue(map.get(i).toString().contains("[Ljava.lang.String"));
    }
  }
Esempio n. 7
0
  @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));
    }
  }
Esempio n. 8
0
  @Test
  public void randomStructuralCheck() {
    Random r = new Random();
    BTreeMap map =
        DBMaker.memoryDB()
            .transactionDisable()
            .make()
            .treeMapCreate("aa")
            .keySerializer(BTreeKeySerializer.INTEGER)
            .valueSerializer(Serializer.INTEGER)
            .make();

    int max = 100000 * TT.scale();

    for (int i = 0; i < max * 10; i++) {
      map.put(r.nextInt(max), r.nextInt());
    }

    map.checkStructure();
  }
Esempio n. 9
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());
  }