Search in sources :

Example 1 with HotRodClient

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

the class HotRodDistributionTest method testSize.

public void testSize(Method m) {
    // Cache contents not cleared between methods to avoid deleting
    // topology information, so just use a different cache
    String newCacheName = "dist-size";
    startCaches(newCacheName);
    List<HotRodClient> newClients = createClients(newCacheName);
    try {
        TestSizeResponse sizeStart = newClients.get(0).size();
        assertStatus(sizeStart, Success);
        assertEquals(0, sizeStart.size);
        for (int i = 0; i < 20; i++) {
            newClients.get(1).assertPut(m, "k-" + i, "v-" + i);
        }
        TestSizeResponse sizeEnd = newClients.get(1).size();
        assertStatus(sizeEnd, Success);
        assertEquals(20, sizeEnd.size);
    } finally {
        newClients.forEach(HotRodTestingUtil::killClient);
    }
}
Also used : TestSizeResponse(org.infinispan.server.hotrod.test.TestSizeResponse) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient) HotRodTestingUtil(org.infinispan.server.hotrod.test.HotRodTestingUtil)

Example 2 with HotRodClient

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

the class HotRodDistributionTest method testDistributedPutWithTopologyChanges.

public void testDistributedPutWithTopologyChanges(Method m) {
    HotRodClient client1 = clients().get(0);
    HotRodClient client2 = clients().get(1);
    TestResponse resp = client1.ping(INTELLIGENCE_HASH_DISTRIBUTION_AWARE, 0);
    assertStatus(resp, Success);
    assertHashTopology20Received(resp.topologyResponse, servers(), cacheName(), currentServerTopologyId());
    resp = client1.put(k(m), 0, 0, v(m), INTELLIGENCE_BASIC, 0);
    assertStatus(resp, Success);
    assertEquals(resp.topologyResponse, null);
    assertSuccess(client2.get(k(m), 0), v(m));
    resp = client1.put(k(m), 0, 0, v(m, "v1-"), INTELLIGENCE_TOPOLOGY_AWARE, 0);
    assertStatus(resp, Success);
    assertTopologyReceived(resp.topologyResponse, servers(), currentServerTopologyId());
    resp = client2.put(k(m), 0, 0, v(m, "v2-"), INTELLIGENCE_TOPOLOGY_AWARE, 0);
    assertStatus(resp, Success);
    assertTopologyReceived(resp.topologyResponse, servers(), currentServerTopologyId());
    resp = client1.put(k(m), 0, 0, v(m, "v3-"), INTELLIGENCE_TOPOLOGY_AWARE, ClusterCacheStatus.INITIAL_TOPOLOGY_ID + 2 * nodeCount());
    assertStatus(resp, Success);
    assertEquals(resp.topologyResponse, null);
    assertSuccess(client2.get(k(m), 0), v(m, "v3-"));
    resp = client1.put(k(m), 0, 0, v(m, "v4-"), INTELLIGENCE_HASH_DISTRIBUTION_AWARE, 0);
    assertStatus(resp, Success);
    assertHashTopology20Received(resp.topologyResponse, servers(), cacheName(), currentServerTopologyId());
    assertSuccess(client2.get(k(m), 0), v(m, "v4-"));
    resp = client2.put(k(m), 0, 0, v(m, "v5-"), INTELLIGENCE_HASH_DISTRIBUTION_AWARE, 0);
    assertStatus(resp, Success);
    assertHashTopology20Received(resp.topologyResponse, servers(), cacheName(), currentServerTopologyId());
    assertSuccess(client2.get(k(m), 0), v(m, "v5-"));
    HotRodServer newServer = startClusteredServer(servers().get(1).getPort() + 25);
    HotRodClient newClient = new HotRodClient("127.0.0.1", newServer.getPort(), cacheName(), protocolVersion());
    List<HotRodServer> allServers = Stream.concat(Stream.of(newServer), servers().stream()).collect(Collectors.toList());
    try {
        log.trace("New client started, modify key to be v6-*");
        resp = newClient.put(k(m), 0, 0, v(m, "v6-"), INTELLIGENCE_HASH_DISTRIBUTION_AWARE, 0);
        assertStatus(resp, Success);
        assertHashTopology20Received(resp.topologyResponse, allServers, cacheName(), currentServerTopologyId());
        log.trace("Get key and verify that's v6-*");
        assertSuccess(client2.get(k(m), 0), v(m, "v6-"));
        resp = client2.put(k(m), 0, 0, v(m, "v7-"), INTELLIGENCE_HASH_DISTRIBUTION_AWARE, 0);
        assertStatus(resp, Success);
        assertHashTopology20Received(resp.topologyResponse, allServers, cacheName(), currentServerTopologyId());
        assertSuccess(newClient.get(k(m), 0), v(m, "v7-"));
    } finally {
        log.trace("Stopping new server");
        killClient(newClient);
        stopClusteredServer(newServer);
        TestingUtil.waitForNoRebalance(cache(0, cacheName()), cache(1, cacheName()));
        log.trace("New server stopped");
    }
    resp = client2.put(k(m), 0, 0, v(m, "v8-"), INTELLIGENCE_HASH_DISTRIBUTION_AWARE, ClusterCacheStatus.INITIAL_TOPOLOGY_ID + 2 * nodeCount());
    assertStatus(resp, Success);
    assertHashTopology20Received(resp.topologyResponse, servers(), cacheName(), currentServerTopologyId());
    assertSuccess(client1.get(k(m), 0), v(m, "v8-"));
}
Also used : TestResponse(org.infinispan.server.hotrod.test.TestResponse) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Example 3 with HotRodClient

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

