You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by xeseo <xe...@gmail.com> on 2012/09/19 09:21:29 UTC

Different module share same container?

Hi, 
In my project, several modules are under same pom project. 
Like: 
Parent (pom) 
 | 
 | ---- module A (jar) 
 | ---- module B (jar) 
 | ---- module C (jar) 

We're using openEJB as embeded container for unit test. However, each module
will have to own its own jndi.properties, and during the Maven install
procedure, the container will init three times and cost lots of time. 
Obviously, there will be more modules in the future. Then the test will cost
more time initializing the container. 

So is it possible that different modules share the same container? Use one
centralized jndi.properties to replace all. 
Do anyone have the idea? 

Thanks,



--
View this message in context: http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Different module share same container?

Posted by Edison Xu <xe...@gmail.com>.
Oh~ sorry, I thought the post is failed due to the subscription issue. So I
recreated the thread...



--
View this message in context: http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657515.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Different module share same container?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm you recreated the thread? btw here was my answer:
http://openejb.979440.n4.nabble.com/Re-Mutiple-module-share-the-same-container-td4657508.html


note you have to <forkMode>once</forkMode> with surefire

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/19 Jean-Louis MONTEIRO <je...@gmail.com>

> Hi,
>
> In my opinion, it should be the target for unit tests. I mean, getting a
> fresh new container for each test.
> Otherwise, you can maybe focus on integration tests using our Arquillian
> adapter.
>
> Just one question: what do you mean by "cost lots of time"?
> Because, we start/stop openejb thousand of times per day and in the CI of
> the project and it's not so painful.
> Maybe, you are in a use case we can optimize a bit more.
>
> Could you share some information?
>
> Jean-Louis
>
>
> 2012/9/19 xeseo <xe...@gmail.com>
>
> > Hi,
> > In my project, several modules are under same pom project.
> > Like:
> > Parent (pom)
> >  |
> >  | ---- module A (jar)
> >  | ---- module B (jar)
> >  | ---- module C (jar)
> >
> > We're using openEJB as embeded container for unit test. However, each
> > module
> > will have to own its own jndi.properties, and during the Maven install
> > procedure, the container will init three times and cost lots of time.
> > Obviously, there will be more modules in the future. Then the test will
> > cost
> > more time initializing the container.
> >
> > So is it possible that different modules share the same container? Use
> one
> > centralized jndi.properties to replace all.
> > Do anyone have the idea?
> >
> > Thanks,
> >
> >
> >
> > --
> > View this message in context:
> >
> http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507.html
> > Sent from the OpenEJB User mailing list archive at Nabble.com.
> >
>

Re: Different module share same container?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
hmm,

currently we don't look for jpa prop in the container prop (we could maybe)

for such tests maybe ApplicationComposer can help (build your custom app)

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/19 Edison Xu <xe...@gmail.com>

> BTW, for the property
> p.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
>
> How can I put it in the jndi.properties?
>
> I tried to add below:
> openjpa.jdbc.SynchronizeMappings = buildSchema(ForeignKeys=true)
>
> but doesn't work. Only have to add in the codes directly when getting
> InitialContext.
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657523.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Different module share same container?

Posted by Edison Xu <xe...@gmail.com>.
That's a encouraging news~

I agree with you. It's more of an integration work. But I still need to do
some analysis on reusing the container in case there'll be too many child
modules in the future. 

Thanks for your information, and I'll try it following your steps.



--
View this message in context: http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657536.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Different module share same container?

Posted by Anthony Fryer <ap...@hotmail.com>.
I went through the same process of trying to speed up my test case execution
by only instantiating a single container.  I was able to setup my test cases
so that only a single container is instantiated and each unit test can
re-use the same container.  This is only within a single maven module
though.  

This might be useful...

http://openejb.979440.n4.nabble.com/Injection-fails-in-any-class-that-didn-t-instantiate-an-embedded-ejb-container-td4396189.html#a4397187

I don't think it makes sense to re-use the same container across modules
though.  That's more of an integration test rather than a unit test.  Maybe
you could create a new maven module just for running unit/integration tests
against your other modules and use a single container.






--
View this message in context: http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657535.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Different module share same container?

Posted by Edison Xu <xe...@gmail.com>.
BTW, for the property 
p.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");

How can I put it in the jndi.properties?

I tried to add below:
openjpa.jdbc.SynchronizeMappings = buildSchema(ForeignKeys=true)

but doesn't work. Only have to add in the codes directly when getting
InitialContext.




--
View this message in context: http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657523.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Different module share same container?

Posted by Edison Xu <xe...@gmail.com>.
yeah, you're right. It feel better in this way. 
Thanks for the correction. :)

However, any idea on the container share?



--
View this message in context: http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657522.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Different module share same container?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
@Before
public void initializeOpenEJB() throws NamingException {
Context ctxt = null;
 try {
 Properties p = new Properties();
 p.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
    p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
 ctxt = new InitialContext(p);
ctxt.bind("inject", this);
}
 finally {
try {
ctxt.close();
 }
catch (NamingException ignored) {
 }
}
}

