Ejemplo n.º 1
0
 @Test
 public void objectWriteRead() {
   // serialize.registerClass(short[].class);
   // serialize.registerClass(TestClass.class);
   DataOutput out = serialize.getDataOutput(128, true);
   String str = "This is a test";
   int i = 5;
   TestClass c = new TestClass(5, 8, new short[] {1, 2, 3, 4, 5}, TestEnum.Two);
   Number n = new Double(3.555);
   out.writeObjectNotNull(str);
   out.putInt(i);
   out.writeObject(c, TestClass.class);
   out.writeClassAndObject(n);
   ReadBuffer b = out.getStaticBuffer().asReadBuffer();
   if (printStats) log.debug(bufferStats(b));
   String str2 = serialize.readObjectNotNull(b, String.class);
   assertEquals(str, str2);
   if (printStats) log.debug(bufferStats(b));
   assertEquals(b.getInt(), i);
   TestClass c2 = serialize.readObject(b, TestClass.class);
   assertEquals(c, c2);
   if (printStats) log.debug(bufferStats(b));
   assertEquals(n, serialize.readClassAndObject(b));
   if (printStats) log.debug(bufferStats(b));
   assertFalse(b.hasRemaining());
 }
Ejemplo n.º 2
0
 @Test
 public void enumSerializeTest() {
   DataOutput out = serialize.getDataOutput(128, true);
   out.writeObjectNotNull(TestEnum.Two);
   ReadBuffer b = out.getStaticBuffer().asReadBuffer();
   if (printStats) log.debug(bufferStats(b));
   assertEquals(TestEnum.Two, serialize.readObjectNotNull(b, TestEnum.class));
   assertFalse(b.hasRemaining());
 }
Ejemplo n.º 3
0
 @Test
 public void largeWriteTest() {
   String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 26 chars
   String str = "";
   for (int i = 0; i < 100; i++) str += base;
   DataOutput out = serialize.getDataOutput(128, true);
   out.writeObjectNotNull(str);
   ReadBuffer b = out.getStaticBuffer().asReadBuffer();
   if (printStats) log.debug(bufferStats(b));
   assertEquals(str, serialize.readObjectNotNull(b, String.class));
   assertFalse(b.hasRemaining());
 }
Ejemplo n.º 4
0
 @Test
 public void longWriteTest() {
   String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 26 chars
   int no = 100;
   DataOutput out = serialize.getDataOutput(128, true);
   for (int i = 0; i < no; i++) {
     String str = base + (i + 1);
     out.writeObjectNotNull(str);
   }
   ReadBuffer b = out.getStaticBuffer().asReadBuffer();
   if (printStats) log.debug(bufferStats(b));
   for (int i = 0; i < no; i++) {
     String str = base + (i + 1);
     String read = serialize.readObjectNotNull(b, String.class);
     assertEquals(str, read);
   }
   assertFalse(b.hasRemaining());
 }