use of com.github.jcustenborder.kafka.connect.cdc.ChangeWriter in project kafka-connect-cdc-mssql by jcustenborder.
the class QueryServiceIT method queryTable.
private void queryTable(ChangeKey input) throws SQLException, IOException {
List<Change> expectedChanges;
String fileName = String.format("%s.%s.json", input.schemaName, input.tableName);
String resourceName = String.format("query/table/%s/%s", input.databaseName, fileName);
long timestamp = 0L;
try (InputStream stream = this.getClass().getResourceAsStream(resourceName)) {
Preconditions.checkNotNull(stream, "Could not find resource %s.", resourceName);
log.info("Loading expected changes from {}", resourceName);
expectedChanges = loadChanges(stream);
for (Change change : expectedChanges) {
timestamp = change.timestamp();
break;
}
}
OffsetStorageReader offsetStorageReader = mock(OffsetStorageReader.class);
TableMetadataProvider tableMetadataProvider = new MsSqlTableMetadataProvider(config, offsetStorageReader);
Time time = mock(Time.class);
ChangeWriter changeWriter = mock(ChangeWriter.class);
List<Change> actualChanges = new ArrayList<>(1000);
doAnswer(invocationOnMock -> {
Change change = invocationOnMock.getArgument(0);
actualChanges.add(change);
return null;
}).when(changeWriter).addChange(any());
QueryService queryService = new QueryService(time, tableMetadataProvider, config, changeWriter);
when(time.milliseconds()).thenReturn(timestamp);
queryService.queryTable(changeWriter, input);
verify(offsetStorageReader, only()).offset(anyMap());
verify(time, atLeastOnce()).milliseconds();
if (log.isDebugEnabled()) {
log.trace("Found {} change(s).", actualChanges.size());
}
assertFalse(actualChanges.isEmpty(), "Changes should have been returned.");
assertEquals(expectedChanges.size(), actualChanges.size(), "The number of actualChanges returned is not the expect count.");
for (int i = 0; i < expectedChanges.size(); i++) {
Change expectedChange = expectedChanges.get(i);
Change actualChange = actualChanges.get(i);
assertChange(expectedChange, actualChange);
}
}
Aggregations