Search in sources :

Example 1 with GridClientOptimizedMarshaller

use of org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller 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 2 with GridClientOptimizedMarshaller

use of org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller 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 3 with GridClientOptimizedMarshaller

use of org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller in project ignite by apache.

the class TcpRestParserSelfTest method testParseClientHandshake.

/**
     * Tests correct parsing of client handshake packets.
     *
     * @throws Exception If failed.
     */
public void testParseClientHandshake() throws Exception {
    for (int splitPos = 1; splitPos < 5; splitPos++) {
        log.info("Checking split position: " + splitPos);
        ByteBuffer tmp = clientHandshakePacket();
        ByteBuffer[] split = split(tmp, splitPos);
        GridNioSession ses = new MockNioSession();
        ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller());
        GridTcpRestParser parser = new GridTcpRestParser(false);
        Collection<GridClientMessage> lst = new ArrayList<>(1);
        for (ByteBuffer buf : split) {
            GridClientMessage r;
            while (buf.hasRemaining() && (r = parser.decode(ses, buf)) != null) lst.add(r);
            assertTrue("Parser has left unparsed bytes.", buf.remaining() == 0);
        }
        assertEquals(1, lst.size());
        GridClientHandshakeRequest req = (GridClientHandshakeRequest) F.first(lst);
        assertNotNull(req);
        assertEquals(U.bytesToShort(new byte[] { 5, 0 }, 0), req.version());
    }
}
Also used : GridClientHandshakeRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequest) 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) GridClientMessage(org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)

Example 4 with GridClientOptimizedMarshaller

use of org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller in project ignite by apache.

the class TcpRestParserSelfTest method testCustomMessages.

/**
     * @throws Exception If failed.
     */
public void testCustomMessages() throws Exception {
    GridClientCacheRequest req = new GridClientCacheRequest(CAS);
    req.key("key");
    req.value(1);
    req.value2(2);
    req.clientId(UUID.randomUUID());
    ByteBuffer raw = clientRequestPacket(req);
    GridNioSession ses = new MockNioSession();
    ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller());
    GridTcpRestParser parser = new GridTcpRestParser(false);
    GridClientMessage msg = parser.decode(ses, raw);
    assertNotNull(msg);
    assertEquals("Parser leaved unparsed bytes", 0, raw.remaining());
    assertTrue(msg instanceof GridClientCacheRequest);
    GridClientCacheRequest res = (GridClientCacheRequest) msg;
    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) 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 5 with GridClientOptimizedMarshaller

use of org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller in project ignite by apache.

the class GridTcpRestProtocol method onKernalStart.

/** {@inheritDoc} */
@Override
public void onKernalStart() {
    super.onKernalStart();
    Map<Byte, GridClientMarshaller> marshMap = new HashMap<>();
    ArrayList<PluginProvider> providers = new ArrayList<>(ctx.plugins().allProviders());
    GridClientOptimizedMarshaller optMarsh = new GridClientOptimizedMarshaller(providers);
    marshMap.put(GridClientOptimizedMarshaller.ID, optMarsh);
    marshMap.put(GridClientZipOptimizedMarshaller.ID, new GridClientZipOptimizedMarshaller(optMarsh, providers));
    marshMap.put(GridClientJdkMarshaller.ID, new GridClientJdkMarshaller());
    lsnr.marshallers(marshMap);
}
Also used : GridClientJdkMarshaller(org.apache.ignite.internal.client.marshaller.jdk.GridClientJdkMarshaller) GridClientMarshaller(org.apache.ignite.internal.client.marshaller.GridClientMarshaller) GridClientOptimizedMarshaller(org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PluginProvider(org.apache.ignite.plugin.PluginProvider) GridClientZipOptimizedMarshaller(org.apache.ignite.internal.client.marshaller.optimized.GridClientZipOptimizedMarshaller)

Aggregations

GridClientOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller)5 ByteBuffer (java.nio.ByteBuffer)4 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)4 ArrayList (java.util.ArrayList)3 GridClientCacheRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)3 GridClientMessage (org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)3 HashMap (java.util.HashMap)1 GridClientMarshaller (org.apache.ignite.internal.client.marshaller.GridClientMarshaller)1 GridClientJdkMarshaller (org.apache.ignite.internal.client.marshaller.jdk.GridClientJdkMarshaller)1 GridClientZipOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientZipOptimizedMarshaller)1 GridClientHandshakeRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequest)1 PluginProvider (org.apache.ignite.plugin.PluginProvider)1