Search in sources :

Example 1 with NodeProgress

use of org.knime.core.node.workflow.NodeProgress in project knime-core by knime.

the class NodeProgressEventTest method testGetters.

@Test
public void testGetters() {
    NodeProgress np = new NodeProgress(null, null);
    NodeProgressEvent e = new NodeProgressEvent(new NodeID(10), np);
    assertEquals(e.getSource(), new NodeID(10));
    assertEquals(e.getNodeProgress(), np);
}
Also used : NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) NodeProgress(org.knime.core.node.workflow.NodeProgress) NodeID(org.knime.core.node.workflow.NodeID) Test(org.junit.Test)

Example 2 with NodeProgress

use of org.knime.core.node.workflow.NodeProgress in project knime-core by knime.

the class DefaultNodeProgressMonitorTest method createListener.

private static NodeProgressListener createListener(final Pointer<NodeProgress> progressPointer, final Function<NodeProgress, Boolean> notificationFunction) {
    return new NodeProgressListener() {

        @Override
        public void progressChanged(final NodeProgressEvent pe) {
            NodeProgress prog = pe.getNodeProgress();
            progressPointer.set(prog);
            if (notificationFunction.apply(prog)) {
                synchronized (notificationFunction) {
                    notificationFunction.notifyAll();
                }
            }
        }
    };
}
Also used : NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress)

Example 3 with NodeProgress

use of org.knime.core.node.workflow.NodeProgress in project knime-core by knime.

the class DefaultNodeProgressMonitorTest method internalTestManyMessageEvents.

/**
 * A lot of incremental numeric progress updates + many message events
 * Previously, this took significantly longer due to expensive string construction.
 */
private void internalTestManyMessageEvents(final NodeProgressMonitor toMonitor, final NodeProgressMonitor toControl) throws Exception {
    final int parts = 1000000;
    final MutableLong stringComposeCounter = new MutableLong();
    Function<Integer, String> msgFct = (index) -> {
        stringComposeCounter.increment();
        return "Row " + index + " (Row \"" + RowKey.createRowKey((long) index) + "\")";
    };
    final Pointer<NodeProgress> progressPointer = new Pointer<>();
    String lastExpectedMsg = msgFct.apply(parts);
    final Function<NodeProgress, Boolean> isLastEventFunction = p -> p.getMessage().equals(lastExpectedMsg);
    NodeProgressListener l = createListener(progressPointer, isLastEventFunction);
    toMonitor.addProgressListener(l);
    try {
        for (int i = 1; i < parts + 1; i++) {
            final int index = i;
            // if this line is replaced by a direct string composition this takes an order of magnitude longer
            toControl.setProgress(i / (double) parts, () -> msgFct.apply(index));
        }
        synchronized (isLastEventFunction) {
            isLastEventFunction.wait(500);
        }
        assertThat(progressPointer.get().getProgress(), is(closeTo(1.0, PROG_EPSILON)));
        assertThat(progressPointer.get().getMessage(), is(equalTo(lastExpectedMsg)));
        // the lazy string creation should only be called 4 times a second at most,
        // it must be at least two - one for the reference string creation and one during an event
        // 2020-01-08, BW: increment from max=5 to max=8 -- encountered a longer running test case on Win Server
        Assert.assertThat(stringComposeCounter.getValue(), is(allOf(greaterThanOrEqualTo(2L), lessThanOrEqualTo(8L))));
    } finally {
        toMonitor.removeProgressListener(l);
    }
}
Also used : Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) RowKey(org.knime.core.data.RowKey) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Test(org.junit.Test) Function(java.util.function.Function) NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) Assert.assertThat(org.junit.Assert.assertThat) Matchers.closeTo(org.hamcrest.Matchers.closeTo) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Assert(org.junit.Assert) SubNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor.SubNodeProgressMonitor) Pointer(org.knime.core.util.Pointer) NodeProgress(org.knime.core.node.workflow.NodeProgress) MutableLong(org.apache.commons.lang3.mutable.MutableLong) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress) Pointer(org.knime.core.util.Pointer)

Example 4 with NodeProgress

use of org.knime.core.node.workflow.NodeProgress in project knime-core by knime.

the class NodeProgressTest method testGetters.

