use of org.jgroups.protocols.UNICAST3 in project geode by apache.
the class JGroupsMessengerJUnitTest method doTestBigMessageIsFragmented.
public void doTestBigMessageIsFragmented(boolean mcastEnabled, boolean mcastMsg) throws Exception {
initMocks(mcastEnabled);
MessageHandler mh = mock(MessageHandler.class);
messenger.addHandler(JoinRequestMessage.class, mh);
InternalDistributedMember sender = messenger.getMemberID();
NetView v = new NetView(sender);
when(joinLeave.getView()).thenReturn(v);
messenger.installView(v);
JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
if (mcastMsg) {
msg.setMulticast(true);
}
messenger.send(msg);
int sentMessages = (mcastEnabled && mcastMsg) ? interceptor.mcastSentDataMessages : interceptor.unicastSentDataMessages;
assertTrue("expected 1 message to be sent but found " + sentMessages, sentMessages == 1);
// send a big message and expect fragmentation
msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int) (services.getConfig().getDistributionConfig().getUdpFragmentSize() * (1.5))], -1, 0);
// configure an incoming message handler for JoinRequestMessage
final DistributionMessage[] messageReceived = new DistributionMessage[1];
MessageHandler handler = new MessageHandler() {
@Override
public void processMessage(DistributionMessage m) {
messageReceived[0] = m;
}
};
messenger.addHandler(JoinRequestMessage.class, handler);
// configure the outgoing message interceptor
interceptor.unicastSentDataMessages = 0;
interceptor.collectMessages = true;
interceptor.collectedMessages.clear();
messenger.send(msg);
assertTrue("expected 2 messages to be sent but found " + interceptor.unicastSentDataMessages, interceptor.unicastSentDataMessages == 2);
List<Message> messages = new ArrayList<>(interceptor.collectedMessages);
UUID fakeMember = new UUID(50, 50);
short unicastHeaderId = ClassConfigurator.getProtocolId(UNICAST3.class);
int seqno = 1;
for (Message m : messages) {
m.setSrc(fakeMember);
UNICAST3.Header oldHeader = (UNICAST3.Header) m.getHeader(unicastHeaderId);
if (oldHeader == null)
continue;
UNICAST3.Header newHeader = UNICAST3.Header.createDataHeader(seqno, oldHeader.connId(), seqno == 1);
seqno += 1;
m.putHeader(unicastHeaderId, newHeader);
interceptor.up(new Event(Event.MSG, m));
}
Thread.sleep(5000);
System.out.println("received message = " + messageReceived[0]);
}
use of org.jgroups.protocols.UNICAST3 in project JGroups by belaban.
the class BecomeServerTest method createChannel.
protected JChannel createChannel(String name) throws Exception {
JChannel ch = new JChannel(new SHARED_LOOPBACK(), new PING(), new NAKACK2().setValue("become_server_queue_size", 10), new UNICAST3(), new GMS().setValue("print_local_addr", false).setValue("join_timeout", 500));
ch.setName(name);
return ch;
}
use of org.jgroups.protocols.UNICAST3 in project JGroups by belaban.
the class MessageBeforeConnectedTestHelper method sendUnicast.
/**
* Sends a unicast message up UNICAST2
*/
public void sendUnicast(JChannel ch) throws Exception {
final Message msg = new Message(ch.getAddress(), "hello-1").src(ch.getAddress());
// Add a UNICAST2 header
final UNICAST3 unicast = ch.getProtocolStack().findProtocol(UNICAST3.class);
UnicastHeader3 hdr = UnicastHeader3.createDataHeader(1, (short) 1, true);
msg.putHeader(unicast.getId(), hdr);
new Thread() {
public void run() {
unicast.down(msg);
}
}.start();
}
use of org.jgroups.protocols.UNICAST3 in project fabric8 by jboss-fuse.
the class TestBase method setUp.
@Before
public void setUp() throws Exception {
for (int i = 0; i < NUM; i++) {
Protocol ping = createPing();
channels[i] = new JChannel(new TCP(), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS());
channels[i].setName(Character.toString((char) ('A' + i)));
channels[i].connect(CLUSTER_NAME);
channels[i].setReceiver(receivers[i] = new MyReceiver());
}
}
use of org.jgroups.protocols.UNICAST3 in project geode by apache.
the class InterceptUDP method handleMessage.
private void handleMessage(Message msg) {
if (collectMessages) {
collectedMessages.add(msg);
}
Object o = msg.getHeader(nakackHeaderId);
if (o != null) {
mcastSentDataMessages++;
} else {
o = msg.getHeader(unicastHeaderId);
if (o != null) {
UNICAST3.Header hdr = (UNICAST3.Header) o;
switch(hdr.type()) {
case UNICAST3.Header.DATA:
unicastSentDataMessages++;
Message response = new Message(uuid, msg.getDest(), null);
response.putHeader(unicastHeaderId, UNICAST3.Header.createAckHeader(hdr.seqno(), hdr.connId(), System.currentTimeMillis()));
up_prot.up(new Event(Event.MSG, response));
break;
}
}
}
}
Aggregations