use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class DistWriteSkewTest method testWriteSkewOnNonOwner.
public void testWriteSkewOnNonOwner() throws Exception {
Cache<Object, Object> cache0 = cache(0);
Cache<Object, Object> cache1 = cache(1);
Cache<Object, Object> cache2 = cache(2);
Cache<Object, Object> cache3 = cache(3);
// Owned by cache0 and cache1
MagicKey hello = new MagicKey("hello", cache(0));
int[] owners = { 0, 0 };
int[] nonOwners = { 0, 0 };
int j = 0, k = 0;
for (int i = 0; i < 4; i++) {
if (DistributionTestHelper.isOwner(cache(i), hello))
owners[j++] = i;
else
nonOwners[k++] = i;
}
// Auto-commit is true
cache(owners[1]).put(hello, "world 1");
tm(nonOwners[0]).begin();
assert "world 1".equals(cache(nonOwners[0]).get(hello));
Transaction t = tm(nonOwners[0]).suspend();
// Induce a write skew
cache(nonOwners[1]).put(hello, "world 3");
assertEquals("world 3", cache0.get(hello));
assertEquals("world 3", cache1.get(hello));
assertEquals("world 3", cache2.get(hello));
assertEquals("world 3", cache3.get(hello));
tm(nonOwners[0]).resume(t);
cache(nonOwners[0]).put(hello, "world 2");
try {
tm(nonOwners[0]).commit();
fail("Transaction should roll back");
} catch (RollbackException re) {
// expected
}
assertEquals("world 3", cache0.get(hello));
assertEquals("world 3", cache1.get(hello));
assertEquals("world 3", cache2.get(hello));
assertEquals("world 3", cache3.get(hello));
}
use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class DistWriteSkewTest method testNullEntries.
public void testNullEntries() throws Exception {
Cache<Object, Object> cache0 = cache(0);
Cache<Object, Object> cache1 = cache(1);
Cache<Object, Object> cache2 = cache(2);
Cache<Object, Object> cache3 = cache(3);
MagicKey hello = new MagicKey("hello", cache2, cache1);
// Auto-commit is true
cache0.put(hello, "world");
tm(0).begin();
assertEquals("world", cache0.get(hello));
Transaction t = tm(0).suspend();
cache1.remove(hello);
assertNull(cache0.get(hello));
assertNull(cache1.get(hello));
assertNull(cache2.get(hello));
assertNull(cache3.get(hello));
tm(0).resume(t);
cache0.put(hello, "world2");
try {
tm(0).commit();
fail("This transaction should roll back");
} catch (RollbackException expected) {
// expected
}
assertNull(cache0.get(hello));
assertNull(cache1.get(hello));
assertNull(cache2.get(hello));
assertNull(cache3.get(hello));
}
use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class DistWriteSkewTest method testWriteSkew.
public void testWriteSkew() throws Exception {
Cache<Object, Object> cache0 = cache(0);
Cache<Object, Object> cache1 = cache(1);
Cache<Object, Object> cache2 = cache(2);
Cache<Object, Object> cache3 = cache(3);
MagicKey hello = new MagicKey("hello", cache(2));
// Auto-commit is true
cache1.put(hello, "world 1");
tm(1).begin();
assertEquals("world 1", cache1.get(hello));
Transaction t = tm(1).suspend();
// Induce a write skew
cache3.put(hello, "world 3");
assertEquals("world 3", cache0.get(hello));
assertEquals("world 3", cache1.get(hello));
assertEquals("world 3", cache2.get(hello));
assertEquals("world 3", cache3.get(hello));
tm(1).resume(t);
cache1.put(hello, "world 2");
try {
tm(1).commit();
fail("Transaction should roll back");
} catch (RollbackException re) {
// expected
}
assertEquals("world 3", cache0.get(hello));
assertEquals("world 3", cache1.get(hello));
assertEquals("world 3", cache2.get(hello));
assertEquals("world 3", cache3.get(hello));
}
use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class FunctionalNoopDoesNotGoToBackupTest method createCacheManagers.
@Override
protected void createCacheManagers() throws Throwable {
createCluster(TestDataSCI.INSTANCE, getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC), 2);
FunctionalMapImpl<Object, Object> fmap0 = FunctionalMapImpl.create(cache(0).getAdvancedCache());
FunctionalMapImpl<Object, Object> fmap1 = FunctionalMapImpl.create(cache(1).getAdvancedCache());
rw0 = ReadWriteMapImpl.create(fmap0);
rw1 = ReadWriteMapImpl.create(fmap1);
wo0 = WriteOnlyMapImpl.create(fmap0);
wo1 = WriteOnlyMapImpl.create(fmap1);
key = new MagicKey(cache(0));
rpcManager0 = TestingUtil.wrapComponent(cache(0), RpcManager.class, CountingRpcManager::new);
rpcManager1 = TestingUtil.wrapComponent(cache(1), RpcManager.class, CountingRpcManager::new);
}
use of org.infinispan.distribution.MagicKey in project infinispan by infinispan.
the class AbstractClusterListenerDistAddListenerTest method testNodeJoiningAndStateNodeDiesWithExistingClusterListener.
/**
* Tests to make sure that if a new node is joining and the node it requested
*/
@Test
public void testNodeJoiningAndStateNodeDiesWithExistingClusterListener() throws TimeoutException, InterruptedException, ExecutionException {
Cache<Object, String> cache0 = cache(0, CACHE_NAME);
Cache<Object, String> cache1 = cache(1, CACHE_NAME);
Cache<Object, String> cache2 = cache(2, CACHE_NAME);
int initialCache0ListenerSize = cache0.getAdvancedCache().getListeners().size();
int initialCache1ListenerSize = cache1.getAdvancedCache().getListeners().size();
int initialCache2ListenerSize = cache2.getAdvancedCache().getListeners().size();
ClusterListener clusterListener = new ClusterListener();
cache2.addListener(clusterListener);
assertEquals(cache0.getAdvancedCache().getListeners().size(), initialCache0ListenerSize + (cacheMode.isDistributed() ? 1 : 0));
assertEquals(cache1.getAdvancedCache().getListeners().size(), initialCache1ListenerSize + (cacheMode.isDistributed() ? 1 : 0));
assertEquals(cache2.getAdvancedCache().getListeners().size(), initialCache2ListenerSize + 1);
assertEquals(manager(0).getAddress(), manager(0).getMembers().get(0));
CheckPoint checkPoint = new CheckPoint();
waitUntilRequestingListeners(cache0, checkPoint);
checkPoint.triggerForever("post_cluster_listeners_release_" + cache0);
addClusteredCacheManager();
Future<Cache<Object, String>> future = fork(() -> cache(3, CACHE_NAME));
checkPoint.awaitStrict("pre_cluster_listeners_invoked_" + cache0, 10, TimeUnit.SECONDS);
log.info("Killing node 0 ..");
// Notice we are killing the manager that doesn't have a cache with the cluster listener
TestingUtil.killCacheManagers(manager(0));
cacheManagers.remove(0);
log.info("Node 0 killed");
TestingUtil.blockUntilViewsReceived(10000, false, cacheManagers);
TestingUtil.waitForNoRebalance(caches(CACHE_NAME));
checkPoint.triggerForever("pre_cluster_listeners_invoked_" + cache0);
Cache<Object, String> cache3 = future.get(10, TimeUnit.SECONDS);
MagicKey key = new MagicKey(cache3);
verifySimpleInsertion(cache3, key, FIRST_VALUE, null, clusterListener, FIRST_VALUE);
}
Aggregations