use join not sleep

This commit is contained in:
Jacky 2017-12-20 08:35:31 -05:00
parent 834b6c493c
commit 2f050322b5
2 changed files with 18 additions and 16 deletions

View File

@ -102,5 +102,11 @@ abstract public class LongRunningProcess extends Process {
} }
} }
public void join(int millesec) throws InterruptedException {
if (_thread == null)
return;
_thread.join(millesec);
}
abstract protected Runnable getRunnable(); abstract protected Runnable getRunnable();
} }

View File

@ -60,6 +60,7 @@ import com.google.refine.model.Column;
import com.google.refine.model.ModelException; import com.google.refine.model.ModelException;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.model.Row; import com.google.refine.model.Row;
import com.google.refine.process.LongRunningProcess;
import com.google.refine.process.Process; import com.google.refine.process.Process;
import com.google.refine.process.ProcessManager; import com.google.refine.process.ProcessManager;
import com.google.refine.operations.OnError; import com.google.refine.operations.OnError;
@ -138,25 +139,20 @@ public class UrlFetchingTests extends RefineTest {
500, 500,
true); true);
ProcessManager pm = project.getProcessManager(); ProcessManager pm = project.getProcessManager();
Process process = op.createProcess(project, options); LongRunningProcess process = (LongRunningProcess) op.createProcess(project, options);
process.startPerforming(pm); process.startPerforming(pm);
Assert.assertTrue(process.isRunning()); Assert.assertTrue(process.isRunning());
for (int i = 0; i < 1200; i++) { try {
try { // We have 100 rows and 500 ms per row but only two distinct
// We have 100 rows and 500 ms per row but only two distinct // values so we should not wait more than ~2000 ms to get the
// values so we should not wait more than ~2000 ms to get the // results. Just to make sure the test passes with plenty of
// results. Just to make sure the test passes with plenty of // net latency we wait for longer (but still less than
// net latency we sleep for longer (but still less than // 50,000ms).
// 50,000ms). process.join(5000 * 1200);
Thread.sleep(5000); } catch (InterruptedException e) {
if (process.isDone()) Assert.fail("Test interrupted");
break;
} catch (InterruptedException e) {
Assert.fail("Test interrupted");
}
} }
Assert.assertTrue(process.isDone()); Assert.assertFalse(process.isRunning());
// Assert.assertFalse(process.isRunning());
// Inspect rows // Inspect rows
String ref_val = (String)project.rows.get(0).getCellValue(1); String ref_val = (String)project.rows.get(0).getCellValue(1);