运行WildFly Swarm Arquillian测试

时间:2016-10-11 00:36:09

标签: jboss-arquillian wildfly-swarm

(由https://issues.jboss.org/projects/SWARM/issues/SWARM-767引用)

我正在尝试使用Arquillian测试我的WildFly Swarm应用程序。我有一个自定义Main类用于我的Swarm和自定义部署。当我尝试运行我的测试时,我在maven的某些第三方库上收到ClassNotFoundException。

首先,这是我的测试:

@RunWith(Arquillian.class)
public class PasswordStorageTest {

    @CreateSwarm
    public static Swarm createSwarm() {
        return TestBuilder.createSwarm();
    }

    @Deployment
    public static WARArchive createDeployment() {
        return TestBuilder.createDeployment();
    }

    @Test
    public void testHashesAreUnique() throws PasswordStorage.CannotPerformOperationException {
        String password = UUID.randomUUID().toString();
        String hash1 = PasswordStorage.createHash(password);
        String hash2 = PasswordStorage.createHash(password);

        assertNotEquals("Hashes were not unique.", hash1, hash2);
    }

    @Test
    public void testVerifyPassword() throws PasswordStorage.CannotPerformOperationException, PasswordStorage.InvalidHashException {
        String password = UUID.randomUUID().toString();
        String hash = PasswordStorage.createHash(password);

        assertTrue("Password verification failed.", PasswordStorage.verifyPassword(password, hash));
    }

}

TestBuilder.createSwarm()TestBuilder.createDeployment()分别只调用这些方法:

public static Swarm buildSwarm() throws Exception {
    Swarm swarm = new Swarm();
    //Configure PostgreSQLDS
    swarm.fraction(new DatasourcesFraction()
            .jdbcDriver("org.postgresql", (d) -> {
                d.driverClassName("org.postgresql.Driver");
                d.xaDatasourceClass("org.postgresql.xa.PGXADataSource");
                d.driverModuleName("org.postgresql");
            })
            .dataSource("PostgreSQLDS", (ds) -> {
                ds.driverName("org.postgresql");
                ds.connectionUrl(System.getenv("JDBC_DATABASE_URL"));
                ds.userName(System.getenv("JDBC_DATABASE_USERNAME"));
                ds.password(System.getenv("JDBC_DATABASE_PASSWORD"));
            })
    );
    //Enable Infinispan Caching
    swarm.fraction(InfinispanFraction.createDefaultFraction());
    //Set Default Datasource
    swarm.fraction(new JPAFraction()
            .defaultDatasource("java:jboss/datasources/PostgreSQLDS"));
    return swarm;
}

public static WARArchive buildDeployment() throws Exception {
    WARArchive deployment = ShrinkWrap.create(WARArchive.class);
    deployment.addModule("org.postgresql");
    //Add all classes
    deployment.addPackages(true, "com.example.myapp");
    //Add all resources
    recursiveAddAsClassesResource(deployment, RESOURCES);
    //Add all web files
    recursiveAddAsWebResource(deployment, WEB);
    //Add all Maven dependencies
    deployment.addAllDependencies();
    return deployment;
}

当我运行测试时,WildFly Swarm启动就好了,但是一旦部署部署,我就会收到此错误:

2016-10-10 18:31:03,841 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."a0fdd090-cd55-4063-be86-23f6331f73f0.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."a0fdd090-cd55-4063-be86-23f6331f73f0.war".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment "a0fdd090-cd55-4063-be86-23f6331f73f0.war"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    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)
Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class com.example.myapp.core.domain.services.FileService with ClassLoader ModuleClassLoader for Module "deployment.a0fdd090-cd55-4063-be86-23f6331f73f0.war:main" from Service Module Loader
    at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)
    at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:106)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:91)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:76)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)
    ... 5 more
Caused by: java.lang.NoClassDefFoundError: net/coobird/thumbnailator/geometry/Position
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredFields(Class.java:1916)
    at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:72)
    at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
    ... 10 more
Caused by: java.lang.ClassNotFoundException: net.coobird.thumbnailator.geometry.Position from [Module "deployment.a0fdd090-cd55-4063-be86-23f6331f73f0.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
    ... 15 more

我删除了引用net/coobird/thumbnailator/geometry/Position的代码,然后在不同的库中遇到了类似的错误。似乎图书馆根本就没有被包括在内。

可能相关,我在部署开始时也会收到大量这些消息:(但是,即使在正常运行应用程序时它们也会出现,并且在应用程序加载完全正常时不会出现任何问题)

WFLYSRV0059: Class Path entry file:/C:/Users/mitch/.m2/repository/net/coobird/thumbnailator/0.4.8/thumbnailator-0.4.8.jar in /C:/a0fdd090-cd55-4063-be86-23f6331f73f0.war/WEB-INF/lib/classpath.jar  does not point to a valid jar for a Class-Path reference.
WFLYSRV0059: Class Path entry file:/C:/Users/mitch/.m2/repository/com/sparkpost/sparkpost-lib/0.16.1/sparkpost-lib-0.16.1.jar in /C:/a0fdd090-cd55-4063-be86-23f6331f73f0.war/WEB-INF/lib/classpath.jar  does not point to a valid jar for a Class-Path reference.

这让我感到困惑,特别是因为如果我在testable = false上设置@Deployment,那么它运行得非常好;但是,由于测试现在在容器外运行,我无法使用我需要的CDI注射。

我可以提供更多所需信息。我不知道从哪里开始。

0 个答案:

没有答案