Search in sources :

Example 6 with UTF8StringMarshaller

use of org.infinispan.commons.marshall.UTF8StringMarshaller in project infinispan by infinispan.

the class JsonKeyValueRawEventsTest method testReceiveKeyValuesAsJson.

public void testReceiveKeyValuesAsJson() throws InterruptedException {
    BlockingQueue<KeyValuePair<String, String>> eventsQueue = new LinkedBlockingQueue<>();
    DataFormat jsonValues = DataFormat.builder().valueType(APPLICATION_JSON).valueMarshaller(new UTF8StringMarshaller()).build();
    RemoteCache<String, Person> cache = remoteCacheManager.getCache();
    RemoteCache<String, String> jsonCache = cache.withDataFormat(jsonValues);
    jsonCache.addClientListener(new EventListener(eventsQueue, jsonCache.getDataFormat()));
    cache.put("1", new Person("John"));
    KeyValuePair<String, String> event = eventsQueue.poll(5, TimeUnit.SECONDS);
    assertNotNull(event);
    assertEquals(event.getKey(), "1");
    assertEquals(event.getValue(), "\n{\n   \"_type\": \"org.infinispan.test.core.Person\",\n   \"name\": \"John\",\n   \"birthDate\": 0,\n   \"accepted_tos\": false\n}\n");
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DataFormat(org.infinispan.client.hotrod.DataFormat) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Person(org.infinispan.test.data.Person)

Example 7 with UTF8StringMarshaller

use of org.infinispan.commons.marshall.UTF8StringMarshaller in project infinispan by infinispan.

the class HotRodQueryIspnDirectoryTest method testReadAsJSON.

public void testReadAsJSON() {
    DataFormat acceptJSON = DataFormat.builder().valueType(APPLICATION_JSON).valueMarshaller(new UTF8StringMarshaller()).build();
    RemoteCache<Integer, String> jsonCache = remoteCache.withDataFormat(acceptJSON);
    Json user1 = Json.read(jsonCache.get(1));
    assertEquals("Tom", user1.at("name").asString());
    assertEquals("Cat", user1.at("surname").asString());
    Query<String> query = Search.getQueryFactory(jsonCache).create("FROM sample_bank_account.User WHERE name = :name");
    query.maxResults(10).startOffset(0).setParameter("name", "Tom");
    QueryResult<String> result = query.execute();
    List<String> results = result.list();
    assertEquals(1, query.getResultSize());
    assertFalse(query.hasProjections());
    Json jsonNode = Json.read(results.iterator().next());
    assertEquals("Tom", jsonNode.at("name").asString());
    assertEquals("Cat", jsonNode.at("surname").asString());
    query = Search.getQueryFactory(jsonCache).create("FROM sample_bank_account.User WHERE name = \"Tom\"");
    results = query.execute().list();
    assertEquals(1, results.size());
}
Also used : UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DataFormat(org.infinispan.client.hotrod.DataFormat) Json(org.infinispan.commons.dataconversion.internal.Json)

Example 8 with UTF8StringMarshaller

use of org.infinispan.commons.marshall.UTF8StringMarshaller in project infinispan by infinispan.

the class EndpointInteroperabilityTest method setup.

@BeforeClass
protected void setup() throws Exception {
    cacheManager = TestCacheManagerFactory.createServerModeCacheManager();
    cacheManager.defineConfiguration(DEFAULT_CACHE_NAME, getDefaultCacheConfiguration().build());
    cacheManager.defineConfiguration(MARSHALLED_CACHE_NAME, getMarshalledCacheConfiguration().build());
    cacheManager.defineConfiguration(STRING_CACHE_NAME, getStringsCacheConfiguration().build());
    RestServerConfigurationBuilder builder = new RestServerConfigurationBuilder();
    builder.port(findFreePort());
    restServer = new RestServer();
    restServer.setServerManagement(new DummyServerManagement(), true);
    restServer.start(builder.build(), cacheManager);
    RestClientConfigurationBuilder clientBuilder = new RestClientConfigurationBuilder();
    RestClientConfiguration configuration = clientBuilder.addServer().host(restServer.getHost()).port(restServer.getPort()).build();
    restClient = RestClient.forConfiguration(configuration);
    HotRodServerConfigurationBuilder serverBuilder = new HotRodServerConfigurationBuilder();
    serverBuilder.adminOperationsHandler(new EmbeddedServerAdminOperationHandler());
    hotRodServer = startHotRodServer(cacheManager, serverBuilder);
    defaultRemoteCache = createRemoteCacheManager(IdentityMarshaller.INSTANCE).getCache(DEFAULT_CACHE_NAME);
    defaultMarshalledRemoteCache = createRemoteCacheManager(null).getCache(MARSHALLED_CACHE_NAME);
    stringRemoteCache = createRemoteCacheManager(new UTF8StringMarshaller()).getCache(STRING_CACHE_NAME);
}
Also used : RestServer(org.infinispan.rest.RestServer) RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) EmbeddedServerAdminOperationHandler(org.infinispan.server.core.admin.embeddedserver.EmbeddedServerAdminOperationHandler) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) DummyServerManagement(org.infinispan.server.core.DummyServerManagement) HotRodServerConfigurationBuilder(org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder) BeforeClass(org.testng.annotations.BeforeClass)

