Search in sources :

Example 16 with HotRodClient

use of org.infinispan.server.hotrod.test.HotRodClient in project infinispan by infinispan.

the class AbstractHotRodClusterEventsTest method testParameterBasedConversionInCluster.

public void testParameterBasedConversionInCluster(Method m) {
    HotRodClient client1 = clients().get(0);
    HotRodClient client2 = clients().get(1);
    EventLogListener listener1 = new EventLogListener();
    byte[] convertedKey = new byte[] { 4, 5, 6 };
    Optional<KeyValuePair<String, List<byte[]>>> converteFactory = Optional.of(new KeyValuePair<>("accepted-keyvalue-converter-factory", Collections.singletonList(new byte[] { 4, 5, 6 })));
    withClusterClientListener(client1, listener1, Optional.empty(), converteFactory, null, false, () -> {
        byte[] key1 = k(m, "k1-");
        byte[] value = v(m);
        byte[] key99 = k(m, "k-99");
        client2.put(key99, 0, 0, v(m));
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(key99));
        client2.put(key1, 0, 0, v(m));
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(key1));
        client2.put(convertedKey, 0, 0, v(m));
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(convertedKey, value));
        client1.remove(convertedKey);
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(convertedKey));
    });
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Example 17 with HotRodClient

use of org.infinispan.server.hotrod.test.HotRodClient in project infinispan by infinispan.

the class AbstractHotRodClusterEventsTest method testFailoverSendsEventsForNewContent.

public void testFailoverSendsEventsForNewContent(Method m) {
    HotRodClient client1 = clients().get(0);
    HotRodClient client2 = clients().get(1);
    HotRodClient client3 = clients().get(2);
    EventLogListener listener1 = new EventLogListener();
    EventLogListener listener2 = new EventLogListener();
    withClientListener(client1, listener1, Optional.empty(), Optional.empty(), false, true, () -> {
        byte[] key = k(m);
        client2.put(key, 0, 0, v(m));
        listener1.expectOnlyCreatedEvent(anyCache(), key);
        client2.remove(key);
        listener1.expectOnlyRemovedEvent(anyCache(), key);
        HotRodServer newServer = startClusteredServer(servers().get(2).getPort() + 50);
        HotRodClient client4 = new HotRodClient("127.0.0.1", newServer.getPort(), cacheName(), protocolVersion());
        try {
            withClientListener(client4, listener2, Optional.empty(), Optional.empty(), false, true, () -> {
                byte[] newKey = k(m, "k2-");
                client3.put(newKey, 0, 0, v(m));
                listener1.expectOnlyCreatedEvent(anyCache(), newKey);
                listener2.expectOnlyCreatedEvent(anyCache(), newKey);
                client1.put(newKey, 0, 0, v(m, "v2-"));
                listener1.expectOnlyModifiedEvent(anyCache(), newKey);
                listener2.expectOnlyModifiedEvent(anyCache(), newKey);
                client4.remove(newKey);
                listener1.expectOnlyRemovedEvent(anyCache(), newKey);
                listener2.expectOnlyRemovedEvent(anyCache(), newKey);
            });
        } finally {
            if (client4 != null) {
                client4.stop();
            }
            stopClusteredServer(newServer);
            TestingUtil.waitForNoRebalance(cache(0, cacheName()), cache(1, cacheName()), cache(2, cacheName()));
        }
        client3.put(key, 0, 0, v(m, "v2-"));
        listener1.expectOnlyCreatedEvent(anyCache(), key);
        listener2.expectNoEvents(Optional.empty());
        client3.put(key, 0, 0, v(m, "v3-"));
        listener1.expectOnlyModifiedEvent(anyCache(), key);
        listener2.expectNoEvents(Optional.empty());
        client2.remove(key);
        listener1.expectOnlyRemovedEvent(anyCache(), key);
        listener2.expectNoEvents(Optional.empty());
    });
}
Also used : HotRodServer(org.infinispan.server.hotrod.HotRodServer) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Example 18 with HotRodClient

use of org.infinispan.server.hotrod.test.HotRodClient in project infinispan by infinispan.

the class AbstractHotRodClusterEventsTest method testClientDisconnectListenerCleanup.

