use of org.infinispan.commons.marshall.UTF8StringMarshaller in project infinispan by infinispan.
the class ExecTypedTest method createExecClient.
private RemoteCacheManager createExecClient() {
org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = super.createHotRodClientConfigurationBuilder(servers.get(0));
clientBuilder.marshaller(new UTF8StringMarshaller());
clientBuilder.version(getProtocolVersion());
return new InternalRemoteCacheManager(clientBuilder.build());
}
use of org.infinispan.commons.marshall.UTF8StringMarshaller in project infinispan by infinispan.
the class ComplexValue method testBatchOperations.
@Test
public void testBatchOperations() {
remoteCache.clear();
Map<ComplexKey, ComplexValue> entries = new HashMap<>();
IntStream.range(0, 50).forEach(i -> {
ComplexKey key = new ComplexKey(String.valueOf(i), (float) i);
ComplexValue value = new ComplexValue(Util.threadLocalRandomUUID());
entries.put(key, value);
});
remoteCache.putAll(entries);
// Read all keys as JSON Strings
RemoteCache<String, String> jsonCache = this.remoteCache.withDataFormat(DataFormat.builder().keyType(APPLICATION_JSON).keyMarshaller(new UTF8StringMarshaller()).build());
Set<String> jsonKeys = new HashSet<>(jsonCache.keySet());
jsonKeys.forEach(k -> assertTrue(k.contains("\"_type\": \"org.infinispan.test.client.DataFormatTest.ComplexKey\"")));
Map<String, String> newEntries = new HashMap<>();
// Write using JSON
IntStream.range(50, 100).forEach(i -> {
Json key = Json.object("_type", "org.infinispan.test.client.DataFormatTest.ComplexKey").set("id", i).set("ratio", i);
Json value = Json.object("_type", "org.infinispan.test.client.DataFormatTest.ComplexValue").set("uuid", Util.threadLocalRandomUUID().toString());
newEntries.put(key.toString(), value.toString());
});
jsonCache.putAll(newEntries);
// Read it back as regular objects
Set<ComplexKey> keys = new HashSet<>();
IntStream.range(60, 70).forEach(i -> keys.add(new ComplexKey(String.valueOf(i), (float) i)));
Set<ComplexKey> returned = remoteCache.getAll(keys).keySet().stream().map(ComplexKey.class::cast).collect(Collectors.toSet());
assertEquals(keys, returned);
}
use of org.infinispan.commons.marshall.UTF8StringMarshaller 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.commons.marshall.UTF8StringMarshaller 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.commons.marshall.UTF8StringMarshaller 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