예제 #1
0
  @Test
  public void test_dir_node_serialization() throws IOException {

    BTreeMap.DirNode n =
        new BTreeMap.DirNode(new Object[] {1, 2, 3}, false, true, false, mkchild(4, 5, 6, 0));
    BTreeMap.DirNode n2 = (BTreeMap.DirNode) TT.clone(n, m.nodeSerializer);

    assertTrue(Arrays.equals(nodeKeysToArray(n), nodeKeysToArray(n2)));
    assertTrue(Arrays.equals((int[]) n.child, (int[]) n2.child));
  }
예제 #2
0
  @Test
  public void root_leaf_insert() {
    if (valsOutside) return;

    m.put(11, 12);
    final long rootRecid = engine.get(m.rootRecidRef, Serializer.RECID);
    BTreeMap.LeafNode n = (BTreeMap.LeafNode) engine.get(rootRecid, m.nodeSerializer);
    assertTrue(Arrays.equals(new Object[] {null, 11, null}, nodeKeysToArray(n)));
    assertTrue(Arrays.equals(new Object[] {12}, (Object[]) n.vals));
    assertEquals(0, n.next);
  }
예제 #3
0
  @Test
  public void insert_many_reopen_check() throws InterruptedException {
    e = openEngine();
    int max = 1000;
    int size = 100000;
    Random r = new Random(0);
    List<Long> recids = new ArrayList<Long>();
    for (int j = 0; j < max; j++) {
      byte[] b = new byte[r.nextInt(size)];
      r.nextBytes(b);
      long recid = e.put(b, Serializer.BYTE_ARRAY_NOSIZE);
      recids.add(recid);
    }
    e.commit();

    reopen();

    r = new Random(0);
    for (long recid : recids) {
      byte[] b = new byte[r.nextInt(size)];
      r.nextBytes(b);
      byte[] b2 = e.get(recid, Serializer.BYTE_ARRAY_NOSIZE);
      assertTrue("Data were not commited recid=" + recid, Arrays.equals(b, b2));
    }
  }
 public boolean matches(Object arg) {
   if (arg == null
       || !(arg.getClass().isArray()
           && InternalFactHandle.class.isAssignableFrom(arg.getClass().getComponentType()))) {
     return false;
   }
   InternalFactHandle[] actual = (InternalFactHandle[]) arg;
   return Arrays.equals(expected, actual);
 }
예제 #5
0
  @Test
  public void test_leaf_node_serialization() throws IOException {

    if (valsOutside) return;

    BTreeMap.LeafNode n =
        new BTreeMap.LeafNode(new Object[] {1, 2, 3}, true, true, false, new Object[] {1, 2, 3}, 0);
    BTreeMap.LeafNode n2 = (BTreeMap.LeafNode) TT.clone(n, m.nodeSerializer);
    assertTrue(Arrays.equals(nodeKeysToArray(n), nodeKeysToArray(n2)));
    assertEquals(n.next, n2.next);
  }
예제 #6
0
 public TestFile assertIsCopyOf(TestFile other) {
   assertIsFile();
   other.assertIsFile();
   assertEquals(
       String.format("%s is not the same length as %s", this, other),
       other.length(),
       this.length());
   assertTrue(
       String.format("%s does not have the same content as %s", this, other),
       Arrays.equals(getHash("MD5"), other.getHash("MD5")));
   return this;
 }
예제 #7
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"));
    }
  }
예제 #8
0
  @Test
  public void recover_with_interrupt() throws InterruptedException {
    int scale = TT.scale();
    if (scale == 0) return;
    e = openEngine();
    if (!e.canRollback()
        || e instanceof StoreHeap) // TODO engine might have crash recovery, but no rollbacks
    return;

    // fill recids
    final int max = scale * 1000;
    final ArrayList<Long> recids = new ArrayList<Long>();
    final AtomicLong a = new AtomicLong(10);
    final long counterRecid = e.put(a.get(), Serializer.LONG);
    Random r = new Random(a.get());
    for (int j = 0; j < max; j++) {
      byte[] b = new byte[r.nextInt(100000)];
      r.nextBytes(b);
      long recid = e.put(b, Serializer.BYTE_ARRAY_NOSIZE);
      recids.add(recid);
    }

    e.commit();

    long endTime = TT.nowPlusMinutes(10);

    while (endTime > System.currentTimeMillis()) {

      final CountDownLatch latch = new CountDownLatch(1);
      Thread t =
          new Thread() {
            @Override
            public void run() {
              try {
                for (; ; ) {
                  long A = a.incrementAndGet();
                  Random r = new Random(A);
                  e.update(counterRecid, A, Serializer.LONG);

                  for (long recid : recids) {
                    byte[] b = new byte[r.nextInt(100000)];
                    r.nextBytes(b);
                    e.update(recid, b, Serializer.BYTE_ARRAY_NOSIZE);
                  }
                  e.commit();
                }
              } finally {
                latch.countDown();
              }
            }
          };
      t.start();
      Thread.sleep(5000);
      t.stop();
      latch.await();
      if (!e.isClosed()) {
        close();
      }

      // reopen and check the content
      e = openEngine();

      // check if A-1 was commited
      long A = e.get(counterRecid, Serializer.LONG);
      assertTrue("" + A + " - " + a.get(), A == a.get() || A == a.get() - 1);
      r = new Random(A);
      for (long recid : recids) {
        byte[] b = new byte[r.nextInt(100000)];
        r.nextBytes(b);
        byte[] b2 = e.get(recid, Serializer.BYTE_ARRAY_NOSIZE);
        assertTrue("Data were not commited recid=" + recid, Arrays.equals(b, b2));
      }
      a.set(A);
    }
    e.close();
  }
예제 #9
0
 public void assertContentsHaveChangedSince(Snapshot snapshot) {
   Snapshot now = snapshot();
   assertTrue(
       String.format("contents of %s have not changed", this),
       !Arrays.equals(now.hash, snapshot.hash));
 }
예제 #10
0
 public void assertHasChangedSince(Snapshot snapshot) {
   Snapshot now = snapshot();
   assertTrue(now.modTime != snapshot.modTime || !Arrays.equals(now.hash, snapshot.hash));
 }