diff --git a/containers/pax-exam-container-karaf/src/main/java/org/ops4j/pax/exam/karaf/container/internal/KarafTestContainer.java b/containers/pax-exam-container-karaf/src/main/java/org/ops4j/pax/exam/karaf/container/internal/KarafTestContainer.java index 54b0ec727..9014a6983 100644 --- a/containers/pax-exam-container-karaf/src/main/java/org/ops4j/pax/exam/karaf/container/internal/KarafTestContainer.java +++ b/containers/pax-exam-container-karaf/src/main/java/org/ops4j/pax/exam/karaf/container/internal/KarafTestContainer.java @@ -38,6 +38,7 @@ import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; +import java.rmi.server.ExportException; import java.rmi.server.UnicastRemoteObject; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -229,7 +230,7 @@ private int openRegistryOnFreePort(String host, int minPort, int maxPort) throws LOGGER.info("Created RMI registry server on {}:{}", host, port); return port; } catch (RemoteException ex) { - if (ex.detail instanceof BindException) { + if (ex instanceof ExportException || ex.detail instanceof BindException) { LOGGER.trace("Tried to open RMI registry on {}: {} but failed.", host, port, ex); if (port >= maxPort) { throw ex; diff --git a/containers/pax-exam-container-karaf/src/test/java/org/ops4j/pax/exam/karaf/container/Karaf4MultipleTestContainersITest.java b/containers/pax-exam-container-karaf/src/test/java/org/ops4j/pax/exam/karaf/container/Karaf4MultipleTestContainersITest.java new file mode 100644 index 000000000..080cf2ecb --- /dev/null +++ b/containers/pax-exam-container-karaf/src/test/java/org/ops4j/pax/exam/karaf/container/Karaf4MultipleTestContainersITest.java @@ -0,0 +1,57 @@ +/* + * 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.ops4j.pax.exam.karaf.container; + +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.karaf.options.LogLevelOption; +import org.ops4j.pax.exam.options.MavenArtifactUrlReference; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; + +import java.io.File; + +import static org.ops4j.pax.exam.CoreOptions.maven; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel; + +@ExamReactorStrategy(PerClass.class) +public class Karaf4MultipleTestContainersITest extends Karaf4TestContainerITest { + + private final MavenArtifactUrlReference KARAF_URL = maven("org.apache.karaf", "apache-karaf").type("zip"); + + @Configuration + public Option[] config() { + String karafVersion = karafVersion(); + return new Option[] { + karafDistributionConfiguration() + .frameworkUrl(KARAF_URL.version(karafVersion)) + .karafVersion(karafVersion) + .useDeployFolder(false) + .unpackDirectory(new File("target/paxexam/unpack/")), + karafDistributionConfiguration() + .frameworkUrl(KARAF_URL.version(karafVersion)) + .karafVersion(karafVersion) + .useDeployFolder(false) + .unpackDirectory(new File("target/paxexam/unpack/second/")), + configureConsole().startLocalConsole().ignoreRemoteShell(), + logLevel(LogLevelOption.LogLevel.INFO) + }; + } +}