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"));
}
Aggregations