the class HotRodFunctionalTest method testLifespan2x.

public void testLifespan2x(Method m) {
    try (HotRodClient client2x = connectClient(HotRodVersion.HOTROD_29.getVersion())) {
        // Expire in 1 day by setting the lifespan in seconds since the Unix epoch
        long startMillis = System.currentTimeMillis();
        long lifespanMillis = TimeUnit.MINUTES.toMillis(1);
        int expirationUnixTime = (int) ((startMillis + lifespanMillis) / 1000);
        assertStatus(client2x.put(k(m), expirationUnixTime, expirationUnixTime, v(m)), Success);
        CacheEntry<byte[], byte[]> entry = advancedCache.withStorageMediaType().getCacheEntry(k(m));
        // The lifespan is set to expirationUnixTime * 1000 - <current time on the server>
        long endMillis = System.currentTimeMillis();
        long lowerBound = expirationUnixTime * 1000L - endMillis;
        long upperBound = expirationUnixTime * 1000L - startMillis;
        assertBetween(lowerBound, upperBound, entry.getLifespan());
        assertBetween(lowerBound, upperBound, entry.getMaxIdle());
    }
}
Also used : HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Example 4 with HotRodClient

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

the class HotRodMergeTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Throwable {
    ConfigurationBuilder dcc = hotRodCacheConfiguration();
    dcc.clustering().cacheMode(cacheMode).hash();
    dcc.clustering().partitionHandling().whenSplit(partitionHandling);
    createClusteredCaches(numMembersInCluster, dcc, new TransportFlags().withFD(true).withMerge(true));
    waitForClusterToForm();
    // Allow servers for both instances to run in parallel
    int threadServerPort = serverPort();
    int nextServerPort = threadServerPort + partitionHandling.ordinal() * numMembersInCluster;
    for (int i = 0; i < numMembersInCluster; i++) {
        servers.add(startHotRodServer(cacheManagers.get(i), nextServerPort));
        nextServerPort += 1;
    }
    client = new HotRodClient("127.0.0.1", servers.get(0).getPort(), getDefaultCacheName(), (byte) 21);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) TransportFlags(org.infinispan.test.fwk.TransportFlags) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Example 5 with HotRodClient

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

the class HotRodReplicationTest method testSize.

public void testSize(Method m) {
    // Cache contents not cleared between methods to avoid deleting
    // topology information, so just use a different cache
    String newCacheName = "repl-size";
    startCaches(newCacheName);
    List<HotRodClient> newClients = createClients(newCacheName);
    try {
        TestSizeResponse sizeStart = newClients.get(0).size();
        assertStatus(sizeStart, Success);
        assertEquals(0, sizeStart.size);
        for (int i = 0; i < 20; i++) {
            newClients.get(1).assertPut(m, "k-" + i, "v-" + i);
        }
        TestSizeResponse sizeEnd = newClients.get(1).size();
        assertStatus(sizeEnd, Success);
        assertEquals(20, sizeEnd.size);
    } finally {
        newClients.forEach(HotRodClient::stop);
    }
}
Also used : TestSizeResponse(org.infinispan.server.hotrod.test.TestSizeResponse) 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