?


don't do it this way, use @BeforeClass and do the close in @AfterClass. the
bind (only it) in @Before is fine

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/19 Edison Xu <xe...@gmail.com>

> I've created some sample codes and upload to github just now.
> https://github.com/EdisonXu/Test/tree/master/ejb-intro
>
> the time consumed:
> Without test:
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Reactor Summary:
> [INFO]
> [INFO] Introduction of EJB ............................... SUCCESS [0.779s]
> [INFO] Message Client .................................... SUCCESS [2.280s]
> [INFO] Message Server .................................... SUCCESS [1.411s]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 5.251s
> [INFO] Finished at: Wed Sep 19 16:31:38 CST 2012
> [INFO] Final Memory: 21M/494M
> [INFO]
> ------------------------------------------------------------------------
>
> With test:
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Reactor Summary:
> [INFO]
> [INFO] Introduction of EJB ............................... SUCCESS [0.847s]
> [INFO] Message Client .................................... SUCCESS [7.180s]
> [INFO] Message Server .................................... SUCCESS [9.784s]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 18.716s
> [INFO] Finished at: Wed Sep 19 16:30:54 CST 2012
> [INFO] Final Memory: 32M/494M
> [INFO]
> ------------------------------------------------------------------------
>
> In this small case, time gap between two total time is about 13s. The
> container launched twice.
> I'm not running this test project on Server but dev machine, and I believe
> it will event cost less on server.
>
> Anyway, the time cost will increase with the number of sub-modules of the
> project. Is there anyway to avoid it?
> Thanks :)
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657520.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Different module share same container?

Posted by Edison Xu <xe...@gmail.com>.
I've created some sample codes and upload to github just now. 
https://github.com/EdisonXu/Test/tree/master/ejb-intro

the time consumed:
Without test: 
[INFO]
------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Introduction of EJB ............................... SUCCESS [0.779s]
[INFO] Message Client .................................... SUCCESS [2.280s]
[INFO] Message Server .................................... SUCCESS [1.411s]
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 5.251s
[INFO] Finished at: Wed Sep 19 16:31:38 CST 2012
[INFO] Final Memory: 21M/494M
[INFO]
------------------------------------------------------------------------

With test:
[INFO]
------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Introduction of EJB ............................... SUCCESS [0.847s]
[INFO] Message Client .................................... SUCCESS [7.180s]
[INFO] Message Server .................................... SUCCESS [9.784s]
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 18.716s
[INFO] Finished at: Wed Sep 19 16:30:54 CST 2012
[INFO] Final Memory: 32M/494M
[INFO]
------------------------------------------------------------------------

In this small case, time gap between two total time is about 13s. The
container launched twice.
I'm not running this test project on Server but dev machine, and I believe
it will event cost less on server.

Anyway, the time cost will increase with the number of sub-modules of the
project. Is there anyway to avoid it?
Thanks :)



--
View this message in context: http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657520.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Different module share same container?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
10s? can you try an "empty" test? normally it is 2-3s

which kind of machine? which config?

*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*




2012/9/19 Edison Xu <xe...@gmail.com>

> Actually, the initialization of the openEJB container and the test running
> within it will cost 10s generally.
> So if I have 50 modules in total, it will increase almost 9 minutes for the
> testing.
> That's why I mentioned as "cost lots of time".
>
> And obviously, the time consumed is mainly cost on the initialization, so
> I'm wondering whether it's possible to initialize only once. That will
> reduce the time.
>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657517.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Different module share same container?

Posted by Edison Xu <xe...@gmail.com>.
Actually, the initialization of the openEJB container and the test running
within it will cost 10s generally.
So if I have 50 modules in total, it will increase almost 9 minutes for the
testing. 
That's why I mentioned as "cost lots of time".

And obviously, the time consumed is mainly cost on the initialization, so
I'm wondering whether it's possible to initialize only once. That will
reduce the time.





--
View this message in context: http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507p4657517.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Different module share same container?

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Hi,

In my opinion, it should be the target for unit tests. I mean, getting a
fresh new container for each test.
Otherwise, you can maybe focus on integration tests using our Arquillian
adapter.

Just one question: what do you mean by "cost lots of time"?
Because, we start/stop openejb thousand of times per day and in the CI of
the project and it's not so painful.
Maybe, you are in a use case we can optimize a bit more.

Could you share some information?

Jean-Louis


2012/9/19 xeseo <xe...@gmail.com>

> Hi,
> In my project, several modules are under same pom project.
> Like:
> Parent (pom)
>  |
>  | ---- module A (jar)
>  | ---- module B (jar)
>  | ---- module C (jar)
>
> We're using openEJB as embeded container for unit test. However, each
> module
> will have to own its own jndi.properties, and during the Maven install
> procedure, the container will init three times and cost lots of time.
> Obviously, there will be more modules in the future. Then the test will
> cost
> more time initializing the container.
>
> So is it possible that different modules share the same container? Use one
> centralized jndi.properties to replace all.
> Do anyone have the idea?
>
> Thanks,
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Different-module-share-same-container-tp4657507.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>