Skip to content

Commit

Permalink
Check that the iterator has only a single record
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrrr committed Sep 6, 2023
1 parent 8362d9a commit 2b184da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.flink.streaming.connectors.kafka;

import java.util.Iterator;
import org.apache.flink.streaming.connectors.kafka.internals.FlinkKafkaInternalProducer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
Expand Down Expand Up @@ -239,9 +240,11 @@ private void assertRecord(String topicName, String expectedKey, String expectedV
records = kafkaConsumer.poll(Duration.ofMillis(10000));
}

ConsumerRecord<String, String> record = records.iterator().next();
final Iterator<ConsumerRecord<String, String>> it = records.iterator();
ConsumerRecord<String, String> record = it.next();
assertThat(record.key()).isEqualTo(expectedKey);
assertThat(record.value()).isEqualTo(expectedValue);
assertThat(it.hasNext()).isFalse();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.flink.streaming.connectors.kafka;

import java.util.Iterator;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.JobID;
import org.apache.flink.api.common.JobStatus;
Expand Down Expand Up @@ -256,7 +257,10 @@ public void run() {
} while (System.nanoTime() < deadline);

// cancel the job & wait for the job to finish
client.cancel(getRunningJobs(client).iterator().next()).get();
final Iterator<JobID> it = getRunningJobs(client).iterator();
final JobID jobId = it.next();
client.cancel(jobId).get();
assertThat(it.hasNext()).isFalse();
runner.join();

final Throwable t = errorRef.get();
Expand Down Expand Up @@ -347,7 +351,10 @@ public void run() {
} while (System.nanoTime() < deadline);

// cancel the job & wait for the job to finish
client.cancel(getRunningJobs(client).iterator().next()).get();
final Iterator<JobID> it = getRunningJobs(client).iterator();
final JobID jobId = it.next();
client.cancel(jobId).get();
assertThat(it.hasNext()).isFalse();
runner.join();

final Throwable t = errorRef.get();
Expand Down

0 comments on commit 2b184da

Please sign in to comment.