-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: moves ActiveMQ to docker based tests
Signed-off-by: Adrian Cole <[email protected]>
- Loading branch information
Adrian Cole
committed
Dec 13, 2023
1 parent
9ca8a6c
commit cfceb8b
Showing
5 changed files
with
162 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
activemq-client/src/test/java/zipkin2/reporter/activemq/ActiveMQExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2016-2023 The OpenZipkin Authors | ||
* | ||
* Licensed 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 zipkin2.reporter.activemq; | ||
|
||
import java.time.Duration; | ||
import org.apache.activemq.ActiveMQConnectionFactory; | ||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.opentest4j.TestAbortedException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
import static org.testcontainers.utility.DockerImageName.parse; | ||
|
||
class ActiveMQExtension implements BeforeAllCallback, AfterAllCallback { | ||
static final Logger LOGGER = LoggerFactory.getLogger(ActiveMQExtension.class); | ||
static final int ACTIVEMQ_PORT = 61616; | ||
|
||
ActiveMQContainer container = new ActiveMQContainer(); | ||
|
||
@Override public void beforeAll(ExtensionContext context) { | ||
if (context.getRequiredTestClass().getEnclosingClass() != null) { | ||
// Only run once in outermost scope. | ||
return; | ||
} | ||
|
||
container.start(); | ||
LOGGER.info("Using brokerURL " + brokerURL()); | ||
} | ||
|
||
@Override public void afterAll(ExtensionContext context) { | ||
if (context.getRequiredTestClass().getEnclosingClass() != null) { | ||
// Only run once in outermost scope. | ||
return; | ||
} | ||
|
||
container.stop(); | ||
} | ||
|
||
ActiveMQSender.Builder newSenderBuilder(String queue) { | ||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); | ||
connectionFactory.setBrokerURL(brokerURL()); | ||
return ActiveMQSender.newBuilder().queue(queue).connectionFactory(connectionFactory); | ||
} | ||
|
||
String brokerURL() { | ||
return "failover:tcp://" + container.getHost() + ":" + container.getMappedPort(ACTIVEMQ_PORT); | ||
} | ||
|
||
// mostly waiting for https://github.com/testcontainers/testcontainers-java/issues/3537 | ||
static final class ActiveMQContainer extends GenericContainer<ActiveMQContainer> { | ||
ActiveMQContainer() { | ||
super(parse("openzipkin/zipkin-activemq:test")); | ||
if ("true".equals(System.getProperty("docker.skip"))) { | ||
throw new TestAbortedException("${docker.skip} == true"); | ||
} | ||
withExposedPorts(ACTIVEMQ_PORT); | ||
waitStrategy = Wait.forListeningPorts(ACTIVEMQ_PORT); | ||
withStartupTimeout(Duration.ofSeconds(60)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="WARN"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |