Search in sources :

Example 1 with TestResponse

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

the class HotRodDefaultCacheTest method testPutOnDefaultCache.

public void testPutOnDefaultCache(Method m) {
    TestResponse resp = client().execute(0xA0, (byte) 0x01, "", k(m), 0, 0, v(m), 0, (byte) 1, 0);
    assertStatus(resp, Success);
    assertHotRodEquals(cacheManager, ANOTHER_CACHE, k(m), v(m));
    assertFalse(cacheManager.getCache().containsKey(k(m)));
}
Also used : TestResponse(org.infinispan.server.hotrod.test.TestResponse)

Example 2 with TestResponse

use of org.infinispan.server.hotrod.test.TestResponse 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 TestResponse

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

the class HotRodFunctionalTest method testBulkGetKeys.

public void testBulkGetKeys(Method m) {
    int size = 100;
    byte[][] keys = new byte[size][];
    for (int i = 0; i < size; i++) {
        keys[i] = k(m, i + "k-");
        TestResponse resp = client().put(keys[i], 0, 0, v(m, i + "v-"));
        assertStatus(resp, Success);
    }
    TestBulkGetKeysResponse resp = client().bulkGetKeys();
    assertStatus(resp, Success);
    Set<byte[]> bulkData = resp.bulkData;
    assertEquals(size, bulkData.size());
    for (int i = 0; i < size; i++) {
        byte[] key = keys[i];
        List<byte[]> filtered = bulkData.stream().filter(bytes -> Arrays.equals(bytes, key)).collect(Collectors.toList());
        assertEquals(1, filtered.size());
    }
    resp = client().bulkGetKeys(1);
    assertStatus(resp, Success);
    bulkData = resp.bulkData;
    assertEquals(size, bulkData.size());
    for (int i = 0; i < size; i++) {
        byte[] key = keys[i];
        List<byte[]> filtered = bulkData.stream().filter(bytes -> java.util.Arrays.equals(bytes, key)).collect(Collectors.toList());
        assertEquals(1, filtered.size());
    }
    resp = client().bulkGetKeys(2);
    assertStatus(resp, Success);
    bulkData = resp.bulkData;
    assertEquals(size, bulkData.size());
    for (int i = 0; i < size; i++) {
        byte[] key = keys[i];
        List<byte[]> filtered = bulkData.stream().filter(bytes -> Arrays.equals(bytes, key)).collect(Collectors.toList());
        assertEquals(1, filtered.size());
    }
}
Also used : HotRodTestingUtil.assertStatus(org.infinispan.server.hotrod.test.HotRodTestingUtil.assertStatus) TestResponseWithPrevious(org.infinispan.server.hotrod.test.TestResponseWithPrevious) SuccessWithPrevious(org.infinispan.server.hotrod.OperationStatus.SuccessWithPrevious) Arrays(java.util.Arrays) OperationNotExecuted(org.infinispan.server.hotrod.OperationStatus.OperationNotExecuted) Test(org.testng.annotations.Test) HotRodTestingUtil.v(org.infinispan.server.hotrod.test.HotRodTestingUtil.v) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) NotExecutedWithPrevious(org.infinispan.server.hotrod.OperationStatus.NotExecutedWithPrevious) TestResponse(org.infinispan.server.hotrod.test.TestResponse) ParseError(org.infinispan.server.hotrod.OperationStatus.ParseError) HotRodTestingUtil.assertHotRodEquals(org.infinispan.server.hotrod.test.HotRodTestingUtil.assertHotRodEquals) Map(java.util.Map) TestErrorResponse(org.infinispan.server.hotrod.test.TestErrorResponse) TestingUtil.generateRandomString(org.infinispan.test.TestingUtil.generateRandomString) Method(java.lang.reflect.Method) KeyDoesNotExist(org.infinispan.server.hotrod.OperationStatus.KeyDoesNotExist) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient) CacheEntry(org.infinispan.container.entries.CacheEntry) InvalidMagicOrMsgId(org.infinispan.server.hotrod.OperationStatus.InvalidMagicOrMsgId) Set(java.util.Set) UnknownOperation(org.infinispan.server.hotrod.OperationStatus.UnknownOperation) HotRodTestingUtil.assertSuccess(org.infinispan.server.hotrod.test.HotRodTestingUtil.assertSuccess) TestingUtil.assertBetween(org.infinispan.test.TestingUtil.assertBetween) Collectors(java.util.stream.Collectors) HotRodServerConfiguration(org.infinispan.server.hotrod.configuration.HotRodServerConfiguration) TestGetWithVersionResponse(org.infinispan.server.hotrod.test.TestGetWithVersionResponse) HotRodTestingUtil.k(org.infinispan.server.hotrod.test.HotRodTestingUtil.k) TimeUnit(java.util.concurrent.TimeUnit) TestBulkGetResponse(org.infinispan.server.hotrod.test.TestBulkGetResponse) HotRodTestingUtil.assertKeyDoesNotExist(org.infinispan.server.hotrod.test.HotRodTestingUtil.assertKeyDoesNotExist) List(java.util.List) Success(org.infinispan.server.hotrod.OperationStatus.Success) TestBulkGetKeysResponse(org.infinispan.server.hotrod.test.TestBulkGetKeysResponse) Optional(java.util.Optional) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) TestSizeResponse(org.infinispan.server.hotrod.test.TestSizeResponse) TestBulkGetKeysResponse(org.infinispan.server.hotrod.test.TestBulkGetKeysResponse) TestResponse(org.infinispan.server.hotrod.test.TestResponse)

