Search in sources :

Example 1 with HttpBridgeError

use of io.strimzi.kafka.bridge.http.model.HttpBridgeError in project strimzi-kafka-bridge by strimzi.

the class ConsumerIT method consumerAlreadyExistsTest.

@Test
void consumerAlreadyExistsTest(VertxTestContext context) throws InterruptedException, ExecutionException, TimeoutException {
    String topic = "consumerAlreadyExistsTest";
    KafkaFuture<Void> future = adminClientFacade.createTopic(topic);
    String name = "my-kafka-consumer4";
    JsonObject json = new JsonObject();
    json.put("name", name);
    future.get();
    // create consumer
    consumerService().createConsumer(context, groupId, json);
    CompletableFuture<Boolean> create2Again = new CompletableFuture<>();
    // create the same consumer again
    consumerService().createConsumerRequest(groupId, json).sendJsonObject(json, ar -> {
        context.verify(() -> {
            assertThat(ar.succeeded(), is(true));
            HttpResponse<JsonObject> response = ar.result();
            HttpBridgeError error = HttpBridgeError.fromJson(response.body());
            assertThat(response.statusCode(), is(HttpResponseStatus.CONFLICT.code()));
            assertThat(error.getCode(), is(HttpResponseStatus.CONFLICT.code()));
            assertThat(error.getMessage(), is("A consumer instance with the specified name already exists in the Kafka Bridge."));
            context.completeNow();
        });
        create2Again.complete(true);
    });
    create2Again.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    CompletableFuture<Boolean> create3Again = new CompletableFuture<>();
    // create another consumer
    json.put("name", name + "diff");
    consumerService().createConsumerRequest(groupId, json).sendJsonObject(json, ar -> {
        context.verify(() -> {
            assertThat(ar.succeeded(), is(true));
            HttpResponse<JsonObject> response = ar.result();
            assertThat(response.statusCode(), is(HttpResponseStatus.OK.code()));
            JsonObject bridgeResponse = response.body();
            String consumerInstanceId = bridgeResponse.getString("instance_id");
            String consumerBaseUri = bridgeResponse.getString("base_uri");
            assertThat(consumerInstanceId, is(name + "diff"));
            assertThat(consumerBaseUri, is(Urls.consumerInstance(groupId, name) + "diff"));
        });
        create3Again.complete(true);
    });
    create3Again.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    consumerService().deleteConsumer(context, groupId, name);
    consumerService().deleteConsumer(context, groupId, name + "diff");
    context.completeNow();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) HttpBridgeError(io.strimzi.kafka.bridge.http.model.HttpBridgeError) Test(org.junit.jupiter.api.Test)

Example 2 with HttpBridgeError

use of io.strimzi.kafka.bridge.http.model.HttpBridgeError in project strimzi-kafka-bridge by strimzi.

the class ConsumerIT method offsetsConsumerDoesNotExist.

@Test
void offsetsConsumerDoesNotExist(VertxTestContext context) {
    // commit offsets
    JsonArray offsets = new JsonArray();
    JsonObject json = new JsonObject();
    json.put("topic", "offsetsConsumerDoesNotExist");
    json.put("partition", 0);
    json.put("offset", 10);
    offsets.add(json);
    JsonObject root = new JsonObject();
    root.put("offsets", offsets);
    consumerService().offsetsRequest(groupId, name, root).sendJsonObject(root, ar -> {
        context.verify(() -> {
            assertThat(ar.succeeded(), is(true));
            HttpResponse<JsonObject> response = ar.result();
            HttpBridgeError error = HttpBridgeError.fromJson(response.body());
            assertThat(response.statusCode(), is(HttpResponseStatus.NOT_FOUND.code()));
            assertThat(error.getCode(), is(HttpResponseStatus.NOT_FOUND.code()));
            assertThat(error.getMessage(), is("The specified consumer instance was not found."));
        });
        context.completeNow();
    });
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) HttpBridgeError(io.strimzi.kafka.bridge.http.model.HttpBridgeError) Test(org.junit.jupiter.api.Test)

Example 3 with HttpBridgeError

use of io.strimzi.kafka.bridge.http.model.HttpBridgeError in project strimzi-kafka-bridge by strimzi.

the class ConsumerIT method recordsConsumerDoesNotExist.

@Test
void recordsConsumerDoesNotExist(VertxTestContext context) {
    // consume records
    consumerService().consumeRecordsRequest(groupId, name, BridgeContentType.KAFKA_JSON_JSON).as(BodyCodec.jsonObject()).send(ar -> {
        context.verify(() -> {
            assertThat(ar.succeeded(), is(true));
            HttpResponse<JsonObject> response = ar.result();
            HttpBridgeError error = HttpBridgeError.fromJson(response.body());
            assertThat(response.statusCode(), is(HttpResponseStatus.NOT_FOUND.code()));
            assertThat(error.getCode(), is(HttpResponseStatus.NOT_FOUND.code()));
            assertThat(error.getMessage(), is("The specified consumer instance was not found."));
        });
        context.completeNow();
    });
}
Also used : JsonObject(io.vertx.core.json.JsonObject) HttpBridgeError(io.strimzi.kafka.bridge.http.model.HttpBridgeError) Test(org.junit.jupiter.api.Test)

