use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.
the class GridCacheBinaryStoreAbstractSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
BinaryConfiguration bCfg = new BinaryConfiguration();
bCfg.setNameMapper(new BinaryBasicNameMapper(false));
bCfg.setIdMapper(new BinaryBasicIdMapper(false));
bCfg.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName()));
cfg.setBinaryConfiguration(bCfg);
cfg.setMarshaller(new BinaryMarshaller());
CacheConfiguration cacheCfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
cacheCfg.setCacheStoreFactory(singletonFactory(STORE));
cacheCfg.setStoreKeepBinary(keepBinaryInStore());
cacheCfg.setReadThrough(true);
cacheCfg.setWriteThrough(true);
cacheCfg.setLoadPreviousValue(true);
cfg.setCacheConfiguration(cacheCfg);
GridCacheBinaryStoreAbstractSelfTest.cfg = cfg;
return cfg;
}
use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.
the class BinaryMarshallerSelfTest method testDuplicateNameSimpleNameMapper.
/**
* @throws Exception If failed.
*/
@Test
public void testDuplicateNameSimpleNameMapper() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true), null, null, null);
Test1.Job job1 = new Test1().new Job();
Test2.Job job2 = new Test2().new Job();
marsh.marshal(job1);
try {
marsh.marshal(job2);
} catch (BinaryObjectException e) {
assertEquals(true, e.getMessage().contains("Failed to register class"));
return;
}
assert false;
}
use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.
the class BinaryMarshallerSelfTest method testDuplicateNameFullNameMapper.
/**
* @throws Exception If failed.
*/
@Test
public void testDuplicateNameFullNameMapper() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false), null, null, null);
Test1.Job job1 = new Test1().new Job();
Test2.Job job2 = new Test2().new Job();
marsh.marshal(job1);
marsh.marshal(job2);
}
use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.
the class BinaryBasicNameMapperSelfTest method testSimpleName.
/**
* @throws Exception If failed.
*/
@Test
public void testSimpleName() throws Exception {
BinaryBasicNameMapper mapper = new BinaryBasicNameMapper(true);
assertEquals("GridBinaryTestClass1", mapper.typeName(GridBinaryTestClass1.class.getName()));
assertEquals("InnerClass", mapper.typeName(GridBinaryTestClass1.class.getName() + "$InnerClass"));
}
use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.
the class BinaryMarshallerSelfTest method testTypeNamesSimpleNameMapper.
/**
* @throws Exception If failed.
*/
@Test
public void testTypeNamesSimpleNameMapper() throws Exception {
BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
customType1.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 300;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.NonExistentClass1");
customType2.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 400;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryTypeConfiguration customType3 = new BinaryTypeConfiguration("NonExistentClass2");
customType3.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 500;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryTypeConfiguration customType4 = new BinaryTypeConfiguration("NonExistentClass0");
customType4.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 0;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true), Arrays.asList(new BinaryTypeConfiguration(Key.class.getName()), new BinaryTypeConfiguration("org.gridgain.NonExistentClass3"), new BinaryTypeConfiguration("NonExistentClass4"), customType1, customType2, customType3, customType4));
BinaryContext ctx = binaryContext(marsh);
// Full name hashCode.
assertEquals("notconfiguredclass".hashCode(), ctx.typeId("NotConfiguredClass"));
assertEquals("key".hashCode(), ctx.typeId(Key.class.getName()));
assertEquals("nonexistentclass3".hashCode(), ctx.typeId("org.gridgain.NonExistentClass3"));
assertEquals("nonexistentclass4".hashCode(), ctx.typeId("NonExistentClass4"));
assertEquals(300, ctx.typeId(Value.class.getName()));
assertEquals(400, ctx.typeId("org.gridgain.NonExistentClass1"));
assertEquals(500, ctx.typeId("NonExistentClass2"));
// BinaryIdMapper.typeId() contract.
assertEquals("nonexistentclass0".hashCode(), ctx.typeId("NonExistentClass0"));
}
Aggregations