Search in sources :

Example 36 with MagicKey

use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.

the class RpcManagerMBeanTest method testSuccessRatio.

@Test(dependsOnMethods = "testEnableJmxStats")
public void testSuccessRatio() throws Exception {
    Cache<MagicKey, Object> cache1 = manager(0).getCache();
    Cache<MagicKey, Object> cache2 = manager(1).getCache();
    MBeanServer mBeanServer = mBeanServerLookup.getMBeanServer();
    ObjectName rpcManager1 = getCacheObjectName(jmxDomain1, getDefaultCacheName() + "(repl_sync)", "RpcManager");
    // the previous test has reset the statistics
    assertEquals(mBeanServer.getAttribute(rpcManager1, "ReplicationCount"), (long) 0);
    assertEquals(mBeanServer.getAttribute(rpcManager1, "ReplicationFailures"), (long) 0);
    assertEquals(mBeanServer.getAttribute(rpcManager1, "SuccessRatio"), "N/A");
    RpcManagerImpl rpcManager = (RpcManagerImpl) extractComponent(cache1, RpcManager.class);
    Transport originalTransport = rpcManager.getTransport();
    try {
        MockTransport transport = new MockTransport(address(0));
        transport.init(originalTransport.getViewId(), originalTransport.getMembers());
        rpcManager.setTransport(transport);
        CompletableFuture<Object> put1 = cache1.putAsync(new MagicKey("a1", cache1), "b1");
        timeService.advance(50);
        transport.expectCommand(SingleRpcCommand.class).singleResponse(address(2), SuccessfulResponse.SUCCESSFUL_EMPTY_RESPONSE);
        put1.get(10, TimeUnit.SECONDS);
        CompletableFuture<Object> put2 = cache1.putAsync(new MagicKey("a2", cache2), "b2");
        timeService.advance(10);
        transport.expectCommand(SingleRpcCommand.class).singleResponse(address(2), SuccessfulResponse.SUCCESSFUL_EMPTY_RESPONSE);
        put2.get(10, TimeUnit.SECONDS);
        assertEquals(mBeanServer.getAttribute(rpcManager1, "ReplicationCount"), (long) 2);
        assertEquals(mBeanServer.getAttribute(rpcManager1, "SuccessRatio"), "100%");
        long avgReplTime = (long) mBeanServer.getAttribute(rpcManager1, "AverageReplicationTime");
        assertEquals(avgReplTime, 30);
        // If cache1 is the primary owner it will be a broadcast, otherwise a unicast
        CompletableFuture<Object> put3 = cache1.putAsync(new MagicKey("a3", cache1), "b3");
        transport.expectCommand(SingleRpcCommand.class).throwException(new RuntimeException());
        Exceptions.expectCompletionException(CacheException.class, put3);
        CompletableFuture<Object> put4 = cache1.putAsync(new MagicKey("a4", cache2), "b4");
        transport.expectCommand(SingleRpcCommand.class).throwException(new RuntimeException());
        Exceptions.expectCompletionException(CacheException.class, put4);
        assertEquals(mBeanServer.getAttribute(rpcManager1, "SuccessRatio"), ("50%"));
    } finally {
        rpcManager.setTransport(originalTransport);
    }
}
Also used : RpcManagerImpl(org.infinispan.remoting.rpc.RpcManagerImpl) RpcManager(org.infinispan.remoting.rpc.RpcManager) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) ObjectName(javax.management.ObjectName) TestingUtil.getCacheObjectName(org.infinispan.test.TestingUtil.getCacheObjectName) MockTransport(org.infinispan.remoting.transport.MockTransport) MockTransport(org.infinispan.remoting.transport.MockTransport) Transport(org.infinispan.remoting.transport.Transport) MagicKey(org.infinispan.distribution.MagicKey) MBeanServer(javax.management.MBeanServer) Test(org.testng.annotations.Test)

Example 37 with MagicKey

use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.

the class BasicSingleLockRepPessimisticTest method testSecondTxCannotPrepare2.

public void testSecondTxCannotPrepare2() throws Exception {
    Object k0 = new MagicKey("k0", cache(0));
    tm(1).begin();
    cache(1).put(k0, "v");
    EmbeddedTransaction dtm = (EmbeddedTransaction) tm(1).suspend();
    assert checkTxCount(0, 0, 1);
    assert checkTxCount(1, 1, 0);
    assert checkTxCount(2, 0, 1);
    tm(0).begin();
    try {
        cache(0).put(k0, "other");
        assert false;
    } catch (Throwable e) {
        tm(0).rollback();
    }
    eventually(() -> checkTxCount(0, 0, 1) && checkTxCount(1, 1, 0) && checkTxCount(2, 0, 1));
    tm(1).begin();
    try {
        cache(1).put(k0, "other");
        assert false;
    } catch (Throwable e) {
        tm(0).rollback();
    }
    eventually(() -> checkTxCount(0, 0, 1) && checkTxCount(1, 1, 0) && checkTxCount(2, 0, 1));
    tm(0).resume(dtm);
    tm(0).commit();
    assertValue(k0, false);
    eventually(() -> noPendingTransactions(0) && noPendingTransactions(1) && noPendingTransactions(2));
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) MagicKey(org.infinispan.distribution.MagicKey)

