check the host readability before test
This commit is contained in:
parent
2f050322b5
commit
29abf730e9
@ -37,6 +37,7 @@ import static org.mockito.Mockito.mock;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -51,8 +52,6 @@ import org.testng.annotations.Test;
|
|||||||
import com.google.refine.ProjectManager;
|
import com.google.refine.ProjectManager;
|
||||||
import com.google.refine.ProjectMetadata;
|
import com.google.refine.ProjectMetadata;
|
||||||
import com.google.refine.browsing.Engine;
|
import com.google.refine.browsing.Engine;
|
||||||
import com.google.refine.browsing.RowVisitor;
|
|
||||||
import com.google.refine.grel.Function;
|
|
||||||
import com.google.refine.io.FileProjectManager;
|
import com.google.refine.io.FileProjectManager;
|
||||||
import com.google.refine.expr.ExpressionUtils;
|
import com.google.refine.expr.ExpressionUtils;
|
||||||
import com.google.refine.model.Cell;
|
import com.google.refine.model.Cell;
|
||||||
@ -60,7 +59,6 @@ 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;
|
||||||
@ -119,12 +117,27 @@ public class UrlFetchingTests extends RefineTest {
|
|||||||
bindings = null;
|
bindings = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isHostReachable(String host, int timeout){
|
||||||
|
boolean state = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
state = InetAddress.getByName(host).isReachable(timeout);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for caching
|
* Test for caching
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUrlCaching() throws Exception {
|
public void testUrlCaching() throws Exception {
|
||||||
|
if (!isHostReachable("www.random.org", 5000))
|
||||||
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
Row row = new Row(2);
|
Row row = new Row(2);
|
||||||
row.setCell(0, new Cell(i < 5 ? "apple":"orange", null));
|
row.setCell(0, new Cell(i < 5 ? "apple":"orange", null));
|
||||||
@ -133,34 +146,36 @@ public class UrlFetchingTests extends RefineTest {
|
|||||||
EngineDependentOperation op = new ColumnAdditionByFetchingURLsOperation(engine_config,
|
EngineDependentOperation op = new ColumnAdditionByFetchingURLsOperation(engine_config,
|
||||||
"fruits",
|
"fruits",
|
||||||
"\"https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new&city=\"+value",
|
"\"https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new&city=\"+value",
|
||||||
OnError.SetToBlank,
|
OnError.StoreError,
|
||||||
"rand",
|
"rand",
|
||||||
1,
|
1,
|
||||||
500,
|
500,
|
||||||
true);
|
true);
|
||||||
ProcessManager pm = project.getProcessManager();
|
ProcessManager pm = project.getProcessManager();
|
||||||
LongRunningProcess process = (LongRunningProcess) op.createProcess(project, options);
|
Process process = op.createProcess(project, options);
|
||||||
process.startPerforming(pm);
|
process.startPerforming(pm);
|
||||||
Assert.assertTrue(process.isRunning());
|
Assert.assertTrue(process.isRunning());
|
||||||
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) {
|
} catch (InterruptedException e) {
|
||||||
Assert.fail("Test interrupted");
|
Assert.fail("Test interrupted");
|
||||||
}
|
}
|
||||||
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).toString();
|
||||||
Assert.assertTrue(ref_val != "apple"); // just to make sure I picked the right column
|
Assert.assertTrue(ref_val != "apple"); // just to make sure I picked the right column
|
||||||
for (int i = 1; i < 4; i++) {
|
for (int i = 1; i < 4; i++) {
|
||||||
|
System.out.println("value:" + project.rows.get(i).getCellValue(1));
|
||||||
// all random values should be equal due to caching
|
// all random values should be equal due to caching
|
||||||
Assert.assertEquals(project.rows.get(i).getCellValue(1), ref_val);
|
Assert.assertEquals(project.rows.get(i).getCellValue(1), ref_val);
|
||||||
}
|
}
|
||||||
|
Assert.assertFalse(process.isRunning());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user