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