Example 38 with MagicKey

use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.

the class BasicSingleLockRepPessimisticTest method testSecondTxCannotPrepare1.

public void testSecondTxCannotPrepare1() throws Exception {
    Object k0 = new MagicKey("k0", cache(0));
    tm(0).begin();
    cache(0).put(k0, "v");
    EmbeddedTransaction dtm = (EmbeddedTransaction) tm(0).suspend();
    assert checkTxCount(0, 1, 0);
    assert checkTxCount(1, 0, 0);
    assert checkTxCount(2, 0, 0);
    tm(0).begin();
    try {
        cache(0).put(k0, "other");
        assert false;
    } catch (Throwable e) {
        tm(0).rollback();
    }
    eventually(() -> checkTxCount(0, 1, 0) && checkTxCount(1, 0, 0) && checkTxCount(2, 0, 0));
    tm(1).begin();
    try {
        cache(1).put(k0, "other");
        assert false;
    } catch (Throwable e) {
        tm(0).rollback();
    }
    eventually(() -> checkTxCount(0, 1, 0) && checkTxCount(1, 0, 0) && checkTxCount(2, 0, 0));
    tm(0).resume(dtm);
    tm(0).commit();
    assertValue(k0, false);
    eventually(() -> noPendingTransactions(0) && noPendingTransactions(1) && noPendingTransactions(2));
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) MagicKey(org.infinispan.distribution.MagicKey)

Example 39 with MagicKey

use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.

the class InitiatorCrashPessimisticReplTest method testInitiatorCrashesBeforeReleasingLock.

public void testInitiatorCrashesBeforeReleasingLock() throws Exception {
    final CountDownLatch releaseLocksLatch = new CountDownLatch(1);
    skipTxCompletion(advancedCache(1), releaseLocksLatch);
    MagicKey key = new MagicKey("k", cache(0));
    Future<Void> future = beginAndCommitTx(key, 1);
    releaseLocksLatch.await();
    assert checkTxCount(0, 0, 1);
    assert checkTxCount(1, 0, 0);
    assert checkTxCount(2, 0, 1);
    assertLocked(cache(0), key);
    assertEventuallyNotLocked(cache(1), key);
    assertEventuallyNotLocked(cache(2), key);
    killMember(1);
    eventually(() -> checkTxCount(0, 0, 0) && checkTxCount(1, 0, 0));
    assertNotLocked(key);
    assert cache(0).get(key).equals("v");
    assert cache(1).get(key).equals("v");
    future.get(30, TimeUnit.SECONDS);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) MagicKey(org.infinispan.distribution.MagicKey)

Example 40 with MagicKey

use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.

the class BasicSingleLockReplOptTest method testTxAndLockOnDifferentNodes.

protected void testTxAndLockOnDifferentNodes(Operation operation, boolean addFirst, boolean removed) throws Exception {
    MagicKey k = new MagicKey("k", cache(0));
    if (addFirst)
        cache(0).put(k, "v_initial");
    assertNotLocked(k);
    tm(0).begin();
    operation.perform(k, 0);
    EmbeddedTransaction dtm = (EmbeddedTransaction) tm(0).getTransaction();
    dtm.runPrepare();
    assert lockManager(0).isLocked(k);
    assert !lockManager(1).isLocked(k);
    assert !lockManager(2).isLocked(k);
    dtm.runCommit(false);
    assertNotLocked(k);
    assertValue(k, removed);
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) MagicKey(org.infinispan.distribution.MagicKey)

Aggregations

MagicKey (org.infinispan.distribution.MagicKey)185 Test (org.testng.annotations.Test)74 TransactionManager (javax.transaction.TransactionManager)23 CheckPoint (org.infinispan.test.fwk.CheckPoint)20 HashMap (java.util.HashMap)16 Map (java.util.Map)16 Transaction (javax.transaction.Transaction)16 Cache (org.infinispan.Cache)16 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)15 CountDownLatch (java.util.concurrent.CountDownLatch)10 CacheMode (org.infinispan.configuration.cache.CacheMode)10 CacheEntry (org.infinispan.container.entries.CacheEntry)10 Address (org.infinispan.remoting.transport.Address)10 StateSequencer (org.infinispan.test.concurrent.StateSequencer)9 AssertJUnit.assertEquals (org.testng.AssertJUnit.assertEquals)9 ArrayList (java.util.ArrayList)8 CyclicBarrier (java.util.concurrent.CyclicBarrier)8 DistributionManager (org.infinispan.distribution.DistributionManager)8 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)8 RollbackException (javax.transaction.RollbackException)7