use of org.infinispan.notifications.cachelistener.CacheNotifier in project infinispan by infinispan.
the class ClientClusterExpirationEventsTest method testNullValueMetadataExpiration.
public void testNullValueMetadataExpiration() {
final Integer key = HotRodClientTestingUtil.getIntKeyForServer(server(0));
final EventLogListener<Integer> l = new EventLogListener<>(client(0).getCache());
withClientListener(l, remote -> {
Cache<Integer, String> cache0 = cache(0);
CacheNotifier notifier = cache0.getAdvancedCache().getComponentRegistry().getComponent(CacheNotifier.class);
byte[] keyBytes = HotRodClientTestingUtil.toBytes(key);
// Note we are manually forcing an expiration event with a null value and metadata
notifier.notifyCacheEntryExpired(keyBytes, null, null, null);
l.expectOnlyExpiredEvent(key);
});
}
use of org.infinispan.notifications.cachelistener.CacheNotifier in project infinispan by infinispan.
the class AbstractClusterListenerUtilTest method waitUntilListenerInstalled.
protected void waitUntilListenerInstalled(final Cache<?, ?> cache, final CheckPoint checkPoint) {
CacheNotifier cn = TestingUtil.extractComponent(cache, CacheNotifier.class);
final Answer<Object> forwardedAnswer = AdditionalAnswers.delegatesTo(cn);
ClusterCacheNotifier mockNotifier = mock(ClusterCacheNotifier.class, withSettings().defaultAnswer(forwardedAnswer));
doAnswer(invocation -> {
// Wait for main thread to sync up
checkPoint.trigger("pre_add_listener_invoked_" + cache);
// Now wait until main thread lets us through
checkPoint.awaitStrict("pre_add_listener_release_" + cache, 10, TimeUnit.SECONDS);
try {
return forwardedAnswer.answer(invocation);
} finally {
// Wait for main thread to sync up
checkPoint.trigger("post_add_listener_invoked_" + cache);
// Now wait until main thread lets us through
checkPoint.awaitStrict("post_add_listener_release_" + cache, 10, TimeUnit.SECONDS);
}
}).when(mockNotifier).addFilteredListener(notNull(), nullable(CacheEventFilter.class), nullable(CacheEventConverter.class), any(Set.class));
TestingUtil.replaceComponent(cache, CacheNotifier.class, mockNotifier, true);
}
use of org.infinispan.notifications.cachelistener.CacheNotifier in project infinispan by infinispan.
the class PrepareCommand method invokeAsync.
@Override
public CompletionStage<?> invokeAsync(ComponentRegistry registry) throws Throwable {
markTransactionAsRemote(true);
RemoteTxInvocationContext ctx = createContext(registry);
if (ctx == null) {
return CompletableFutures.completedNull();
}
if (log.isTraceEnabled())
log.tracef("Invoking remotely originated prepare: %s with invocation context: %s", this, ctx);
CacheNotifier notifier = registry.getCacheNotifier().running();
CompletionStage<Void> stage = notifier.notifyTransactionRegistered(ctx.getGlobalTransaction(), false);
AsyncInterceptorChain invoker = registry.getInterceptorChain().running();
for (VisitableCommand nested : getModifications()) nested.init(registry);
if (CompletionStages.isCompletedSuccessfully(stage)) {
return invoker.invokeAsync(ctx, this);
} else {
return stage.thenCompose(v -> invoker.invokeAsync(ctx, this));
}
}
use of org.infinispan.notifications.cachelistener.CacheNotifier in project infinispan by infinispan.
the class AbstractClusterListenerUtilTest method waitUntilNotificationRaised.
protected void waitUntilNotificationRaised(final Cache<?, ?> cache, final CheckPoint checkPoint) {
CacheNotifier cn = TestingUtil.extractComponent(cache, CacheNotifier.class);
final Answer<Object> forwardedAnswer = AdditionalAnswers.delegatesTo(cn);
CacheNotifier mockNotifier = mock(CacheNotifier.class, withSettings().extraInterfaces(ClusterCacheNotifier.class).defaultAnswer(forwardedAnswer));
Answer answer = invocation -> {
// Wait for main thread to sync up
checkPoint.trigger("pre_raise_notification_invoked");
// Now wait until main thread lets us through
checkPoint.awaitStrict("pre_raise_notification_release", 10, TimeUnit.SECONDS);
try {
return forwardedAnswer.answer(invocation);
} finally {
// Wait for main thread to sync up
checkPoint.trigger("post_raise_notification_invoked");
// Now wait until main thread lets us through
checkPoint.awaitStrict("post_raise_notification_release", 10, TimeUnit.SECONDS);
}
};
doAnswer(answer).when(mockNotifier).notifyCacheEntryCreated(any(), any(), any(Metadata.class), eq(false), any(InvocationContext.class), any(FlagAffectedCommand.class));
doAnswer(answer).when(mockNotifier).notifyCacheEntryModified(any(), any(), any(Metadata.class), any(), any(Metadata.class), anyBoolean(), any(InvocationContext.class), any(FlagAffectedCommand.class));
doAnswer(answer).when(mockNotifier).notifyCacheEntryRemoved(any(), any(), any(Metadata.class), eq(false), any(InvocationContext.class), any(FlagAffectedCommand.class));
TestingUtil.replaceComponent(cache, CacheNotifier.class, mockNotifier, true);
}
use of org.infinispan.notifications.cachelistener.CacheNotifier in project infinispan by infinispan.
the class SecureListenerTest method testAddListenerWithoutPermission.
public void testAddListenerWithoutPermission() throws IOException, PrivilegedActionException {
org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = newClientBuilder();
clientBuilder.security().authentication().saslMechanism("CRAM-MD5").username("RWuser").password("password");
remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
RemoteCache<Object, Object> clientCache = remoteCacheManager.getCache(CACHE_NAME);
EventLogListener<Object> listener = new EventLogListener<>(clientCache);
Exceptions.expectException(HotRodClientException.class, () -> clientCache.addClientListener(listener));
Cache<Object, Object> serverCache = cacheManager.getCache(CACHE_NAME);
CacheNotifier cacheNotifier = TestingUtil.extractComponent(serverCache, CacheNotifier.class);
assertEquals(0, cacheNotifier.getListeners().size());
remoteCacheManager.close();
assertEquals(0, cacheNotifier.getListeners().size());
}
Aggregations