use of org.infinispan.client.hotrod.DataFormat in project infinispan by infinispan.
the class Codec20 method readCacheEvent.
@Override
public AbstractClientEvent readCacheEvent(ByteBuf buf, Function<byte[], DataFormat> listenerDataFormat, short eventTypeId, ClassAllowList allowList, SocketAddress serverAddress) {
short status = buf.readUnsignedByte();
// ignore, no topology expected
buf.readUnsignedByte();
ClientEvent.Type eventType;
switch(eventTypeId) {
case CACHE_ENTRY_CREATED_EVENT_RESPONSE:
eventType = ClientEvent.Type.CLIENT_CACHE_ENTRY_CREATED;
break;
case CACHE_ENTRY_MODIFIED_EVENT_RESPONSE:
eventType = ClientEvent.Type.CLIENT_CACHE_ENTRY_MODIFIED;
break;
case CACHE_ENTRY_REMOVED_EVENT_RESPONSE:
eventType = ClientEvent.Type.CLIENT_CACHE_ENTRY_REMOVED;
break;
case ERROR_RESPONSE:
checkForErrorsInResponseStatus(buf, null, status, serverAddress);
// Fall through if we didn't throw an exception already
default:
throw HOTROD.unknownEvent(eventTypeId);
}
byte[] listenerId = ByteBufUtil.readArray(buf);
short isCustom = buf.readUnsignedByte();
boolean isRetried = buf.readUnsignedByte() == 1;
DataFormat dataFormat = listenerDataFormat.apply(listenerId);
if (isCustom == 1) {
final Object eventData = dataFormat.valueToObj(ByteBufUtil.readArray(buf), allowList);
return createCustomEvent(listenerId, eventData, eventType, isRetried);
} else {
switch(eventType) {
case CLIENT_CACHE_ENTRY_CREATED:
long createdDataVersion = buf.readLong();
return createCreatedEvent(listenerId, dataFormat.keyToObj(ByteBufUtil.readArray(buf), allowList), createdDataVersion, isRetried);
case CLIENT_CACHE_ENTRY_MODIFIED:
long modifiedDataVersion = buf.readLong();
return createModifiedEvent(listenerId, dataFormat.keyToObj(ByteBufUtil.readArray(buf), allowList), modifiedDataVersion, isRetried);
case CLIENT_CACHE_ENTRY_REMOVED:
return createRemovedEvent(listenerId, dataFormat.keyToObj(ByteBufUtil.readArray(buf), allowList), isRetried);
default:
throw HOTROD.unknownEvent(eventTypeId);
}
}
}
use of org.infinispan.client.hotrod.DataFormat in project infinispan by infinispan.
the class ComplexValue method testListenersWithDifferentFormats.
@Test
public void testListenersWithDifferentFormats() {
remoteCache.clear();
ComplexKey complexKey = new ComplexKey("Key-1", 89.88f);
ComplexValue complexValue = new ComplexValue(Util.threadLocalRandomUUID());
// Receive events as JSON Strings
DataFormat jsonStringFormat = DataFormat.builder().keyType(APPLICATION_JSON).keyMarshaller(new UTF8StringMarshaller()).build();
EventLogListener<Object> l = new EventLogListener<>(remoteCache.withDataFormat(jsonStringFormat));
withClientListener(l, remote -> {
remoteCache.put(complexKey, complexValue);
l.expectOnlyCreatedEvent("\n{\n \"_type\": \"org.infinispan.test.client.DataFormatTest.ComplexKey\",\n \"id\": \"Key-1\",\n \"ratio\": 89.88\n}\n");
});
}
use of org.infinispan.client.hotrod.DataFormat in project infinispan by infinispan.
the class ComplexValue method testJsonFromDefaultCache.
@Test
public void testJsonFromDefaultCache() {
RemoteCache<String, String> schemaCache = remoteCacheManager.getCache(PROTOBUF_METADATA_CACHE_NAME);
schemaCache.put("schema.proto", "message M { optional string json_key = 1; }");
RemoteQueryTestUtils.checkSchemaErrors(schemaCache);
DataFormat jsonValues = DataFormat.builder().valueType(APPLICATION_JSON).valueMarshaller(new UTF8StringMarshaller()).build();
RemoteCache<Integer, String> cache = remoteCacheManager.getCache().withDataFormat(jsonValues);
String value = "{\"_type\":\"M\",\"json_key\":\"json_value\"}";
cache.put(1, value);
String valueAsJson = cache.get(1);
Json node = Json.read(valueAsJson);
assertEquals("json_value", node.at("json_key").asString());
}
use of org.infinispan.client.hotrod.DataFormat in project infinispan by infinispan.
the class RemoteQueryRepeatedMappingTest method testCreateAndQuery.
@Test
public void testCreateAndQuery() throws Exception {
registerProtoBuf();
RemoteCache<Object, Object> cache = remoteCacheManager.administration().withFlags(VOLATILE).createCache(CACHE_NAME, createCacheXMLConfig());
DataFormat dataFormat = DataFormat.builder().keyType(APPLICATION_JSON).valueType(APPLICATION_JSON).build();
RemoteCache<byte[], byte[]> jsonCache = cache.withDataFormat(dataFormat);
jsonCache.put(keyAsJson(), valueAsJson());
Query<Object> querySlowChildren = Search.getQueryFactory(cache).create("SELECT COUNT(*) FROM Parent p WHERE p.slowChildren.id = 0");
Query<Object> queryFastChildren = Search.getQueryFactory(cache).create("SELECT COUNT(*) FROM Parent p WHERE p.fastChildren.id = 10");
Query<Object> queryFieldChildren = Search.getQueryFactory(cache).create("SELECT COUNT(*) FROM Parent p WHERE p.fieldLessChildren.id = 0");
Query<Object> queryNotIndexedWithFieldChildren = Search.getQueryFactory(cache).create("SELECT COUNT(*) FROM Parent p WHERE p.notIndexedWithFieldChild.id = 37");
assertEquals(1, querySlowChildren.execute().hitCount().orElse(-1));
assertEquals(1, queryFastChildren.execute().hitCount().orElse(-1));
assertEquals(1, queryFieldChildren.execute().hitCount().orElse(-1));
assertEquals(1, queryNotIndexedWithFieldChildren.execute().hitCount().orElse(-1));
}
use of org.infinispan.client.hotrod.DataFormat in project infinispan by infinispan.
the class JsonEventsTest method testCreatedEvent.
public void testCreatedEvent() {
DataFormat jsonValues = DataFormat.builder().valueType(APPLICATION_JSON).valueMarshaller(new UTF8StringMarshaller()).build();
final EventLogListener<Integer> l = new EventLogListener<>(remoteCacheManager.getCache().withDataFormat(jsonValues));
withClientListener(l, remote -> {
l.expectNoEvents();
remote.put(1, "{\"_type\":\"A\",\"key\":\"one\"}");
l.expectOnlyCreatedEvent(1);
remote.put(2, "{\"_type\":\"A\",\"key\":\"two\"}");
l.expectOnlyCreatedEvent(2);
});
}
Aggregations