亲爱的, 我正在尝试使用testcontainers和weld-unit和junit 5对Smallrye反应消息进行某种集成测试。这是我的测试代码:
@EnableWeld
public class MicroprofileReactiveMsgIT {
private static final KafkaContainer KAFKA = new KafkaContainer();
@Inject
@Channel("my-channel") Emitter<String> emitter;
@Inject
@Channel("kafka") Publisher<String> receiver;
@SuppressWarnings("unchecked")
@WeldSetup
public WeldInitiator weld = WeldInitiator.of(WeldInitiator.createWeld()
.addExtensions(ReactiveMessagingExtension.class));
@BeforeAll
public static void configureTestKafka() {
KAFKA.start();
System.setProperty("kafka.bootstrap.servers", KAFKA.getBootstrapServers());
System.out.println(KAFKA.getContainerId());
}
@AfterAll
public static void stopTestKafka() {
System.clearProperty("kafka.bootstrap.servers");
KAFKA.close();
}
@Test
public void testMessaging() {
final StringBuilder msg = new StringBuilder();
receiver.subscribe(new Subscriber<String>() {
@Override
public void onSubscribe(Subscription s) {
}
@Override
public void onNext(String t) {
msg.append(t);
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
});
emitter.send("Sending message one.");
Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> msg.length() > 0);
}
}
在进行单元测试时,出现以下错误:
由以下原因引起:org.jboss.weld.exceptions.UnsatisfiedResolutionException:WELD-001334:具有限定符的ChannelRegistry类型的依赖项不满足
在org.jboss.weld.bean.builtin.InstanceImpl.checkBeanResolved(InstanceImpl.java:241) 在org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:113) 在io.smallrye.reactive.messaging.extension.ReactiveMessagingExtension.afterDeploymentValidation(ReactiveMessagingExtension.java:65) 在java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在java.base / jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.base / java.lang.reflect.Method.invoke(Method.java:566) 在org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95) 在org.jboss.weld.injection.MethodInvocationStrategy $ SpecialParamPlusBeanManagerStrategy.invoke(MethodInvocationStrategy.java:187) 在org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330) 在org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:123) 在org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308) 在org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286) 在javax.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:124) 在org.jboss.weld.util.Observers.notify(Observers.java:166) 在org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285) 在org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273) 在org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:177) 在org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:171) 在org.jboss.weld.bootstrap.events.AbstractContainerEvent.fire(AbstractContainerEvent.java:53) 在org.jboss.weld.bootstrap.events.AbstractDeploymentContainerEvent.fire(AbstractDeploymentContainerEvent.java:35)
任何提示都会有用。我正在使用以下环境: