Search in sources :

Example 31 with ValueSource

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());
}
Also used : Uuid(org.apache.kafka.common.Uuid) TopicPartition(org.apache.kafka.common.TopicPartition) FetchRequest(org.apache.kafka.common.requests.FetchRequest) FetchResponse(org.apache.kafka.common.requests.FetchResponse) TopicIdPartition(org.apache.kafka.common.TopicIdPartition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with ValueSource

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);
}
Also used : Response(javax.ws.rs.core.Response) Person(com.example.helloworld.core.Person) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with ValueSource

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);
}
Also used : Response(javax.ws.rs.core.Response) Person(com.example.helloworld.core.Person) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with ValueSource

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));
    }
}
Also used : ProducerMetadata(org.apache.kafka.clients.producer.internals.ProducerMetadata) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutionException(java.util.concurrent.ExecutionException) MockTime(org.apache.kafka.common.utils.MockTime) TimeoutException(org.apache.kafka.common.errors.TimeoutException) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with ValueSource

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));
}
Also used : ProducerMetadata(org.apache.kafka.clients.producer.internals.ProducerMetadata) HashMap(java.util.HashMap) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)266 ValueSource (org.junit.jupiter.params.provider.ValueSource)266 HashSet (java.util.HashSet)23 HistogramTestUtils.constructDoubleHistogram (org.HdrHistogram.HistogramTestUtils.constructDoubleHistogram)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)20 ApiResponse (org.hisp.dhis.dto.ApiResponse)15 UpdateModel (com.synopsys.integration.alert.update.model.UpdateModel)13 File (java.io.File)13 List (java.util.List)13 OffsetDateTime (java.time.OffsetDateTime)10 Map (java.util.Map)10 TimeUnit (java.util.concurrent.TimeUnit)10 TopicPartition (org.apache.kafka.common.TopicPartition)9 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)8 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)8 ZooKeeper (org.apache.zookeeper.ZooKeeper)8 JsonObject (com.google.gson.JsonObject)7 IOException (java.io.IOException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7