Search in sources :

Example 1 with UTF8StringMarshaller

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());
}
Also used : InternalRemoteCacheManager(org.infinispan.client.hotrod.test.InternalRemoteCacheManager) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller)

Example 2 with UTF8StringMarshaller

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);
}
Also used : HashMap(java.util.HashMap) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) Json(org.infinispan.commons.dataconversion.internal.Json) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) SingleHotRodServerTest(org.infinispan.client.hotrod.test.SingleHotRodServerTest)

Example 3 with UTF8StringMarshaller

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");
    });
}
Also used : RawStaticFilteredEventLogListener(org.infinispan.client.hotrod.event.EventLogListener.RawStaticFilteredEventLogListener) StaticFilteredEventLogListener(org.infinispan.client.hotrod.event.EventLogListener.StaticFilteredEventLogListener) EventLogListener(org.infinispan.client.hotrod.event.EventLogListener) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DataFormat(org.infinispan.client.hotrod.DataFormat) Test(org.testng.annotations.Test) SingleHotRodServerTest(org.infinispan.client.hotrod.test.SingleHotRodServerTest)

Example 4 with UTF8StringMarshaller

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());
}
Also used : UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DataFormat(org.infinispan.client.hotrod.DataFormat) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test) SingleHotRodServerTest(org.infinispan.client.hotrod.test.SingleHotRodServerTest)

Example 5 with UTF8StringMarshaller

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);
    });
}
Also used : UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DataFormat(org.infinispan.client.hotrod.DataFormat)

Aggregations

UTF8StringMarshaller (org.infinispan.commons.marshall.UTF8StringMarshaller)13 DataFormat (org.infinispan.client.hotrod.DataFormat)6 Test (org.testng.annotations.Test)5 SingleHotRodServerTest (org.infinispan.client.hotrod.test.SingleHotRodServerTest)4 Json (org.infinispan.commons.dataconversion.internal.Json)3 RawStaticFilteredEventLogListener (org.infinispan.client.hotrod.event.EventLogListener.RawStaticFilteredEventLogListener)2 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)2 JavaSerializationMarshaller (org.infinispan.commons.marshall.JavaSerializationMarshaller)2 ProtoStreamMarshaller (org.infinispan.commons.marshall.ProtoStreamMarshaller)2 RestServer (org.infinispan.rest.RestServer)2 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)2 DummyServerManagement (org.infinispan.server.core.DummyServerManagement)2 HotRodServerConfigurationBuilder (org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)1 EventLogListener (org.infinispan.client.hotrod.event.EventLogListener)1