use of org.junit.jupiter.params.provider.ValueSource in project kafka by apache.
the class FetchSessionHandlerTest method testIdUsageWithAllForgottenPartitions.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testIdUsageWithAllForgottenPartitions(boolean useTopicIds) {
// We want to test when all topics are removed from the session
TopicPartition foo0 = new TopicPartition("foo", 0);
Uuid topicId = useTopicIds ? Uuid.randomUuid() : Uuid.ZERO_UUID;
short responseVersion = useTopicIds ? ApiKeys.FETCH.latestVersion() : 12;
FetchSessionHandler handler = new FetchSessionHandler(LOG_CONTEXT, 1);
// Add topic foo to the session
FetchSessionHandler.Builder builder = handler.newBuilder();
builder.add(foo0, new FetchRequest.PartitionData(topicId, 0, 100, 200, Optional.empty()));
FetchSessionHandler.FetchRequestData data = builder.build();
assertMapsEqual(reqMap(new ReqEntry("foo", topicId, 0, 0, 100, 200)), data.toSend(), data.sessionPartitions());
assertTrue(data.metadata().isFull());
assertEquals(useTopicIds, data.canUseTopicIds());
FetchResponse resp = FetchResponse.of(Errors.NONE, 0, 123, respMap(new RespEntry("foo", 0, topicId, 10, 20)));
handler.handleResponse(resp, responseVersion);
// Remove the topic from the session
FetchSessionHandler.Builder builder2 = handler.newBuilder();
FetchSessionHandler.FetchRequestData data2 = builder2.build();
assertEquals(Collections.singletonList(new TopicIdPartition(topicId, foo0)), data2.toForget());
// Should have the same session ID, next epoch, and same ID usage.
assertEquals(123, data2.metadata().sessionId(), "Did not use same session when useTopicIds was " + useTopicIds);
assertEquals(1, data2.metadata().epoch(), "Did not have correct epoch when useTopicIds was " + useTopicIds);
assertEquals(useTopicIds, data2.canUseTopicIds());
}
use of org.junit.jupiter.params.provider.ValueSource in project dropwizard by dropwizard.
the class IntegrationTest method testRenderingPerson.
@ParameterizedTest
@ValueSource(strings = { "view_freemarker", "view_mustache" })
void testRenderingPerson(String viewName) {
final Person person = new Person("Dr. IntegrationTest", "Chief Wizard", 1525);
final Person newPerson = postPerson(person);
final String url = "http://localhost:" + APP.getLocalPort() + "/people/" + newPerson.getId() + "/" + viewName;
Response response = APP.client().target(url).request().get();
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
}
use of org.junit.jupiter.params.provider.ValueSource in project dropwizard by dropwizard.
the class DockerIntegrationTest method testRenderingPerson.
@ParameterizedTest
@ValueSource(strings = { "view_freemarker", "view_mustache" })
void testRenderingPerson(String viewName) {
final Person person = new Person("Dr. IntegrationTest", "Chief Wizard", 1525);
final Person newPerson = postPerson(person);
final String url = "http://localhost:" + APP.getLocalPort() + "/people/" + newPerson.getId() + "/" + viewName;
Response response = APP.client().target(url).request().get();
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
}
use of org.junit.jupiter.params.provider.ValueSource in project kafka by apache.
the class KafkaProducerTest method testMetadataTimeoutWithPartitionOutOfRange.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMetadataTimeoutWithPartitionOutOfRange(boolean isIdempotenceEnabled) throws Exception {
Map<String, Object> configs = new HashMap<>();
configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
configs.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 60000);
configs.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, isIdempotenceEnabled);
// Create a record with a partition higher than the initial (outdated) partition range
ProducerRecord<String, String> record = new ProducerRecord<>(topic, 2, null, "value");
ProducerMetadata metadata = mock(ProducerMetadata.class);
MockTime mockTime = new MockTime();
AtomicInteger invocationCount = new AtomicInteger(0);
when(metadata.fetch()).then(invocation -> {
invocationCount.incrementAndGet();
if (invocationCount.get() == 5) {
mockTime.setCurrentTimeMs(mockTime.milliseconds() + 70000);
}
return onePartitionCluster;
});
KafkaProducer<String, String> producer = producerWithOverrideNewSender(configs, metadata, mockTime);
// Four request updates where the requested partition is out of range, at which point the timeout expires
// and a TimeoutException is thrown
// For idempotence enabled case, the first and last metadata.fetch will be called in Sender#maybeSendAndPollTransactionalRequest,
// before the producer#send and after it finished
Future<RecordMetadata> future = producer.send(record);
verify(metadata, times(4)).requestUpdateForTopic(topic);
verify(metadata, times(4)).awaitUpdate(anyInt(), anyLong());
verify(metadata, times(5)).fetch();
try {
future.get();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof TimeoutException);
} finally {
producer.close(Duration.ofMillis(0));
}
}
use of org.junit.jupiter.params.provider.ValueSource in project kafka by apache.
the class KafkaProducerTest method testMetadataFetch.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMetadataFetch(boolean isIdempotenceEnabled) throws InterruptedException {
Map<String, Object> configs = new HashMap<>();
configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
configs.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, isIdempotenceEnabled);
ProducerMetadata metadata = mock(ProducerMetadata.class);
// Return empty cluster 4 times and cluster from then on
when(metadata.fetch()).thenReturn(emptyCluster, emptyCluster, emptyCluster, emptyCluster, onePartitionCluster);
KafkaProducer<String, String> producer = producerWithOverrideNewSender(configs, metadata);
ProducerRecord<String, String> record = new ProducerRecord<>(topic, "value");
producer.send(record);
// One request update for each empty cluster returned
verify(metadata, times(4)).requestUpdateForTopic(topic);
verify(metadata, times(4)).awaitUpdate(anyInt(), anyLong());
verify(metadata, times(5)).fetch();
// Should not request update for subsequent `send`
producer.send(record, null);
verify(metadata, times(4)).requestUpdateForTopic(topic);
verify(metadata, times(4)).awaitUpdate(anyInt(), anyLong());
verify(metadata, times(6)).fetch();
// Should not request update for subsequent `partitionsFor`
producer.partitionsFor(topic);
verify(metadata, times(4)).requestUpdateForTopic(topic);
verify(metadata, times(4)).awaitUpdate(anyInt(), anyLong());
verify(metadata, times(7)).fetch();
producer.close(Duration.ofMillis(0));
}
Aggregations