Search in sources :

Example 1 with JavaSerializationMarshaller

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"));
    }
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) InputStream(java.io.InputStream) ByRef(org.infinispan.commons.util.ByRef) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 2 with JavaSerializationMarshaller

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));
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) DelegatingUserMarshaller(org.infinispan.marshall.core.impl.DelegatingUserMarshaller) PersistenceMarshallerImpl(org.infinispan.marshall.persistence.impl.PersistenceMarshallerImpl) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Person(org.infinispan.test.data.Person) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller)

Example 3 with JavaSerializationMarshaller

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));
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) TriangleDistributionInterceptor(org.infinispan.interceptors.distribution.TriangleDistributionInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller)

Example 4 with JavaSerializationMarshaller

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;
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller)

Example 5 with JavaSerializationMarshaller

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());
}
Also used : ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller) Test(org.junit.Test)

Aggregations

JavaSerializationMarshaller (org.infinispan.commons.marshall.JavaSerializationMarshaller)17 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)4 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)3 ProtoStreamMarshaller (org.infinispan.commons.marshall.ProtoStreamMarshaller)3 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)3 Test (org.testng.annotations.Test)3 InputStream (java.io.InputStream)2 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)2 UTF8StringMarshaller (org.infinispan.commons.marshall.UTF8StringMarshaller)2 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)2 BeforeClass (org.junit.BeforeClass)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Bean (org.springframework.context.annotation.Bean)2 Conditional (org.springframework.context.annotation.Conditional)2 Properties (java.util.Properties)1