(Referenced by https://issues.jboss.org/projects/SWARM/issues/SWARM-767)
I am trying to test my WildFly Swarm application using Arquillian. I have a custom Main
class for my Swarm, and a custom deployment. When I attempt to run my tests, I receive a ClassNotFoundException on some third party libraries from maven.
First of all, here is my test:
@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()
and TestBuilder.createDeployment()
simply call these methods, respectively:
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;
}
When I run the test, WildFly Swarm starts up just fine, but as soon as the deployment is deployed, I receive this error:
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
I removed the code that references net/coobird/thumbnailator/geometry/Position
, and then got a similar error with a different library. It seems like the libraries are just not being included at all.
Possibly related, I also receive a ton of these messages on deployment start: (However, they appear even when running the app normally, and cause no problems as the app loads perfectly fine)
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.
This is confusing me, especially because if I set testable = false
on @Deployment
, then it runs perfectly fine; however, since the test is now running outside the container, I can't use CDI injections, which I need.
I can provide any more info needed. I don't know where to go from here.