Search in sources :

Example 81 with MagicKey

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

the class AbstractClusterListenerTxTest method testBatchedCommitOriginatorNotLocal.

@Test
public void testBatchedCommitOriginatorNotLocal() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
    Cache<Object, String> cache0 = cache(0, CACHE_NAME);
    Cache<Object, String> cache1 = cache(1, CACHE_NAME);
    Cache<Object, String> cache2 = cache(2, CACHE_NAME);
    ClusterListener clusterListener = new ClusterListener();
    cache0.addListener(clusterListener);
    MagicKey key1 = new MagicKey(cache1, cache2);
    MagicKey key2 = new MagicKey(cache2, cache1);
    TransactionManager tm = cache2.getAdvancedCache().getTransactionManager();
    tm.begin();
    cache2.put(key1, FIRST_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    cache2.put(key2, SECOND_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    tm.commit();
    assertEquals(clusterListener.events.size(), 2);
    verifyCreation(clusterListener.events, key1, FIRST_VALUE);
    verifyCreation(clusterListener.events, key2, SECOND_VALUE);
}
Also used : TransactionManager(javax.transaction.TransactionManager) MagicKey(org.infinispan.distribution.MagicKey) Test(org.testng.annotations.Test)

Example 82 with MagicKey

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

the class AbstractClusterListenerTxTest method testRolledBackLocal.

@Test
public void testRolledBackLocal() throws SystemException, NotSupportedException {
    Cache<Object, String> cache0 = cache(0, CACHE_NAME);
    Cache<Object, String> cache1 = cache(1, CACHE_NAME);
    Cache<Object, String> cache2 = cache(2, CACHE_NAME);
    ClusterListener clusterListener = new ClusterListener();
    cache0.addListener(clusterListener);
    MagicKey key1 = new MagicKey(cache0);
    MagicKey key2 = new MagicKey(cache1, cache0);
    TransactionManager tm = cache2.getAdvancedCache().getTransactionManager();
    tm.begin();
    cache0.put(key1, FIRST_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    cache0.put(key2, SECOND_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    tm.rollback();
    assertEquals(clusterListener.events.size(), 0);
}
Also used : TransactionManager(javax.transaction.TransactionManager) MagicKey(org.infinispan.distribution.MagicKey) Test(org.testng.annotations.Test)

Example 83 with MagicKey

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

the class AbstractClusterListenerTxTest method testBatchedCommitLocal.

@Test
public void testBatchedCommitLocal() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException, NotSupportedException {
    Cache<Object, String> cache0 = cache(0, CACHE_NAME);
    Cache<Object, String> cache1 = cache(1, CACHE_NAME);
    Cache<Object, String> cache2 = cache(2, CACHE_NAME);
    ClusterListener clusterListener = new ClusterListener();
    cache0.addListener(clusterListener);
    MagicKey key1 = new MagicKey(cache0);
    MagicKey key2 = new MagicKey(cache1, cache0);
    TransactionManager tm = cache2.getAdvancedCache().getTransactionManager();
    tm.begin();
    cache0.put(key1, FIRST_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    cache0.put(key2, SECOND_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    tm.commit();
    assertEquals(clusterListener.events.size(), 2);
    verifyCreation(clusterListener.events, key1, FIRST_VALUE);
    verifyCreation(clusterListener.events, key2, SECOND_VALUE);
}
Also used : TransactionManager(javax.transaction.TransactionManager) MagicKey(org.infinispan.distribution.MagicKey) Test(org.testng.annotations.Test)

Example 84 with MagicKey

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

the class AbstractClusterListenerTxTest method testMultipleKeysSameOwnerBatchNotified.

@Test
public void testMultipleKeysSameOwnerBatchNotified() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
    Cache<Object, String> cache0 = cache(0, CACHE_NAME);
    Cache<Object, String> cache1 = cache(1, CACHE_NAME);
    Cache<Object, String> cache2 = cache(2, CACHE_NAME);
    ClusterListener clusterListener = new ClusterListener();
    cache0.addListener(clusterListener);
    MagicKey key1 = new MagicKey(cache1);
    MagicKey key2 = new MagicKey(cache1);
    TransactionManager tm = cache2.getAdvancedCache().getTransactionManager();
    tm.begin();
    cache2.put(key1, FIRST_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    cache2.put(key2, SECOND_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    tm.commit();
    assertEquals(clusterListener.events.size(), 2);
    verifyCreation(clusterListener.events, key1, FIRST_VALUE);
    verifyCreation(clusterListener.events, key2, SECOND_VALUE);
}
Also used : TransactionManager(javax.transaction.TransactionManager) MagicKey(org.infinispan.distribution.MagicKey) Test(org.testng.annotations.Test)

Example 85 with MagicKey

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

the class StreamDistPartitionHandlingTest method testRetrievalWhenPartitionIsDegradedButLocal.

public void testRetrievalWhenPartitionIsDegradedButLocal() {
    Cache<MagicKey, String> cache0 = cache(0);
    cache0.put(new MagicKey(cache(1), cache(2)), "not-local");
    cache0.put(new MagicKey(cache(0), cache(1)), "local");
    splitCluster(new int[] { 0, 1 }, new int[] { 2, 3 });
    partition(0).assertDegradedMode();
    try (CloseableIterator<Map.Entry<MagicKey, String>> iterator = Closeables.iterator(cache0.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).entrySet().stream())) {
        assertEquals("local", iterator.next().getValue());
        assertFalse(iterator.hasNext());
    }
}
Also used : 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