Example #1
0
  @Test
  public void zero_size_serializer() {
    Serializer s =
        new Serializer<String>() {

          @Override
          public void serialize(DataOutput out, String value) throws IOException {
            if ("".equals(value)) return;
            Serializer.STRING.serialize(out, value);
          }

          @Override
          public String deserialize(DataInput in, int available) throws IOException {
            if (available == 0) return "";
            return Serializer.STRING.deserialize(in, available);
          }
        };

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

    e.update(recid, "a", s);
    assertEquals("a", e.get(recid, s));

    e.compareAndSwap(recid, "a", "", s);
    assertEquals("", e.get(recid, s));

    e.update(recid, "a", s);
    assertEquals("a", e.get(recid, s));

    e.update(recid, "", s);
    assertEquals("", e.get(recid, s));
    e.close();
  }
Example #2
0
 @Test
 public void preallocate_get_update_delete_update_get() {
   e = openEngine();
   long recid = e.preallocate();
   assertNull(e.get(recid, Serializer.ILLEGAL_ACCESS));
   e.update(recid, 1L, Serializer.LONG);
   assertEquals((Long) 1L, e.get(recid, Serializer.LONG));
   e.delete(recid, Serializer.LONG);
   assertNull(e.get(recid, Serializer.ILLEGAL_ACCESS));
   e.update(recid, 1L, Serializer.LONG);
   assertEquals((Long) 1L, e.get(recid, Serializer.LONG));
   e.close();
 }
Example #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();
 }
Example #4
0
  @Test
  public void nosize_array() {
    e = openEngine();
    byte[] b = new byte[0];
    long recid = e.put(b, Serializer.BYTE_ARRAY_NOSIZE);
    assertTrue(Serializer.BYTE_ARRAY.equals(b, e.get(recid, Serializer.BYTE_ARRAY_NOSIZE)));

    b = new byte[] {1, 2, 3};
    e.update(recid, b, Serializer.BYTE_ARRAY_NOSIZE);
    assertTrue(Serializer.BYTE_ARRAY.equals(b, e.get(recid, Serializer.BYTE_ARRAY_NOSIZE)));

    b = new byte[] {};
    e.update(recid, b, Serializer.BYTE_ARRAY_NOSIZE);
    assertTrue(Serializer.BYTE_ARRAY.equals(b, e.get(recid, Serializer.BYTE_ARRAY_NOSIZE)));

    e.delete(recid, Serializer.BYTE_ARRAY_NOSIZE);
    assertTrue(Serializer.BYTE_ARRAY.equals(null, e.get(recid, Serializer.BYTE_ARRAY_NOSIZE)));
    e.close();
  }
Example #5
0
  @Test
  public void snapshot() {
    e = openEngine();
    if (!e.canSnapshot()) return;

    long recid = e.put("a", Serializer.STRING);
    Engine snapshot = e.snapshot();
    e.update(recid, "b", Serializer.STRING);
    assertEquals("a", snapshot.get(recid, Serializer.STRING));
    e.close();
  }
Example #6
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();
  }
Example #7
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();
  }
Example #8
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();
 }
Example #9
0
  @Test
  public void putGetUpdateDelete() {
    e = openEngine();
    String s = "aaaad9009";
    long recid = e.put(s, Serializer.STRING);

    assertEquals(s, e.get(recid, Serializer.STRING));

    s = "da8898fe89w98fw98f9";
    e.update(recid, s, Serializer.STRING);
    assertEquals(s, e.get(recid, Serializer.STRING));

    e.delete(recid, Serializer.STRING);
    assertNull(e.get(recid, Serializer.STRING));
    e.close();
  }
Example #10
0
 @Test
 public void large_record_update() {
   e = openEngine();
   byte[] b = new byte[100000];
   new Random().nextBytes(b);
   long recid = e.put(b, BYTE_ARRAY_NOSIZE);
   new Random().nextBytes(b);
   e.update(recid, 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();
 }
Example #11
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();
  }
Example #12
0
 @Test(expected = NullPointerException.class)
 public void NPE_update() {
   e = openEngine();
   e.update(1, 1L, null);
 }