Package org.apache.accumulo.tserver

Examples of org.apache.accumulo.tserver.NativeMap$NMEntry


    return f;
  }

  @Test
  public void test11() {
    NativeMap nm = new NativeMap();

    // insert things with varying field sizes and value sizes

    // generate random data
    Random r = new Random(75);

    ArrayList<Pair<Key,Value>> testData = new ArrayList<Pair<Key,Value>>();

    for (int i = 0; i < 100000; i++) {

      Key k = new Key(rlrf(r, 97), rlrf(r, 13), rlrf(r, 31), rlrf(r, 11), (r.nextLong() & 0x7fffffffffffffffl), false, false);
      Value v = new Value(rlrf(r, 511));

      testData.add(new Pair<Key,Value>(k, v));
    }

    // insert unsorted data
    for (Pair<Key,Value> pair : testData) {
      nm.put(pair.getFirst(), pair.getSecond());
    }

    for (int i = 0; i < 2; i++) {

      // sort data
      Collections.sort(testData, new Comparator<Pair<Key,Value>>() {
        @Override
        public int compare(Pair<Key,Value> o1, Pair<Key,Value> o2) {
          return o1.getFirst().compareTo(o2.getFirst());
        }
      });

      // verify
      Iterator<Entry<Key,Value>> iter1 = nm.iterator();
      Iterator<Pair<Key,Value>> iter2 = testData.iterator();

      while (iter1.hasNext() && iter2.hasNext()) {
        Entry<Key,Value> e = iter1.next();
        Pair<Key,Value> p = iter2.next();

        if (!e.getKey().equals(p.getFirst()))
          throw new RuntimeException("Keys not equal");

        if (!e.getValue().equals(p.getSecond()))
          throw new RuntimeException("Values not equal");
      }

      if (iter1.hasNext())
        throw new RuntimeException("Not all of native map consumed");

      if (iter2.hasNext())
        throw new RuntimeException("Not all of test data consumed");

      System.out.println("test 11 nm mem " + nm.getMemoryUsed());

      // insert data again w/ different value
      Collections.shuffle(testData, r);
      // insert unsorted data
      for (Pair<Key,Value> pair : testData) {
        pair.getSecond().set(rlrf(r, 511));
        nm.put(pair.getFirst(), pair.getSecond());
      }
    }

    nm.delete();
  }
View Full Code Here


    nm.delete();
  }

  @Test
  public void testBinary() {
    NativeMap nm = new NativeMap();

    byte emptyBytes[] = new byte[0];

    for (int i = 0; i < 256; i++) {
      for (int j = 0; j < 256; j++) {
        byte row[] = new byte[] {'r', (byte) (0xff & i), (byte) (0xff & j)};
        byte data[] = new byte[] {'v', (byte) (0xff & i), (byte) (0xff & j)};

        Key k = new Key(row, emptyBytes, emptyBytes, emptyBytes, 1);
        Value v = new Value(data);

        nm.put(k, v);
      }
    }

    Iterator<Entry<Key,Value>> iter = nm.iterator();
    for (int i = 0; i < 256; i++) {
      for (int j = 0; j < 256; j++) {
        byte row[] = new byte[] {'r', (byte) (0xff & i), (byte) (0xff & j)};
        byte data[] = new byte[] {'v', (byte) (0xff & i), (byte) (0xff & j)};

        Key k = new Key(row, emptyBytes, emptyBytes, emptyBytes, 1);
        Value v = new Value(data);

        assertTrue(iter.hasNext());
        Entry<Key,Value> entry = iter.next();

        assertEquals(k, entry.getKey());
        assertEquals(v, entry.getValue());

      }
    }

    assertFalse(iter.hasNext());

    for (int i = 0; i < 256; i++) {
      for (int j = 0; j < 256; j++) {
        byte row[] = new byte[] {'r', (byte) (0xff & i), (byte) (0xff & j)};
        byte data[] = new byte[] {'v', (byte) (0xff & i), (byte) (0xff & j)};

        Key k = new Key(row, emptyBytes, emptyBytes, emptyBytes, 1);
        Value v = new Value(data);

        Value v2 = nm.get(k);

        assertEquals(v, v2);
      }
    }

    nm.delete();
  }
