use of org.apache.ignite.internal.util.typedef.COX in project ignite by apache.
the class GridMarshallerPerformanceTest method testGridMarshaller.
/**
* @throws Exception If failed.
*/
@Test
public void testGridMarshaller() throws Exception {
final GridTuple<byte[]> tuple = new GridTuple<>();
final BinaryMarshaller marsh = createStandaloneBinaryMarshaller();
IgniteInClosure<TestObject> writer = new CIX1<TestObject>() {
@Override
public void applyx(TestObject obj) throws IgniteCheckedException {
tuple.set(marsh.marshal(obj));
}
};
IgniteOutClosure<TestObject> reader = new COX<TestObject>() {
@Override
public TestObject applyx() throws IgniteCheckedException {
return marsh.unmarshal(tuple.get(), null);
}
};
runTest("GridMarshaller", writer, reader);
}
use of org.apache.ignite.internal.util.typedef.COX in project ignite by apache.
the class GridMarshallerPerformanceTest method testSerialization.
/**
* @throws Exception If failed.
*/
@Test
public void testSerialization() throws Exception {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
IgniteInClosure<TestObject> writer = new CIX1<TestObject>() {
@Override
public void applyx(TestObject obj) throws IgniteCheckedException {
out.reset();
ObjectOutputStream objOut = null;
try {
objOut = new ObjectOutputStream(out);
objOut.writeObject(obj);
} catch (IOException e) {
throw new IgniteCheckedException(e);
} finally {
U.close(objOut, log);
}
}
};
IgniteOutClosure<TestObject> reader = new COX<TestObject>() {
@Override
public TestObject applyx() throws IgniteCheckedException {
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ObjectInputStream objIn = null;
try {
objIn = new ObjectInputStream(in);
return (TestObject) objIn.readObject();
} catch (ClassNotFoundException | IOException e) {
throw new IgniteCheckedException(e);
} finally {
U.close(objIn, log);
}
}
};
runTest("Serialization", writer, reader);
}
Aggregations