use of com.google.refine.operations.EngineDependentOperation 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);
}
}
use of com.google.refine.operations.EngineDependentOperation in project OpenRefine by OpenRefine.
the class CacheTests method testIssue567.
/**
* Test for issue 567. Problem doesn't seem to occur when testing
* interactively, but this demonstrates that the facet count cache
* can get stale after row removal operations
*
* @throws Exception
*/
@Test
public void testIssue567() throws Exception {
for (int i = 0; i < 5; i++) {
Row row = new Row(5);
row.setCell(0, new Cell(i < 4 ? "a" : "b", null));
project.rows.add(row);
}
engine.getAllRows().accept(project, new CountingRowVisitor(5));
engine.getAllFilteredRows().accept(project, new CountingRowVisitor(4));
Function fc = new FacetCount();
Integer count = (Integer) fc.call(bindings, new Object[] { "a", "value", "Column A" });
Assert.assertEquals(count.intValue(), 4);
EngineDependentOperation op = new RowRemovalOperation(engine_config);
op.createProcess(project, options).performImmediate();
engine.getAllRows().accept(project, new CountingRowVisitor(1));
engine.getAllFilteredRows().accept(project, new CountingRowVisitor(0));
count = (Integer) fc.call(bindings, new Object[] { "a", "value", "Column A" });
Assert.assertEquals(count.intValue(), 0);
}
Aggregations