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);
}
}
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));
}
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));
}
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);
}
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);
}
Aggregations