You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2010/11/02 14:20:58 UTC
svn commit: r1030035 - in /incubator/hama/trunk: CHANGES.txt
src/test/org/apache/hama/bsp/TestBSPPeer.java
Author: edwardyoon
Date: Tue Nov 2 13:20:58 2010
New Revision: 1030035
URL: http://svn.apache.org/viewvc?rev=1030035&view=rev
Log:
JUnit test threads with GroboTestingJUnit
Modified:
incubator/hama/trunk/CHANGES.txt
incubator/hama/trunk/src/test/org/apache/hama/bsp/TestBSPPeer.java
Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=1030035&r1=1030034&r2=1030035&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Tue Nov 2 13:20:58 2010
@@ -50,6 +50,7 @@ Trunk (unreleased changes)
IMPROVEMENTS
+ HAMA-322: JUnit test threads with GroboTestingJUnit (Filipe Manana via edwardyoon)
HAMA-323: Remove generic warnings (edwardyoon)
HAMA-254: Add news about rid of MapReduce and Hbase (edwardyoon)
HAMA-320: Add twitter widget to website (edwardyoon)
Modified: incubator/hama/trunk/src/test/org/apache/hama/bsp/TestBSPPeer.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/test/org/apache/hama/bsp/TestBSPPeer.java?rev=1030035&r1=1030034&r2=1030035&view=diff
==============================================================================
--- incubator/hama/trunk/src/test/org/apache/hama/bsp/TestBSPPeer.java (original)
+++ incubator/hama/trunk/src/test/org/apache/hama/bsp/TestBSPPeer.java Tue Nov 2 13:20:58 2010
@@ -28,6 +28,9 @@ import java.util.Set;
import junit.framework.AssertionFailedError;
+import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;
+import net.sourceforge.groboutils.junit.v1.TestRunnable;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
@@ -81,11 +84,10 @@ public class TestBSPPeer extends HamaClu
}
}
- public class BSPPeerThread extends Thread {
+ public class BSPPeerThread extends TestRunnable {
private BSPPeer peer;
private int MAXIMUM_DURATION = 5;
private int lastTwoDigitsOfPort;
- private int errorCount = 0;
public BSPPeerThread(Configuration conf) throws IOException {
lastTwoDigitsOfPort = conf.getInt(Constants.PEER_PORT, 0) - 30000;
@@ -97,7 +99,8 @@ public class TestBSPPeer extends HamaClu
peer.setAllPeerNames(peerNames);
}
- public void run() throws AssertionFailedError {
+ @Override
+ public void runTest() throws AssertionFailedError {
int randomTime;
byte[] dummyData = new byte[PAYLOAD];
BSPMessage msg = null;
@@ -141,28 +144,18 @@ public class TestBSPPeer extends HamaClu
LOG.info("[" + peer.getPeerName() + "] verifying " + numMessages
+ " messages");
- try {
- if (lastTwoDigitsOfPort < 10) {
- assertEquals(20, numMessages);
- } else {
- assertEquals(0, numMessages);
- }
- } catch (AssertionFailedError afe) {
- LOG.error(afe);
- errorCount++;
+ if (lastTwoDigitsOfPort < 10) {
+ assertEquals(20, numMessages);
+ } else {
+ assertEquals(0, numMessages);
}
BSPMessage msg = null;
try {
while ((msg = peer.getCurrentMessage()) != null) {
- try {
- assertEquals(Bytes.compareTo(msg.tag, 0, 128, msg.data,
- msg.data.length - 128, 128), 0);
- } catch (AssertionFailedError afe) {
- LOG.error(afe);
- errorCount++;
- }
+ assertEquals(Bytes.compareTo(msg.tag, 0, 128, msg.data,
+ msg.data.length - 128, 128), 0);
}
} catch (IOException e) {
LOG.error(e);
@@ -174,37 +167,24 @@ public class TestBSPPeer extends HamaClu
public BSPPeer getBSPPeer() {
return this.peer;
}
-
- public int getErrorCount() {
- return this.errorCount;
- }
}
- public void testSync() throws InterruptedException, IOException {
+ public void testSync() throws Throwable {
- BSPPeerThread thread;
conf.setInt("bsp.peers.num", NUM_PEER);
conf.set(Constants.ZOOKEEPER_QUORUM, "localhost");
conf.set(Constants.PEER_HOST, "localhost");
conf.set(Constants.ZOOKEEPER_SERVER_ADDRS, "localhost:21810");
- for (int i = 0; i < NUM_PEER; i++) {
- conf.set(Constants.PEER_PORT, String.valueOf(30000 + i));
- thread = new BSPPeerThread(conf);
- list.add(thread);
- }
-
- for (int i = 0; i < NUM_PEER; i++) {
- list.get(i).start();
- }
+ TestRunnable[] threads = new TestRunnable[NUM_PEER];
for (int i = 0; i < NUM_PEER; i++) {
- list.get(i).join();
+ conf.set(Constants.PEER_PORT, String.valueOf(30000 + i));
+ threads[i] = new BSPPeerThread(conf);
}
- for (int i = 0; i < NUM_PEER; i++) {
- assertEquals(list.get(i).getErrorCount(), 0);
- }
+ MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(threads);
+ mttr.runTestRunnables();
}
@Override