NIFI-5202: Fixed timing issue in TestListDatabaseTables

This closes #2709

Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
This commit is contained in:
Matthew Burgess 2018-05-16 13:26:14 -04:00 committed by Mike Thomsen
parent 807e1e5c7a
commit 5613bf4012
1 changed files with 5 additions and 2 deletions

View File

@ -206,6 +206,7 @@ public class TestListDatabaseTables {
runner.setProperty(ListDatabaseTables.INCLUDE_COUNT, "true");
runner.setProperty(ListDatabaseTables.REFRESH_INTERVAL, "200 millis");
runner.run();
long startTimer = System.currentTimeMillis();
runner.assertTransferCount(ListDatabaseTables.REL_SUCCESS, 1);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ListDatabaseTables.REL_SUCCESS);
assertEquals("2", results.get(0).getAttribute(ListDatabaseTables.DB_TABLE_COUNT));
@ -215,9 +216,11 @@ public class TestListDatabaseTables {
stmt.execute("create table TEST_TABLE2 (id integer not null, val1 integer, val2 integer, constraint my_pk2 primary key (id))");
stmt.close();
runner.run();
runner.assertTransferCount(ListDatabaseTables.REL_SUCCESS, 1);
long endTimer = System.currentTimeMillis();
// Expect 1 or 2 tables (whether execution has taken longer than the refresh time)
runner.assertTransferCount(ListDatabaseTables.REL_SUCCESS, (endTimer - startTimer > 200) ? 2 : 1);
results = runner.getFlowFilesForRelationship(ListDatabaseTables.REL_SUCCESS);
assertEquals("0", results.get(0).getAttribute(ListDatabaseTables.DB_TABLE_COUNT));
assertEquals((endTimer - startTimer > 200) ? "2": "0", results.get(0).getAttribute(ListDatabaseTables.DB_TABLE_COUNT));
runner.clearTransferState();
// Now wait longer than the refresh interval and assert the refresh has happened (i.e. the two tables are re-listed)