@Test public void testOne() throws Exception { MarshallableFactory.getInstance().addMarshallable(Image.class); MarshallableFactory.getInstance().addMarshallable(Media.class); MarshallableFactory.getInstance().addMarshallable(MediaContent.class); MarshallableFactory.getInstance().addMarshallable(ArrayList.class, ListSerializer.class); MediaContent mc; long t1 = System.nanoTime(); ObjectToByteBuffer otbb = new ObjectToByteBuffer(2048); ByteBufferToObject bbto = new ByteBufferToObject(otbb.getByteBuffer()); mc = create(); for (int i = 0; i < 1000000; i++) { otbb.clearM(); otbb.writeObject(mc); MediaContent mc2 = (MediaContent) bbto.readObject(); } long t2 = System.nanoTime(); System.out.println("done: " + (t2 - t1) / 1000000); }
@Test public void testSmallBufferWriterAndReader() throws Exception { MarshallableFactory.getInstance().addMarshallable(Image.class); MarshallableFactory.getInstance().addMarshallable(Media.class); MarshallableFactory.getInstance().addMarshallable(MediaContent.class); MarshallableFactory.getInstance().addMarshallable(ArrayList.class, ListSerializer.class); ObjectToByteBuffer otbb = new ObjectToByteBuffer(8); ByteBuffer src = otbb.getByteBuffer(); ByteBufferToObject bbto = new ByteBufferToObject(16384); ByteBuffer dst = bbto.getByteBuffer(); MediaContent mc = create(); int writeCnt = 0; boolean done = false; do { if (otbb.writeObject(mc)) { done = true; } writeCnt++; src.flip(); dst.put(src); src.compact(); } while (!done); Object o = bbto.readObject(); Assert.assertEquals(mc, o); Assert.assertTrue(writeCnt > (335 / 8)); }
@Test public void testB() throws Exception { BooleanMarshallable m = new BooleanMarshallable(); ObjectToByteBuffer otbb = new ObjectToByteBuffer(2048); otbb.writeObject(m); ByteBufferToObject bbto = new ByteBufferToObject(otbb.getByteBuffer()); m = (BooleanMarshallable) bbto.readObject(); System.out.println("got: " + m.getClass().getName()); }
@Test public void testZero() throws Exception { MarshallableFactory.getInstance().addMarshallable(MyEmptyMarshallable.class); MyEmptyMarshallable m = new MyEmptyMarshallable(); ObjectToByteBuffer otbb = new ObjectToByteBuffer(2048); otbb.writeObject(m); ByteBufferToObject bbto = new ByteBufferToObject(otbb.getByteBuffer()); m = (MyEmptyMarshallable) bbto.readObject(); System.out.println("got: " + m.getClass().getName()); }