Search in sources :

Example 1 with COX

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);
}
Also used : CIX1(org.apache.ignite.internal.util.typedef.CIX1) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridTuple(org.apache.ignite.internal.util.lang.GridTuple) COX(org.apache.ignite.internal.util.typedef.COX) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with COX

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);
}
Also used : CIX1(org.apache.ignite.internal.util.typedef.CIX1) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) COX(org.apache.ignite.internal.util.typedef.COX) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CIX1 (org.apache.ignite.internal.util.typedef.CIX1)2 COX (org.apache.ignite.internal.util.typedef.COX)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)1 GridTuple (org.apache.ignite.internal.util.lang.GridTuple)1