使用pax-exam karaf容器

时间:2015-05-04 15:05:39

标签: apache-karaf karaf pax-exam

我正在尝试使用pax-exam-container-karaf来测试OSGi包。在运行测试时,测试"挂起"几分钟然后"死了"除以下例外:

java.lang.RuntimeException: Cannot get the remote bundle context
    at org.ops4j.pax.exam.rbc.client.intern.RemoteBundleContextClientImpl.getRemoteBundleContext(RemoteBundleContextClientImpl.java:255)
    at org.ops4j.pax.exam.rbc.client.intern.RemoteBundleContextClientImpl.waitForState(RemoteBundleContextClientImpl.java:211)
    at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.waitForState(KarafTestContainer.java:528)
    at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.startKaraf(KarafTestContainer.java:214)
    at org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.start(KarafTestContainer.java:164)
    at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.setUp(EagerSingleStagedReactor.java:86)
    at org.ops4j.pax.exam.spi.reactors.EagerSingleStagedReactor.beforeClass(EagerSingleStagedReactor.java:136)
    at org.ops4j.pax.exam.spi.reactors.ReactorManager.beforeClass(ReactorManager.java:447)
    at org.ops4j.pax.exam.junit.impl.ProbeRunner.run(ProbeRunner.java:97)
    at org.ops4j.pax.exam.junit.PaxExam.run(PaxExam.java:93)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ...
Caused by: java.rmi.NotBoundException: a86ba245-b66b-498e-8752-05679dc9041b
    at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:166)
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:410) 
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:268)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$78(TCPTransport.java:683)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/1267686416.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at org.ops4j.pax.exam.rbc.client.intern.RemoteBundleContextClientImpl.getRemoteBundleContext(RemoteBundleContextClientImpl.java:242)
    ... 34 more

我将Pax-Exam配置为(使用debug == false):

@Configuration
public Option[] config() throws Exception {
    final boolean debug = ConfigurationHelper.getBoolean(
            "org.hibernate.testing.osgi.paxExam.debug",
            Environment.getProperties(),
            DEBUG
    );

    return options(
            when( debug ).useOptions( debugConfiguration( "5005", true ) ),
            karafDistributionConfiguration()
                    .frameworkUrl(
                            maven()
                                    .groupId( "org.apache.karaf" )
                                    .artifactId( "apache-karaf" )
                                    .type( "tar.gz" )
                                    .versionAsInProject()
                    )
                    .unpackDirectory( new File( "target/exam" ) )
                    .useDeployFolder( false ),
            configureConsole()
                    .ignoreLocalConsole()
                    .ignoreRemoteShell(),
            when( debug ).useOptions( keepRuntimeFolder() ),
            logLevel( LogLevelOption.LogLevel.INFO ),
            // avoiding additional boot features; specifically "enterprise"
            editConfigurationFilePut(
                    "etc/org.apache.karaf.features.cfg",
                    "featuresBoot",
                    "standard"
            ),
            features( hibernateKarafFeatureFile(), "hibernate-native", "hibernate-jpa" )
    );
}

我玩过上述配置的各种表现形式,但无法正常工作。

输出显示许多解决工件的问题,例如:

Caused by: shaded.org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact org.ops4j.pax.exam:pax-exam-features:xml:4.5.0

(不是我明确命名的^^),并且:

Caused by: shaded.org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact com.h2database:h2:jar:1.3.170

Caused by: shaded.org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact log4j:log4j:jar:1.2.17

更重要的是......我从未将这些内容解析为本地Maven缓存。 Karaf(由Pax Exam发起)是否远程找不到这些maven依赖项?我不能说wrt org.ops4j.pax.exam:pax-exam-features:xml:4.5.0,但是log4j和h2 jars以Maven Central中的名字存在。

任何想法我可能缺少什么?

0 个答案:

没有答案