use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.
the class MessageDispatcherUnitTest method sendMessageToBothChannels.
private void sendMessageToBothChannels(int size) throws Exception {
long start, stop;
da.setRequestHandler(new MyHandler(new byte[size]));
b = createChannel();
b.setName("B");
db = new MessageDispatcher(b, new MyHandler(new byte[size]));
b.connect("MessageDispatcherUnitTest");
assert 2 == b.getView().size();
System.out.println("casting message");
start = System.currentTimeMillis();
// RspList<Object> rsps=d1.castMessage(null, buf, new RequestOptions(ResponseMode.GET_ALL, 0));
RspList<Object> rsps = da.castMessage(null, new BytesMessage(null, buf), new RequestOptions(ResponseMode.GET_ALL, 0));
stop = System.currentTimeMillis();
System.out.println("rsps:\n" + rsps);
System.out.println("call took " + (stop - start) + " ms");
assert rsps != null;
Assert.assertEquals(2, rsps.size());
Rsp rsp = rsps.get(a.getAddress());
assert rsp != null;
byte[] ret = (byte[]) rsp.getValue();
Assert.assertEquals(size, ret.length);
rsp = rsps.get(b.getAddress());
assert rsp != null;
ret = (byte[]) rsp.getValue();
Assert.assertEquals(size, ret.length);
Util.close(b);
}
use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.
the class MessageDispatcherUnitTest method testBlockingSecondMember.
/**
* In this scenario we block the second member so to verify the sender actually waits;
* this won't trigger a timeout but will produce a response having "received=false".
* It's hard to otherwise make sure casting isn't being done asynchronously.
*/
public void testBlockingSecondMember() throws Exception {
RequestOptions requestOptions = RequestOptions.SYNC().exclusionList(// redundant - simplifies debugging
a.getAddress()).setMode(// redundant - implied by SYNC()
ResponseMode.GET_ALL).setTransientFlags(// redundant - self is excluded
Message.TransientFlag.DONT_LOOPBACK).setTimeout(// Speed up the test execution
1000);
b = createChannel().name("B");
BlockableRequestHandler blockableHandler = new BlockableRequestHandler();
db = new MessageDispatcher(b).setRequestHandler(blockableHandler);
b.connect("MessageDispatcherUnitTest");
assert 2 == b.getView().size();
blockableHandler.installThreadTrap();
try {
RspList<Object> rsps = da.castMessage(null, new BytesMessage(null, buf), requestOptions);
System.out.printf("responses: %s\n", rsps);
assert 1 == rsps.size();
Rsp rsp = rsps.get(b.getAddress());
assert rsp != null;
assert !rsp.wasReceived();
assert !rsp.wasSuspected();
} catch (Exception e) {
Assert.fail("exception returned by castMessage", e);
} finally {
blockableHandler.releaseBlockedThreads();
}
assert blockableHandler.receivedAnything();
}
use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.
the class MessageDispatcherUnitTest method sendMessage.
private void sendMessage(int size) throws Exception {
long start, stop;
MyHandler handler = new MyHandler(new byte[size]);
da.setRequestHandler(handler);
Message msg = new BytesMessage(null, buf);
RequestOptions opts = new RequestOptions(ResponseMode.GET_ALL, 0);
start = System.currentTimeMillis();
RspList<byte[]> rsps = da.castMessage(null, msg, opts);
stop = System.currentTimeMillis();
System.out.println("rsps:\n" + rsps);
System.out.println("call took " + (stop - start) + " ms");
assert rsps != null;
Assert.assertEquals(1, rsps.size());
byte[] tmp = rsps.getFirst();
assert tmp != null;
Assert.assertEquals(size, tmp.length);
}
use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.
the class MessageDispatcherUnitTest method testNullMessageToSelf.
public void testNullMessageToSelf() throws Exception {
MyHandler handler = new MyHandler(null);
da.setRequestHandler(handler);
RspList<byte[]> rsps = da.castMessage(null, new BytesMessage(null, buf), new RequestOptions(ResponseMode.GET_ALL, 0));
System.out.println("rsps:\n" + rsps);
assert rsps != null;
assert 1 == rsps.size();
Object obj = rsps.getFirst();
assert obj == null;
}
use of org.jgroups.blocks.RequestOptions in project JGroups by belaban.
the class UPerf method eventLoop.
// ================================= end of callbacks =====================================
public void eventLoop() {
while (looping) {
try {
int c = Util.keyPress(String.format(format, num_threads, time, Util.printBytes(msg_size), sync, oob, rpc_timeout, anycast_count, read_percentage, allow_local_gets, print_details, print_invokers));
switch(c) {
case '1':
startBenchmark();
break;
case '2':
printView();
break;
case '4':
changeFieldAcrossCluster(NUM_THREADS, Util.readIntFromStdin("Number of sender threads: "));
break;
case '6':
changeFieldAcrossCluster(TIME, Util.readIntFromStdin("Time (secs): "));
break;
case '7':
changeFieldAcrossCluster(MSG_SIZE, Util.readIntFromStdin("Message size: "));
break;
case 'a':
int tmp = getAnycastCount();
if (tmp >= 0)
changeFieldAcrossCluster(ANYCAST_COUNT, tmp);
break;
case 'o':
changeFieldAcrossCluster(OOB, !oob);
break;
case 's':
changeFieldAcrossCluster(SYNC, !sync);
break;
case 'r':
double percentage = getReadPercentage();
if (percentage >= 0)
changeFieldAcrossCluster(READ_PERCENTAGE, percentage);
break;
case 'd':
changeFieldAcrossCluster(PRINT_DETAILS, !print_details);
break;
case 'i':
changeFieldAcrossCluster(PRINT_INVOKERS, !print_invokers);
break;
case 'l':
changeFieldAcrossCluster(ALLOW_LOCAL_GETS, !allow_local_gets);
break;
case 't':
changeFieldAcrossCluster(RPC_TIMEOUT, Util.readIntFromStdin("RPC timeout (millisecs): "));
break;
case 'v':
System.out.printf("Version: %s, Java version: %s\n", Version.printVersion(), System.getProperty("java.vm.version", "n/a"));
break;
case 'x':
case -1:
looping = false;
break;
case 'X':
try {
RequestOptions options = new RequestOptions(ResponseMode.GET_NONE, 0).flags(Message.Flag.OOB, Message.Flag.DONT_BUNDLE, Message.Flag.NO_FC);
disp.callRemoteMethods(null, new MethodCall(QUIT_ALL), options);
break;
} catch (Throwable t) {
System.err.println("Calling quitAll() failed: " + t);
}
break;
default:
break;
}
} catch (Throwable t) {
t.printStackTrace();
}
}
stop();
}
Aggregations