use of org.infinispan.commons.marshall.JavaSerializationMarshaller in project infinispan by infinispan.
the class SingleFileGracefulShutdownMigrationTest method testAllEntriesRecovered.
@Test(dataProvider = "testFiles")
public void testAllEntriesRecovered(String fileName, Marshaller marshallerType) throws Exception {
int numEntries = 1003;
InputStream is = FileLookupFactory.newInstance().lookupFile(fileName, Thread.currentThread().getContextClassLoader());
Files.copy(is, Paths.get(tmpDirectory).resolve(CACHE_NAME + ".dat"), StandardCopyOption.REPLACE_EXISTING);
ConfigurationBuilderHolder cbh = new ConfigurationBuilderHolder();
if (marshallerType == Marshaller.JAVA_SERIALIZATION)
cbh.getGlobalConfigurationBuilder().serialization().marshaller(new JavaSerializationMarshaller());
cbh.newConfigurationBuilder(CACHE_NAME).persistence().addSingleFileStore().segmented(false).location(tmpDirectory);
try (EmbeddedCacheManager cacheManager = new DefaultCacheManager(cbh, true)) {
Cache<Object, Object> cache = cacheManager.getCache(CACHE_NAME);
ByRef.Integer i = new ByRef.Integer(0);
// Iterate all entries to ensure values can be read
cache.forEach((k, v) -> i.inc());
assertEquals(numEntries, i.get());
// Write to a migrated key
cache.put(0, "RuntimeValue");
// Create a new key
cache.put("NewKey", "NewValue");
}
// Start it up a second time to make sure the migrated data is properly read still
try (EmbeddedCacheManager cacheManager = new DefaultCacheManager(cbh, true)) {
Cache<Object, Object> cache = cacheManager.getCache(CACHE_NAME);
ByRef.Integer i = new ByRef.Integer(0);
// Iterate all entries to ensure values can be read
cache.forEach((k, v) -> i.inc());
assertEquals(numEntries + 1, i.get());
// Ensure that the entry updated after migration can be read
assertEquals("RuntimeValue", cache.get(0));
// Ensure that the entry created after migration can be read
assertEquals("NewValue", cache.get("NewKey"));
}
}
use of org.infinispan.commons.marshall.JavaSerializationMarshaller in project infinispan by infinispan.
the class MultimapStoreBucketTest method testMultimapWithJavaSerializationMarshaller.
public void testMultimapWithJavaSerializationMarshaller() throws Exception {
GlobalConfigurationBuilder globalBuilder = new GlobalConfigurationBuilder().nonClusteredDefault();
globalBuilder.defaultCacheName("test");
globalBuilder.serialization().marshaller(new JavaSerializationMarshaller()).allowList().addClass(SuperPerson.class.getName());
ConfigurationBuilder config = new ConfigurationBuilder();
config.persistence().addStore(DummyInMemoryStoreConfigurationBuilder.class);
EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(globalBuilder, config);
MultimapCacheManager<String, Person> multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cm);
MultimapCache<String, Person> multimapCache = multimapCacheManager.get("test");
multimapCache.put("k1", new SuperPerson());
PersistenceMarshallerImpl pm = TestingUtil.extractPersistenceMarshaller(cm);
DelegatingUserMarshaller userMarshaller = (DelegatingUserMarshaller) pm.getUserMarshaller();
assertTrue(userMarshaller.getDelegate() instanceof JavaSerializationMarshaller);
assertTrue(pm.getSerializationContext().canMarshall(Bucket.class));
assertTrue(multimapCache.containsKey("k1").get(1, TimeUnit.SECONDS));
}
use of org.infinispan.commons.marshall.JavaSerializationMarshaller in project infinispan by infinispan.
the class TriangleExceptionDuringMarshallingTest method createCacheManagers.
@Override
protected void createCacheManagers() throws Throwable {
GlobalConfigurationBuilder globalBuilder = GlobalConfigurationBuilder.defaultClusteredBuilder();
globalBuilder.serialization().marshaller(new JavaSerializationMarshaller());
globalBuilder.serialization().allowList().addClasses(MagicKey.class, MarshallingExceptionGenerator.class);
ConfigurationBuilder cacheBuilder = new ConfigurationBuilder();
ControlledConsistentHashFactory<?> chf = new ControlledConsistentHashFactory.Default(new int[][] { { 0, 1 }, { 1, 2 }, { 2, 0 } });
cacheBuilder.clustering().cacheMode(CacheMode.DIST_SYNC).hash().numSegments(NUM_SEGMENTS).consistentHashFactory(chf);
createCluster(globalBuilder, cacheBuilder, 3);
// Make sure we're using the triangle algorithm
AsyncInterceptorChain asyncInterceptorChain = extractInterceptorChain(cache(0));
assertTrue(asyncInterceptorChain.containsInterceptorType(TriangleDistributionInterceptor.class));
}
use of org.infinispan.commons.marshall.JavaSerializationMarshaller in project infinispan by infinispan.
the class ClusterExpirationLifespanTest method defaultGlobalConfigurationBuilder.
@Override
protected GlobalConfigurationBuilder defaultGlobalConfigurationBuilder() {
GlobalConfigurationBuilder globalConfigurationBuilder = super.defaultGlobalConfigurationBuilder();
globalConfigurationBuilder.serialization().marshaller(new JavaSerializationMarshaller()).allowList().addClasses(ExpirationFunctionalTest.NoEquals.class, MagicKey.class);
return globalConfigurationBuilder;
}
use of org.infinispan.commons.marshall.JavaSerializationMarshaller in project infinispan by infinispan.
the class PojoMarshalling method testPojoMarshalling.
@Test
public void testPojoMarshalling() {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addJavaSerialAllowList(".*");
org.infinispan.configuration.cache.ConfigurationBuilder cacheBuilder = new org.infinispan.configuration.cache.ConfigurationBuilder();
// If you use JavaSerializationMarshaller or GenericJBossMarshaller you should encode caches with the application/x-java-serialized-object or application/x-jboss-marshalling media type, respectively.
cacheBuilder.encoding().key().mediaType(MediaType.APPLICATION_SERIALIZED_OBJECT_TYPE);
cacheBuilder.encoding().value().mediaType(MediaType.APPLICATION_SERIALIZED_OBJECT_TYPE);
cacheBuilder.clustering().cacheMode(CacheMode.DIST_SYNC);
RemoteCache<String, Person> cache = SERVER_TEST.hotrod().withServerConfiguration(cacheBuilder).withClientConfiguration(builder).withMarshaller(JavaSerializationMarshaller.class).create();
cache.put("123", new Person("Enrique", 29));
Person person = cache.get("123");
assertEquals("Enrique", person.getName());
assertEquals(29, person.getAge());
}
Aggregations