Search in sources :

Example 1 with KafkaProducer

use of io.vertx.kafka.client.producer.KafkaProducer in project hono by eclipse.

the class CachingKafkaProducerFactoryTest method setUp.

@BeforeEach
void setUp() {
    final VertxInternal vertxMock = mock(VertxInternal.class);
    final ContextInternal context = VertxMockSupport.mockContextInternal(vertxMock);
    final PromiseInternal<Void> promiseInternal = VertxMockSupport.promiseInternal();
    when(promiseInternal.future()).thenReturn(Future.succeededFuture());
    doAnswer(invocation -> {
        return promiseInternal;
    }).when(context).promise();
    when(vertxMock.getOrCreateContext()).thenReturn(context);
    doAnswer(invocation -> {
        final Promise<Object> result = Promise.promise();
        final Handler<Future<Object>> blockingCode = invocation.getArgument(0);
        final Handler<AsyncResult<Object>> resultHandler = invocation.getArgument(1);
        result.future().onComplete(resultHandler);
        blockingCode.handle(result.future());
        return null;
    }).when(context).executeBlocking(VertxMockSupport.anyHandler(), VertxMockSupport.anyHandler());
    final BiFunction<String, Map<String, String>, KafkaProducer<String, Buffer>> instanceSupplier = (n, c) -> {
        final MockProducer<String, Buffer> mockProducer = new MockProducer<>(true, new StringSerializer(), new BufferSerializer());
        return KafkaProducer.create(vertxMock, mockProducer);
    };
    factory = CachingKafkaProducerFactory.testFactory(vertxMock, instanceSupplier);
    configProperties.setProducerConfig(Map.of("bootstrap.servers", "localhost:9092"));
}
Also used : KafkaProducer(io.vertx.kafka.client.producer.KafkaProducer) BeforeEach(org.junit.jupiter.api.BeforeEach) BufferSerializer(io.vertx.kafka.client.serialization.BufferSerializer) BiFunction(java.util.function.BiFunction) KafkaException(org.apache.kafka.common.KafkaException) ContextInternal(io.vertx.core.impl.ContextInternal) KafkaProducer(io.vertx.kafka.client.producer.KafkaProducer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) AsyncResult(io.vertx.core.AsyncResult) VertxInternal(io.vertx.core.impl.VertxInternal) PromiseInternal(io.vertx.core.impl.future.PromiseInternal) AuthorizationException(org.apache.kafka.common.errors.AuthorizationException) Promise(io.vertx.core.Promise) OutOfOrderSequenceException(org.apache.kafka.common.errors.OutOfOrderSequenceException) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) Buffer(io.vertx.core.buffer.Buffer) VertxMockSupport(org.eclipse.hono.test.VertxMockSupport) ProducerFencedException(org.apache.kafka.common.errors.ProducerFencedException) UnsupportedForMessageFormatException(org.apache.kafka.common.errors.UnsupportedForMessageFormatException) Optional(java.util.Optional) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Handler(io.vertx.core.Handler) MockProducer(org.apache.kafka.clients.producer.MockProducer) Mockito.mock(org.mockito.Mockito.mock) BufferSerializer(io.vertx.kafka.client.serialization.BufferSerializer) VertxInternal(io.vertx.core.impl.VertxInternal) MockProducer(org.apache.kafka.clients.producer.MockProducer) ContextInternal(io.vertx.core.impl.ContextInternal) Future(io.vertx.core.Future) AsyncResult(io.vertx.core.AsyncResult) Map(java.util.Map) StringSerializer(org.apache.kafka.common.serialization.StringSerializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Truth.assertThat (com.google.common.truth.Truth.assertThat)1 AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 Promise (io.vertx.core.Promise)1 Buffer (io.vertx.core.buffer.Buffer)1 ContextInternal (io.vertx.core.impl.ContextInternal)1 VertxInternal (io.vertx.core.impl.VertxInternal)1 PromiseInternal (io.vertx.core.impl.future.PromiseInternal)1 KafkaProducer (io.vertx.kafka.client.producer.KafkaProducer)1 BufferSerializer (io.vertx.kafka.client.serialization.BufferSerializer)1 Map (java.util.Map)1 Optional (java.util.Optional)1 BiFunction (java.util.function.BiFunction)1 MockProducer (org.apache.kafka.clients.producer.MockProducer)1 KafkaException (org.apache.kafka.common.KafkaException)1 AuthorizationException (org.apache.kafka.common.errors.AuthorizationException)1 OutOfOrderSequenceException (org.apache.kafka.common.errors.OutOfOrderSequenceException)1 ProducerFencedException (org.apache.kafka.common.errors.ProducerFencedException)1 UnsupportedForMessageFormatException (org.apache.kafka.common.errors.UnsupportedForMessageFormatException)1