Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,20 @@ private Long lastUpdates(CacheScheduler.EntryImpl<JdbcExtractionNamespace> key,
if (tsColumn == null) {
return null;
}
final String query = StringUtils.format(
"SELECT MAX(%s) FROM %s",
tsColumn, table
);
final Timestamp update = dbi.withHandle(
handle -> {
final String query = StringUtils.format(
"SELECT MAX(%s) FROM %s",
tsColumn, table
);
return handle
.createQuery(query)
.map(TimestampMapper.FIRST)
.first();
}
handle -> handle
.createQuery(query)
.map(TimestampMapper.FIRST)
.first()
);
if (update == null) {
LOG.info("Lookup table[%s] is empty. No rows returned for the query[%s].", table, query);
return null;
}
return update.getTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testNewTask() throws Exception
Assert.assertNotNull(version);
Map<String, String> map = cache.getCache();
Assert.assertEquals("bar", map.get("foo"));
Assert.assertEquals(null, map.get("baz"));
Assert.assertNull(map.get("baz"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,36 @@ public void testMappingWithFilter()
}
}

@Test(timeout = 60_000L)
public void testEmptyTable()
throws InterruptedException
{
// Delete existing rows from table.
final Handle handle = derbyConnectorRule.getConnector().getDBI().open();
handle.createStatement(
StringUtils.format("DELETE FROM %s", TABLE_NAME)
).setQueryTimeout(1).execute();

final JdbcExtractionNamespace extractionNamespace = new JdbcExtractionNamespace(
derbyConnectorRule.getMetadataConnectorConfig(),
TABLE_NAME,
KEY_NAME,
VAL_NAME,
tsColumn,
null,
new Period(0),
null,
0,
null,
new JdbcAccessSecurityConfig()
);
try (CacheScheduler.Entry entry = scheduler.schedule(extractionNamespace)) {
CacheSchedulerTest.waitFor(entry);
final Map<String, String> map = entry.getCache();
Assert.assertTrue(map.isEmpty());
}
}

@Test(timeout = 60_000L)
public void testSkipOld()
throws InterruptedException
Expand Down