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();
}
}
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());
}
}
}
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());
}
}
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());
}
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);
}
Aggregations