fix unit test bug

This commit is contained in:
Fangjin Yang 2013-01-25 14:33:05 -08:00
parent 0f4746450b
commit efdff7b9f1
2 changed files with 21 additions and 1 deletions

View File

@ -264,6 +264,16 @@ public class RemoteTaskRunner implements TaskRunner
return zkWorkers.size();
}
public boolean isTaskRunning(String taskId)
{
for (WorkerWrapper workerWrapper : zkWorkers.values()) {
if (workerWrapper.getRunningTasks().contains(taskId)) {
return true;
}
}
return false;
}
@Override
public void run(Task task, TaskContext context, TaskCallback callback)
{

View File

@ -196,8 +196,13 @@ public class RemoteTaskRunnerTest
);
// Really don't like this way of waiting for the task to appear
while (remoteTaskRunner.getNumWorkers() == 0) {
int count = 0;
while (!remoteTaskRunner.isTaskRunning("task1")) {
Thread.sleep(500);
if (count > 10) {
throw new ISE("WTF?! Task still not announced in ZK?");
}
count++;
}
final MutableBoolean callbackCalled = new MutableBoolean(false);
@ -364,8 +369,13 @@ public class RemoteTaskRunnerTest
String.format("%s/worker1", announcementsPath),
jsonMapper.writeValueAsBytes(worker1)
);
int count = 0;
while (remoteTaskRunner.getNumWorkers() == 0) {
Thread.sleep(500);
if (count > 10) {
throw new ISE("WTF?! Still can't find worker!");
}
count++;
}
}