Search in sources :

Example 1 with CacheNotifier

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);
    });
}
Also used : FilterCustomEventLogListener(org.infinispan.client.hotrod.event.CustomEventLogListener.FilterCustomEventLogListener) StaticCustomEventLogListener(org.infinispan.client.hotrod.event.CustomEventLogListener.StaticCustomEventLogListener) StaticFilteredEventLogListener(org.infinispan.client.hotrod.event.EventLogListener.StaticFilteredEventLogListener) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier)

Example 2 with CacheNotifier

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);
}
Also used : CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) CacheEventConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverter) Set(java.util.Set) CacheEventFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilter)

Example 3 with CacheNotifier

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));
    }
}
Also used : VisitableCommand(org.infinispan.commands.VisitableCommand) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain)

Example 4 with CacheNotifier

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);
}
Also used : CheckPoint(org.infinispan.test.fwk.CheckPoint) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) CacheEntryModifiedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent) Cache(org.infinispan.Cache) InvocationContext(org.infinispan.context.InvocationContext) CacheContainer(org.infinispan.manager.CacheContainer) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) Mockito.doAnswer(org.mockito.Mockito.doAnswer) CacheEntryRemovedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent) TestingUtil(org.infinispan.test.TestingUtil) ProtoField(org.infinispan.protostream.annotations.ProtoField) KeyValueFilter(org.infinispan.filter.KeyValueFilter) Listener(org.infinispan.notifications.Listener) CacheEventConverter(org.infinispan.notifications.cachelistener.filter.CacheEventConverter) Set(java.util.Set) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) CacheEntryExpired(org.infinispan.notifications.cachelistener.annotation.CacheEntryExpired) AdditionalAnswers(org.mockito.AdditionalAnswers) CacheEntryCreated(org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated) CacheEventFilterConverter(org.infinispan.notifications.cachelistener.filter.CacheEventFilterConverter) List(java.util.List) ControlledTimeService(org.infinispan.util.ControlledTimeService) Mockito.withSettings(org.mockito.Mockito.withSettings) ArgumentMatchers.notNull(org.mockito.ArgumentMatchers.notNull) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProtoName(org.infinispan.protostream.annotations.ProtoName) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) Metadata(org.infinispan.metadata.Metadata) ArrayList(java.util.ArrayList) ProtoFactory(org.infinispan.protostream.annotations.ProtoFactory) Answer(org.mockito.stubbing.Answer) CacheEntryExpiredEvent(org.infinispan.notifications.cachelistener.event.CacheEntryExpiredEvent) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) EventType(org.infinispan.notifications.cachelistener.filter.EventType) AutoProtoSchemaBuilder(org.infinispan.protostream.annotations.AutoProtoSchemaBuilder) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) CacheEntryModified(org.infinispan.notifications.cachelistener.annotation.CacheEntryModified) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Address(org.infinispan.remoting.transport.Address) CacheEventFilter(org.infinispan.notifications.cachelistener.filter.CacheEventFilter) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) TransactionMode(org.infinispan.transaction.TransactionMode) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) CacheManagerNotifier(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier) TimeUnit(java.util.concurrent.TimeUnit) CacheMode(org.infinispan.configuration.cache.CacheMode) IsolationLevel(org.infinispan.util.concurrent.IsolationLevel) CacheEntryEvent(org.infinispan.notifications.cachelistener.event.CacheEntryEvent) Event(org.infinispan.notifications.cachelistener.event.Event) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Collections(java.util.Collections) TimeService(org.infinispan.commons.time.TimeService) CacheEntryCreatedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryCreatedEvent) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Metadata(org.infinispan.metadata.Metadata) InvocationContext(org.infinispan.context.InvocationContext)

Example 5 with CacheNotifier

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());
}
Also used : EventLogListener(org.infinispan.client.hotrod.event.EventLogListener) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier)

Aggregations

CacheNotifier (org.infinispan.notifications.cachelistener.CacheNotifier)8 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 TimeUnit (java.util.concurrent.TimeUnit)3 CacheMode (org.infinispan.configuration.cache.CacheMode)3 Address (org.infinispan.remoting.transport.Address)3 TestingUtil (org.infinispan.test.TestingUtil)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 Mockito.mock (org.mockito.Mockito.mock)3 Answer (org.mockito.stubbing.Answer)3 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutorService (java.util.concurrent.ExecutorService)2 Cache (org.infinispan.Cache)2 EventLogListener (org.infinispan.client.hotrod.event.EventLogListener)2 CommandsFactory (org.infinispan.commands.CommandsFactory)2 StateTransferCancelCommand (org.infinispan.commands.statetransfer.StateTransferCancelCommand)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2