Ejemplo n.º 1
0
  @Test
  public void snapshot_after_commit2() {
    e = openEngine();
    if (!e.canSnapshot()) return;

    long recid = e.put("a", Serializer.STRING);
    e.commit();
    Engine snapshot = e.snapshot();
    e.update(recid, "b", Serializer.STRING);
    assertEquals("a", snapshot.get(recid, Serializer.STRING));
    e.commit();
    assertEquals("a", snapshot.get(recid, Serializer.STRING));
    e.close();
  }
Ejemplo n.º 2
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));
    }
  }
Ejemplo n.º 3
0
 @Test
 public void update_reserved_recid() {
   e = openEngine();
   e.update(Engine.RECID_NAME_CATALOG, 111L, Serializer.LONG);
   assertEquals(new Long(111L), e.get(Engine.RECID_NAME_CATALOG, Serializer.LONG));
   e.commit();
   assertEquals(new Long(111L), e.get(Engine.RECID_NAME_CATALOG, Serializer.LONG));
   e.close();
 }
Ejemplo n.º 4
0
 @Test
 public void compact_large_record() {
   e = openEngine();
   byte[] b = TT.randomByteArray(100000);
   long recid = e.put(b, Serializer.BYTE_ARRAY_NOSIZE);
   e.commit();
   e.compact();
   assertTrue(Serializer.BYTE_ARRAY.equals(b, e.get(recid, Serializer.BYTE_ARRAY_NOSIZE)));
   e.close();
 }
Ejemplo n.º 5
0
  @Test
  public void test_store_reopen() {
    e = openEngine();
    long recid = e.put("aaa", Serializer.STRING_NOSIZE);
    e.commit();
    reopen();

    String aaa = e.get(recid, Serializer.STRING_NOSIZE);
    assertEquals("aaa", aaa);
    e.close();
  }
Ejemplo n.º 6
0
 @Test
 public void dirty_compact() {
   e = openEngine();
   long recid1 = e.put(new byte[1000 * 1000], Serializer.BYTE_ARRAY_NOSIZE);
   long recid2 = e.put(new byte[1000 * 1000], Serializer.BYTE_ARRAY_NOSIZE);
   e.delete(recid1, Serializer.BYTE_ARRAY_NOSIZE);
   e.compact();
   e.commit();
   assertArrayEquals(new byte[1000 * 1000], e.get(recid2, Serializer.BYTE_ARRAY_NOSIZE));
   e.close();
 }
Ejemplo n.º 7
0
 @Test
 public void put_reopen_get() {
   e = openEngine();
   if (!canReopen()) return;
   Long l = 11231203099090L;
   long recid = e.put(l, Serializer.LONG);
   e.commit();
   reopen();
   assertEquals(l, e.get(recid, Serializer.LONG));
   e.close();
 }
Ejemplo n.º 8
0
 @Test
 public void put_reopen_get_large() {
   e = openEngine();
   if (!canReopen()) return;
   byte[] b = new byte[(int) 1e6];
   new Random().nextBytes(b);
   long recid = e.put(b, Serializer.BYTE_ARRAY_NOSIZE);
   e.commit();
   reopen();
   assertTrue(Serializer.BYTE_ARRAY.equals(b, e.get(recid, Serializer.BYTE_ARRAY_NOSIZE)));
   e.close();
 }
Ejemplo n.º 9
0
  @Test
  public void test_store_reopen_nocommit() {
    e = openEngine();
    long recid = e.put("aaa", Serializer.STRING_NOSIZE);
    e.commit();
    e.update(recid, "bbb", Serializer.STRING_NOSIZE);
    reopen();

    String expected = canRollback() && canReopen() ? "aaa" : "bbb";
    assertEquals(expected, e.get(recid, Serializer.STRING_NOSIZE));
    e.close();
  }
Ejemplo n.º 10
0
  @Test
  public void rollback() {
    e = openEngine();
    long recid = e.put("aaa", Serializer.STRING_NOSIZE);
    e.commit();
    e.update(recid, "bbb", Serializer.STRING_NOSIZE);

    if (!canRollback()) return;
    e.rollback();

    assertEquals("aaa", e.get(recid, Serializer.STRING_NOSIZE));
    e.close();
  }
Ejemplo n.º 11
0
 @Test
 public void update_reserved_recid_large() {
   e = openEngine();
   byte[] data = TT.randomByteArray((int) 1e7);
   e.update(Engine.RECID_NAME_CATALOG, data, Serializer.BYTE_ARRAY_NOSIZE);
   assertTrue(
       Serializer.BYTE_ARRAY.equals(
           data, e.get(Engine.RECID_NAME_CATALOG, Serializer.BYTE_ARRAY_NOSIZE)));
   e.commit();
   assertTrue(
       Serializer.BYTE_ARRAY.equals(
           data, e.get(Engine.RECID_NAME_CATALOG, Serializer.BYTE_ARRAY_NOSIZE)));
   e.close();
 }