@Test
public void testGetters() {
    NodeProgress np = new NodeProgress(.432, "message ...");
    assertTrue(np.hasProgress());
    assertTrue(np.hasMessage());
    assertEquals(np.getMessage(), "message ...");
    assertEquals(np.getProgress().doubleValue(), .432, 0.0);
    np = new NodeProgress(null, null);
    assertFalse(np.hasProgress());
    assertFalse(np.hasMessage());
}
Also used : NodeProgress(org.knime.core.node.workflow.NodeProgress) Test(org.junit.Test)

Example 5 with NodeProgress

use of org.knime.core.node.workflow.NodeProgress in project knime-core by knime.

the class TableSorterWorker method doInBackgroundWithContext.

/**
 * {@inheritDoc}
 */
@Override
protected DataTable doInBackgroundWithContext() throws Exception {
    // passed to table sorter for progress
    long rowCount;
    if (m_inputTable instanceof BufferedDataTable) {
        rowCount = ((BufferedDataTable) m_inputTable).size();
    } else if (m_inputTable instanceof ContainerTable) {
        rowCount = ((ContainerTable) m_inputTable).size();
    } else {
        // unknown, no progress
        rowCount = -1;
    }
    publish(new NodeProgress(0.0, "Starting table sort..."));
    Collection<String> sortColNames = new ArrayList<String>(2);
    DataTableSpec spec = m_inputTable.getDataTableSpec();
    for (int i : m_sortOrder.getSortColumnIndices()) {
        String name;
        if (i < 0) {
            // row id
            name = DataTableSorter.ROWKEY_SORT_SPEC.getName();
        } else {
            name = spec.getColumnSpec(i).getName();
        }
        sortColNames.add(name);
    }
    long start = System.currentTimeMillis();
    LOGGER.debug("Starting interactive table sorting on column(s) " + sortColNames);
    boolean[] sortOrders = m_sortOrder.getSortColumnOrder();
    // it DOES NOT respect blobs -- they will be copied (expensive)
    DataTableSorter sorter = new DataTableSorter(m_inputTable, rowCount, sortColNames, sortOrders, false);
    NodeProgressListener progLis = new NodeProgressListener() {

        @Override
        public void progressChanged(final NodeProgressEvent pe) {
            publish(pe.getNodeProgress());
        }
    };
    m_nodeProgressMonitor = new DefaultNodeProgressMonitor();
    ExecutionMonitor exec = new ExecutionMonitor(m_nodeProgressMonitor);
    m_nodeProgressMonitor.addProgressListener(progLis);
    try {
        DataTable result = sorter.sort(exec);
        long elapsedMS = System.currentTimeMillis() - start;
        String time = StringFormat.formatElapsedTime(elapsedMS);
        LOGGER.debug("Interactive table sorting finished (" + time + ")");
        return result;
    } finally {
        m_nodeProgressMonitor.removeProgressListener(progLis);
    }
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress) ArrayList(java.util.ArrayList) ContainerTable(org.knime.core.data.container.ContainerTable) NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) DataTableSorter(org.knime.core.data.sort.DataTableSorter) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) BufferedDataTable(org.knime.core.node.BufferedDataTable) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Aggregations

NodeProgress (org.knime.core.node.workflow.NodeProgress)9 NodeProgressEvent (org.knime.core.node.workflow.NodeProgressEvent)8 NodeProgressListener (org.knime.core.node.workflow.NodeProgressListener)7 Test (org.junit.Test)4 DataTableSpec (org.knime.core.data.DataTableSpec)3 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)3 ArrayList (java.util.ArrayList)2 Function (java.util.function.Function)2 MutableLong (org.apache.commons.lang3.mutable.MutableLong)2 Matchers.allOf (org.hamcrest.Matchers.allOf)2 Matchers.closeTo (org.hamcrest.Matchers.closeTo)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)2 Matchers.is (org.hamcrest.Matchers.is)2 Matchers.lessThanOrEqualTo (org.hamcrest.Matchers.lessThanOrEqualTo)2 Assert (org.junit.Assert)2 Assert.assertThat (org.junit.Assert.assertThat)2 DataTable (org.knime.core.data.DataTable)2 RowKey (org.knime.core.data.RowKey)2 ContainerTable (org.knime.core.data.container.ContainerTable)2