Example 4 with HttpBridgeError

use of io.strimzi.kafka.bridge.http.model.HttpBridgeError in project strimzi-kafka-bridge by strimzi.

the class ConsumerIT method formatAndAcceptMismatch.

@Test
void formatAndAcceptMismatch(VertxTestContext context) throws InterruptedException, ExecutionException, TimeoutException {
    String topic = "formatAndAcceptMismatch";
    KafkaFuture<Void> future = adminClientFacade.createTopic(topic);
    future.get();
    String sentBody = "Simple message";
    basicKafkaClient.sendJsonMessagesPlain(topic, 1, sentBody, 0);
    // create consumer
    // subscribe to a topic
    consumerService().createConsumer(context, groupId, consumerJson).subscribeConsumer(context, groupId, name, topic);
    CompletableFuture<Boolean> consume = new CompletableFuture<>();
    // consume records
    consumerService().consumeRecordsRequest(groupId, name, BridgeContentType.KAFKA_JSON_BINARY).as(BodyCodec.jsonObject()).send(ar -> {
        context.verify(() -> {
            assertThat(ar.succeeded(), is(true));
            HttpResponse<JsonObject> response = ar.result();
            HttpBridgeError error = HttpBridgeError.fromJson(response.body());
            assertThat(response.statusCode(), is(HttpResponseStatus.NOT_ACCEPTABLE.code()));
            assertThat(error.getCode(), is(HttpResponseStatus.NOT_ACCEPTABLE.code()));
            assertThat(error.getMessage(), is("Consumer format does not match the embedded format requested by the Accept header."));
        });
        consume.complete(true);
    });
    consume.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    // consumer deletion
    consumerService().deleteConsumer(context, groupId, name);
    context.completeNow();
    assertThat(context.awaitCompletion(TEST_TIMEOUT, TimeUnit.SECONDS), is(true));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) HttpBridgeError(io.strimzi.kafka.bridge.http.model.HttpBridgeError) Test(org.junit.jupiter.api.Test)

Example 5 with HttpBridgeError

use of io.strimzi.kafka.bridge.http.model.HttpBridgeError in project strimzi-kafka-bridge by strimzi.

the class ConsumerIT method doNotRespondTooLongMessage.

@Test
void doNotRespondTooLongMessage(VertxTestContext context) throws InterruptedException, ExecutionException, TimeoutException {
    String topic = "doNotRespondTooLongMessage";
    KafkaFuture<Void> future = adminClientFacade.createTopic(topic);
    future.get();
    basicKafkaClient.sendStringMessagesPlain(topic, 1);
    JsonObject json = new JsonObject();
    json.put("name", name);
    // create consumer
    // subscribe to a topic
    consumerService().createConsumer(context, groupId, json).subscribeConsumer(context, groupId, name, topic);
    CompletableFuture<Boolean> consume = new CompletableFuture<>();
    // consume records
    consumerService().consumeRecordsRequest(groupId, name, null, 1, BridgeContentType.KAFKA_JSON_BINARY).as(BodyCodec.jsonObject()).send(ar -> {
        context.verify(() -> {
            assertThat(ar.succeeded(), is(true));
            HttpResponse<JsonObject> response = ar.result();
            HttpBridgeError error = HttpBridgeError.fromJson(response.body());
            assertThat(response.statusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
            assertThat(error.getCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
            assertThat(error.getMessage(), is("Response exceeds the maximum number of bytes the consumer can receive"));
        });
        consume.complete(true);
    });
    consume.get(TEST_TIMEOUT, TimeUnit.SECONDS);
    // consumer deletion
    consumerService().deleteConsumer(context, groupId, name);
    context.completeNow();
    assertThat(context.awaitCompletion(TEST_TIMEOUT, TimeUnit.SECONDS), is(true));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) HttpBridgeError(io.strimzi.kafka.bridge.http.model.HttpBridgeError) Test(org.junit.jupiter.api.Test)

Aggregations

HttpBridgeError (io.strimzi.kafka.bridge.http.model.HttpBridgeError)53 JsonObject (io.vertx.core.json.JsonObject)39 Test (org.junit.jupiter.api.Test)27 JsonArray (io.vertx.core.json.JsonArray)25 CompletableFuture (java.util.concurrent.CompletableFuture)19 Endpoint (io.strimzi.kafka.bridge.Endpoint)8 SinkBridgeEndpoint (io.strimzi.kafka.bridge.SinkBridgeEndpoint)6 Map (java.util.Map)6 AdminClientEndpoint (io.strimzi.kafka.bridge.AdminClientEndpoint)5 TopicPartition (io.vertx.kafka.client.common.TopicPartition)5 HashMap (java.util.HashMap)5 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)4 TextMap (io.opentracing.propagation.TextMap)4 ConsumerInstanceId (io.strimzi.kafka.bridge.ConsumerInstanceId)4 Span (io.opentracing.Span)3 SpanContext (io.opentracing.SpanContext)3 Tracer (io.opentracing.Tracer)3 SpanBuilder (io.opentracing.Tracer.SpanBuilder)3 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)3 GlobalTracer (io.opentracing.util.GlobalTracer)3