Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#222] Fix test infra error of not consuming records #223

Merged
merged 2 commits into from
Jun 2, 2023
Merged
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 @@ -8,12 +8,9 @@
import io.debezium.embedded.EmbeddedEngine;
import io.debezium.engine.DebeziumEngine;
import io.debezium.engine.spi.OffsetCommitPolicy;
import io.debezium.relational.history.HistoryRecord;
import io.debezium.util.LoggingContext;
import io.debezium.util.Testing;
import org.apache.kafka.connect.data.Field;
import org.apache.kafka.connect.data.Struct;
import org.apache.kafka.connect.runtime.standalone.StandaloneConfig;
import org.apache.kafka.connect.source.SourceRecord;
import org.apache.kafka.connect.storage.MemoryOffsetBackingStore;
import org.awaitility.Awaitility;
Expand All @@ -25,12 +22,7 @@

import java.time.Duration;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.function.Consumer;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -50,7 +42,7 @@ public class TestBaseClass extends AbstractConnectorTest {
protected static String yugabytedStartCommand = "";
protected Map<String, ?> offsetMapForRecords = new HashMap<>();
protected ExecutorService engineExecutor;
protected static BlockingQueue<SourceRecord> consumedLines;
protected static Queue<SourceRecord> consumedLines;

protected void awaitUntilConnectorIsReady() throws Exception {
Awaitility.await()
Expand All @@ -64,11 +56,7 @@ protected void awaitUntilConnectorIsReady() throws Exception {
@BeforeAll
public static void initializeTestFramework() {
LoggingContext.forConnector(YugabyteDBConnector.class.getSimpleName(), "", "test");
consumedLines = new ArrayBlockingQueue<>(getMaximumRecordCount());
}

protected static int getMaximumRecordCount() {
return 200;
consumedLines = new LinkedList<>();
}

@Override
Expand Down Expand Up @@ -174,7 +162,7 @@ public void taskStarted() {
.using(this.getClass().getClassLoader())
.notifying((records, committer) -> {
for (SourceRecord record: records) {
consumedLines.offer(record);
consumedLines.add(record);
committer.markProcessed(record);

offsetMapForRecords = record.sourceOffset();
Expand All @@ -193,12 +181,15 @@ public void taskStarted() {
}

protected int consumeAvailableRecords(Consumer<SourceRecord> recordConsumer) {
List<SourceRecord> records = new LinkedList<>();
consumedLines.drainTo(records);
if (recordConsumer != null) {
records.forEach(recordConsumer);
consumedLines.forEach(recordConsumer);
}
return records.size();

// Read the size of the queue to return later and clear it.
final int queueSize = consumedLines.size();
consumedLines.clear();

return queueSize;
}

protected SourceRecords consumeByTopic(int numRecords) throws InterruptedException {
Expand Down