Example 4 with TestResponse

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

the class HotRodFunctionalTest method testRemoveIfUnmodifiedNotExecuted.

public void testRemoveIfUnmodifiedNotExecuted(Method m) {
    client().assertPut(m);
    TestGetWithVersionResponse resp = client().getWithVersion(k(m), 0);
    assertSuccess(resp, v(m), 0);
    TestResponse resp2 = client().replaceIfUnmodified(k(m), 0, 0, v(m, "v1-"), resp.dataVersion);
    assertStatus(resp2, Success);
    TestGetWithVersionResponse resp3 = client().getWithVersion(k(m), 0);
    assertSuccess(resp3, v(m, "v1-"), 0);
    assertTrue(resp.dataVersion != resp3.dataVersion);
    TestResponse resp4 = client().removeIfUnmodified(k(m), 0, 0, v(m, "v2-"), resp.dataVersion);
    assertStatus(resp4, OperationNotExecuted);
    TestResponse resp5 = client().removeIfUnmodified(k(m), 0, 0, v(m, "v2-"), resp3.dataVersion);
    assertStatus(resp5, Success);
}
Also used : TestResponse(org.infinispan.server.hotrod.test.TestResponse) TestGetWithVersionResponse(org.infinispan.server.hotrod.test.TestGetWithVersionResponse)

Example 5 with TestResponse

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

the class HotRodFunctionalTest method testRemoveIfUmodifiedWithPreviousValue.

public void testRemoveIfUmodifiedWithPreviousValue(Method m) {
    TestResponse resp = client().removeIfUnmodified(k(m), 999, 0);
    assertStatus(resp, KeyDoesNotExist);
    client().assertPut(m);
    TestGetWithVersionResponse getResp = client().getWithVersion(k(m), 0);
    assertSuccess(getResp, v(m), 0);
    TestResponseWithPrevious resp2 = (TestResponseWithPrevious) client().removeIfUnmodified(k(m), 888, 1);
    assertNotExecutedPrevious(resp2, v(m));
    TestResponseWithPrevious resp3 = (TestResponseWithPrevious) client().removeIfUnmodified(k(m), getResp.dataVersion, 1);
    assertSuccessPrevious(resp3, v(m));
}
Also used : TestResponse(org.infinispan.server.hotrod.test.TestResponse) TestResponseWithPrevious(org.infinispan.server.hotrod.test.TestResponseWithPrevious) TestGetWithVersionResponse(org.infinispan.server.hotrod.test.TestGetWithVersionResponse)

Aggregations

TestResponse (org.infinispan.server.hotrod.test.TestResponse)53 TestGetWithVersionResponse (org.infinispan.server.hotrod.test.TestGetWithVersionResponse)11 TestResponseWithPrevious (org.infinispan.server.hotrod.test.TestResponseWithPrevious)7 CounterException (org.infinispan.counter.exception.CounterException)5 HotRodClient (org.infinispan.server.hotrod.test.HotRodClient)5 TestErrorResponse (org.infinispan.server.hotrod.test.TestErrorResponse)5 CounterOp (org.infinispan.server.hotrod.counter.op.CounterOp)3 CreateCounterOp (org.infinispan.server.hotrod.counter.op.CreateCounterOp)3 CounterConfigurationTestResponse (org.infinispan.server.hotrod.counter.response.CounterConfigurationTestResponse)3 CounterNamesTestResponse (org.infinispan.server.hotrod.counter.response.CounterNamesTestResponse)3 CounterValueTestResponse (org.infinispan.server.hotrod.counter.response.CounterValueTestResponse)3 Method (java.lang.reflect.Method)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2