<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Running AS7 embedded in Arquillian
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/thomas.diesler%40jboss.com">Thomas Diesler</a> in <i>JBoss AS7 Development</i> - <a href="http://community.jboss.org/message/572225#572225">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>This post describes what I have done and have seen when running AS7 embedded in Arquillian. There is a large overlap with what Kabir has done with embedded AS7 so lets try to converge.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The <a class="jive-link-external-small" href="https://github.com/jbosgi/arquillian/blob/jbas7/containers/jbossas-embedded-7/src/main/java/org/jboss/arquillian/container/jbossas/embedded_7/JBossASEmbeddedContainer.java">JBossASEmbeddedContainer</a> the <a class="jive-link-external-small" href="https://github.com/jbosgi/jboss-as/blob/arquillian/server/src/main/java/org/jboss/as/server/StandaloneServerFactory.java">StandaloneServerFactory</a> and waits for the Arquillian MBean to become available</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Properties sysprops = new Properties();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sysprops.putAll(System.getProperties());<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sysprops.setProperty("jboss.home.dir", jbossHomeDir.getAbsolutePath());<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sysprops.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sysprops.setProperty("logging.configuration", "file:" + jbossHomeDir + "/standalone/configuration/logging.properties");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sysprops.setProperty("org.jboss.boot.log.file", jbossHomeDir + "/standalone/log/boot.log");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; server = StandaloneServerFactory.create(jbossHomeDir, sysprops);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; server.start();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The StandaloneServerFactory uses the <a class="jive-link-external-small" href="https://github.com/jbosgi/jboss-as/blob/arquillian/server/src/main/java/org/jboss/as/server/InitialModuleLoaderFactory.java">InitialModuleLoaderFactory</a> to bootstrap modules with a controlled set of packages from the app classpath. I agree with Jason, it is impossible to put stuff on the appclasspath and somehow hope the test deployemnts will behave like they would in a running server.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>For this to work in ARQ it is necessary that nothing initializes jdk logging before we have a chance to load the LoggingManager from the "org.jboss.logmanager" module. Therefore, I added a <a class="jive-link-external-small" href="https://github.com/jbosgi/arquillian/commit/6a7e152a1416a634047cf11178c7a901eee5d5cd">looging abstraction</a> to ARQ that allows you do disable or redirect ARQ logging to System.out</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-xml">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;plugin&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;artifactId&gt;</span>maven-surefire-plugin<span class="jive-xml-tag">&lt;/artifactId&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;configuration&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;systemProperties&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;property&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;name&gt;</span>java.util.logging.manager<span class="jive-xml-tag">&lt;/name&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;value&gt;</span>org.jboss.logmanager.LogManager<span class="jive-xml-tag">&lt;/value&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/property&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;property&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;name&gt;</span>arquillian.logging<span class="jive-xml-tag">&lt;/name&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;value&gt;</span>system<span class="jive-xml-tag">&lt;/value&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/property&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/systemProperties&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/configuration&gt;</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/plugin&gt;</span> 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The StandaloneServerFactory loads the server module and uses reflection and a proxy to bootstrap the server.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Currently, the server comes up and deployment fails with</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">12:46:07,295 ERROR [org.jboss.as.protocol.connection] (pool-1-thread-2) Failed to read a message: java.util.ServiceConfigurationError: org.jboss.marshalling.ProviderDescriptor: Provider org.jboss.marshalling.river.RiverProviderDescriptor could not be instantiated: java.lang.ClassCastException
&#160;&#160;&#160; at java.util.ServiceLoader.fail(ServiceLoader.java:207) [:1.6.0_21]
&#160;&#160;&#160; at java.util.ServiceLoader.access$100(ServiceLoader.java:164) [:1.6.0_21]
&#160;&#160;&#160; at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:353) [:1.6.0_21]
&#160;&#160;&#160; at java.util.ServiceLoader$1.next(ServiceLoader.java:421) [:1.6.0_21]
&#160;&#160;&#160; at org.jboss.marshalling.Marshalling.loadMarshallerFactory(Marshalling.java:78) [jboss-marshalling-1.3.0.CR8.jar:1.3.0.CR8]
&#160;&#160;&#160; at org.jboss.marshalling.Marshalling.getMarshallerFactory(Marshalling.java:74) [jboss-marshalling-1.3.0.CR8.jar:1.3.0.CR8]
&#160;&#160;&#160; at org.jboss.as.protocol.ProtocolUtils.&lt;clinit&gt;(ProtocolUtils.java:50) [jboss-as-protocol-7.0.0.Alpha1.jar:7.0.0.Alpha1]
&#160;&#160;&#160; at org.jboss.as.protocol.mgmt.ManagementProtocolHeader.read(ManagementProtocolHeader.java:75) [jboss-as-protocol-7.0.0.Alpha1.jar:7.0.0.Alpha1]
&#160;&#160;&#160; at org.jboss.as.protocol.mgmt.ManagementResponseHeader.read(ManagementResponseHeader.java:60) [jboss-as-protocol-7.0.0.Alpha1.jar:7.0.0.Alpha1]
&#160;&#160;&#160; at org.jboss.as.protocol.mgmt.ManagementProtocolHeader.&lt;init&gt;(ManagementProtocolHeader.java:55) [jboss-as-protocol-7.0.0.Alpha1.jar:7.0.0.Alpha1]
&#160;&#160;&#160; at org.jboss.as.protocol.mgmt.ManagementResponseHeader.&lt;init&gt;(ManagementResponseHeader.java:45) [jboss-as-protocol-7.0.0.Alpha1.jar:7.0.0.Alpha1]
&#160;&#160;&#160; at org.jboss.as.protocol.mgmt.ManagementRequest$1.handle(ManagementRequest.java:124) [jboss-as-protocol-7.0.0.Alpha1.jar:7.0.0.Alpha1]

</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>StandaloneServer is now an interface that also supports StandaloneServer.stop(). The idea is that the factory installs a service that can be used to bring down the server.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>To try this out you need to checkout these branches</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><a class="jive-link-external-small" href="https://github.com/jbosgi/arquillian/tree/jbas7" target="_blank">https://github.com/jbosgi/arquillian/tree/jbas7</a></p><p><a class="jive-link-external-small" href="https://github.com/jbosgi/jboss-as/tree/arquillian" target="_blank">https://github.com/jbosgi/jboss-as/tree/arquillian</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Build AS7 and in arquillian run</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code">mvn -Djboss.home=/home/tdiesler/git/jboss-as/build/target/jboss-7.0.0.Alpha2 -pl container/jbossas-embedded-7 -am install
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I'll talk this through with Kabir. So hopefully the demos and other smoke/integration tests can be embedded ARQ tests soon.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>cheers</p><p>-thomas</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/572225#572225">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS7 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>