public void testBlukPut() throws Exception {
    File indexFile = new File("tmp/bulkput");
    indexFile.delete();

    DiskTreap<String, Integer> index = new DiskTreap<String, Integer>(indexFile);

    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("foo", 1);
    map.put("footbar", 2);
    map.put("azb", 3);
    map.put("dddddd", 4);
    map.put("aojiao", 5);

    Map<String, Integer> map2 = new HashMap<String, Integer>();
    map2.put("azb", 13);
    map2.put("footbar", 14);
    map2.put("sjy", 140);

    index.bulkPut(map);
    index.bulkPut(map2);
    index.close();

    index = new DiskTreap<String, Integer>(indexFile);
    assertEquals(index.prefix("a", 10).toString(), "{aojiao=5, azb=13}");
    assertEquals(index.prefix("f", 10).toString(), "{foo=1, footbar=14}");
    assertEquals(index.get("dddddd").toString(), "4");
    assertEquals(index.length(), 6);
    index.close();
  }
Пример #2
0
 @Override
 public void execute(
     DiskTreap<FastString, byte[]> diskTreap, String command, byte[] body, BufferedOutputStream os)
     throws Exception {
   Integer len = diskTreap.length();
   os.write(("" + len + "\r\n").getBytes());
   os.write(("END\r\n").getBytes());
 }
  public void testRemove() throws Exception {
    new File("tmp/remove_test").delete();
    new File("tmp/remove_faststr_test").delete();
    DiskTreap<String, Integer> treap = new DiskTreap<String, Integer>(new File("tmp/remove_test"));
    for (int i = 0; i < 100; i++) {
      treap.put("thing" + i, i);
    }
    assertEquals(100, treap.length());
    for (int i = 0; i < 9; i++) {
      treap.removePrefix("thing" + i);
    }
    assertEquals(11, treap.length());
    assertEquals(
        "{thing99=99, thing98=98, thing97=97, thing96=96, thing95=95, thing94=94, thing93=93, thing92=92, thing91=91, thing90=90, thing9=9}",
        treap.kmax(100).toString());
    treap.delete("thing9");
    assertEquals(10, treap.length());
    assertEquals(
        "{thing99=99, thing98=98, thing97=97, thing96=96, thing95=95, thing94=94, thing93=93, thing92=92, thing91=91, thing90=90}",
        treap.kmax(100).toString());
    assertNull(treap.get("thing77"));
    treap.close();
    treap = new DiskTreap<String, Integer>(new File("tmp/remove_test"));
    for (int i = 0; i < 100; i++) {
      treap.put("thing" + i, i);
    }
    assertEquals(100, treap.length());

    DiskTreap<FastString, Integer> treap2 =
        new DiskTreap<FastString, Integer>(new File("tmp/remove_faststr_test"));
    for (int i = 0; i < 100; i++) {
      treap2.put(new FastString("thing" + i), i);
    }
    assertEquals(100, treap2.length());
    for (int i = 0; i < 9; i++) {
      treap2.removePrefix(new FastString("thing" + i));
    }
    assertEquals(11, treap2.length());
    assertEquals(
        "{thing99=99, thing98=98, thing97=97, thing96=96, thing95=95, thing94=94, thing93=93, thing92=92, thing91=91, thing90=90, thing9=9}",
        treap2.kmax(100).toString());
    treap2.delete(new FastString("thing9"));
    assertEquals(10, treap2.length());
    assertEquals(
        "{thing99=99, thing98=98, thing97=97, thing96=96, thing95=95, thing94=94, thing93=93, thing92=92, thing91=91, thing90=90}",
        treap2.kmax(100).toString());
    assertNull(treap2.get(new FastString("thing77")));
    treap2.close();
  }
 public void testLength() throws Exception {
   File strKeyIndexFile = prepareDataStringKey();
   DiskTreap<String, Integer> strKeyIndex = new DiskTreap<String, Integer>(strKeyIndexFile);
   assertEquals(strKeyIndex.length(), 4);
   strKeyIndex.close();
 }