예제 #1
0
  @Test
  public void delayedUpdate() throws Exception {
    View ix = openIndex("foo");

    byte[] key = "hello".getBytes();
    byte[] value1 = "world".getBytes();

    ix.store(null, key, value1);

    int i = 0;
    Updater u = start(ix, key, ("world-" + (i++)).getBytes());

    fastAssertArrayEquals(u.mValue, ix.load(null, key));

    u = start(ix, key, ("world-" + (i++)).getBytes());
    Transaction txn2 = mDb.newTransaction();
    fastAssertArrayEquals(u.mValue, ix.load(txn2, key));
    txn2.reset();

    u = start(ix, key, ("world-" + (i++)).getBytes());
    txn2.lockMode(LockMode.UPGRADABLE_READ);
    fastAssertArrayEquals(u.mValue, ix.load(txn2, key));
    txn2.reset();

    u = start(ix, key, ("world-" + (i++)).getBytes());
    txn2.lockMode(LockMode.REPEATABLE_READ);
    fastAssertArrayEquals(u.mValue, ix.load(txn2, key));
    txn2.reset();

    u = start(ix, key, ("world-" + (i++)).getBytes());
    txn2.lockMode(LockMode.READ_COMMITTED);
    fastAssertArrayEquals(u.mValue, ix.load(txn2, key));
    txn2.reset();
  }
예제 #2
0
    public void run() {
      try {
        Transaction txn = mDb.newTransaction();

        if (mNoGhost) {
          mIx.lockExclusive(txn, mKey);
          mIx.store(Transaction.BOGUS, mKey, mValue);
        } else {
          mIx.store(txn, mKey, mValue);
        }

        synchronized (this) {
          mSleeping = true;
          notify();
        }
        Thread.sleep(500);
        txn.commit();
      } catch (Exception e) {
      }
    }
예제 #3
0
  @Test
  public void timedOutUpdate() throws Exception {
    View ix = openIndex("foo");

    byte[] key = "hello".getBytes();
    byte[] value1 = "world".getBytes();
    byte[] value2 = "world!!!".getBytes();

    ix.store(null, key, value1);

    Transaction txn = mDb.newTransaction();
    ix.store(txn, key, value2);

    fastAssertArrayEquals(value2, ix.load(Transaction.BOGUS, key));

    try {
      ix.load(null, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    Transaction txn2 = mDb.newTransaction();
    try {
      ix.load(txn2, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    txn2.lockMode(LockMode.UPGRADABLE_READ);
    try {
      ix.load(txn2, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    txn2.lockMode(LockMode.REPEATABLE_READ);
    try {
      ix.load(txn2, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    txn2.lockMode(LockMode.READ_COMMITTED);
    try {
      ix.load(txn2, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    txn2.lockMode(LockMode.READ_UNCOMMITTED);
    fastAssertArrayEquals(value2, ix.load(txn2, key));

    txn2.lockMode(LockMode.UNSAFE);
    fastAssertArrayEquals(value2, ix.load(txn2, key));

    txn.commit();

    fastAssertArrayEquals(value2, ix.load(null, key));
  }
예제 #4
0
  private void delayedDelete(boolean noGhost) throws Exception {
    View ix = openIndex("foo");

    byte[] key = "hello".getBytes();
    byte[] value1 = "world".getBytes();

    ix.store(null, key, value1);

    Updater u = start(ix, key, null, noGhost);

    assertEquals(null, ix.load(null, key));

    ix.store(null, key, value1);
    u = start(ix, key, null, noGhost);
    Transaction txn2 = mDb.newTransaction();
    assertEquals(null, ix.load(txn2, key));
    txn2.reset();

    ix.store(null, key, value1);
    u = start(ix, key, null, noGhost);
    txn2.lockMode(LockMode.UPGRADABLE_READ);
    assertEquals(null, ix.load(txn2, key));
    txn2.reset();

    ix.store(null, key, value1);
    u = start(ix, key, null, noGhost);
    txn2.lockMode(LockMode.REPEATABLE_READ);
    assertEquals(null, ix.load(txn2, key));
    txn2.reset();

    ix.store(null, key, value1);
    u = start(ix, key, null, noGhost);
    txn2.lockMode(LockMode.READ_COMMITTED);
    assertEquals(null, ix.load(txn2, key));
    txn2.reset();
  }
예제 #5
0
 @Override
 public Cursor newCursor(Transaction txn) {
   return new UnmodifiableCursor(mSource.newCursor(txn));
 }
예제 #6
0
 @Override
 public byte[] load(Transaction txn, byte[] key) throws IOException {
   return mSource.load(txn, key);
 }
예제 #7
0
 static View apply(View view) {
   return view.isUnmodifiable() ? view : new UnmodifiableView(view);
 }
예제 #8
0
 @Override
 public Ordering getOrdering() {
   return mSource.getOrdering();
 }
예제 #9
0
 @Override
 public View viewTransformed(Transformer transformer) {
   return new UnmodifiableView(mSource.viewTransformed(transformer));
 }
예제 #10
0
 @Override
 public View viewReverse() {
   return new UnmodifiableView(mSource.viewReverse());
 }
예제 #11
0
 @Override
 public View viewPrefix(byte[] prefix, int trim) {
   return new UnmodifiableView(mSource.viewPrefix(prefix, trim));
 }
예제 #12
0
 @Override
 public View viewLt(byte[] key) {
   return new UnmodifiableView(mSource.viewLt(key));
 }
예제 #13
0
 @Override
 public Stream newStream() {
   return new UnmodifiableStream(mSource.newStream());
 }
예제 #14
0
 @Override
 public LockResult lockCheck(Transaction txn, byte[] key) throws ViewConstraintException {
   return mSource.lockCheck(txn, key);
 }
예제 #15
0
 @Override
 public LockResult lockExclusive(Transaction txn, byte[] key)
     throws LockFailureException, ViewConstraintException {
   return mSource.lockExclusive(txn, key);
 }