Search in sources :

Example 1 with Infinispan8Marshaller

use of org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller in project infinispan by infinispan.

the class MigratorConfigurationTest method testInfinipsan8MarshallerAndExternalizersLoaded.

public void testInfinipsan8MarshallerAndExternalizersLoaded() throws Exception {
    String externalizers = String.format("%d:%s", 1, PersonExternalizer.class.getName());
    Properties properties = createBaseProperties();
    properties.put(propKey(SOURCE, VERSION), String.valueOf(8));
    properties.put(propKey(SOURCE, MARSHALLER, EXTERNALIZERS), externalizers);
    StoreProperties props = new StoreProperties(SOURCE, properties);
    Marshaller marshaller = SerializationConfigUtil.getMarshaller(props);
    assertNotNull(marshaller);
    assertTrue(marshaller instanceof Infinispan8Marshaller);
    byte[] bytes = new byte[] { 3, 1, -2, 3, -1, 1, 1 };
    Object object = marshaller.objectFromByteBuffer(bytes);
    assertNotNull(object);
    assertTrue(object instanceof Person);
    assertEquals(1, externalizerReadCount.get());
}
Also used : Infinispan8Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller) Infinispan8Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller) Infinispan9Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan9.Infinispan9Marshaller) GenericJBossMarshaller(org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) DelegatingUserMarshaller(org.infinispan.marshall.core.impl.DelegatingUserMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) Properties(java.util.Properties) Person(org.infinispan.test.data.Person)

Example 2 with Infinispan8Marshaller

use of org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller in project infinispan by infinispan.

the class SerializationConfigUtil method getMarshaller.

public static Marshaller getMarshaller(StoreProperties props) {
    int majorVersion = props.getMajorVersion();
    if (props.isTargetStore() && majorVersion != Integer.parseInt(Version.getMajor())) {
        throw new CacheConfigurationException(String.format("The marshaller associated with Infinispan %d can only be specified for source stores.", majorVersion));
    }
    if (majorVersion < 8 || majorVersion > Integer.parseInt(Version.getMajor())) {
        throw new IllegalStateException(String.format("Unexpected major version '%d'", majorVersion));
    }
    switch(majorVersion) {
        case 8:
        case 9:
            Marshaller marshaller = loadMarshallerInstance(props);
            if (marshaller != null) {
                return marshaller;
            }
            Map<Integer, AdvancedExternalizer> userExts = getExternalizersFromProps(props);
            return majorVersion == 8 ? new Infinispan8Marshaller(userExts) : new Infinispan9Marshaller(userExts);
        case 10:
        case 11:
            String marshallerClass = props.get(MARSHALLER, CLASS);
            PersistenceMarshaller pm = createPersistenceMarshaller(props);
            if (marshallerClass != null) {
                // If a custom marshaller was specified, then return PersistenceMarshaller as user values are all wrapped
                return pm;
            }
            // Return the user marshaller so that PersistenceMarshaller object wrapping is avoided
            return pm.getUserMarshaller();
        default:
            return props.isTargetStore() ? null : createPersistenceMarshaller(props);
    }
}
Also used : Infinispan8Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller) Infinispan8Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller) Infinispan9Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan9.Infinispan9Marshaller) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) Marshaller(org.infinispan.commons.marshall.Marshaller) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) AdvancedExternalizer(org.infinispan.commons.marshall.AdvancedExternalizer) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) Infinispan9Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan9.Infinispan9Marshaller)

Example 3 with Infinispan8Marshaller

use of org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller in project infinispan by infinispan.

the class LegacyMarshallerTest method beforeTest.

@BeforeClass(alwaysRun = true)
public void beforeTest() throws Exception {
    Map<Integer, AdvancedExternalizer> userExts = new HashMap<>();
    userExts.put(256, new TestUtil.TestObjectExternalizer());
    this.marshaller = majorVersion == 8 ? new Infinispan8Marshaller(userExts) : new Infinispan9Marshaller(userExts);
    String filename = String.format("src/test/resources/infinispan%d/marshalled_bytes.bin", majorVersion);
    Path path = new File(filename).toPath();
    byte[] bytes = Files.readAllBytes(path);
    byteMap = (Map<String, byte[]>) marshaller.objectFromByteBuffer(bytes);
}
Also used : Infinispan8Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller) Path(java.nio.file.Path) TestUtil(org.infinispan.tools.store.migrator.TestUtil) HashMap(java.util.HashMap) AdvancedExternalizer(org.infinispan.commons.marshall.AdvancedExternalizer) Infinispan9Marshaller(org.infinispan.tools.store.migrator.marshaller.infinispan9.Infinispan9Marshaller) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

Infinispan8Marshaller (org.infinispan.tools.store.migrator.marshaller.infinispan8.Infinispan8Marshaller)3 Infinispan9Marshaller (org.infinispan.tools.store.migrator.marshaller.infinispan9.Infinispan9Marshaller)3 AdvancedExternalizer (org.infinispan.commons.marshall.AdvancedExternalizer)2 Marshaller (org.infinispan.commons.marshall.Marshaller)2 PersistenceMarshaller (org.infinispan.marshall.persistence.PersistenceMarshaller)2 File (java.io.File)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 CacheConfigurationException (org.infinispan.commons.CacheConfigurationException)1 GenericJBossMarshaller (org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller)1 DelegatingUserMarshaller (org.infinispan.marshall.core.impl.DelegatingUserMarshaller)1 Person (org.infinispan.test.data.Person)1 TestUtil (org.infinispan.tools.store.migrator.TestUtil)1 BeforeClass (org.testng.annotations.BeforeClass)1