1

I want to deploy an EAR that is about 70MB big using Arquillian, but no matter what I do, I get:

Exception in thread "management-client-thread 1-1" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3236)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
at org.jboss.as.protocol.StreamUtils.copyStream(StreamUtils.java:52)
at org.jboss.as.controller.client.impl.InputStreamEntry$InMemoryEntry.initialize(InputStreamEntry.java:76)
at org.jboss.as.controller.client.impl.AbstractModelControllerClient$ReadAttachmentInputStreamRequestHandler$1.execute(AbstractModelControllerClient.java:193)
at org.jboss.as.protocol.mgmt.AbstractMessageHandler$2$1.doExecute(AbstractMessageHandler.java:283)
at org.jboss.as.protocol.mgmt.AbstractMessageHandler$AsyncTaskRunner.run(AbstractMessageHandler.java:504)
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 org.jboss.threads.JBossThread.run(JBossThread.java:122)

I tried:

EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class);
ear.addAsModules(Maven.resolver().loadPomFromFile("pom.xml")
        .resolve("org.acme:module1:war:?","org.acme:module2","org.acme:module3:war:?")
        .withoutTransitivity().asFile());

Then

EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class);
ear.addAsModules(new File("lib/module1-4.4.2.war"));
ear.addAsModules(new File("lib/module2-3.7.0.jar"));
ear.addAsModules(new File("lib/module3-3.7.war"));

And then

EnterpriseArchive ear = ShrinkWrap.createFromZipFile(EnterpriseArchive.class, new File(
        "../org.acme.project.ear/target/org.acme.project.ear.ear"));

Which brought an exception even Google didn't know (java.lang.UnsupportedOperationException: Multiple WebArchives found in org.acme.project.ear. Can not determine which to enrich), so I added:

ear.delete("/module1-4.4.2.war");
// AND / OR
ear.delete("/module3-3.7.war");

Which (depending on the modules I removed) either brought me back to the OutOfMemoryError or to an exception because of course now the application.xml of the EAR doesn't work with the new module list (and since the application.xml is dynamically created by Maven, there's now way I get a modified file into my Arquillian test harness).

And somewhere along the line I fiddled with the Xms and Xmx attributes in the arquillian.xml:

<container qualifier="jboss" default="true">
    <configuration>
        <property name="javaVmArguments">-Xms512m -Xmx1024m</property>
    </configuration>
</container>

The crux of the problem seems to be this one 50MB WAR, which I don't feel is that big, but evidently it is. What can I do to get my EAR to work?

Stefan S.
  • 3,950
  • 5
  • 25
  • 77

1 Answers1

4

Regarding the error java.lang.UnsupportedOperationException: Multiple WebArchives found in org.acme.project.ear. Can not determine which to enrich:

Arquillian has to add some libraries to the deployment (except for when @Deployment(testable = false) is used).

  • If an ear does not contain any web modules it will add a new test.war that contains the required libs and will trigger the tests from this context (in case the servlet protocol is used).
  • If the ear contains exactly one web module it will piggyback this one and add the required resources to this module and execute the tests in the context of this single web module.
  • Now with multiple web modules Arquillian doesn't know which web module to use and will not add an additional module. Instead in that case you have to mark one of the web modules as a Testable web module.

To mark module1 as the testable archive you would do this:

EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class);
ear.addAsModules(
    org.jboss.arquillian.container.test.api.Testable.archiveToTest(
        ShrinkWrap.createFromZipFile(WebArchive.class, new File("lib/module1-4.4.2.war"));
ear.addAsModules(new File("lib/module2-3.7.0.jar"));
ear.addAsModules(new File("lib/module3-3.7.war"));

Note: In fact you should see this error in the other cases as well if the OOM would not occur first.

Concerning the OOM I think you should increase the heap size of your test process, the heap size configured in the arquillian.xml will define the heap size of the JBoss server. But the OOM occurs even before the application is deployed at all. This might help you if you are using Maven: https://stackoverflow.com/a/16969122/2779488

Community
  • 1
  • 1
Robert Panzer
  • 1,419
  • 12
  • 14
  • Adding a dummy archive works as well (`ear.addAsModules(Testable.archiveToTest(ShrinkWrap.create(WebArchive.class)))`). – Stefan S. Jan 04 '16 at 12:45