public void testClientDisconnectListenerCleanup(Method m) throws InterruptedException {
    HotRodClient client1 = clients().get(0);
    HotRodClient newClient = new HotRodClient("127.0.0.1", servers().get(1).getPort(), cacheName(), protocolVersion());
    EventLogListener listener = new EventLogListener();
    assertStatus(newClient.addClientListener(listener, false, Optional.empty(), Optional.empty(), true), Success);
    byte[] key = k(m);
    client1.put(key, 0, 0, v(m));
    listener.expectOnlyCreatedEvent(anyCache(), key);
    newClient.stop().await();
    client1.put(k(m, "k2-"), 0, 0, v(m));
    listener.expectNoEvents(Optional.empty());
    client1.remove(key);
    client1.remove(k(m, "k2-"));
}
Also used : HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Example 19 with HotRodClient

use of org.infinispan.server.hotrod.test.HotRodClient in project infinispan by infinispan.

the class AbstractHotRodClusterEventsTest method testNoEventsAfterRemovingListenerInDifferentNode.

public void testNoEventsAfterRemovingListenerInDifferentNode(Method m) {
    HotRodClient client1 = clients().get(0);
    HotRodClient client2 = clients().get(1);
    EventLogListener listener1 = new EventLogListener();
    byte[] key = k(m);
    assertStatus(client1.addClientListener(listener1, false, Optional.empty(), Optional.empty(), true), Success);
    try {
        client1.put(key, 0, 0, v(m));
        listener1.expectOnlyCreatedEvent(anyCache(), key);
        client1.put(key, 0, 0, v(m, "v2-"));
        listener1.expectOnlyModifiedEvent(anyCache(), key);
        client1.remove(key);
        listener1.expectOnlyRemovedEvent(anyCache(), key);
        // Use a client connected to a different node to attempt trying to remove listener
        client2.removeClientListener(listener1.getId());
        // The remoint has no effect since the listener information is not clustered
        // Remoint needs to be done in the node where the listener was added
        client1.put(key, 0, 0, v(m));
        listener1.expectOnlyCreatedEvent(anyCache(), key);
        client1.remove(key);
        listener1.expectOnlyRemovedEvent(anyCache(), key);
    } finally {
        assertStatus(client1.removeClientListener(listener1.getId()), Success);
    }
}
Also used : HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Example 20 with HotRodClient

use of org.infinispan.server.hotrod.test.HotRodClient in project infinispan by infinispan.

the class TxFunctionalTest method testKeyNotReadWithConcurrentTransaction.

public void testKeyNotReadWithConcurrentTransaction(Method method) {
    final byte[] k1 = k(method, "k1");
    final byte[] k2 = k(method, "k2");
    final byte[] v1 = v(method, "v1");
    final byte[] v2 = v(method, "v2");
    final byte[] v1_1 = v(method, "v1_1");
    HotRodClient otherClient = clients().get(1);
    RemoteTransaction tx = RemoteTransaction.startTransaction(clients().get(0));
    tx.set(k1, v1);
    tx.getAndAssert(k1, v1);
    tx.set(k2, v2);
    tx.getAndAssert(k2, v2);
    otherClient.put(k1, 0, 0, v1_1);
    tx.prepareAndAssert(XAResource.XA_OK);
    tx.commitAndAssert(XAResource.XA_OK);
    tx.forget();
    assertData(k1, v1);
    assertData(k2, v2);
    assertServerTransactionTableEmpty();
}
Also used : RemoteTransaction(org.infinispan.server.hotrod.test.RemoteTransaction) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Aggregations

HotRodClient (org.infinispan.server.hotrod.test.HotRodClient)29 KeyValuePair (org.infinispan.util.KeyValuePair)4 ArrayList (java.util.ArrayList)3 TestResponse (org.infinispan.server.hotrod.test.TestResponse)3 NetworkInterface (java.net.NetworkInterface)2 List (java.util.List)2 XidImpl (org.infinispan.commons.tx.XidImpl)2 TestSizeResponse (org.infinispan.server.hotrod.test.TestSizeResponse)2 TxResponse (org.infinispan.server.hotrod.test.TxResponse)2 BeforeClass (org.testng.annotations.BeforeClass)2 InetAddress (java.net.InetAddress)1 InterfaceAddress (java.net.InterfaceAddress)1 Future (java.util.concurrent.Future)1 SSLContext (javax.net.ssl.SSLContext)1 SSLEngine (javax.net.ssl.SSLEngine)1 SslContextFactory (org.infinispan.commons.util.SslContextFactory)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 SslConfiguration (org.infinispan.server.core.configuration.SslConfiguration)1 ServerTestingUtil (org.infinispan.server.core.test.ServerTestingUtil)1 HotRodServer (org.infinispan.server.hotrod.HotRodServer)1