Example 9 with UTF8StringMarshaller

use of org.infinispan.commons.marshall.UTF8StringMarshaller in project infinispan by infinispan.

the class RemoteCacheManager method actualStart.

private void actualStart() {
    log.debugf("Starting remote cache manager %x", System.identityHashCode(this));
    channelFactory = createChannelFactory();
    marshallerRegistry.registerMarshaller(BytesOnlyMarshaller.INSTANCE);
    marshallerRegistry.registerMarshaller(new UTF8StringMarshaller());
    marshallerRegistry.registerMarshaller(new JavaSerializationMarshaller(configuration.getClassAllowList()));
    registerProtoStreamMarshaller();
    boolean customMarshallerInstance = true;
    marshaller = configuration.marshaller();
    if (marshaller == null) {
        Class<? extends Marshaller> clazz = configuration.marshallerClass();
        marshaller = marshallerRegistry.getMarshaller(clazz);
        if (marshaller == null) {
            marshaller = Util.getInstance(clazz);
        } else {
            customMarshallerInstance = false;
        }
    }
    if (customMarshallerInstance) {
        if (!configuration.serialAllowList().isEmpty()) {
            marshaller.initialize(configuration.getClassAllowList());
        }
        if (marshaller instanceof ProtoStreamMarshaller) {
            initializeProtoStreamMarshaller((ProtoStreamMarshaller) marshaller);
        }
        // Replace any default marshaller with the same media type
        marshallerRegistry.registerMarshaller(marshaller);
    }
    codec = configuration.version().getCodec();
    listenerNotifier = new ClientListenerNotifier(codec, marshaller, channelFactory, configuration);
    ExecutorFactory executorFactory = configuration.asyncExecutorFactory().factory();
    if (executorFactory == null) {
        executorFactory = Util.getInstance(configuration.asyncExecutorFactory().factoryClass());
    }
    asyncExecutorService = executorFactory.getExecutor(configuration.asyncExecutorFactory().properties());
    channelFactory.start(codec, configuration, marshaller, asyncExecutorService, listenerNotifier, marshallerRegistry);
    counterManager.start(channelFactory, codec, configuration, listenerNotifier);
    TransactionOperationFactory txOperationFactory = new TransactionOperationFactory(configuration, channelFactory, codec);
    syncTransactionTable.start(txOperationFactory);
    xaTransactionTable.start(txOperationFactory);
    // Print version to help figure client version run
    HOTROD.version(Version.printVersion());
    started = true;
}
Also used : TransactionOperationFactory(org.infinispan.client.hotrod.impl.transaction.TransactionOperationFactory) UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) ExecutorFactory(org.infinispan.commons.executors.ExecutorFactory) ClientListenerNotifier(org.infinispan.client.hotrod.event.impl.ClientListenerNotifier) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller)

Example 10 with UTF8StringMarshaller

use of org.infinispan.commons.marshall.UTF8StringMarshaller in project infinispan by infinispan.

the class ComplexValue method testRawFilteredListeners.

@Test
public void testRawFilteredListeners() {
    remoteCache.clear();
    RemoteCache<Object, Object> jsonCache = this.remoteCache.withDataFormat(DataFormat.builder().keyType(APPLICATION_JSON).keyMarshaller(new UTF8StringMarshaller()).build());
    RawStaticFilteredEventLogListener<Object> l = new RawStaticFilteredEventLogListener<>(jsonCache);
    withClientListener(l, remote -> {
        jsonCache.put("{\"_type\":\"int32\",\"_value\":1}", Util.threadLocalRandomUUID().toString());
        l.expectNoEvents();
        jsonCache.put("{\"_type\":\"int32\",\"_value\":2}", Util.threadLocalRandomUUID().toString());
        l.expectOnlyCreatedEvent("\n{\n   \"_type\": \"int32\",\n   \"_value\": 2\n}\n");
    });
}
Also used : UTF8StringMarshaller(org.infinispan.commons.marshall.UTF8StringMarshaller) RawStaticFilteredEventLogListener(org.infinispan.client.hotrod.event.EventLogListener.RawStaticFilteredEventLogListener) Test(org.testng.annotations.Test) SingleHotRodServerTest(org.infinispan.client.hotrod.test.SingleHotRodServerTest)

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