Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for consumer name prefix (bridge ID) #296

Merged
merged 5 commits into from Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/main/java/io/strimzi/kafka/bridge/http/HttpBridge.java
Expand Up @@ -161,24 +161,13 @@ public void stop(Future<Void> stopFuture) throws Exception {

this.isReady = false;

//Consumers cleanup
this.httpBridgeContext.getHttpSinkEndpoints().forEach((consumerId, httpEndpoint) -> {
if (httpEndpoint != null) {
httpEndpoint.close();
}
});
this.httpBridgeContext.getHttpSinkEndpoints().clear();
// Consumers cleanup
this.httpBridgeContext.closeAllSinkBridgeEndpoints();

//producer cleanup
// producer cleanup
// for each connection, we have to close the connection itself but before that
// all the sink/source endpoints (so the related links inside each of them)
this.httpBridgeContext.getHttpSourceEndpoints().forEach((connection, endpoint) -> {

if (endpoint != null) {
endpoint.close();
}
});
this.httpBridgeContext.getHttpSourceEndpoints().clear();
this.httpBridgeContext.closeAllSourceBridgeEndpoints();

if (this.httpServer != null) {

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/io/strimzi/kafka/bridge/http/HttpBridgeContext.java
Expand Up @@ -56,4 +56,20 @@ public void setOpenApiOperation(HttpOpenApiOperations openApiOperation) {
public HttpOpenApiOperations getOpenApiOperation() {
return this.openApiOperation;
}

public void closeAllSinkBridgeEndpoints() {
for (Map.Entry<String, SinkBridgeEndpoint> sink: getHttpSinkEndpoints().entrySet()) {
if (sink.getValue() != null)
sink.getValue().close();
}
getHttpSinkEndpoints().clear();
}

public void closeAllSourceBridgeEndpoints() {
for (Map.Entry<HttpConnection, SourceBridgeEndpoint> source: getHttpSourceEndpoints().entrySet()) {
if (source.getValue() != null)
source.getValue().close();
}
getHttpSourceEndpoints().clear();
}
}
24 changes: 24 additions & 0 deletions src/test/java/io/strimzi/kafka/bridge/http/HttpBridgeTest.java
Expand Up @@ -74,6 +74,7 @@ class HttpBridgeTest extends KafkaClusterTestBase {
config.put(KafkaConfig.KAFKA_CONFIG_PREFIX + ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
config.put(KafkaConsumerConfig.KAFKA_CONSUMER_CONFIG_PREFIX + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
config.put(HttpConfig.HTTP_CONSUMER_TIMEOUT, timeout);
config.put(BridgeConfig.BRIDGE_ID, "my-bridge");
}

private static final String BRIDGE_HOST = "127.0.0.1";
Expand Down Expand Up @@ -3640,4 +3641,27 @@ void consumerDeletedAfterInactivity(VertxTestContext context) {
create.complete(true);
});
}

@Test
void createConsumerWithGeneratedName(VertxTestContext context) {
sknot-rh marked this conversation as resolved.
Show resolved Hide resolved
String groupId = "my-group";

JsonObject json = new JsonObject();

postRequest("/consumers/" + groupId)
.putHeader("Content-length", String.valueOf(json.toBuffer().length()))
.putHeader("Content-type", BridgeContentType.KAFKA_JSON)
.as(BodyCodec.jsonObject())
.sendJsonObject(json, ar -> {
context.verify(() -> {
assertTrue(ar.succeeded());
HttpResponse<JsonObject> response = ar.result();
assertEquals(HttpResponseStatus.OK.code(), response.statusCode());
JsonObject bridgeResponse = response.body();
String consumerInstanceId = bridgeResponse.getString("instance_id");
assertTrue(consumerInstanceId.startsWith(config.get(BridgeConfig.BRIDGE_ID).toString()));
});
context.completeNow();
});
}
}