Methods Summary |
---|
public static void | main(java.lang.String[] args)
TestSuite suite = new TestSuite();
suite.addTestSuite(TestOrderInterceptor.class);
suite.run(new TestResult());
|
protected void | setUp()
System.out.println("Setup");
super.setUp();
channels = new GroupChannel[channelCount];
orderitcs = new OrderInterceptor[channelCount];
mangleitcs = new MangleOrderInterceptor[channelCount];
test = new TestListener[channelCount];
threads = new Thread[channelCount];
for ( int i=0; i<channelCount; i++ ) {
channels[i] = new GroupChannel();
orderitcs[i] = new OrderInterceptor();
mangleitcs[i] = new MangleOrderInterceptor();
orderitcs[i].setExpire(Long.MAX_VALUE);
channels[i].addInterceptor(orderitcs[i]);
channels[i].addInterceptor(mangleitcs[i]);
test[i] = new TestListener(i);
channels[i].addChannelListener(test[i]);
final int j = i;
threads[i] = new Thread() {
public void run() {
try {
channels[j].start(Channel.DEFAULT);
Thread.sleep(50);
} catch (Exception x) {
x.printStackTrace();
}
}
};
}
for ( int i=0; i<channelCount; i++ ) threads[i].start();
for ( int i=0; i<channelCount; i++ ) threads[i].join();
Thread.sleep(1000);
|
protected void | tearDown()
System.out.println("tearDown");
super.tearDown();
for ( int i=0; i<channelCount; i++ ) {
channels[i].stop(Channel.DEFAULT);
}
|
public void | testOrder1()
Member[] dest = channels[0].getMembers();
final AtomicInteger value = new AtomicInteger(0);
for ( int i=0; i<100; i++ ) {
channels[0].send(dest,new Integer(value.getAndAdd(1)),0);
}
Thread.sleep(5000);
for ( int i=0; i<test.length; i++ ) {
super.assertEquals(false,test[i].fail);
}
|
public void | testOrder2()
final Member[] dest = channels[0].getMembers();
final AtomicInteger value = new AtomicInteger(0);
Runnable run = new Runnable() {
public void run() {
for (int i = 0; i < 100; i++) {
try {
synchronized (channels[0]) {
channels[0].send(dest, new Integer(value.getAndAdd(1)), 0);
}
}catch ( Exception x ) {
x.printStackTrace();
assertEquals(true,false);
}
}
}
};
Thread[] threads = new Thread[5];
for (int i=0;i<threads.length;i++) {
threads[i] = new Thread(run);
}
for (int i=0;i<threads.length;i++) {
threads[i].start();
}
for (int i=0;i<threads.length;i++) {
threads[i].join();
}
Thread.sleep(5000);
for ( int i=0; i<test.length; i++ ) {
super.assertEquals(false,test[i].fail);
}
|