Search in sources :

Example 6 with MarshallerContextTestImpl

use of org.apache.ignite.marshaller.MarshallerContextTestImpl in project ignite by apache.

the class GridSessionCheckpointSelfTest method testCacheCheckpoint.

/**
 * @throws Exception If failed.
 */
public void testCacheCheckpoint() throws Exception {
    IgniteConfiguration cfg = getConfiguration();
    String cacheName = "test-checkpoints";
    CacheConfiguration cacheCfg = defaultCacheConfiguration();
    cacheCfg.setName(cacheName);
    CacheCheckpointSpi spi = new CacheCheckpointSpi();
    spi.setCacheName(cacheName);
    cfg.setCacheConfiguration(cacheCfg);
    cfg.setCheckpointSpi(spi);
    if (cfg.getMarshaller() instanceof BinaryMarshaller) {
        BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), cfg, new NullLogger());
        Marshaller marsh = cfg.getMarshaller();
        marsh.setContext(new MarshallerContextTestImpl(null));
        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, cfg);
    }
    GridSessionCheckpointSelfTest.spi = spi;
    checkCheckpoints(cfg);
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) Marshaller(org.apache.ignite.marshaller.Marshaller) CacheCheckpointSpi(org.apache.ignite.spi.checkpoint.cache.CacheCheckpointSpi) NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 7 with MarshallerContextTestImpl

use of org.apache.ignite.marshaller.MarshallerContextTestImpl in project ignite by apache.

the class OptimizedMarshallerEnumSelfTest method testEnumSerialisation.

/**
 * @throws Exception If failed.
 */
public void testEnumSerialisation() throws Exception {
    OptimizedMarshaller marsh = new OptimizedMarshaller();
    MarshallerContextTestImpl context = new MarshallerContextTestImpl();
    context.onMarshallerProcessorStarted(newContext(), null);
    marsh.setContext(context);
    byte[] bytes = marsh.marshal(TestEnum.Bond);
    TestEnum unmarshalled = marsh.unmarshal(bytes, Thread.currentThread().getContextClassLoader());
    assertEquals(TestEnum.Bond, unmarshalled);
    assertEquals(TestEnum.Bond.desc, unmarshalled.desc);
}
Also used : MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl)

Example 8 with MarshallerContextTestImpl

use of org.apache.ignite.marshaller.MarshallerContextTestImpl in project ignite by apache.

the class BinaryFieldExtractionSelfTest method createMarshaller.

/**
 * Create marshaller.
 *
 * @return Binary marshaller.
 * @throws Exception If failed.
 */
protected BinaryMarshaller createMarshaller() throws Exception {
    BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), log());
    BinaryMarshaller marsh = new BinaryMarshaller();
    BinaryConfiguration bCfg = new BinaryConfiguration();
    IgniteConfiguration iCfg = new IgniteConfiguration();
    iCfg.setBinaryConfiguration(bCfg);
    marsh.setContext(new MarshallerContextTestImpl(null));
    IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
    return marsh;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl)

Example 9 with MarshallerContextTestImpl

use of org.apache.ignite.marshaller.MarshallerContextTestImpl in project ignite by apache.

the class BinaryFieldsAbstractSelfTest method createMarshaller.

/**
 * Create marshaller.
 *
 * @return Binary marshaller.
 * @throws Exception If failed.
 */
protected BinaryMarshaller createMarshaller() throws Exception {
    BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), new NullLogger());
    BinaryMarshaller marsh = new BinaryMarshaller();
    BinaryConfiguration bCfg = new BinaryConfiguration();
    bCfg.setCompactFooter(compactFooter());
    bCfg.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(TestObject.class.getName()), new BinaryTypeConfiguration(TestOuterObject.class.getName()), new BinaryTypeConfiguration(TestInnerObject.class.getName())));
    IgniteConfiguration iCfg = new IgniteConfiguration();
    iCfg.setBinaryConfiguration(bCfg);
    marsh.setContext(new MarshallerContextTestImpl(null));
    IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
    return marsh;
}
Also used : NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl)

Example 10 with MarshallerContextTestImpl

use of org.apache.ignite.marshaller.MarshallerContextTestImpl in project ignite by apache.

the class BinaryMarshallerSelfTest method testDeclaredBodyEnum.

/**
 * @throws Exception If failed.
 */
public void testDeclaredBodyEnum() throws Exception {
    final MarshallerContextTestImpl ctx = new MarshallerContextTestImpl();
    ctx.registerClassName((byte) 0, 1, EnumObject.class.getName());
    ctx.registerClassName((byte) 0, 2, DeclaredBodyEnum.class.getName());
    BinaryMarshaller marsh = binaryMarshaller();
    marsh.setContext(ctx);
    EnumObject obj = new EnumObject(1L, "test 1", DeclaredBodyEnum.TWO);
    final byte[] marshal = marsh.marshal(obj);
    final Object restored = marsh.unmarshal(marshal, null);
    assertTrue(restored instanceof EnumObject);
    obj = (EnumObject) restored;
    assertEquals(1, obj.id);
    assertEquals(DeclaredBodyEnum.TWO.ordinal(), obj.type.ordinal());
    assertEquals(DeclaredBodyEnum.TWO, obj.type);
    assertTrue(obj.type == DeclaredBodyEnum.TWO);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl)

Aggregations

MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)9 NullLogger (org.apache.ignite.logger.NullLogger)9 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)6 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)5 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)2 GridDiscoveryManager (org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)2 Marshaller (org.apache.ignite.marshaller.Marshaller)2 DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)2 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)2 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)2 Random (java.util.Random)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)1 CacheCheckpointSpi (org.apache.ignite.spi.checkpoint.cache.CacheCheckpointSpi)1 Nullable (org.jetbrains.annotations.Nullable)1