use of org.apache.ignite.internal.util.typedef.CO in project ignite by apache.
the class GridMarshallerPerformanceTest method testByteBuffer.
/**
* @throws Exception If failed.
*/
public void testByteBuffer() throws Exception {
final ByteBuffer buf = ByteBuffer.allocate(1024);
IgniteInClosure<TestObject> writer = new CI1<TestObject>() {
@Override
public void apply(TestObject obj) {
buf.clear();
obj.write(buf);
}
};
IgniteOutClosure<TestObject> reader = new CO<TestObject>() {
@Override
public TestObject apply() {
buf.flip();
return TestObject.read(buf);
}
};
runTest("ByteBuffer", writer, reader);
}
use of org.apache.ignite.internal.util.typedef.CO in project ignite by apache.
the class GridMarshallerPerformanceTest method testKryo.
/**
* @throws Exception If failed.
*/
public void testKryo() throws Exception {
final Kryo kryo = new Kryo();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
IgniteInClosure<TestObject> writer = new CI1<TestObject>() {
@Override
public void apply(TestObject obj) {
out.reset();
Output kryoOut = null;
try {
kryoOut = new Output(out);
kryo.writeObject(kryoOut, obj);
} finally {
U.close(kryoOut, log);
}
}
};
IgniteOutClosure<TestObject> reader = new CO<TestObject>() {
@Override
public TestObject apply() {
Input kryoIn = null;
try {
kryoIn = new Input(new ByteArrayInputStream(out.toByteArray()));
return kryo.readObject(kryoIn, TestObject.class);
} finally {
U.close(kryoIn, log);
}
}
};
runTest("Kryo", writer, reader);
}
Aggregations