Esempio n. 1
0
  public static void testWriteView() throws Exception {
    List<Address> members = new ArrayList<>();
    View v;
    Address a1 = Util.createRandomAddress();
    Address a2 = Util.createRandomAddress();
    Address a4 = Util.createRandomAddress();
    ViewId vid = new ViewId(a1, 12345);
    members.add(a1);
    members.add(a2);
    members.add(a4);
    v = new View(vid, members);

    ByteArrayOutputStream outstream = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(outstream);
    Util.writeGenericStreamable(v, dos);
    Util.writeStreamable(v, dos);
    dos.close();
    byte[] buf = outstream.toByteArray();
    ByteArrayInputStream instream = new ByteArrayInputStream(buf);
    DataInputStream dis = new DataInputStream(instream);
    View v2 = (View) Util.readGenericStreamable(dis);
    Assert.assertEquals(v, v2);
    v2 = (View) Util.readStreamable(View.class, dis);
    Assert.assertEquals(v, v2);
  }
Esempio n. 2
0
 public static void testWriteStreamable() throws Exception {
   Message m = new Message(null, null, "Hello");
   ViewId vid2 = new ViewId(Util.createRandomAddress(), 35623);
   ByteArrayOutputStream outstream = new ByteArrayOutputStream();
   DataOutputStream dos = new DataOutputStream(outstream);
   Util.writeGenericStreamable(m, dos);
   Util.writeGenericStreamable(vid2, dos);
   dos.close();
   byte[] buf = outstream.toByteArray();
   ByteArrayInputStream instream = new ByteArrayInputStream(buf);
   DataInputStream dis = new DataInputStream(instream);
   Message m2 = (Message) Util.readGenericStreamable(dis);
   ViewId v3 = (ViewId) Util.readGenericStreamable(dis);
   assert m2.getBuffer() != null;
   Assert.assertEquals(m.getLength(), m2.getLength());
   assert v3 != null;
 }