Search in sources :

Example 1 with ObjectMessage

use of org.jgroups.ObjectMessage in project JGroups by belaban.

the class ObjectMessageTest method testSetObject.

public void testSetObject() {
    Message msg = new ObjectMessage(null, new Person(53, "Bela"));
    assert msg.getObject() != null;
    msg.setObject(new Person(15, "Nicole"));
    Person p = msg.getObject();
    assert p.age == 15 && p.name.equals("Nicole");
    msg.setObject(null);
    assert msg.getObject() == null;
}
Also used : ObjectMessage(org.jgroups.ObjectMessage) Message(org.jgroups.Message) ObjectMessage(org.jgroups.ObjectMessage)

Example 2 with ObjectMessage

use of org.jgroups.ObjectMessage in project JGroups by belaban.

the class ObjectMessageTest method testMarshalling.

public void testMarshalling() throws Exception {
    Object[] objects = { null, int.class, Boolean.class, byte[].class, Person.class, "hello".getBytes(), (short) 50, 50, 50L, 3.2345F, 3.1234, "hello world", "B\u00e9la B\u00060n" };
    for (Object obj : objects) {
        Message msg = new ObjectMessage(null, obj);
        _testSize(msg);
        byte[] buf = marshal(msg);
        Message msg2 = unmarshal(ObjectMessage.class, buf);
        Object tmp = msg2.getObject();
        if (tmp instanceof byte[] && obj instanceof byte[])
            assert Arrays.equals((byte[]) tmp, (byte[]) obj);
        else
            assert Objects.equals(tmp, obj) : String.format("%s (%s) != %s (%s)", tmp, tmp != null ? tmp.getClass() : "null", obj, obj != null ? obj.getClass() : "null");
    }
}
Also used : ObjectMessage(org.jgroups.ObjectMessage) Message(org.jgroups.Message) ObjectMessage(org.jgroups.ObjectMessage)

Example 3 with ObjectMessage

use of org.jgroups.ObjectMessage in project JGroups by belaban.

the class ObjectMessageTest method testSetNullObject.

public void testSetNullObject() throws Exception {
    Message msg = new ObjectMessage(null, null);
    _testSize(msg);
    byte[] buf = marshal(msg);
    Message msg2 = unmarshal(ObjectMessage.class, buf);
    Person p = msg2.getObject();
    assert p == null;
}
Also used : ObjectMessage(org.jgroups.ObjectMessage) Message(org.jgroups.Message) ObjectMessage(org.jgroups.ObjectMessage)

Example 4 with ObjectMessage

use of org.jgroups.ObjectMessage in project JGroups by belaban.

the class ObjectMessageTest method testObject.

public void testObject() throws Exception {
    Message msg = new ObjectMessage(null, new Person(53, "Bela"));
    _testSize(msg);
    byte[] buf = marshal(msg);
    Message msg2 = unmarshal(ObjectMessage.class, buf);
    Person p = msg2.getObject();
    assert p != null && p.name.equals("Bela") && p.age == 53;
}
Also used : ObjectMessage(org.jgroups.ObjectMessage) Message(org.jgroups.Message) ObjectMessage(org.jgroups.ObjectMessage)

Example 5 with ObjectMessage

use of org.jgroups.ObjectMessage in project JGroups by belaban.

the class PartialOutputStreamTest method testFragmentationWithSizeStreamableObject.

public void testFragmentationWithSizeStreamableObject() throws Exception {
    MessageSendTest.MySizeData data = new MessageSendTest.MySizeData(1, 1200);
    Message msg = new ObjectMessage(null, data);
    int size = data.serializedSize();
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(size);
    Range[] fragments = { new Range(0, 500), new Range(500, 500), new Range(1000, 300) };
    for (Range r : fragments) {
        PartialOutputStream pos = new PartialOutputStream(out, (int) r.low, (int) r.high);
        msg.writeTo(pos);
    }
    assert out.position() <= 1300 : String.format("we should not expand the initial capacity (1300): capacity is %d\n", out.position());
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer(), 0, out.position());
    ObjectMessage msg2 = new ObjectMessage();
    msg2.readFrom(in);
    MessageSendTest.MySizeData obj = msg2.getObject();
    System.out.printf("re-read obj: %s\n", obj);
    assert obj.num == data.num;
    assert Arrays.equals(obj.data, data.data);
}
Also used : ObjectMessage(org.jgroups.ObjectMessage) Message(org.jgroups.Message) ObjectMessage(org.jgroups.ObjectMessage)

Aggregations

ObjectMessage (org.jgroups.ObjectMessage)16 Message (org.jgroups.Message)14 JChannel (org.jgroups.JChannel)2 MyReceiver (org.jgroups.util.MyReceiver)2