use of org.infinispan.test.data.Person in project infinispan by infinispan.
the class JavaSerializationTranscoderTest method setUp.
@BeforeClass(alwaysRun = true)
public void setUp() {
dataSrc = new Person("Joe");
Address address = new Address();
address.setCity("London");
dataSrc.setAddress(address);
transcoder = new JavaSerializationTranscoder(new ClassAllowList(Collections.singletonList(".*")));
supportedMediaTypes = transcoder.getSupportedMediaTypes();
}
use of org.infinispan.test.data.Person in project infinispan by infinispan.
the class DataConversionTest method testConversionWithListeners.
@Test
public void testConversionWithListeners() {
ConfigurationBuilder cfg = new ConfigurationBuilder();
withCacheManager(new CacheManagerCallable(createCacheManager(TestDataSCI.INSTANCE, cfg)) {
@Override
public void call() {
Cache<String, Person> cache = cm.getCache();
cm.getClassAllowList().addClasses(Person.class);
// Obtain cache with custom valueEncoder
Cache storeMarshalled = cache.getAdvancedCache().withEncoding(JavaSerializationEncoder.class);
// Add a listener
SimpleListener simpleListener = new SimpleListener();
storeMarshalled.addListener(simpleListener);
Person value = new Person();
storeMarshalled.put("1", value);
// Assert values returned are passed through the valueEncoder
assertEquals(simpleListener.events.size(), 1);
assertEquals(simpleListener.events.get(0).getKey(), "1");
assertEquals(simpleListener.events.get(0).getValue(), value);
}
});
}
use of org.infinispan.test.data.Person in project infinispan by infinispan.
the class DataConversionTest method testReadUnencoded.
@Test
public void testReadUnencoded() {
ConfigurationBuilder cfg = new ConfigurationBuilder();
cfg.memory().storage(StorageType.OFF_HEAP);
withCacheManager(new CacheManagerCallable(createCacheManager(TestDataSCI.INSTANCE, cfg)) {
private final EncoderRegistry registry = TestingUtil.extractGlobalComponent(cm, EncoderRegistry.class);
public Object asStored(Object object) {
return registry.convert(object, APPLICATION_OBJECT, APPLICATION_PROTOSTREAM);
}
@Override
public void call() {
cm.getClassAllowList().addClasses(Person.class);
Cache<String, Person> cache = cm.getCache();
Person value = new Person();
cache.put("1", value);
// Read using default valueEncoder
assertEquals(cache.get("1"), value);
// Read unencoded
Cache<?, ?> unencodedCache = cache.getAdvancedCache().withStorageMediaType();
assertEquals(unencodedCache.get(asStored("1")), asStored(value));
}
});
}
use of org.infinispan.test.data.Person in project infinispan by infinispan.
the class ProtostreamTranscoderTest method testToFromObject.
@Test
public void testToFromObject() throws IOException {
Person objectContent = new Person("value");
final byte[] marshalled = toWrappedByteArray(ctx, objectContent);
byte[] marshalledHex = Base16Codec.encode(marshalled).getBytes(UTF_8);
// Converting from Object to protostream with different binary encodings
Object result = transcoder.transcode(objectContent, APPLICATION_OBJECT, APPLICATION_PROTOSTREAM);
assertArrayEquals(marshalled, (byte[]) result);
result = transcoder.transcode(objectContent, APPLICATION_OBJECT, APPLICATION_PROTOSTREAM.withEncoding("hex"));
assertEquals(Base16Codec.encode(marshalled), result);
result = transcoder.transcode(objectContent, APPLICATION_OBJECT, APPLICATION_PROTOSTREAM.withEncoding("hex").withClassType(String.class));
assertEquals(Base16Codec.encode(marshalled), result);
// convert from protostream with different encodings back to object
result = transcoder.transcode(marshalled, APPLICATION_PROTOSTREAM, APPLICATION_OBJECT);
assertEquals(objectContent, result);
result = transcoder.transcode(marshalledHex, APPLICATION_PROTOSTREAM.withEncoding("hex"), APPLICATION_OBJECT);
assertEquals(objectContent, result);
}
use of org.infinispan.test.data.Person in project infinispan by infinispan.
the class BaseStoreFunctionalTest method testPreloadStoredAsBinary.
public void testPreloadStoredAsBinary() {
ConfigurationBuilder cb = getDefaultCacheConfiguration();
createCacheStoreConfig(cb.persistence(), "testPreloadStoredAsBinary", true).memory().storageType(StorageType.BINARY);
TestingUtil.defineConfiguration(cacheManager, "testPreloadStoredAsBinary", cb.build());
Cache<String, Person> cache = cacheManager.getCache("testPreloadStoredAsBinary");
cache.start();
assert cache.getCacheConfiguration().persistence().preload();
assertEquals(StorageType.BINARY, cache.getCacheConfiguration().memory().storageType());
byte[] pictureBytes = new byte[] { 1, 82, 123, 19 };
cache.put("k1", new Person("1"));
cache.put("k2", new Person("2", null, pictureBytes, null, null, false), 111111, TimeUnit.MILLISECONDS);
cache.put("k3", new Person("3", null, null, Sex.MALE, null, false), -1, TimeUnit.MILLISECONDS, 222222, TimeUnit.MILLISECONDS);
cache.put("k4", new Person("4", new Address("Street", "City", 12345), null, null, null, true), 333333, TimeUnit.MILLISECONDS, 444444, TimeUnit.MILLISECONDS);
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("EST"));
calendar.set(2009, Calendar.MARCH, 18, 3, 22, 57);
// Chop off the last milliseconds as some databases don't have that high of accuracy
calendar.setTimeInMillis((calendar.getTimeInMillis() / 1000) * 1000);
Date infinispanBirthDate = calendar.getTime();
Person infinispanPerson = createEmptyPerson("Infinispan");
infinispanPerson.setBirthDate(infinispanBirthDate);
infinispanPerson.setAcceptedToS(true);
cache.put("Infinispan", infinispanPerson);
// Just to prove nothing in memory even with stop
cache.getAdvancedCache().getDataContainer().clear();
assertEquals(createEmptyPerson("1"), cache.get("k1"));
Person person2 = createEmptyPerson("2");
person2.setPicture(pictureBytes);
assertEquals(person2, cache.get("k2"));
Person person3 = createEmptyPerson("3");
person3.setSex(Sex.MALE);
assertEquals(person3, cache.get("k3"));
assertEquals(new Person("4", new Address("Street", "City", 12345), null, null, null, true), cache.get("k4"));
assertEquals(infinispanPerson, cache.get("Infinispan"));
cache.stop();
cache.start();
assertEquals(5, cache.entrySet().size());
assertEquals(createEmptyPerson("1"), cache.get("k1"));
assertEquals(person2, cache.get("k2"));
assertEquals(person3, cache.get("k3"));
assertEquals(new Person("4", new Address("Street", "City", 12345), null, null, null, true), cache.get("k4"));
assertEquals(infinispanPerson, cache.get("Infinispan"));
}
Aggregations