Exemple #1
0
  @Test
  public void par_update_get_compact() throws InterruptedException {
    int scale = TT.scale();
    if (scale == 0) return;
    int threadNum = Math.min(4, scale * 4);
    final long end = TT.nowPlusMinutes(10);
    e = openEngine();
    final BlockingQueue<Fun.Pair<Long, byte[]>> q = new ArrayBlockingQueue(threadNum * 10);
    for (int i = 0; i < threadNum; i++) {
      byte[] b = TT.randomByteArray(new Random().nextInt(10000));
      long recid = e.put(b, BYTE_ARRAY_NOSIZE);
      q.put(new Fun.Pair(recid, b));
    }

    final CountDownLatch l = new CountDownLatch(2);
    Thread tt =
        new Thread() {
          @Override
          public void run() {
            try {
              while (l.getCount() > 1) e.compact();
            } finally {
              l.countDown();
            }
          }
        };
    tt.setDaemon(true);
    tt.run();

    Exec.execNTimes(
        threadNum,
        new Callable() {
          @Override
          public Object call() throws Exception {
            Random r = new Random();
            while (System.currentTimeMillis() < end) {
              Fun.Pair<Long, byte[]> t = q.take();
              assertTrue(
                  Serializer.BYTE_ARRAY.equals(t.b, e.get(t.a, Serializer.BYTE_ARRAY_NOSIZE)));
              int size = r.nextInt(1000);
              if (r.nextInt(10) == 1) size = size * 100;
              byte[] b = TT.randomByteArray(size);
              e.update(t.a, b, Serializer.BYTE_ARRAY_NOSIZE);
              q.put(new Fun.Pair<Long, byte[]>(t.a, b));
            }
            return null;
          }
        });
    l.countDown();
    l.await();

    for (Fun.Pair<Long, byte[]> t : q) {
      assertTrue(Serializer.BYTE_ARRAY.equals(t.b, e.get(t.a, Serializer.BYTE_ARRAY_NOSIZE)));
    }
    e.close();
  }
Exemple #2
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();
 }
Exemple #3
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();
 }
  @Test
  public void replay_commit_over_file_edge() {
    String f = TT.tempDbFile().getPath();
    WriteAheadLog wal = new WriteAheadLog(f);

    byte[] b = TT.randomByteArray(20 * 1024 * 1024);
    wal.walPutRecord(11L, b, 0, b.length);
    wal.walPutRecord(33L, b, 0, b.length);
    wal.commit();
    wal.close();

    wal = new WriteAheadLog(f);
    wal.open(
        new WALSequence(
            new Object[] {WALSequence.beforeReplayStart},
            new Object[] {WALSequence.writeRecord, 11L, 16L, b},
            new Object[] {WALSequence.writeRecord, 33L, 4294967312L, b},
            new Object[] {WALSequence.commit}));
  }
  @Test
  public void empty_commit() {
    String f = TT.tempDbFile().getPath();
    WriteAheadLog wal = new WriteAheadLog(f);

    byte[] b = TT.randomByteArray(1024);
    wal.walPutRecord(33L, b, 0, b.length);
    wal.commit();
    wal.commit();
    wal.seal();
    wal.close();

    wal = new WriteAheadLog(f);
    wal.open(
        new WALSequence(
            new Object[] {WALSequence.beforeReplayStart},
            new Object[] {WALSequence.writeRecord, 33L, 16L, b},
            new Object[] {WALSequence.commit},
            new Object[] {WALSequence.commit}));
  }
Exemple #6
0
  @Test
  public void par_cas() throws InterruptedException {
    int scale = TT.scale();
    if (scale == 0) return;
    int threadNum = 8 * scale;
    final long end = TT.nowPlusMinutes(10);
    e = openEngine();
    final BlockingQueue<Fun.Pair<Long, byte[]>> q = new ArrayBlockingQueue(threadNum * 10);
    for (int i = 0; i < threadNum; i++) {
      byte[] b = TT.randomByteArray(new Random().nextInt(10000));
      long recid = e.put(b, BYTE_ARRAY_NOSIZE);
      q.put(new Fun.Pair(recid, b));
    }

    Exec.execNTimes(
        threadNum,
        new Callable() {
          @Override
          public Object call() throws Exception {
            Random r = new Random();
            while (System.currentTimeMillis() < end) {
              Fun.Pair<Long, byte[]> t = q.take();
              int size = r.nextInt(10000);
              if (r.nextInt(10) == 1) size = size * 100;
              byte[] b = TT.randomByteArray(size);
              assertTrue(e.compareAndSwap(t.a, t.b, b, Serializer.BYTE_ARRAY_NOSIZE));
              q.put(new Fun.Pair<Long, byte[]>(t.a, b));
            }
            return null;
          }
        });

    for (Fun.Pair<Long, byte[]> t : q) {
      assertTrue(Serializer.BYTE_ARRAY.equals(t.b, e.get(t.a, Serializer.BYTE_ARRAY_NOSIZE)));
    }
    e.close();
  }
 @Test
 public void large_record() {
   testRecord(11111L, TT.randomByteArray(1000000));
 }
 @Test
 public void ten_record() {
   testRecord(11111L, TT.randomByteArray(10));
 }