Search in sources :

Example 1 with ColumnAdditionByFetchingURLsOperation

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);
    }
}
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)

Aggregations

Cell (com.google.refine.model.Cell)1 Row (com.google.refine.model.Row)1 EngineDependentOperation (com.google.refine.operations.EngineDependentOperation)1 ColumnAdditionByFetchingURLsOperation (com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation)1 Process (com.google.refine.process.Process)1 ProcessManager (com.google.refine.process.ProcessManager)1 RefineTest (com.google.refine.tests.RefineTest)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1