@BeforeClass protected void setup() throws Exception { cacheFactory = new CompatibilityCacheFactory<String, String>( CACHE_NAME, new UTF8StringMarshaller(), CacheMode.LOCAL).setup(); }
@BeforeClass protected void setup() throws Exception { cacheFactory = new CompatibilityCacheFactory<String, Object>("testCache", new UTF8StringMarshaller(), CacheMode.LOCAL).setup(); }
@Test public void testStringKeysAndStringValues() throws Exception { // Write via Hot Rod (the HR client is configured with a String marshaller) stringRemoteCache.put("key", "Hello World"); assertEquals(stringRemoteCache.get("key"), "Hello World"); // Read via Rest Object bytesFromRest = new RestRequest().cache(STRING_CACHE_NAME).key("key").accept(TEXT_PLAIN).read(); assertEquals(asString(bytesFromRest), "Hello World"); // Write via rest new RestRequest().cache(STRING_CACHE_NAME).key("key2").value("Testing").write(); // Read via Hot Rod assertEquals(stringRemoteCache.get("key2"), "Testing"); // Get values as JSON from Hot Rod Object jsonString = stringRemoteCache.withDataFormat(DataFormat.builder() .valueType(APPLICATION_JSON).valueMarshaller(new UTF8StringMarshaller()).build()) .get("key"); assertEquals("\"Hello World\"", jsonString); }
@Test @SuppressWarnings("unchecked") public void testDataConversionsWithDefaultRemoteCache() throws Exception { String key = "key-byte-array-1"; byte[] value = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21}; // Hello! String stringValue = new String(value); DataFormat writeValueUnmarshalled = DataFormat.builder().valueType(APPLICATION_OCTET_STREAM).build(); // Avoid marshalling values when writing RemoteCache<String, byte[]> octetStreamCacheValue = this.remoteCache.withDataFormat(writeValueUnmarshalled); octetStreamCacheValue.put(key, value); assertArrayEquals(value, octetStreamCacheValue.get(key)); // Read as UTF Object utfValue = this.remoteCache .withDataFormat(DataFormat.builder().valueType(TEXT_PLAIN).valueMarshaller(new UTF8StringMarshaller()).build()) .get(key); assertEquals(stringValue, utfValue); // Read as XML Object xmlValue = this.remoteCache .withDataFormat(DataFormat.builder().valueType(APPLICATION_XML).valueMarshaller(new UTF8StringMarshaller()).build()) .get(key); assertEquals("<string>" + stringValue + "</string>", xmlValue); // Read as JSON Object jsonValue = this.remoteCache .withDataFormat(DataFormat.builder().valueType(APPLICATION_JSON).valueMarshaller(new UTF8StringMarshaller()).build()) .get(key); assertEquals("\"Hello!\"", jsonValue); }
@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.start(builder.build(), cacheManager); restClient = new HttpClient(); hotRodServer = startHotRodServer(cacheManager); defaultRemoteCache = createRemoteCacheManager(IdentityMarshaller.INSTANCE).getCache(DEFAULT_CACHE_NAME); defaultMarshalledRemoteCache = createRemoteCacheManager(null).getCache(MARSHALLED_CACHE_NAME); stringRemoteCache = createRemoteCacheManager(new UTF8StringMarshaller()).getCache(STRING_CACHE_NAME); }