Filtering environment specific configuration files
TweetPosted on Tuesday Mar 04, 2014 at 04:45PM in Technology
Environment
- Apache Maven 3.1.1
- Jenkins 1.551
- Eclipse Kepler SR1
- Oracle JDK7u51
- PostgreSQL 9.2.4
- OS X 10.9.2
Requirement
- I'm searching an appropriate way to define environment specific configuration.
- I don't want to create separate files for each environment.
- I don't want to define environment specific information on pom.xml.
Where to define?
- There are some candidates for achieve it with Maven.
- Maven Properties
- Maven can reference it as ${name}.
- Java System Properties
- Maven can reference it as ${name}.
- Environment Variables
- Maven can reference it as ${env.name}.
- Maven Properties
Maven Properties
- User-local properties are can be defined on ~/.m2/settings.xml
- It's easy to define on Jenkins jobs through configuration of MAVEN_OPTS.
- We can specify it like: “-Dname=value”
- We have to take care on Eclipse to make sure select a profile explicitly.
- activeByDefault won't work on some cases[8].
- I go with this way at this time.
Java System Properties
- We need to define it through arguments of java command.
- It's annoying to define on Eclipse.
- I can't found any way on define globally for Run Configuration.
- Thus, I have to configure it for each programs. It's pretty annoying.
- It's easy to define it on Jenkins jobs through configuration of MAVEN_OPTS.
- We can specify it like: “-Dname=value”
Environment Variables
- We need to define it through platform-specific way.
- But any programs can reference it through cross-platform way.
- I guess it's more cross-platform way than Java System Properties.
- We need a plugin[2] for Jenkins to define environment variables in jobs.
- I guess it's not bad to achieve it.
- But it's might not a good idea to storing security informations such as password.
Sample
- This sample executes simple SQL which acquires the name of connected database.
- Assume PostgreSQL is running at localhost:5432 and database named “kyle”, “testdb”, “testdb001” are exists.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.nailedtothex</groupId> <artifactId>mavenprops</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build> <dependencies> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.3-1100-jdbc41</version> </dependency> </dependencies> </project>
~/.m2/settings.xml
- This defines variables of the development environment with Eclipse.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <profiles> <profile> <id>development</id> <properties> <hogeApp.jdbc.url>jdbc:postgresql://localhost:5432/kyle</hogeApp.jdbc.url> <hogeApp.jdbc.user>kyle</hogeApp.jdbc.user> <hogeApp.jdbc.password>***</hogeApp.jdbc.password> </properties> </profile> </profiles> </settings>
Activate the profile on Eclipse explicitly
Right-click the project - Maven - Select Maven Profiles
Check “development” - OK
main/resources/jdbc.properties
url=${hogeApp.jdbc.url} user=${hogeApp.jdbc.user} password=${hogeApp.jdbc.password}
Main.java
package mavenprops; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Properties; public class Main { public static void main(String[] args) throws Exception { Properties info = new Properties(); try (InputStream is = Main.class.getResourceAsStream("/jdbc.properties")) { info.load(is); } try (Connection cn = DriverManager.getConnection(info.getProperty("url"), info); Statement st = cn.createStatement(); ResultSet rs = st.executeQuery("select current_database()")) { rs.next(); System.out.println("current_database(): " + rs.getString(1)); } } }
Run
Run on Eclipse
current_database(): kyle
- The database specified in ~/.m2/settings.xml is shown.
Run from command-line
kyle-no-MacBook:mavenprops kyle$ mvn clean compile exec:java -Dexec.mainClass="mavenprops.Main" -DhogeApp.jdbc.url=jdbc:postgresql://localhost:5432/testdb -DhogeApp.jdbc.user=kyle -DhogeApp.jdbc.password=*** Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building mavenprops 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mavenprops --- [INFO] Deleting /Users/kyle/Documents/workspace/mavenprops/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenprops --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ mavenprops --- [INFO] Compiling 1 source file to /Users/kyle/Documents/workspace/mavenprops/target/classes [INFO] [INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ mavenprops >>> [INFO] [INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ mavenprops <<< [INFO] [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ mavenprops --- current_database(): testdb [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.333s [INFO] Finished at: Tue Mar 04 18:25:25 JST 2014 [INFO] Final Memory: 13M/245M [INFO] ------------------------------------------------------------------------ kyle-no-MacBook:mavenprops kyle$
- The database specified at the command-line arguments is shown.
kyle-no-MacBook:mavenprops kyle$ cat target/classes/jdbc.properties url=jdbc:postgresql://localhost:5432/testdb user=kyle password=***
- Filter worked as expectedly.
How to apply this method on Jenkins job
- We can specify the variables on the configure of the job like this:
Build log
<===[JENKINS REMOTING CAPACITY]===>channel started log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter). log4j:WARN Please initialize the log4j system properly. Executing Maven: -B -f /Users/Shared/Jenkins/Home/jobs/MavenProps/workspace/mavenprops/pom.xml clean compile exec:java [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building mavenprops 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mavenprops --- [INFO] Deleting /Users/Shared/Jenkins/Home/jobs/MavenProps/workspace/mavenprops/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenprops --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ mavenprops --- [INFO] Compiling 1 source file to /Users/Shared/Jenkins/Home/jobs/MavenProps/workspace/mavenprops/target/classes [INFO] [INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ mavenprops >>> [WARNING] Failed to getClass for org.codehaus.mojo.exec.ExecJavaMojo [INFO] [INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ mavenprops <<< [INFO] [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ mavenprops --- current_database(): testdb001 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.472s [INFO] Finished at: Tue Mar 04 19:08:39 JST 2014 [INFO] Final Memory: 15M/245M [INFO] ------------------------------------------------------------------------ [JENKINS] Archiving /Users/Shared/Jenkins/Home/jobs/MavenProps/workspace/mavenprops/pom.xml to org.nailedtothex/mavenprops/0.0.1-SNAPSHOT/mavenprops-0.0.1-SNAPSHOT.pom channel stopped Finished: SUCCESS
- The database specified at configured in the job is shown.
jdbc.properties on the workspace of Jenkins
- Filter worked expectedly.
References
- フィルタリング
- EnvInject Plugin - Jenkins - Jenkins Wiki
- Setting the system-wide PATH environment variable in Mavericks - Ask Different
- HowTo: Set an Environment Variable in Mac OS X - /etc/launchd.conf - Dowd and Associates
- Maven Settings Example - Users | Community
- maven-war-pluginで環境ごとの設定ファイルを管理してみた - Challenge Java EE !
- I can't get maven to use properties defined in ~/.m2/settings.xml? - Stack Overflow
- Happy Wide Grove: Eclipse+maven+m2e+JavaFX2
Tags: maven
Comparison of 2 ways of integration testing: Arquillian and Remote EJB
TweetPosted on Tuesday Mar 04, 2014 at 06:51AM in Technology
Arquillian
Pros
- It enables us to testing of all kind of beans or methods.
- CDI Managed Beans
- EJBs that have only no interface view or local interface
- Methods what returns/receives object which not serializable
- everything
- There are many various ways of manipulating testing package.
- e.g. adding data source definition or persistence descriptor (persistence.xml) for testing purpose is easy because of useful ShrinkWrap.
- We can keep the package for testing deployment smaller.
- We can create smaller deployment package which contains only necessary resources for each test case.
Cons
- It needs deployment for each test execution.
- It brings longer deployment time for some cases. if you can keep test packages smaller or you can use faster embedded containers, you might think that it's not problem at all.
- When I want to execute all of test classes, It will execute deployment many times (same as numbers of test classes). I guess it's inefficient.
- Also there are some ways to avoid it such as creating delegate test classes, but I think it's annoying.
- It takes some times for making test package.
- It gives us great ability to manipulate test package with ShrinkWrap, but it takes some time for making test package. it needs to make WAR or EAR through scanning all necessary classes and dependencies (jar files), for each test execution.
- Dependency resolving is annoying.
- We can manipulate what testing package contains completely with Arquillian, but I guess it's annoying for some cases.
- I have tried to resolve dependencies through Arquillian's Maven Plug-in API, but sometimes I got unexpected result which different with standalone Maven (such as exclusion, etc), and resolving is need to be executed for each test execution.
- We have to include testing dependencies such as Mockito or DBUnit on the deployment.
- I know it's not a problem for many cases, I just feel it is not likely to me. I guess that these are not required on the server-side.
Remote EJB
Pros
- We can control the time of deployment completely.
- We can execute many test classes for deployment only once.
- It reduces many deployment time and test execution time for some cases.
- We can do testing against pure production resources.
- We don't need to another preparation of testing packages through resolving resources and dependencies.
- It depends on only more simply and standardized technologies.
- We don't need to mark @RunWith(Arquillian.class) on test classes.
- All we need is just lookup the remote bean on the method marked @Before, and invoke target method.
Cons
- Testable resources are limited on EJBs that have remote interface.
- We can't test CDI Managed Beans on this way.
- All of method parameters and return object are need to be serializable.
- Also larger serializable objects in the test would make testing performance worse.
- We have to create remote interfaces for beans that needs to be tested.
- It's annoying, and remote interfaces are unnecessary for production environment at some occasions.
- EJBs are considered as heavier than CDI Managed Beans.
- Performance of remote EJB lookups may vary between environments.
- I experienced that it takes 1 second or more with GlassFish3.
- Now I'm using WildFly 8.0.0Final, it takes only some milli-seconds.
- We have to deploy the whole application package for every testing.
- Larger application needs more time for deployment.
- So, we have to keep the size of projects at appropriate size.
Conclusion and how to overcome cons
- I prefer Remote EJB at present time.
- Annoying preparation of remote interfaces are not pain as much to me.
- we can make remote interfaces this way, it needs only small amount of additional code:
public interface BusinessDayUtil { boolean isBusinessDay(Date date); Date addDays(Date date, int days); @javax.ejb.Remote interface Remote extends BusinessDayUtil { } @javax.ejb.Local interface Local extends BusinessDayUtil { } }
- Implementation class:
@Stateless public class BusinessDayUtilImpl implements BusinessDayUtil.Local, BusinessDayUtil.Remote { ...
- And we can inject the bean through local-view easily:
public class MyJobOperatorImpl implements JobOperator { @Inject BusinessDayUtil.Local businessDayUtil; ...
- We don't want to EJBs to wrapping Exceptions with EJBException at some occasions.
- It can avoid on application classes with annotate @ApplicationException
- Also can achieve on API classes through placement of ejb-jar.xml.
- I know it's a sidetracking topic, but I wrote for just a note for me.
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"> <assembly-descriptor> <application-exception> <exception-class>javax.persistence.NoResultException</exception-class> <rollback>true</rollback> </application-exception> </assembly-descriptor> </ejb-jar>
- Making all of arguments and return object serializable is impossible at some occasions.
- Such as use of InputStream or OutputStream
- But I guess we can take the old way which stick with plain JUnit testing with mocking frameworks, at such occasions.
Tags: test
Avoiding EJBException wrapping
TweetPosted on Sunday Mar 02, 2014 at 03:33PM in Technology
How to avoid EJBException wrapping.
Environment
- WildFly 8.0.0.Final
- Oracle JDK7u51
How?
- We can avoid EJBException wrapping with @ApplicationException annotation.
- Also API classes (e.g. NoResultException) can be specified in WEB-INF/ejb-jar.xml.
Project
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.nailedtothex</groupId> <artifactId>avoidejbexception</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <failOnMissingWebXml>false</failOnMissingWebXml> </properties> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> </dependencies> </project>
Stateless Session Bean
package org.nailedtothex.ex; import javax.ejb.Stateless; import javax.persistence.NoResultException; @Stateless public class MyEJB { public void throwIllegalArgumentException(){ throw new IllegalArgumentException(); } public void throwNoResultException(){ throw new NoResultException(); } public void throwMyApplicationException(){ throw new MyApplicationException(); } }
Servlet
package org.nailedtothex.ex; import java.io.IOException; import javax.inject.Inject; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/*") public class MyServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Inject MyEJB myEJB; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringBuilder sb = new StringBuilder(); try{ myEJB.throwNoResultException(); }catch(Exception e){ sb.append("throwNoResultException() thrown: ").append(e.getClass()).append('\n'); } try{ myEJB.throwIllegalArgumentException(); }catch(Exception e){ sb.append("throwIllegalArgumentException() thrown: ").append(e.getClass()).append('\n'); } try{ myEJB.throwMyApplicationException(); }catch(Exception e){ sb.append("throwMyApplicationException() thrown: ").append(e.getClass()); } System.out.println(sb); } }
MyApplicationException
package org.nailedtothex.ex; import java.io.Serializable; import javax.ejb.ApplicationException; @ApplicationException public class MyApplicationException extends RuntimeException implements Serializable { private static final long serialVersionUID = 1L; }
/WEB-INF/ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"> <assembly-descriptor> <application-exception> <exception-class>javax.persistence.NoResultException</exception-class> <rollback>true</rollback> </application-exception> </assembly-descriptor> </ejb-jar>
- Taken from [1].
Log
16:21:39,152 INFO [stdout] (default task-13) throwNoResultException() thrown: class javax.persistence.NoResultException 16:21:39,152 INFO [stdout] (default task-13) throwIllegalArgumentException() thrown: class javax.ejb.EJBException 16:21:39,153 INFO [stdout] (default task-13) throwMyApplicationException() thrown: class org.nailedtothex.ex.MyApplicationException
Whole Log
16:21:39,146 ERROR [org.jboss.as.ejb3.invocation] (default task-13) JBAS014134: EJB Invocation failed on component MyEJB for method public void org.nailedtothex.ex.MyEJB.throwIllegalArgumentException(): javax.ejb.EJBException: java.lang.IllegalArgumentException at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:340) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326) at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:448) at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326) at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185) at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73) at org.nailedtothex.ex.MyEJB$$$view1064.throwIllegalArgumentException(Unknown Source) [classes:] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_51] at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_51] at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:401) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:99) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] at org.jboss.weld.bean.proxy.InjectionPointPropagatingEnterpriseTargetBeanInstance.invoke(InjectionPointPropagatingEnterpriseTargetBeanInstance.java:65) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] at org.nailedtothex.ex.MyEJB$Proxy$_$$_Weld$EnterpriseProxy$.throwIllegalArgumentException(Unknown Source) [classes:] at org.nailedtothex.ex.MyServlet.doGet(MyServlet.java:30) [classes:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final] at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final] at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687) [undertow-core-1.0.0.Final.jar:1.0.0.Final] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_51] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_51] at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51] Caused by: java.lang.IllegalArgumentException at org.nailedtothex.ex.MyEJB.throwIllegalArgumentException(MyEJB.java:10) [classes:] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_51] at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_51] at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407) at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82) [wildfly-weld-8.0.0.Final.jar:8.0.0.Final] at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93) [wildfly-weld-8.0.0.Final.jar:8.0.0.Final] at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407) at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23] at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83) [wildfly-weld-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final] ... 70 more 16:21:39,152 INFO [stdout] (default task-13) throwNoResultException() thrown: class javax.persistence.NoResultException 16:21:39,152 INFO [stdout] (default task-13) throwIllegalArgumentException() thrown: class javax.ejb.EJBException 16:21:39,153 INFO [stdout] (default task-13) throwMyApplicationException() thrown: class org.nailedtothex.ex.MyApplicationException
- Stacktraces of application exception were not logged.
Specifying java.lang.RuntimeException as an application exception in ejb-jar.xml
log
16:26:13,256 INFO [stdout] (default task-12) throwNoResultException() thrown: class javax.persistence.NoResultException 16:26:13,256 INFO [stdout] (default task-12) throwIllegalArgumentException() thrown: class java.lang.IllegalArgumentException 16:26:13,256 INFO [stdout] (default task-12) throwMyApplicationException() thrown: class org.nailedtothex.ex.MyApplicationException
- Seems to be working.
Specifying java.lang.Exception as an application exception in ejb-jar.xml
log
16:26:54,294 INFO [stdout] (default task-1) throwNoResultException() thrown: class javax.ejb.EJBException 16:26:54,294 INFO [stdout] (default task-1) throwIllegalArgumentException() thrown: class javax.ejb.EJBException 16:26:54,294 INFO [stdout] (default task-1) throwMyApplicationException() thrown: class org.nailedtothex.ex.MyApplicationException
- Not working?
References
Tags: ejb
Integration testing on an application server with Maven
TweetPosted on Thursday Feb 27, 2014 at 11:50AM in Technology
For a example of integration testing, I will try to test a Stateless Session Bean through Remote Interface.
Environment
- WildFly 8.0.0.Final
- Apache Maven 3.1.1
- Oracle JDK7u51
How does the test case work?
- Run Unit Testing JUnit classes
- Start the application server
- Deploy the application to the application server
- Run Integration Testing JUnit classes
- Remote EJB invocation testing
- Undeploy the application
- Stop the application server
Resources of the sample project
- Whole resources are available in GitHub
pom.xml
- 2 profiles are declared.
production
- It's just a skeleton. additional configuration are required here if you want to deploy to production environment using this pom.xml.
integration-test
- We can fire the integration-test by command “mvn -P integration-test verify”
- WildFly installation at “/Users/kyle/apps2/wildfly-8.0.0.Final” is assumed.
- It has a declaration of port-offset 30000 because I'm already using 8080 or 9990 ports for development.
- Consequently, this pom.xml fires WildFly at port 38080 and 39990.
Test target classes
Hoge.java
- Just a POJO class.
- Supposed to be tested at unit test phase.
HigeImpl.java
- Stateless Session Bean class which implements Remote Interface.
- Supposed to be tested at integration-test phase.
JUnit Test classes
HogeTest.java
- Just a plain JUnit class.
- Supposed to be excluded at integration-test phase.
HigeTestIT.java
- There are some EJB lookup codes, and JNDI reference name declared here.
- Supposed to be excluded at unit-test phase.
jndi.properties
- Some JNDI remote lookup configurations here.
- If you want to run this project at a application server except WildFly, then you need to edit this.
- Port number 8080 is supposed to be used with the application server which integrated with IDE.
- When kicked by Maven, it will be override by system property (related logics are available at HigeTestIT.java and pom.xml).
- Consequently, both IDE and Maven can run the test case.
Log
kyle-no-MacBook:it kyle$ mvn -P integration-test verify Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building it 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ it --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ it --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ it --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ it --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.16:test (default-test) @ it --- [INFO] Surefire report directory: /Users/kyle/Documents/workspace/it/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8 Running org.nailedtothex.it.HogeTest ***THIS IS A UNIT TEST*** Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.04 sec - in org.nailedtothex.it.HogeTest Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ it --- [INFO] Packaging webapp [INFO] Assembling webapp [it] in [/Users/kyle/Documents/workspace/it/target/it-0.0.1-SNAPSHOT] [INFO] Processing war project [INFO] Copying webapp resources [/Users/kyle/Documents/workspace/it/src/main/webapp] [INFO] Webapp assembled in [23 msecs] [INFO] Building war: /Users/kyle/Documents/workspace/it/target/it-0.0.1-SNAPSHOT.war [INFO] [INFO] --- wildfly-maven-plugin:1.0.1.Final:start (wildfly-run) @ it --- [INFO] JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre [INFO] JBOSS_HOME=/Users/kyle/apps2/wildfly-8.0.0.Final [INFO] Server is starting up. Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8 2 27, 2014 4:07:33 午後 org.xnio.Xnio <clinit> INFO: XNIO version 3.2.0.Final 2 27, 2014 4:07:34 午後 org.xnio.nio.NioXnio <clinit> INFO: XNIO NIO Implementation Version 3.2.0.Final 2 27, 2014 4:07:34 午後 org.jboss.remoting3.EndpointImpl <clinit> INFO: JBoss Remoting version 4.0.0.Final 16:07:34,277 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final 16:07:34,482 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.0.Final 16:07:34,542 INFO [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.0.0.Final "WildFly" starting 16:07:35,326 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http) 16:07:35,340 INFO [org.xnio] (MSC service thread 1-15) XNIO version 3.2.0.Final 16:07:35,346 INFO [org.xnio.nio] (MSC service thread 1-15) XNIO NIO Implementation Version 3.2.0.Final 16:07:35,366 INFO [org.jboss.as.security] (ServerService Thread Pool -- 46) JBAS013171: Activating Security Subsystem 16:07:35,369 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 33) JBAS010280: Activating Infinispan subsystem. 16:07:35,378 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 41) JBAS011800: Activating Naming Subsystem 16:07:35,382 INFO [org.jboss.as.security] (MSC service thread 1-16) JBAS013170: Current PicketBox version=4.0.20.Final 16:07:35,383 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 50) JBAS015537: Activating WebServices Extension 16:07:35,384 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 39) JBAS012615: Activated the following JSF Implementations: [main] 16:07:35,409 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017502: Undertow 1.0.0.Final starting 16:07:35,409 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017502: Undertow 1.0.0.Final starting 16:07:35,419 INFO [org.jboss.remoting] (MSC service thread 1-15) JBoss Remoting version 4.0.0.Final 16:07:35,420 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3) 16:07:35,430 INFO [org.jboss.as.connector.logging] (MSC service thread 1-12) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.3.Final) 16:07:35,436 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-14) JBAS010417: Started Driver service with driver-name = h2 16:07:35,449 INFO [org.jboss.as.naming] (MSC service thread 1-8) JBAS011802: Starting Naming Service 16:07:35,449 INFO [org.jboss.as.mail.extension] (MSC service thread 1-12) JBAS015400: Bound mail session [java:jboss/mail/Default] 16:07:35,498 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017527: Creating file handler for path /Users/kyle/apps2/wildfly-8.0.0.Final/welcome-content 16:07:35,518 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017525: Started server default-server. 16:07:35,532 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017531: Host default-host starting 16:07:35,588 INFO [org.wildfly.extension.undertow] (MSC service thread 1-9) JBAS017519: Undertow HTTP listener default listening on /127.0.0.1:38080 16:07:35,786 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) JBAS015012: Started FileSystemDeploymentService for directory /Users/kyle/apps2/wildfly-8.0.0.Final/standalone/deployments 16:07:35,795 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-11) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS] 16:07:36,025 INFO [org.jboss.ws.common.management] (MSC service thread 1-10) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final 16:07:36,065 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:39990/management 16:07:36,066 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:39990 16:07:36,066 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Final "WildFly" started in 2067ms - Started 183 of 232 services (80 services are lazy, passive or on-demand) [INFO] [INFO] >>> wildfly-maven-plugin:1.0.1.Final:deploy (wildfly-run) @ it >>> [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ it --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ it --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ it --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ it --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.16:test (default-test) @ it --- [INFO] Skipping execution of surefire because it has already been run for this configuration [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ it --- [INFO] Packaging webapp [INFO] Assembling webapp [it] in [/Users/kyle/Documents/workspace/it/target/it-0.0.1-SNAPSHOT] [INFO] Processing war project [INFO] Copying webapp resources [/Users/kyle/Documents/workspace/it/src/main/webapp] [INFO] Webapp assembled in [5 msecs] [INFO] Building war: /Users/kyle/Documents/workspace/it/target/it-0.0.1-SNAPSHOT.war [INFO] [INFO] <<< wildfly-maven-plugin:1.0.1.Final:deploy (wildfly-run) @ it <<< [INFO] [INFO] --- wildfly-maven-plugin:1.0.1.Final:deploy (wildfly-run) @ it --- 16:07:39,415 INFO [org.jboss.as.repository] (management-handler-thread - 3) JBAS014900: Content added at location /Users/kyle/apps2/wildfly-8.0.0.Final/standalone/data/content/63/45e9720d69aeb3604f94f608a25f9d036229a2/content 16:07:39,427 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "it.war" (runtime-name: "it.war") 16:07:39,564 INFO [org.jboss.weld.deployer] (MSC service thread 1-15) JBAS016002: Processing weld deployment it.war 16:07:39,604 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-15) HV000001: Hibernate Validator 5.0.3.Final 16:07:39,654 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-15) JNDI bindings for session bean named HigeImpl in deployment unit deployment "it.war" are as follows: java:global/it/HigeImpl!org.nailedtothex.it.Hige java:app/it/HigeImpl!org.nailedtothex.it.Hige java:module/HigeImpl!org.nailedtothex.it.Hige java:jboss/exported/it/HigeImpl!org.nailedtothex.it.Hige java:global/it/HigeImpl java:app/it/HigeImpl java:module/HigeImpl 16:07:39,741 INFO [org.jboss.weld.deployer] (MSC service thread 1-11) JBAS016005: Starting Services for CDI deployment: it.war 16:07:39,762 INFO [org.jboss.weld.Version] (MSC service thread 1-11) WELD-000900: 2.1.2 (Final) 16:07:39,788 INFO [org.jboss.weld.deployer] (MSC service thread 1-9) JBAS016008: Starting weld service for deployment it.war 16:07:40,560 INFO [org.wildfly.extension.undertow] (MSC service thread 1-11) JBAS017534: Registered web context: /it 16:07:40,596 INFO [org.jboss.as.server] (management-handler-thread - 3) JBAS018559: Deployed "it.war" (runtime-name : "it.war") [INFO] [INFO] --- maven-failsafe-plugin:2.16:integration-test (default) @ it --- [INFO] Failsafe report directory: /Users/kyle/Documents/workspace/it/target/failsafe-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8 Running org.nailedtothex.it.HigeTestIT 2 27, 2014 4:07:41 午後 org.xnio.Xnio <clinit> INFO: XNIO version 3.2.0.Final 2 27, 2014 4:07:41 午後 org.xnio.nio.NioXnio <clinit> INFO: XNIO NIO Implementation Version 3.2.0.Final 2 27, 2014 4:07:41 午後 org.jboss.remoting3.EndpointImpl <clinit> INFO: JBoss Remoting version 4.0.0.Final 2 27, 2014 4:07:41 午後 org.jboss.ejb.client.remoting.VersionReceiver handleMessage INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river] 2 27, 2014 4:07:41 午後 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@6d3a3c8e, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@a5dc6a8,channel=jboss.ejb,nodename=kyle-no-macbook]} on channel Channel ID b8296d49 (outbound) of Remoting connection 09445fbe to localhost/127.0.0.1:38080 2 27, 2014 4:07:41 午後 org.jboss.ejb.client.EJBClient <clinit> INFO: JBoss EJB Client version 2.0.0.Final ***THIS IS A INTEGRATION TEST*** Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.574 sec - in org.nailedtothex.it.HigeTestIT Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- wildfly-maven-plugin:1.0.1.Final:undeploy (wildfly-stop) @ it --- 16:07:41,535 INFO [org.wildfly.extension.undertow] (MSC service thread 1-14) JBAS017535: Unregistered web context: /it 16:07:41,547 INFO [org.jboss.weld.deployer] (MSC service thread 1-10) JBAS016009: Stopping weld service for deployment it.war 16:07:41,562 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment it.war (runtime-name: it.war) in 30ms 16:07:41,578 INFO [org.jboss.as.repository] (management-handler-thread - 4) JBAS014901: Content removed from location /Users/kyle/apps2/wildfly-8.0.0.Final/standalone/data/content/63/45e9720d69aeb3604f94f608a25f9d036229a2/content 16:07:41,578 INFO [org.jboss.as.server] (management-handler-thread - 4) JBAS018558: Undeployed "it.war" (runtime-name: "it.war") [INFO] [INFO] --- wildfly-maven-plugin:1.0.1.Final:shutdown (wildfly-stop) @ it --- 16:07:41,603 INFO [org.wildfly.extension.undertow] (MSC service thread 1-16) JBAS017532: Host default-host stopping 16:07:41,605 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-12) JBAS010409: Unbound data source [java:jboss/datasources/ExampleDS] 16:07:41,611 INFO [org.wildfly.extension.undertow] (MSC service thread 1-10) JBAS017521: Undertow HTTP listener default suspending 16:07:41,612 INFO [org.wildfly.extension.undertow] (MSC service thread 1-10) JBAS017520: Undertow HTTP listener default stopped, was bound to /127.0.0.1:38080 16:07:41,616 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) JBAS010418: Stopped Driver service with driver-name = h2 16:07:41,617 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017506: Undertow 1.0.0.Final stopping 16:07:41,620 INFO [org.jboss.as] (MSC service thread 1-7) JBAS015950: WildFly 8.0.0.Final "WildFly" stopped in 10ms [INFO] [INFO] --- maven-failsafe-plugin:2.16:verify (default) @ it --- [INFO] Failsafe report directory: /Users/kyle/Documents/workspace/it/target/failsafe-reports [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 10.129s [INFO] Finished at: Thu Feb 27 16:07:42 JST 2014 [INFO] Final Memory: 13M/245M [INFO] ------------------------------------------------------------------------ kyle-no-MacBook:it kyle$
References
Tags: test
Job testing with remote EJB invocation
TweetPosted on Wednesday Feb 26, 2014 at 04:50PM in Technology
I introduced that a way to test a JSR352 job with Arquillian, but I guess it's might too complex for testing of a JSR352 job, so I'm going to try to test them without Arquillian.
Environment
- WildFly 8.0.0.Final
- Oracle JDK7u51
Sample project
- Whole resources are available at GitHub.
- Example test class is HelloJobTest.
How does it work?
- JUnit test class lookups javax.batch.operations.JobOperator instance from Remote WildFly through Remote EJB Interface.
- Test class kicks the job.
- Test class will wait till the job finished.
- Assert BatchStatus.
How do I run on other application servers?
- I don't know surely, but edit below resources may helps:
- jndi.properties
- AbstractJobTest.java (JNDI_NAME)
- Also appropriate jar files for remote EJB invocation are required.
Log of WildFly
17:06:18,214 INFO [stdout] (batch-batch - 3) hello
Local log
2 26, 2014 5:14:39 午後 org.xnio.Xnio <clinit> INFO: XNIO version 3.2.0.Final 2 26, 2014 5:14:40 午後 org.xnio.nio.NioXnio <clinit> INFO: XNIO NIO Implementation Version 3.2.0.Final 2 26, 2014 5:14:40 午後 org.jboss.remoting3.EndpointImpl <clinit> INFO: JBoss Remoting version 4.0.0.Final 2 26, 2014 5:14:40 午後 org.jboss.ejb.client.remoting.VersionReceiver handleMessage INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river] 2 26, 2014 5:14:40 午後 org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@2db9e6d7, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@7e244b5,channel=jboss.ejb,nodename=kyle-no-macbook]} on channel Channel ID c584a9f3 (outbound) of Remoting connection 09168b43 to localhost/127.0.0.1:8080 2 26, 2014 5:14:40 午後 org.jboss.ejb.client.EJBClient <clinit> INFO: JBoss EJB Client version 2.0.0.Final
Remarks
- It's much faster than Arquillian Remoting on my environment.
Tags: jbatch