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