You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by to...@apache.org on 2012/11/15 08:44:51 UTC
svn commit: r1409675 - in
/hama/trunk/core/src/test/java/org/apache/hama/bsp: TestZooKeeper.java
message/TestAvroMessageManager.java sync/TestSyncServiceFactory.java
Author: tommaso
Date: Thu Nov 15 07:44:50 2012
New Revision: 1409675
URL: http://svn.apache.org/viewvc?rev=1409675&view=rev
Log:
[HAMA-677] - starting getting rid of Thread.sleep
Modified:
hama/trunk/core/src/test/java/org/apache/hama/bsp/TestZooKeeper.java
hama/trunk/core/src/test/java/org/apache/hama/bsp/message/TestAvroMessageManager.java
hama/trunk/core/src/test/java/org/apache/hama/bsp/sync/TestSyncServiceFactory.java
Modified: hama/trunk/core/src/test/java/org/apache/hama/bsp/TestZooKeeper.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/test/java/org/apache/hama/bsp/TestZooKeeper.java?rev=1409675&r1=1409674&r2=1409675&view=diff
==============================================================================
--- hama/trunk/core/src/test/java/org/apache/hama/bsp/TestZooKeeper.java (original)
+++ hama/trunk/core/src/test/java/org/apache/hama/bsp/TestZooKeeper.java Thu Nov 15 07:44:50 2012
@@ -20,6 +20,9 @@
package org.apache.hama.bsp;
import java.io.IOException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
@@ -35,6 +38,7 @@ import org.apache.hama.bsp.sync.ZooKeepe
import org.apache.hama.bsp.sync.ZooKeeperSyncServerImpl;
import org.apache.hama.util.BSPNetUtils;
import org.apache.zookeeper.KeeperException;
+import org.junit.Test;
import org.mortbay.log.Log;
public class TestZooKeeper extends TestCase {
@@ -57,25 +61,26 @@ public class TestZooKeeper extends TestC
.getCanonicalName());
}
+ @Test
public void testClearZKNodes() throws IOException, KeeperException,
InterruptedException {
final ZooKeeperSyncServerImpl server = new ZooKeeperSyncServerImpl();
boolean done = false;
try {
server.init(configuration);
- new Thread(new Runnable() {
-
+ ExecutorService executorService = Executors.newCachedThreadPool();
+ executorService.submit(new Runnable() {
@Override
public void run() {
- try {
- server.start();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ try {
+ server.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- }).start();
+ });
- Thread.sleep(1000);
+ executorService.awaitTermination(10, TimeUnit.SECONDS);
String bspRoot = "/bsp";
Modified: hama/trunk/core/src/test/java/org/apache/hama/bsp/message/TestAvroMessageManager.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/test/java/org/apache/hama/bsp/message/TestAvroMessageManager.java?rev=1409675&r1=1409674&r2=1409675&view=diff
==============================================================================
--- hama/trunk/core/src/test/java/org/apache/hama/bsp/message/TestAvroMessageManager.java (original)
+++ hama/trunk/core/src/test/java/org/apache/hama/bsp/message/TestAvroMessageManager.java Thu Nov 15 07:44:50 2012
@@ -37,6 +37,7 @@ import org.apache.hama.bsp.message.type.
import org.apache.hama.bsp.message.type.DoubleMessage;
import org.apache.hama.bsp.message.type.IntegerMessage;
import org.apache.hama.util.BSPNetUtils;
+import org.junit.Test;
public class TestAvroMessageManager extends TestCase {
@@ -49,6 +50,7 @@ public class TestAvroMessageManager exte
public static final String TMP_OUTPUT_PATH = "/tmp/messageQueue";
+ @Test
public void testAvroMessenger() throws Exception {
BSPMessageBundle<Writable> randomBundle = getRandomBundle();
Configuration conf = new Configuration();
@@ -95,7 +97,7 @@ public class TestAvroMessageManager exte
}
- public final static BSPMessageBundle<Writable> getRandomBundle() {
+ private final static BSPMessageBundle<Writable> getRandomBundle() {
BSPMessageBundle<Writable> bundle = new BSPMessageBundle<Writable>();
for (int i = 0; i < INT_MSG_COUNT; i++) {
Modified: hama/trunk/core/src/test/java/org/apache/hama/bsp/sync/TestSyncServiceFactory.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/test/java/org/apache/hama/bsp/sync/TestSyncServiceFactory.java?rev=1409675&r1=1409674&r2=1409675&view=diff
==============================================================================
--- hama/trunk/core/src/test/java/org/apache/hama/bsp/sync/TestSyncServiceFactory.java (original)
+++ hama/trunk/core/src/test/java/org/apache/hama/bsp/sync/TestSyncServiceFactory.java Thu Nov 15 07:44:50 2012
@@ -17,7 +17,9 @@
*/
package org.apache.hama.bsp.sync;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
@@ -31,6 +33,7 @@ import org.apache.hama.bsp.BSPJobID;
import org.apache.hama.bsp.TaskAttemptID;
import org.apache.hama.bsp.TaskID;
import org.apache.hama.util.BSPNetUtils;
+import org.junit.Test;
public class TestSyncServiceFactory extends TestCase {
@@ -67,6 +70,7 @@ public class TestSyncServiceFactory exte
}
+ @Test
public void testClientInstantiation() throws Exception {
Configuration conf = new Configuration();
@@ -75,6 +79,7 @@ public class TestSyncServiceFactory exte
assertTrue(syncClient instanceof ZooKeeperSyncClientImpl);
}
+ @Test
public void testServerInstantiation() throws Exception {
Configuration conf = new Configuration();
@@ -102,6 +107,7 @@ public class TestSyncServiceFactory exte
}
+ @Test
public void testZKSyncStore() throws Exception {
Configuration conf = new Configuration();
int zkPort = BSPNetUtils.getFreePort(21811);
@@ -118,10 +124,10 @@ public class TestSyncServiceFactory exte
assertTrue(syncServer instanceof ZooKeeperSyncServerImpl);
ZKServerThread serverThread = new ZKServerThread(syncServer);
- Executors.newFixedThreadPool(1).submit(serverThread);
+ ExecutorService executorService = Executors.newFixedThreadPool(1);
+ executorService.submit(serverThread);
- // FIXME wait for syncServer is up
- Thread.sleep(5000);
+ executorService.awaitTermination(10, TimeUnit.SECONDS);
final PeerSyncClient syncClient = SyncServiceFactory
.getPeerSyncClient(conf);