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);
}
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");
}
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());
}
Aggregations