Ejemplo n.º 12
0
 /* after deletion it enters preallocated state */
 @Test
 public void delete_and_get() {
   e = openEngine();
   long recid = e.put("aaa", Serializer.STRING);
   e.delete(recid, Serializer.STRING);
   assertNull(e.get(recid, Serializer.ILLEGAL_ACCESS));
   e.commit();
   reopen();
   long recid2 = e.put("bbb", Serializer.STRING);
   if (e instanceof StoreHeap || e instanceof StoreAppend)
     return; // TODO implement it at those two
   assertEquals(recid, recid2);
   e.close();
 }
Ejemplo n.º 13
0
 @Test
 public void large_record_larger() {
   e = openEngine();
   byte[] b = new byte[10000000];
   new Random().nextBytes(b);
   long recid = e.put(b, BYTE_ARRAY_NOSIZE);
   byte[] b2 = e.get(recid, BYTE_ARRAY_NOSIZE);
   assertTrue(Serializer.BYTE_ARRAY.equals(b, b2));
   e.commit();
   reopen();
   b2 = e.get(recid, BYTE_ARRAY_NOSIZE);
   assertTrue(Serializer.BYTE_ARRAY.equals(b, b2));
   e.close();
 }
Ejemplo n.º 14
0
  @Test
  public void compact0() {
    e = openEngine();
    Long v1 = 129031920390121423L;
    Long v2 = 909090901290129990L;
    Long v3 = 998898989L;
    long recid1 = e.put(v1, Serializer.LONG);
    long recid2 = e.put(v2, Serializer.LONG);

    e.commit();
    e.compact();

    assertEquals(v1, e.get(recid1, Serializer.LONG));
    assertEquals(v2, e.get(recid2, Serializer.LONG));
    long recid3 = e.put(v3, Serializer.LONG);
    assertEquals(v1, e.get(recid1, Serializer.LONG));
    assertEquals(v2, e.get(recid2, Serializer.LONG));
    assertEquals(v3, e.get(recid3, Serializer.LONG));
    e.commit();
    assertEquals(v1, e.get(recid1, Serializer.LONG));
    assertEquals(v2, e.get(recid2, Serializer.LONG));
    assertEquals(v3, e.get(recid3, Serializer.LONG));
    e.close();
  }
Ejemplo n.º 15
0
 @Test
 public void get_non_existent_after_delete_and_compact() {
   e = openEngine();
   long recid = e.put(1L, Serializer.LONG);
   e.delete(recid, Serializer.LONG);
   assertNull(e.get(recid, Serializer.ILLEGAL_ACCESS));
   e.commit();
   e.compact();
   try {
     e.get(recid, Serializer.STRING);
     if (!(e instanceof StoreAppend)) // TODO remove after compact on StoreAppend
     fail();
   } catch (DBException.EngineGetVoid e) {
   }
   e.close();
 }
Ejemplo n.º 16
0
  @Test
  public void commit_huge() {
    if (TT.shortTest()) return;
    e = openEngine();
    long recid = e.put(new byte[1000 * 1000 * 1000], Serializer.BYTE_ARRAY_NOSIZE);
    e.commit();

    reopen();

    byte[] b = e.get(recid, Serializer.BYTE_ARRAY_NOSIZE);
    assertEquals(1000 * 1000 * 1000, b.length);
    for (byte bb : b) {
      assertEquals(0, bb);
    }
    e.close();
  }
Ejemplo n.º 17
0
  @Test
  public void empty_update_commit() {
    if (TT.scale() == 0) return;

    e = openEngine();
    long recid = e.put("", Serializer.STRING_NOSIZE);
    assertEquals("", e.get(recid, Serializer.STRING_NOSIZE));

    for (int i = 0; i < 10000; i++) {
      String s = TT.randomString(80000);
      e.update(recid, s, Serializer.STRING_NOSIZE);
      assertEquals(s, e.get(recid, Serializer.STRING_NOSIZE));
      e.commit();
      assertEquals(s, e.get(recid, Serializer.STRING_NOSIZE));
    }
    e.close();
  }
Ejemplo n.º 18
0
  @Test
  public void compact() {
    e = openEngine();
    Map<Long, Long> recids = new HashMap<Long, Long>();
    for (Long l = 0L; l < 1000; l++) {
      recids.put(l, e.put(l, Serializer.LONG));
    }

    e.commit();
    e.compact();

    for (Map.Entry<Long, Long> m : recids.entrySet()) {
      Long recid = m.getValue();
      Long value = m.getKey();
      assertEquals(value, e.get(recid, Serializer.LONG));
    }
    e.close();
  }
Ejemplo n.º 19
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();
  }