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