Search in sources :

Example 6 with MockNioSession

use of org.apache.ignite.internal.util.nio.impl.MockNioSession in project ignite by apache.

the class TcpRestParserSelfTest method testCustomMessages.

/**
 * @throws Exception If failed.
 */
@Test
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 : MockNioSession(org.apache.ignite.internal.util.nio.impl.MockNioSession) 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) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)6 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)6 MockNioSession (org.apache.ignite.internal.util.nio.impl.MockNioSession)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 GridClientOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller)4 GridClientMessage (org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)4 GridClientCacheRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 GridClientHandshakeRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequest)1 Nullable (org.jetbrains.annotations.Nullable)1