Search in sources :

Example 81 with Message

use of org.jgroups.Message 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 82 with Message

use of org.jgroups.Message 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 83 with Message

use of org.jgroups.Message 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)

Example 84 with Message

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

the class PartialOutputStreamTest method testFragmentationWithSerializableObject.

public void testFragmentationWithSerializableObject() throws Exception {
    MessageSendTest.MyData data = new MessageSendTest.MyData(1, 1200);
    Message msg = new ObjectMessage(null, data);
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1300);
    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.MyData 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)

Example 85 with Message

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

the class NioMessageTest method testSetObject3.

public void testSetObject3() throws Exception {
    Message msg = new NioMessage(null).setObject("hello world");
    _testSize(msg);
    byte[] buf = marshal(msg);
    Message msg2 = unmarshal(NioMessage.class, buf);
    String s = msg2.getObject();
    assert Objects.equals(s, "hello world");
}
Also used : Message(org.jgroups.Message) NioMessage(org.jgroups.NioMessage) NioMessage(org.jgroups.NioMessage)

Aggregations

Message (org.jgroups.Message)246 Address (org.jgroups.Address)50 MessageBatch (org.jgroups.util.MessageBatch)37 BytesMessage (org.jgroups.BytesMessage)31 NioMessage (org.jgroups.NioMessage)14 ObjectMessage (org.jgroups.ObjectMessage)14 EmptyMessage (org.jgroups.EmptyMessage)12 Test (org.testng.annotations.Test)12 Event (org.jgroups.Event)11 ToaHeader (org.jgroups.protocols.tom.ToaHeader)11 Test (org.junit.Test)11 IOException (java.io.IOException)8 JChannel (org.jgroups.JChannel)8 MessageID (org.jgroups.protocols.tom.MessageID)8 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)7 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)7 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)7 TimeoutException (java.util.concurrent.TimeoutException)6 Collectors (java.util.stream.Collectors)6 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)6