Search in sources :

Example 1 with EventLogListener

use of org.infinispan.client.hotrod.event.EventLogListener in project infinispan by infinispan.

the class ComplexValue method testListenersWithDifferentFormats.

@Test
public void testListenersWithDifferentFormats() {
    remoteCache.clear();
    ComplexKey complexKey = new ComplexKey("Key-1", 89.88f);
    ComplexValue complexValue = new ComplexValue(Util.threadLocalRandomUUID());
    // Receive events as JSON Strings
    DataFormat jsonStringFormat = DataFormat.builder().keyType(APPLICATION_JSON).keyMarshaller(new UTF8StringMarshaller()).build();
    EventLogListener<Object> l = new EventLogListener<>(remoteCache.withDataFormat(jsonStringFormat));
    withClientListener(l, remote -> {
        remoteCache.put(complexKey, complexValue);
        l.expectOnlyCreatedEvent("\n{\n   \"_type\": \"org.infinispan.test.client.DataFormatTest.ComplexKey\",\n   \"id\": \"Key-1\",\n   \"ratio\": 89.88\n}\n");
    });
}
Also used : RawStaticFilteredEventLogListener(org.infinispan.client.hotrod.event.EventLogListener.RawStaticFilteredEventLogListener) StaticFilteredEventLogListener(org.infinispan.client.hotrod.event.EventLogListener.StaticFilteredEventLogListener) EventLogListener(org.infinispan.client.hotrod.event.EventLogListener) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DataFormat(org.infinispan.client.hotrod.DataFormat) Test(org.testng.annotations.Test) SingleHotRodServerTest(org.infinispan.client.hotrod.test.SingleHotRodServerTest)

Example 2 with EventLogListener

use of org.infinispan.client.hotrod.event.EventLogListener 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)

Example 3 with EventLogListener

use of org.infinispan.client.hotrod.event.EventLogListener in project infinispan by infinispan.

the class SecureListenerTest method testImplicitRemoveOnClose.

public void testImplicitRemoveOnClose() throws IOException, PrivilegedActionException {
    org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = newClientBuilder();
    clientBuilder.security().authentication().callbackHandler(new TestCallbackHandler("RWLuser", null, "password"));
    remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
    RemoteCache<Object, Object> clientCache = remoteCacheManager.getCache(CACHE_NAME);
    EventLogListener<Object> listener = new EventLogListener<>(clientCache);
    clientCache.addClientListener(listener);
    Cache<Object, Object> serverCache = cacheManager.getCache(CACHE_NAME);
    CacheNotifier cacheNotifier = TestingUtil.extractComponent(serverCache, CacheNotifier.class);
    assertEquals(1, cacheNotifier.getListeners().size());
    clientCache.put("key", "value");
    listener.expectSingleEvent("key", ClientEvent.Type.CLIENT_CACHE_ENTRY_CREATED);
    remoteCacheManager.close();
    eventuallyEquals(0, () -> cacheNotifier.getListeners().size());
}
Also used : EventLogListener(org.infinispan.client.hotrod.event.EventLogListener) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) TestCallbackHandler(org.infinispan.server.hotrod.test.TestCallbackHandler)

Aggregations

EventLogListener (org.infinispan.client.hotrod.event.EventLogListener)3 CacheNotifier (org.infinispan.notifications.cachelistener.CacheNotifier)2 DataFormat (org.infinispan.client.hotrod.DataFormat)1 RawStaticFilteredEventLogListener (org.infinispan.client.hotrod.event.EventLogListener.RawStaticFilteredEventLogListener)1 StaticFilteredEventLogListener (org.infinispan.client.hotrod.event.EventLogListener.StaticFilteredEventLogListener)1 SingleHotRodServerTest (org.infinispan.client.hotrod.test.SingleHotRodServerTest)1 UTF8StringMarshaller (org.infinispan.commons.marshall.UTF8StringMarshaller)1 TestCallbackHandler (org.infinispan.server.hotrod.test.TestCallbackHandler)1 Test (org.testng.annotations.Test)1