use of org.apache.ignite.binary.BinaryReader in project ignite by apache.
the class BinaryConfigurationConsistencySelfTest method customConfig.
/**
* @return Custom BinaryConfiguration.
* @param compactFooter Compact footer.
*/
private BinaryConfiguration customConfig(boolean compactFooter) {
BinaryConfiguration c = new BinaryConfiguration();
c.setIdMapper(new BinaryBasicIdMapper(true));
c.setSerializer(new BinarySerializer() {
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
// No-op.
}
});
c.setCompactFooter(compactFooter);
BinaryTypeConfiguration btc = new BinaryTypeConfiguration("org.MyClass");
btc.setIdMapper(BinaryContext.defaultIdMapper());
btc.setEnum(false);
btc.setSerializer(new BinarySerializer() {
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
// No-op.
}
});
c.setTypeConfigurations(Arrays.asList(btc));
return c;
}
use of org.apache.ignite.binary.BinaryReader in project ignite by apache.
the class GridCacheBinaryObjectUserClassloaderSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setCacheConfiguration(cacheConfiguration(igniteInstanceName));
cfg.setMarshaller(new BinaryMarshaller());
cfg.setClassLoader(useWrappingLoader ? new WrappingClassLoader(getExternalClassLoader()) : getExternalClassLoader());
if (customBinaryConf) {
BinarySerializer bs = new BinarySerializer() {
/**
* {@inheritDoc}
*/
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
/**
* {@inheritDoc}
*/
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
deserialized = true;
}
};
BinaryTypeConfiguration btcfg1 = new BinaryTypeConfiguration();
btcfg1.setTypeName("org.apache.ignite.tests.p2p.CacheDeploymentTestValue");
btcfg1.setSerializer(bs);
BinaryTypeConfiguration btcfg2 = new BinaryTypeConfiguration();
btcfg2.setTypeName("org.apache.ignite.internal.processors.cache.binary." + "GridCacheBinaryObjectUserClassloaderSelfTest$TestValue1");
btcfg2.setSerializer(bs);
BinaryConfiguration bcfg = new BinaryConfiguration();
Set<BinaryTypeConfiguration> set = new HashSet<>();
set.add(btcfg1);
set.add(btcfg2);
bcfg.setTypeConfigurations(set);
cfg.setBinaryConfiguration(bcfg);
}
return cfg;
}
use of org.apache.ignite.binary.BinaryReader in project ignite by apache.
the class IgniteBinaryTest method testBinarySerializer.
/**
* Test custom binary type serializer.
*/
@Test
public void testBinarySerializer() throws Exception {
BinarySerializer binSer = new BinarySerializer() {
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("f1", ((Person) obj).getId());
}
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
((Person) obj).setId(reader.readInt("f1"));
}
};
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(Person.class.getName()).setSerializer(binSer);
BinaryConfiguration binCfg = new BinaryConfiguration().setTypeConfigurations(Collections.singleton(typeCfg));
try (Ignite ignite = Ignition.start(Config.getServerConfiguration().setBinaryConfiguration(binCfg))) {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setBinaryConfiguration(binCfg))) {
IgniteCache<Integer, Person> igniteCache = ignite.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
ClientCache<Integer, Person> clientCache = client.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
Person val = new Person(123, "Joe");
clientCache.put(1, val);
assertEquals(val.getId(), clientCache.get(1).getId());
assertNull(clientCache.get(1).getName());
assertEquals(val.getId(), igniteCache.get(1).getId());
assertNull(igniteCache.get(1).getName());
}
}
}
Aggregations