Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
valdar committed Sep 5, 2023
1 parent fd44e1c commit 9016fb7
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
import org.apache.kafka.connect.runtime.Worker;
import org.apache.kafka.connect.runtime.WorkerInfo;
import org.apache.kafka.connect.runtime.isolation.Plugins;
import org.apache.kafka.connect.runtime.rest.RestClient;
import org.apache.kafka.connect.runtime.rest.RestServer;
import org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo;
import org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo;
import org.apache.kafka.connect.runtime.standalone.StandaloneConfig;
import org.apache.kafka.connect.runtime.standalone.StandaloneHerder;
import org.apache.kafka.connect.storage.FileOffsetBackingStore;
import org.apache.kafka.connect.util.ConnectUtils;
import org.apache.kafka.connect.util.FutureCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -127,10 +127,11 @@ private void init() {
Plugins plugins = new Plugins(standAloneProperties);

StandaloneConfig config = new StandaloneConfig(standAloneProperties);
String kafkaClusterId = ConnectUtils.lookupKafkaClusterId(config);
String kafkaClusterId = config.kafkaClusterId();
AllConnectorClientConfigOverridePolicy allConnectorClientConfigOverridePolicy = new AllConnectorClientConfigOverridePolicy();

RestServer rest = new RestServer(config);
RestClient restClient = new RestClient(config);
RestServer rest = new RestServer(config, restClient);
rest.initializeServer();

/*
Expand Down
42 changes: 13 additions & 29 deletions tests/itests-cxf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,16 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf-rest</artifactId>
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<artifactId>cxf-rt-transports-http-undertow</artifactId>
<version>${cxf-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
Expand All @@ -105,5 +83,11 @@
<artifactId>commons-io</artifactId>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.camel.kafkaconnector.cxf.sink;

import jakarta.xml.ws.Endpoint;

import org.apache.camel.kafkaconnector.cxf.services.JaxWsServiceConfigurator;
import org.apache.cxf.jaxws.EndpointImpl;

Expand Down
44 changes: 12 additions & 32 deletions tests/itests-cxfrs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,44 +54,24 @@

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf-soap</artifactId>
<artifactId>camel-cxf-rest</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf-rest</artifactId>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<scope>test</scope>
<artifactId>cxf-rt-transports-http-undertow</artifactId>
<version>${cxf-version}</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/
package org.apache.camel.kafkaconnector.cxfrs;

import javax.xml.bind.annotation.XmlRootElement;


import jakarta.xml.bind.annotation.XmlRootElement;
import org.apache.camel.util.ObjectHelper;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*/
package org.apache.camel.kafkaconnector.cxfrs;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Response;

// START SNIPPET: example
@Path("/customerservice/")
Expand Down
10 changes: 9 additions & 1 deletion tests/itests-hdfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
<exclusion>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<artifactId>camel-test-junit5</artifactId>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -109,6 +113,10 @@
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</exclusion>
<exclusion>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.camel.kafkaconnector.common.test.CamelSinkTestSupport;
import org.apache.camel.kafkaconnector.common.test.StringMessageProducer;
import org.apache.camel.kafkaconnector.hdfs.utils.HDFSEasy;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.infra.common.TestUtils;
import org.apache.camel.test.infra.hdfs.v2.services.HDFSService;
import org.apache.camel.test.infra.hdfs.v2.services.HDFSServiceFactory;
Expand All @@ -47,7 +48,7 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class CamelSinkHDFSITCase extends CamelSinkTestSupport {
@RegisterExtension
public static HDFSService hdfsService = HDFSServiceFactory.createSingletonService();
public static HDFSService hdfsService = HDFSServiceFactory.createSingletonService(AvailablePortFinder.getNextAvailable());

private static final Logger LOG = LoggerFactory.getLogger(CamelSinkHDFSITCase.class);

Expand Down
2 changes: 2 additions & 0 deletions tests/itests-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
</dependency>


</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import org.apache.camel.kafkaconnector.common.ConnectorPropertyFactory;
import org.apache.camel.kafkaconnector.common.test.CamelSinkTestSupport;
import org.apache.camel.kafkaconnector.common.utils.NetworkUtils;
import org.apache.http.impl.bootstrap.HttpServer;
import org.apache.http.impl.bootstrap.ServerBootstrap;
import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
import org.apache.hc.core5.io.CloseMode;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void setUp() throws IOException {
localServer = ServerBootstrap.bootstrap()
.setLocalAddress(localhost)
.setListenerPort(NetworkUtils.getFreePort())
.registerHandler("/ckc", validationHandler)
.register("/ckc", validationHandler)
.create();

localServer.start();
Expand All @@ -79,7 +80,7 @@ public void tearDown() {
try {
localServer.stop();
} finally {
localServer.shutdown(2, TimeUnit.SECONDS);
localServer.close(CloseMode.IMMEDIATE, org.apache.hc.core5.util.Timeout.ofSeconds(2L));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.util.EntityUtils;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.HttpRequestHandler;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.protocol.HttpContext;


class HTTPTestValidationHandler implements HttpRequestHandler {
private final List<String> replies = new ArrayList<>();
Expand All @@ -47,37 +48,36 @@ class HTTPTestValidationHandler implements HttpRequestHandler {
this.expected = expected;
}


@Override
public void handle(HttpRequest httpRequest, HttpResponse httpResponse, HttpContext httpContext) throws IOException {
public Future<List<String>> getReplies() throws InterruptedException {
lock.lock();
try {
HttpEntity entity = ((HttpEntityEnclosingRequest) httpRequest).getEntity();
String content = EntityUtils.toString(entity);

replies.add(content);
if (replies.size() == expected) {
receivedExpectedMessages.signal();
}
receivedExpectedMessages.await(10, TimeUnit.SECONDS);

httpResponse.setStatusCode(HttpStatus.SC_OK);
List<String> ret = new ArrayList<>(replies);
replies.clear();
return CompletableFuture.supplyAsync(() -> ret);
} finally {
lock.unlock();
}


}

public Future<List<String>> getReplies() throws InterruptedException {
@Override
public void handle(ClassicHttpRequest classicHttpRequest, ClassicHttpResponse classicHttpResponse, HttpContext httpContext) throws HttpException, IOException {
lock.lock();
try {
receivedExpectedMessages.await(10, TimeUnit.SECONDS);
HttpEntity entity = classicHttpRequest.getEntity();
String content = EntityUtils.toString(entity);

List<String> ret = new ArrayList<>(replies);
replies.clear();
return CompletableFuture.supplyAsync(() -> ret);
replies.add(content);
if (replies.size() == expected) {
receivedExpectedMessages.signal();
}

classicHttpResponse.setCode(HttpStatus.SC_OK);
} finally {
lock.unlock();
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.apache.camel.kafkaconnector.common.ConnectorPropertyFactory;
import org.apache.camel.kafkaconnector.common.services.mockweb.MockWebService;
import org.apache.camel.kafkaconnector.common.test.CamelSinkTestSupport;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand Down Expand Up @@ -112,7 +112,7 @@ protected void verifyMessages(CountDownLatch latch) throws InterruptedException
@Timeout(60)
public void testBasicSendReceive() throws Exception {
mockWebService.enqueueResponses(expect);
LOG.info("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: {}", toPath("client-truststore.jks"));
LOG.info("Trusted store path: {}", toPath("client-truststore.jks"));
String uri = mockServer.getHostName() + ":" + mockServer.getPort() + "/ckc";
ConnectorPropertyFactory connectorPropertyFactory = CamelHTTPSPropertyFactory.basic()
.withTopics(topicName)
Expand Down
7 changes: 7 additions & 0 deletions tests/itests-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
<artifactId>camel-mongodb</artifactId>
</dependency>

<!-- XXX: remove when https://github.com/apache/camel-kamelets/issues/1602 is released -->
<dependency>
<groupId>org.apache.camel.kamelets</groupId>
<artifactId>camel-kamelets-utils</artifactId>
<version>${camel.kamelet.catalog.version}</version>
</dependency>

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion tests/itests-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Session;

import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Loading

0 comments on commit 9016fb7

Please sign in to comment.