Skip to content

Commit

Permalink
Fix RocketMQ latestDepTest (open-telemetry#6731)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Sep 23, 2022
1 parent d26e456 commit 557c6d1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ dependencies {

tasks.withType<Test>().configureEach {
jvmArgs("-Dotel.instrumentation.rocketmq-client.experimental-span-attributes=true")

systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}
4 changes: 4 additions & 0 deletions instrumentation/rocketmq-client-4.8/library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ dependencies {

testImplementation(project(":instrumentation:rocketmq-client-4.8:testing"))
}

tasks.withType<Test>().configureEach {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ abstract class AbstractRocketMqClientTest extends InstrumentationSpecification {
configureMQProducer(producer)
consumer = BaseConf.getConsumer(BaseConf.nsAddr, sharedTopic, "*", tracingMessageListener)
configureMQPushConsumer(consumer)

// for RocketMQ 5.x wait a bit to ensure that consumer is properly started up
if (Boolean.getBoolean("testLatestDeps")) {
Thread.sleep(30_000)
}
}

def cleanupSpec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

package base;

import static java.util.Collections.emptyMap;

import io.opentelemetry.instrumentation.test.utils.PortUtils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.common.BrokerConfig;
Expand All @@ -23,7 +28,6 @@
import org.apache.rocketmq.remoting.netty.NettyClientConfig;
import org.apache.rocketmq.remoting.netty.NettyServerConfig;
import org.apache.rocketmq.store.config.MessageStoreConfig;
import org.apache.rocketmq.test.util.MQAdmin;
import org.junit.Assert;

public final class IntegrationTestBase {
Expand Down Expand Up @@ -128,7 +132,31 @@ public static BrokerController createAndStartBroker(
}

public static void initTopic(String topic, String nsAddr, String clusterName) {
MQAdmin.createTopic(nsAddr, clusterName, topic, 20);
try {
// RocketMQ 4.x
Class<?> mqAdmin = Class.forName("org.apache.rocketmq.test.util.MQAdmin");
Method createTopic =
mqAdmin.getMethod("createTopic", String.class, String.class, String.class, int.class);
createTopic.invoke(null, nsAddr, clusterName, topic, 20);
} catch (ClassNotFoundException
| InvocationTargetException
| NoSuchMethodException
| IllegalAccessException e) {

// RocketMQ 5.x
try {
Class<?> mqAdmin = Class.forName("org.apache.rocketmq.test.util.MQAdminTestUtils");
Method createTopic =
mqAdmin.getMethod(
"createTopic", String.class, String.class, String.class, int.class, Map.class);
createTopic.invoke(null, nsAddr, clusterName, topic, 20, emptyMap());
} catch (ClassNotFoundException
| InvocationTargetException
| NoSuchMethodException
| IllegalAccessException ex) {
throw new LinkageError("Could not initialize topic", ex);
}
}
}

private IntegrationTestBase() {}
Expand Down

0 comments on commit 557c6d1

Please sign in to comment.