Search in sources :

Example 1 with EngineDependentOperation

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);
    }
}
Also used : EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) ColumnAdditionByFetchingURLsOperation(com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation) Process(com.google.refine.process.Process) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) ProcessManager(com.google.refine.process.ProcessManager) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Example 2 with EngineDependentOperation

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);
}
Also used : RowRemovalOperation(com.google.refine.operations.row.RowRemovalOperation) Function(com.google.refine.grel.Function) EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) JSONObject(org.json.JSONObject) Row(com.google.refine.model.Row) FacetCount(com.google.refine.expr.functions.FacetCount) Cell(com.google.refine.model.Cell) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Aggregations

Cell (com.google.refine.model.Cell)2 Row (com.google.refine.model.Row)2 EngineDependentOperation (com.google.refine.operations.EngineDependentOperation)2 RefineTest (com.google.refine.tests.RefineTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 FacetCount (com.google.refine.expr.functions.FacetCount)1 Function (com.google.refine.grel.Function)1 ColumnAdditionByFetchingURLsOperation (com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation)1 RowRemovalOperation (com.google.refine.operations.row.RowRemovalOperation)1 Process (com.google.refine.process.Process)1 ProcessManager (com.google.refine.process.ProcessManager)1 JSONObject (org.json.JSONObject)1