Search in sources :

Example 76 with MagicKey

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

the class AbstractClusterListenerTest method testClusterListenerRemovedWithMultipleInstalledOnSameNode.

@Test
public void testClusterListenerRemovedWithMultipleInstalledOnSameNode() {
    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 = listener();
    cache0.addListener(clusterListener);
    // Adding a cluster listener should add to each node in cluster
    assertEquals(cache0.getAdvancedCache().getListeners().size(), initialCache0ListenerSize + 1);
    assertEquals(cache1.getAdvancedCache().getListeners().size(), initialCache1ListenerSize + (cacheMode.isDistributed() ? 1 : 0));
    assertEquals(cache2.getAdvancedCache().getListeners().size(), initialCache2ListenerSize + (cacheMode.isDistributed() ? 1 : 0));
    ClusterListener clusterListener2 = listener();
    cache0.addListener(clusterListener2);
    // Adding a second cluster listener should add to each node in cluster as well
    assertEquals(cache0.getAdvancedCache().getListeners().size(), initialCache0ListenerSize + 2);
    assertEquals(cache1.getAdvancedCache().getListeners().size(), initialCache1ListenerSize + (cacheMode.isDistributed() ? 2 : 0));
    assertEquals(cache2.getAdvancedCache().getListeners().size(), initialCache2ListenerSize + (cacheMode.isDistributed() ? 2 : 0));
    MagicKey key = new MagicKey(cache2, cache1);
    cache1.put(key, FIRST_VALUE);
    // Both listeners should have been notified
    assertEquals(clusterListener.events.size(), 1);
    assertEquals(clusterListener2.events.size(), 1);
    verifySimpleInsertionEvents(clusterListener, key, FIRST_VALUE);
    verifySimpleInsertionEvents(clusterListener2, key, FIRST_VALUE);
    cache0.removeListener(clusterListener);
    assertEquals(cache0.getAdvancedCache().getListeners().size(), initialCache0ListenerSize + 1);
    assertEquals(cache1.getAdvancedCache().getListeners().size(), initialCache1ListenerSize + (cacheMode.isDistributed() ? 1 : 0));
    assertEquals(cache2.getAdvancedCache().getListeners().size(), initialCache2ListenerSize + (cacheMode.isDistributed() ? 1 : 0));
    // Change the value again to make sure other listener is still working properly
    cache2.put(key, SECOND_VALUE);
    assertEquals(clusterListener2.events.size(), 2);
    CacheEntryEvent event = clusterListener2.events.get(1);
    assertEquals(Event.Type.CACHE_ENTRY_MODIFIED, event.getType());
    assertEquals(key, event.getKey());
    assertEquals(SECOND_VALUE, ((CacheEntryModifiedEvent) event).getValue());
}
Also used : MagicKey(org.infinispan.distribution.MagicKey) CacheEntryEvent(org.infinispan.notifications.cachelistener.event.CacheEntryEvent) Test(org.testng.annotations.Test)

Example 77 with MagicKey

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

the class AbstractClusterListenerTest method testNodeComesUpWithClusterListenerAlreadyInstalled.

@Test
public void testNodeComesUpWithClusterListenerAlreadyInstalled() {
    Cache<Object, String> cache0 = cache(0, CACHE_NAME);
    ClusterListener clusterListener = listener();
    cache0.addListener(clusterListener);
    addClusteredCacheManager();
    waitForClusterToForm(CACHE_NAME);
    Cache<Object, String> cache3 = cache(3, CACHE_NAME);
    MagicKey key = new MagicKey(cache3);
    verifySimpleInsertion(cache3, key, FIRST_VALUE, null, clusterListener, FIRST_VALUE);
}
Also used : MagicKey(org.infinispan.distribution.MagicKey) Test(org.testng.annotations.Test)

Example 78 with MagicKey

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

the class AbstractClusterListenerTest method testSimpleExpirationConverterNotOwner.

@Test
public void testSimpleExpirationConverterNotOwner() {
    long lifespan = 1000;
    StringTruncator converter = new StringTruncator(0, 2);
    testExpirationConverter(new MagicKey(cache(1, CACHE_NAME), cache(2, CACHE_NAME)), FIRST_VALUE, FIRST_VALUE.substring(0, 2), lifespan, converter);
}
Also used : MagicKey(org.infinispan.distribution.MagicKey) Test(org.testng.annotations.Test)

Example 79 with MagicKey

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

the class AbstractClusterListenerTest method testMetadataConverterNoPassReturnOriginalLocalOnly.

@Test
public void testMetadataConverterNoPassReturnOriginalLocalOnly() {
    long lifespan = 25000;
    LifespanConverter converter = new LifespanConverter(true, Long.MAX_VALUE);
    testConverter(new MagicKey(cache(0, CACHE_NAME)), FIRST_VALUE, FIRST_VALUE, lifespan, converter);
}
Also used : MagicKey(org.infinispan.distribution.MagicKey) Test(org.testng.annotations.Test)

Example 80 with MagicKey

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

the class AbstractClusterListenerTxTest method testRolledBackOriginatorNotLocal.

@Test
public void testRolledBackOriginatorNotLocal() 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();
    cache2.put(key1, FIRST_VALUE);
    assertEquals(clusterListener.events.size(), 0);
    cache2.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)

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