Author: kkolinko
Date: Wed Sep 28 21:03:09 2011
New Revision: 1177060
URL: http://svn.apache.org/viewvc?rev=1177060&view=rev
Log:
Improve TestNonBlockingCoordinator:
- Format code for better readbility.
- In testCoord1() change how equality is tested. Read expected value from 0th
member, instead of (i-1)th. They all should be the same.
- Remove unneeded main() method.
Modified:
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java
Modified:
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java?rev=1177060&r1=1177059&r2=1177060&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java
(original)
+++
tomcat/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java
Wed Sep 28 21:03:09 2011
@@ -30,15 +30,14 @@ public class TestNonBlockingCoordinator
private GroupChannel[] channels = null;
private NonBlockingCoordinator[] coordinators = null;
- private int channelCount = 10;
- private Thread[] threads = null;
+ private final int channelCount = 10;
@Before
public void setUp() throws Exception {
System.out.println("Setup");
channels = new GroupChannel[channelCount];
coordinators = new NonBlockingCoordinator[channelCount];
- threads = new Thread[channelCount];
+ Thread[] threads = new Thread[channelCount];
for ( int i=0; i<channelCount; i++ ) {
channels[i] = new GroupChannel();
coordinators[i] = new NonBlockingCoordinator();
@@ -57,21 +56,36 @@ public class TestNonBlockingCoordinator
}
};
}
- for ( int i=0; i<channelCount; i++ ) threads[i].start();
- for ( int i=0; i<channelCount; i++ ) threads[i].join();
+ for (int i = 0; i < channelCount; i++) {
+ threads[i].start();
+ }
+ for (int i = 0; i < channelCount; i++) {
+ threads[i].join();
+ }
Thread.sleep(1000);
}
@Test
public void testCoord1() throws Exception {
- for (int i=1; i<channelCount; i++ )
- assertEquals("Message count expected to be
equal.",channels[i-1].getMembers().length,channels[i].getMembers().length);
+ int expectedCount = channels[0].getMembers().length;
+ for (int i = 1; i < channelCount; i++) {
+ assertEquals("Message count expected to be equal.", expectedCount,
+ channels[i].getMembers().length);
+ }
Member member = coordinators[0].getCoordinator();
int cnt = 0;
- while ( member == null && (cnt++ < 100 ) ) try {Thread.sleep(100);
member = coordinators[0].getCoordinator();}catch ( Exception x){ /* Ignore */ }
- for (int i=0; i<channelCount; i++ )
assertEquals(member,coordinators[i].getCoordinator());
- System.out.println("Coordinator[1] is:"+member);
-
+ while (member == null && (cnt++ < 100)) {
+ try {
+ Thread.sleep(100);
+ member = coordinators[0].getCoordinator();
+ } catch (Exception x) {
+ /* Ignore */
+ }
+ }
+ for (int i = 0; i < channelCount; i++) {
+ assertEquals(member, coordinators[i].getCoordinator());
+ }
+ System.out.println("Coordinator[1] is:" + member);
}
@Test
@@ -88,10 +102,18 @@ public class TestNonBlockingCoordinator
}
int dead = index;
Thread.sleep(1000);
- if ( index == 0 ) index = 1; else index = 0;
+ if (index == 0) {
+ index = 1;
+ } else {
+ index = 0;
+ }
System.out.println("Member
count:"+channels[index].getMembers().length);
member = coordinators[index].getCoordinator();
- for (int i = 1; i < channelCount; i++) if ( i != dead )
assertEquals(member, coordinators[i].getCoordinator());
+ for (int i = 1; i < channelCount; i++) {
+ if (i != dead) {
+ assertEquals(member, coordinators[i].getCoordinator());
+ }
+ }
System.out.println("Coordinator[2b] is:" + member);
}
@@ -103,9 +125,4 @@ public class TestNonBlockingCoordinator
}
}
- public static void main(String[] args) throws Exception {
-
org.junit.runner.JUnitCore.main(TestNonBlockingCoordinator.class.getName());
- }
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]