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