use of com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation in project OpenRefine by OpenRefine.
the class UrlFetchingTests method testUrlCaching.
/**
* Test for caching
*/
@Test
public void testUrlCaching() throws Exception {
for (int i = 0; i < 100; i++) {
Row row = new Row(2);
row.setCell(0, new Cell(i < 5 ? "apple" : "orange", null));
project.rows.add(row);
}
EngineDependentOperation op = new ColumnAdditionByFetchingURLsOperation(engine_config, "fruits", "\"https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new&city=\"+value", OnError.SetToBlank, "rand", 1, 500, true);
ProcessManager pm = project.getProcessManager();
Process process = op.createProcess(project, options);
process.startPerforming(pm);
Assert.assertTrue(process.isRunning());
try {
// 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
// results. Just to make sure the test passes with plenty of
// net latency we sleep for longer (but still less than
// 50,000ms).
Thread.sleep(5000);
} catch (InterruptedException e) {
Assert.fail("Test interrupted");
}
Assert.assertFalse(process.isRunning());
// Inspect rows
String ref_val = (String) project.rows.get(0).getCellValue(1);
// just to make sure I picked the right column
Assert.assertTrue(ref_val != "apple");
for (int i = 1; i < 4; i++) {
// all random values should be equal due to caching
Assert.assertEquals(project.rows.get(i).getCellValue(1), ref_val);
}
}
Aggregations