View Full Code Here

    nm.delete();
  }

  @Test
  public void testEmpty() {
    NativeMap nm = new NativeMap();

    assertTrue(nm.size() == 0);
    assertTrue(nm.getMemoryUsed() == 0);

    nm.delete();
  }
View Full Code Here

    nm.delete();
  }

  @Test
  public void testConcurrentIter() throws IOException {
    NativeMap nm = new NativeMap();

    nm.put(nk(0), nv(0));
    nm.put(nk(1), nv(1));
    nm.put(nk(3), nv(3));

    SortedKeyValueIterator<Key,Value> iter = nm.skvIterator();

    // modify map after iter created
    nm.put(nk(2), nv(2));

    assertTrue(iter.hasTop());
    assertEquals(iter.getTopKey(), nk(0));
    iter.next();

    assertTrue(iter.hasTop());
    assertEquals(iter.getTopKey(), nk(1));
    iter.next();

    assertTrue(iter.hasTop());
    assertEquals(iter.getTopKey(), nk(2));
    iter.next();

    assertTrue(iter.hasTop());
    assertEquals(iter.getTopKey(), nk(3));
    iter.next();

    assertFalse(iter.hasTop());

    nm.delete();
  }
View Full Code Here

    assertEquals(num * num * num * num * num * 2, nm.size());
  }

  @Test
  public void test1() {
    NativeMap nm = new NativeMap();
    Iterator<Entry<Key,Value>> iter = nm.iterator();
    assertFalse(iter.hasNext());
    nm.delete();
  }
View Full Code Here

    nm.delete();
  }

  @Test
  public void test2() {
    NativeMap nm = new NativeMap();

    insertAndVerify(nm, 1, 10, 0);
    insertAndVerify(nm, 1, 10, 1);
    insertAndVerify(nm, 1, 10, 2);

    nm.delete();
  }
View Full Code Here

    nm.delete();
  }

  @Test
  public void test4() {
    NativeMap nm = new NativeMap();

    insertAndVerifyExhaustive(nm, 3, 0);
    insertAndVerifyExhaustive(nm, 3, 1);

    nm.delete();
  }
View Full Code Here

    nm.delete();
  }

  @Test
  public void test5() {
    NativeMap nm = new NativeMap();

    insertAndVerify(nm, 1, 10, 0);

    Iterator<Entry<Key,Value>> iter = nm.iterator();
    iter.next();

    nm.delete();

    try {
      nm.put(nk(1), nv(1));
      assertTrue(false);
    } catch (IllegalStateException e) {

    }

    try {
      nm.get(nk(1));
      assertTrue(false);
    } catch (IllegalStateException e) {

    }

    try {
      nm.iterator();
      assertTrue(false);
    } catch (IllegalStateException e) {

    }

    try {
      nm.iterator(nk(1));
      assertTrue(false);
    } catch (IllegalStateException e) {

    }

    try {
      nm.size();
      assertTrue(false);
    } catch (IllegalStateException e) {

    }
View Full Code Here

  }

  @Test
  public void test7() {
    NativeMap nm = new NativeMap();

    insertAndVerify(nm, 1, 10, 0);

    nm.delete();

    try {
      nm.delete();
      assertTrue(false);
    } catch (IllegalStateException e) {

    }
  }
View Full Code Here

  @Test
  public void test8() {
    // test verifies that native map sorts keys sharing some common prefix properly

    NativeMap nm = new NativeMap();

    TreeMap<Key,Value> tm = new TreeMap<Key,Value>();

    tm.put(new Key(new Text("fo")), new Value(new byte[] {'0'}));
    tm.put(new Key(new Text("foo")), new Value(new byte[] {'1'}));
    tm.put(new Key(new Text("foo1")), new Value(new byte[] {'2'}));
    tm.put(new Key(new Text("foo2")), new Value(new byte[] {'3'}));
    for (Entry<Key,Value> entry : tm.entrySet()) {
      nm.put(entry.getKey(), entry.getValue());
    }

    Iterator<Entry<Key,Value>> iter = nm.iterator();

    for (Entry<Key,Value> entry : tm.entrySet()) {
      assertTrue(iter.hasNext());
      Entry<Key,Value> entry2 = iter.next();

      assertEquals(entry.getKey(), entry2.getKey());
      assertEquals(entry.getValue(), entry2.getValue());
    }

    assertFalse(iter.hasNext());

    nm.delete();
  }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.tserver.NativeMap$NMEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.