Skip to content

Commit

Permalink
Execute test-infra services via Camel JBang
Browse files Browse the repository at this point in the history
Add non-test-jar dependency for component test-infra

Signed-off-by: Tom Cunningham <[email protected]>

Revert "Add non-test-jar dependency for component test-infra"

This reverts commit 954da18.

Add non-test-jar dependency for component test-infra

CAMEL-21452 Changes to xmpp/zookeeper

CAMEL-21452 Decouple the infrastructure from the testing API

CAMEL-21452 Decouple the infrastructure from the testing API

aws

azure

cassandra

chatscript

consul

couchbase

couchdb

elasticsearch

etcd3

fhir

ftp

jms/artemis

Create a test-jar that contain main and test classes

Align all components

let camel compile

Fix langchain4j compilation

Revert Jetty test-infra

Rebase

Execute test-infra with camel jbang

Add Camel JBang command

Fix camel jbang infra run

let mvnd compile

Sort import
  • Loading branch information
Croway committed Jan 10, 2025
1 parent bfadc5d commit 6a3840a
Show file tree
Hide file tree
Showing 82 changed files with 1,249 additions and 50 deletions.
6 changes: 0 additions & 6 deletions components/camel-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@
</dependency>

<!-- test infra -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-core</artifactId>
Expand Down
1 change: 1 addition & 0 deletions components/camel-solr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<description>Camel Solr Support</description>

<properties>
<skipITs.ppc64le>true</skipITs.ppc64le>
</properties>

<dependencies>
Expand Down
6 changes: 0 additions & 6 deletions components/camel-tahu/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@
</dependency>

<!-- test infra -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.apache.camel.test;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AvailablePort {
private static final Logger LOG = LoggerFactory.getLogger(AvailablePort.class);

/**
* Probe a port to see if it is free
*
* @param port an integer port number to be tested. If port is 0, then the next available port is
* returned.
* @throws IllegalStateException if the port is not free or, in case of port 0, if there are no ports available at
* all.
* @return the port number itself if the port is free or, in case of port 0, the first
* available port number.
*/
public static int probePort(InetAddress address, int port) {

try (ServerSocket ss = new ServerSocket()) {
ss.setReuseAddress(true);
ss.bind(new InetSocketAddress(address, port), 1);
int probedPort = ss.getLocalPort();
LOG.info("Available port is -> {}", probedPort);
return probedPort;
} catch (IOException e) {
throw new IllegalStateException("Cannot find free port", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
*/
package org.apache.camel.test;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -201,29 +197,7 @@ public static <T> int getSpecificPort(int portNumber, T failurePayload, Function
* available port number.
*/
public static int probePort(int port) {
return probePort(null, port);
}

/**
* Probe a port to see if it is free
*
* @param port an integer port number to be tested. If port is 0, then the next available port is
* returned.
* @throws IllegalStateException if the port is not free or, in case of port 0, if there are no ports available at
* all.
* @return the port number itself if the port is free or, in case of port 0, the first
* available port number.
*/
public static int probePort(InetAddress address, int port) {
try (ServerSocket ss = new ServerSocket()) {
ss.setReuseAddress(true);
ss.bind(new InetSocketAddress(address, port), 1);
int probedPort = ss.getLocalPort();
LOG.info("Available port is -> {}", probedPort);
return probedPort;
} catch (IOException e) {
throw new IllegalStateException("Cannot find free port", e);
}
return AvailablePort.probePort(null, port);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.test.infra.cassandra.services;
package org.apache.camel.spi.annotations;

public class CassandraLocalContainerService extends CassandraLocalContainerInfraService
implements CassandraService {
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target({ ElementType.TYPE })
public @interface InfraService {

Class service();

String[] serviceAlias();

String[] serviceImplementationAlias() default {};
}
15 changes: 15 additions & 0 deletions dsl/camel-jbang/camel-jbang-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@
<version>${jansi-version}</version>
</dependency>

<!-- test infra run -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-all</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import org.apache.camel.dsl.jbang.core.commands.config.ConfigSet;
import org.apache.camel.dsl.jbang.core.commands.config.ConfigUnset;
import org.apache.camel.dsl.jbang.core.commands.exceptionhandler.MissingPluginParameterExceptionHandler;
import org.apache.camel.dsl.jbang.core.commands.infra.InfraCommand;
import org.apache.camel.dsl.jbang.core.commands.infra.InfraList;
import org.apache.camel.dsl.jbang.core.commands.infra.InfraRun;
import org.apache.camel.dsl.jbang.core.commands.plugin.PluginAdd;
import org.apache.camel.dsl.jbang.core.commands.plugin.PluginCommand;
import org.apache.camel.dsl.jbang.core.commands.plugin.PluginDelete;
Expand Down Expand Up @@ -161,6 +164,9 @@ public static void run(CamelJBangMain main, String... args) {
.addSubcommand("get", new CommandLine(new VersionGet(main)))
.addSubcommand("set", new CommandLine(new VersionSet(main)))
.addSubcommand("list", new CommandLine(new VersionList(main))))
.addSubcommand("infra", new CommandLine(new InfraCommand(main))
.addSubcommand("list", new CommandLine(new InfraList(main)))
.addSubcommand("run", new CommandLine(new InfraRun(main))))
.setParameterExceptionHandler(new MissingPluginParameterExceptionHandler());

PluginHelper.addPlugins(commandLine, main, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.dsl.jbang.core.commands.infra;

import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import picocli.CommandLine;

@CommandLine.Command(name = "infra",
description = "List and Run external services for testing and prototyping")
public class InfraCommand extends CamelCommand {

static final ObjectMapper JSON_MAPPER = new ObjectMapper();
static final ObjectMapper YAML_MAPPER = new ObjectMapper(new YAMLFactory());

{
YAML_MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
YAML_MAPPER.registerModule(new JavaTimeModule());
YAML_MAPPER.registerModule(new Jdk8Module());
}

public InfraCommand(CamelJBangMain main) {
super(main);
}

@Override
public Integer doCall() throws Exception {
// defaults to list
new CommandLine(new InfraList(getMain())).execute();
return 0;
}

record TestInfraService(String service, String implementation, List<String> alias, List<String> aliasImplementation) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.dsl.jbang.core.commands.infra;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import picocli.CommandLine;

@CommandLine.Command(name = "list", description = "Displays available external services", sortOptions = false,
showDefaultValues = true)
public class InfraList extends CamelCommand {

public InfraList(CamelJBangMain main) {
super(main);
}

@Override
public Integer doCall() throws Exception {
Map<String, Set<String>> services = new HashMap<>();

List<InfraCommand.TestInfraService> metadata;

try (InputStream is
= this.getClass().getClassLoader().getResourceAsStream("META-INF/test-infra-metadata.json")) {
String json = new String(is.readAllBytes(), StandardCharsets.UTF_8);

metadata = InfraCommand.JSON_MAPPER.readValue(json, new TypeReference<List<InfraCommand.TestInfraService>>() {
});
}

for (InfraCommand.TestInfraService service : metadata) {
for (String alias : service.alias()) {
if (!services.containsKey(alias)) {
services.put(alias, new HashSet<>());
}

if (service.aliasImplementation() != null) {
for (String aliasImplementation : service.aliasImplementation()) {
services.get(alias).add(aliasImplementation);
}
}
}
}

printer().print(InfraCommand.YAML_MAPPER.writeValueAsString(services));
return 0;
}

}
Loading

0 comments on commit 6a3840a

Please sign in to comment.