Search in sources :

Example 6 with MarshallerMappingItem

use of org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem in project ignite by apache.

the class MarshallerContextSelfTest method testCacheStructure1.

/**
     * Tests that there are no null values in allCaches list
     * if platform ids passed to marshaller context were sequential.
     */
public void testCacheStructure1() throws Exception {
    MarshallerContextImpl ctx = new MarshallerContextImpl(null);
    ctx.onMarshallerProcessorStarted(this.ctx, null);
    MarshallerMappingItem item1 = new MarshallerMappingItem(JAVA_ID, 1, String.class.getName());
    ctx.onMappingAccepted(item1);
    MarshallerMappingItem item2 = new MarshallerMappingItem((byte) 1, 2, "Random.Class.Name");
    ctx.onMappingProposed(item2);
    List list = U.field(ctx, "allCaches");
    assertNotNull("Mapping cache is null for platformId: 0", list.get(0));
    assertNotNull("Mapping cache is null for platformId: 1", list.get(1));
    boolean excObserved = false;
    try {
        list.get(2);
    } catch (ArrayIndexOutOfBoundsException ignored) {
        excObserved = true;
    }
    assertTrue("ArrayIndexOutOfBoundsException had to be thrown", excObserved);
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with MarshallerMappingItem

use of org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem in project ignite by apache.

the class MarshallerContextSelfTest method testOnUpdated.

/**
     * @throws Exception If failed.
     */
public void testOnUpdated() throws Exception {
    File workDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), "marshaller", false);
    MarshallerContextImpl ctx = new MarshallerContextImpl(null);
    ctx.onMarshallerProcessorStarted(this.ctx, null);
    MarshallerMappingItem item1 = new MarshallerMappingItem(JAVA_ID, 1, String.class.getName());
    ctx.onMappingAccepted(item1);
    // Wait until marshaller context write class to file.
    U.sleep(2_000);
    checkFileName("java.lang.String", Paths.get(workDir + "/1.classname0"));
    MarshallerMappingItem item2 = new MarshallerMappingItem((byte) 2, 2, "Random.Class.Name");
    ctx.onMappingProposed(item2);
    ctx.onMappingAccepted(item2);
    execSvc.shutdown();
    if (execSvc.awaitTermination(1000, TimeUnit.MILLISECONDS))
        checkFileName("Random.Class.Name", Paths.get(workDir + "/2.classname2"));
    else
        fail("Failed to wait for executor service to shutdown");
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) File(java.io.File)

Example 8 with MarshallerMappingItem

use of org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem in project ignite by apache.

the class MarshallerContextSelfTest method testMultiplatformMappingsCollecting.

/**
     * Test for adding non-java mappings (with platformId > 0) to MarshallerContext and collecting them
     * for discovery.
     *
     * @throws Exception If failed.
     */
public void testMultiplatformMappingsCollecting() throws Exception {
    String nonJavaClassName = "random.platform.Mapping";
    MarshallerContextImpl marshCtx = new MarshallerContextImpl(null);
    marshCtx.onMarshallerProcessorStarted(ctx, null);
    MarshallerMappingItem item = new MarshallerMappingItem((byte) 2, 101, nonJavaClassName);
    marshCtx.onMappingProposed(item);
    marshCtx.onMappingAccepted(item);
    ArrayList<Map<Integer, MappedName>> allMappings = marshCtx.getCachedMappings();
    assertEquals(allMappings.size(), 3);
    assertTrue(allMappings.get(0).isEmpty());
    assertTrue(allMappings.get(1).isEmpty());
    Map<Integer, MappedName> nonJavaMappings = allMappings.get(2);
    assertNotNull(nonJavaMappings);
    assertNotNull(nonJavaMappings.get(101));
    assertEquals(nonJavaClassName, nonJavaMappings.get(101).className());
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName) Map(java.util.Map)

Aggregations

MarshallerMappingItem (org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem)8 MarshallerContextImpl (org.apache.ignite.internal.MarshallerContextImpl)6 MappedName (org.apache.ignite.internal.processors.marshaller.MappedName)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Ignite (org.apache.ignite.Ignite)2 File (java.io.File)1 Map (java.util.Map)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 MappingExchangeResult (org.apache.ignite.internal.processors.marshaller.MappingExchangeResult)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1