Пример #1
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));
  }
  @AfterClass
  public static void tearDownAfterClass() throws Exception {
    final Transaction transaction = session.getTransaction();

    if (transaction.isActive()) transaction.commit();

    if (session != null) session.close();
  }
Пример #3
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) {
      }
    }
 @Test
 public void testIssue508And513() throws Exception {
   HazelcastClient client = getHazelcastClient();
   IMap<String, HashSet<byte[]>> callEventsMap = client.getMap("CALL_EVENTS");
   IMap<String, Long> metaDataMap = client.getMap("CALL_META_DATA");
   IMap<String, byte[]> callStartMap = client.getMap("CALL_START_EVENTS");
   MultiMap<String, String> calls = client.getMultiMap("CALLS");
   calls.lock("1");
   calls.unlock("1");
   byte[] bytes = new byte[10];
   HashSet<byte[]> hashSet = new HashSet<byte[]>();
   hashSet.add(bytes);
   String callId = "1";
   callEventsMap.put(callId, hashSet);
   callStartMap.put(callId, bytes);
   metaDataMap.put(callId, 10L);
   Transaction txn = client.getTransaction();
   txn.begin();
   try {
     // remove the data
     callEventsMap.remove(callId);
     // remove meta data
     metaDataMap.remove(callId);
     // remove call start
     callStartMap.remove(callId);
     calls.put(callId, callId);
     txn.commit();
   } catch (Exception e) {
     fail();
   }
   assertNull(callEventsMap.get(callId));
   assertNull(metaDataMap.get(callId));
   assertNull(callStartMap.get(callId));
   assertEquals(0, callEventsMap.size());
   assertEquals(0, metaDataMap.size());
   assertEquals(0, callStartMap.size());
 }