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