Search in sources :

Example 1 with GridClientCacheRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.

the class TestBinaryClient method cachePutAll.

/**
     * @param cacheName Cache name.
     * @param entries Entries.
     * @return {@code True} if map contained more then one entry or if put succeeded in case of one entry,
     *      {@code false} otherwise
     * @throws IgniteCheckedException In case of error.
     */
public <K, V> boolean cachePutAll(@NotNull String cacheName, Map<K, V> entries) throws IgniteCheckedException {
    assert entries != null;
    GridClientCacheRequest req = new GridClientCacheRequest(PUT_ALL);
    req.requestId(idCntr.incrementAndGet());
    req.cacheName(cacheName);
    req.values((Map<Object, Object>) entries);
    return makeRequest(req).<Boolean>getObject();
}
Also used : GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)

Example 2 with GridClientCacheRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.

the class TcpRestParserSelfTest method testMixedParsing.

/**
     * @throws Exception If failed.
     */
public void testMixedParsing() throws Exception {
    GridNioSession ses1 = new MockNioSession();
    GridNioSession ses2 = new MockNioSession();
    ses1.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller());
    ses2.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller());
    GridTcpRestParser parser = new GridTcpRestParser(false);
    GridClientCacheRequest req = new GridClientCacheRequest(CAS);
    req.key("key");
    String val = "value";
    req.value(val);
    req.value2(val);
    req.clientId(UUID.randomUUID());
    byte[] opaque = new byte[] { 0x01, 0x02, 0x03, (byte) 0xFF };
    String key = "key";
    ByteBuffer raw1 = rawPacket(MEMCACHE_REQ_FLAG, (byte) 0x01, opaque, key.getBytes(), val.getBytes(), EXTRAS);
    ByteBuffer raw2 = clientRequestPacket(req);
    raw1.mark();
    raw2.mark();
    int splits = Math.min(raw1.remaining(), raw2.remaining());
    for (int i = 1; i < splits; i++) {
        ByteBuffer[] packet1 = split(raw1, i);
        ByteBuffer[] packet2 = split(raw2, i);
        GridClientMessage msg = parser.decode(ses1, packet1[0]);
        assertNull(msg);
        msg = parser.decode(ses2, packet2[0]);
        assertNull(msg);
        msg = parser.decode(ses1, packet1[1]);
        assertTrue(msg instanceof GridMemcachedMessage);
        assertEquals(key, ((GridMemcachedMessage) msg).key());
        assertEquals(val, ((GridMemcachedMessage) msg).value());
        msg = parser.decode(ses2, packet2[1]);
        assertTrue(msg instanceof GridClientCacheRequest);
        assertEquals(val, ((GridClientCacheRequest) msg).value());
        assertEquals(val, ((GridClientCacheRequest) msg).value2());
        raw1.reset();
        raw2.reset();
    }
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridClientOptimizedMarshaller(org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller) GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest) ByteBuffer(java.nio.ByteBuffer) GridClientMessage(org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)

Example 3 with GridClientCacheRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.

the class TcpRestParserSelfTest method testParseContinuousSplit.

/**
     * @throws Exception If failed.
     */
public void testParseContinuousSplit() throws Exception {
    ByteBuffer tmp = ByteBuffer.allocate(10 * 1024);
    GridClientCacheRequest req = new GridClientCacheRequest(CAS);
    req.key("key");
    req.value(1);
    req.value2(2);
    req.clientId(UUID.randomUUID());
    for (int i = 0; i < 5; i++) tmp.put(clientRequestPacket(req));
    tmp.flip();
    for (int splitPos = 0; splitPos < tmp.remaining(); splitPos++) {
        ByteBuffer[] split = split(tmp, splitPos);
        tmp.flip();
        GridNioSession ses = new MockNioSession();
        ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller());
        GridTcpRestParser parser = new GridTcpRestParser(false);
        Collection<GridClientCacheRequest> lst = new ArrayList<>(5);
        for (ByteBuffer buf : split) {
            GridClientCacheRequest r;
            while (buf.hasRemaining() && (r = (GridClientCacheRequest) parser.decode(ses, buf)) != null) lst.add(r);
            assertTrue("Parser has left unparsed bytes.", buf.remaining() == 0);
        }
        assertEquals(5, lst.size());
        for (GridClientCacheRequest res : lst) {
            assertEquals("Invalid operation", req.operation(), res.operation());
            assertEquals("Invalid clientId", req.clientId(), res.clientId());
            assertEquals("Invalid key", req.key(), res.key());
            assertEquals("Invalid value 1", req.value(), res.value());
            assertEquals("Invalid value 2", req.value2(), res.value2());
        }
    }
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridClientOptimizedMarshaller(org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)

Example 4 with GridClientCacheRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.

the class TestBinaryClient method cacheRemoveAll.

/**
     * @param cacheName Cache name.
     * @param keys Keys.
     * @return Whether entries were actually removed
     * @throws IgniteCheckedException In case of error.
     */
public <K> boolean cacheRemoveAll(@NotNull String cacheName, K... keys) throws IgniteCheckedException {
    assert keys != null;
    GridClientCacheRequest req = new GridClientCacheRequest(RMV_ALL);
    req.requestId(idCntr.getAndIncrement());
    req.cacheName(cacheName);
    req.keys((Iterable<Object>) Arrays.asList(keys));
    return makeRequest(req).isSuccess();
}
Also used : GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)

Example 5 with GridClientCacheRequest

use of org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest in project ignite by apache.

the class TestBinaryClient method cacheReplace.

/**
     * @param cacheName Cache name.
     * @param key Key.
     * @param val Value.
     * @return Whether value was actually replaced.
     * @throws IgniteCheckedException In case of error.
     */
public <K, V> boolean cacheReplace(@NotNull String cacheName, K key, V val) throws IgniteCheckedException {
    assert key != null;
    assert val != null;
    GridClientCacheRequest replace = new GridClientCacheRequest(REPLACE);
    replace.requestId(idCntr.getAndIncrement());
    replace.cacheName(cacheName);
    replace.key(key);
    replace.value(val);
    return makeRequest(replace).<Boolean>getObject();
}
Also used : GridClientCacheRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)

Aggregations

GridClientCacheRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)24 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 GridClientOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller)3 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)3 GridClientMessage (org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)2 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GridClientMarshaller (org.apache.ignite.internal.client.marshaller.GridClientMarshaller)1 GridClientAuthenticationRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest)1 GridClientStateRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientStateRequest)1 GridClientTaskRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientTaskRequest)1 GridClientTopologyRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)1 GridRestCacheRequest (org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest)1 GridRestChangeStateRequest (org.apache.ignite.internal.processors.rest.request.GridRestChangeStateRequest)1 GridRestRequest (org.apache.ignite.internal.processors.rest.request.GridRestRequest)1 GridRestTaskRequest (org.apache.ignite.internal.processors.rest.request.GridRestTaskRequest)1