Search in sources :

Example 96 with MagicKey

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));
}
Also used : Transaction(javax.transaction.Transaction) RollbackException(javax.transaction.RollbackException) MagicKey(org.infinispan.distribution.MagicKey)

Example 97 with MagicKey

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));
}
Also used : Transaction(javax.transaction.Transaction) RollbackException(javax.transaction.RollbackException) MagicKey(org.infinispan.distribution.MagicKey)

Example 98 with MagicKey

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));
}
Also used : Transaction(javax.transaction.Transaction) RollbackException(javax.transaction.RollbackException) MagicKey(org.infinispan.distribution.MagicKey)

Example 99 with MagicKey

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);
}
Also used : RpcManager(org.infinispan.remoting.rpc.RpcManager) CountingRpcManager(org.infinispan.util.CountingRpcManager) MagicKey(org.infinispan.distribution.MagicKey)

Example 100 with MagicKey

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);
}
Also used : MagicKey(org.infinispan.distribution.MagicKey) CheckPoint(org.infinispan.test.fwk.CheckPoint) CheckPoint(org.infinispan.test.fwk.CheckPoint) Cache(org.infinispan.Cache) Test(org.testng.annotations.Test)

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