You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by JimOR <ji...@clearviewcatv.net> on 2008/05/13 20:23:42 UTC
Enhancer annoyance
I'm running into a mild annoyance running a junit test suite directly from
within Eclipse. I have the -javaagent VM arg in my run configuration, and
the problem does goes away if I run an ant task to call the enhancer
directly prior to running my test suite.
The problem is that access to any collection from the first Entity listed as
'subclassed' gives an NPE, which in my configuration is a failure. The
remaining Entities test fine, and you'll notice that the enhancer happily
processes that Entity after reporting it being subclassed.
As I stated, it's a mild annoyance because when any tests fail, I only have
to launch that ant enhancer task and re-run the test. Any thoughts?
following is a portion of my test suite output:
INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:45) -
InitialTestSetup Started
Apache OpenEJB 3.0 build: 20080408-04:13
http://openejb.apache.org/
656 PortfolioData INFO [main] openjpa.Runtime - Starting OpenJPA 1.0.1
1250 PortfolioData INFO [main] openjpa.jdbc.JDBC - Using dictionary
class "org.apache.openjpa.jdbc.sql.PostgresDictionary" (PostgreSQL 8.1.4
,PostgreSQL Native Driver PostgreSQL 8.1 JDBC3 with SSL (build 405)).
1625 PortfolioData INFO [main] openjpa.Enhance - Creating subclass for
"[class portfolio.data.entities.Category, class
portfolio.data.entities.Account, class portfolio.data.entities.Accounttype,
class portfolio.data.entities.Owner]". This means that your application will
be less efficient and will consume more memory than it would if you ran the
OpenJPA enhancer. Additionally, lazy loading will not be available for
one-to-one and many-to-one persistent attributes in types using field
access; they will be loaded eagerly instead.
2578 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type "class
portfolio.data.entities.Category".
2938 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type "class
portfolio.data.entities.Account".
3328 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type "class
portfolio.data.entities.Accounttype".
3594 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type "class
portfolio.data.entities.Owner".
INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:54) -
Context is Set, ejb in Context:
.=
AccountBeanLocal=proxy=portfolio.data.beans.PortfolioCRUD;deployment=AccountBean;pk=2291cc984d5ae5a2:-3af9f98d:119e366778c:-8000
AccounttypeBeanLocal=proxy=portfolio.data.beans.AccounttypeManager;deployment=AccounttypeBean;pk=2291cc984d5ae5a2:-3af9f98d:119e366778c:-7fff
CategoryBeanLocal=proxy=portfolio.data.beans.PortfolioCRUD;deployment=CategoryBean;pk=2291cc984d5ae5a2:-3af9f98d:119e366778c:-7ffd
OwnerBeanLocal=proxy=portfolio.data.beans.PortfolioCRUD;deployment=OwnerBean;pk=2291cc984d5ae5a2:-3af9f98d:119e366778c:-7ffc
PortFolioCRUDBeanLocal=proxy=portfolio.data.beans.PortfolioCRUD;deployment=PortFolioCRUDBean;pk=2291cc984d5ae5a2:-3af9f98d:119e366778c:-7ffe
INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:64) -
Framework initialization and bean lookup took 8.844
--
View this message in context: http://www.nabble.com/Enhancer-annoyance-tp17215212p17215212.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Enhancer annoyance
Posted by Dain Sundstrom <da...@iq80.com>.
If you switch to Java6 OpenJPA will use the dynamic class rewriting
stuff in the Java6 vm when enhancing. It also doesn't need the
javaagent arg, since in Java6 you can late start the agent.
-dain
On May 13, 2008, at 11:23 AM, JimOR wrote:
>
> I'm running into a mild annoyance running a junit test suite
> directly from
> within Eclipse. I have the -javaagent VM arg in my run
> configuration, and
> the problem does goes away if I run an ant task to call the enhancer
> directly prior to running my test suite.
>
> The problem is that access to any collection from the first Entity
> listed as
> 'subclassed' gives an NPE, which in my configuration is a failure.
> The
> remaining Entities test fine, and you'll notice that the enhancer
> happily
> processes that Entity after reporting it being subclassed.
>
> As I stated, it's a mild annoyance because when any tests fail, I
> only have
> to launch that ant enhancer task and re-run the test. Any thoughts?
>
> following is a portion of my test suite output:
>
> INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:
> 45) -
> InitialTestSetup Started
> Apache OpenEJB 3.0 build: 20080408-04:13
> http://openejb.apache.org/
> 656 PortfolioData INFO [main] openjpa.Runtime - Starting OpenJPA
> 1.0.1
> 1250 PortfolioData INFO [main] openjpa.jdbc.JDBC - Using
> dictionary
> class "org.apache.openjpa.jdbc.sql.PostgresDictionary" (PostgreSQL
> 8.1.4
> ,PostgreSQL Native Driver PostgreSQL 8.1 JDBC3 with SSL (build 405)).
> 1625 PortfolioData INFO [main] openjpa.Enhance - Creating
> subclass for
> "[class portfolio.data.entities.Category, class
> portfolio.data.entities.Account, class
> portfolio.data.entities.Accounttype,
> class portfolio.data.entities.Owner]". This means that your
> application will
> be less efficient and will consume more memory than it would if you
> ran the
> OpenJPA enhancer. Additionally, lazy loading will not be available for
> one-to-one and many-to-one persistent attributes in types using field
> access; they will be loaded eagerly instead.
> 2578 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type
> "class
> portfolio.data.entities.Category".
> 2938 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type
> "class
> portfolio.data.entities.Account".
> 3328 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type
> "class
> portfolio.data.entities.Accounttype".
> 3594 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type
> "class
> portfolio.data.entities.Owner".
> INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:
> 54) -
> Context is Set, ejb in Context:
> .=
>
> AccountBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .PortfolioCRUD;deployment=AccountBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-8000
>
> AccounttypeBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .AccounttypeManager
> ;deployment=AccounttypeBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-7fff
>
> CategoryBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .PortfolioCRUD;deployment=CategoryBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-7ffd
>
> OwnerBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .PortfolioCRUD;deployment=OwnerBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-7ffc
>
> PortFolioCRUDBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .PortfolioCRUD
> ;deployment=PortFolioCRUDBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-7ffe
> INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:
> 64) -
> Framework initialization and bean lookup took 8.844
> --
> View this message in context: http://www.nabble.com/Enhancer-annoyance-tp17215212p17215212.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: Enhancer annoyance
Posted by David Blevins <da...@visi.com>.
On May 14, 2008, at 8:32 AM, JimOR wrote:
>
>
> David Blevins wrote:
>>
>> One way to verify would be to split your test case into two classes;
>> the TestCase subclass which would do nothing more than setup OpenEJB
>> via the InitialContext and have a test method that delegated to your
>> second class which actually did test. The idea being the second
>> class
>> which references the entity classes wouldn't get loaded until after
>> the first class has run and setup the dynamic enhancer.
>>
>> Let us know if that's the case as we can probably document this kind
>> of OpenJPA specific testing technique.
>> -David
>>
>>
>
> I had the same thought initially and refactored my test classes to
> extend an
> abstract parent with a @BeforeClass annotation that sets my
> InitialContext.
> Then I setup lazy bean instantiation in a parent @Before method, and
> moved
> all @Entity references inside methods annotated with @Test.
>
> Perhaps the parent test class level @Stateful bean references (which
> reference @Entities) are the culprit?
Could be. The bean classes themselves wouldn't be the issue but
likely the entity types are listed in the business interface method
signatures. There definitely should be some way to swizzle things
around so the issue is avoided.
One tricky way might be to put static initializers with "i'm being
loaded" system.out statements in a few classes. That may be
ineffective if the classes are loaded with initialization off --
Class.forName("foo", false, classLoader) -- but it's worth a quick try.
-David
Re: Enhancer annoyance
Posted by JimOR <ji...@clearviewcatv.net>.
David Blevins wrote:
>
> One way to verify would be to split your test case into two classes;
> the TestCase subclass which would do nothing more than setup OpenEJB
> via the InitialContext and have a test method that delegated to your
> second class which actually did test. The idea being the second class
> which references the entity classes wouldn't get loaded until after
> the first class has run and setup the dynamic enhancer.
>
> Let us know if that's the case as we can probably document this kind
> of OpenJPA specific testing technique.
> -David
>
>
I had the same thought initially and refactored my test classes to extend an
abstract parent with a @BeforeClass annotation that sets my InitialContext.
Then I setup lazy bean instantiation in a parent @Before method, and moved
all @Entity references inside methods annotated with @Test.
Perhaps the parent test class level @Stateful bean references (which
reference @Entities) are the culprit?
--
View this message in context: http://www.nabble.com/Enhancer-annoyance-tp17215212p17233957.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Enhancer annoyance
Posted by David Blevins <da...@visi.com>.
I wonder if what's going on is that the test case is getting it's
hands on the Entity classes before we're loaded and able to tell
OpenJPA that the classes need to be dynamically enhanced. OpenJPA's
unenhanced support is ok, but not feature complete.
One way to verify would be to split your test case into two classes;
the TestCase subclass which would do nothing more than setup OpenEJB
via the InitialContext and have a test method that delegated to your
second class which actually did test. The idea being the second class
which references the entity classes wouldn't get loaded until after
the first class has run and setup the dynamic enhancer.
Let us know if that's the case as we can probably document this kind
of OpenJPA specific testing technique. Definitely in Java 6 this kind
of thing will be easier as class redefining is there as well as being
able to install an enhancer post-startup (i.e. no agent).
-David
On May 13, 2008, at 11:23 AM, JimOR wrote:
>
> I'm running into a mild annoyance running a junit test suite
> directly from
> within Eclipse. I have the -javaagent VM arg in my run
> configuration, and
> the problem does goes away if I run an ant task to call the enhancer
> directly prior to running my test suite.
>
> The problem is that access to any collection from the first Entity
> listed as
> 'subclassed' gives an NPE, which in my configuration is a failure.
> The
> remaining Entities test fine, and you'll notice that the enhancer
> happily
> processes that Entity after reporting it being subclassed.
>
> As I stated, it's a mild annoyance because when any tests fail, I
> only have
> to launch that ant enhancer task and re-run the test. Any thoughts?
>
> following is a portion of my test suite output:
>
> INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:
> 45) -
> InitialTestSetup Started
> Apache OpenEJB 3.0 build: 20080408-04:13
> http://openejb.apache.org/
> 656 PortfolioData INFO [main] openjpa.Runtime - Starting OpenJPA
> 1.0.1
> 1250 PortfolioData INFO [main] openjpa.jdbc.JDBC - Using
> dictionary
> class "org.apache.openjpa.jdbc.sql.PostgresDictionary" (PostgreSQL
> 8.1.4
> ,PostgreSQL Native Driver PostgreSQL 8.1 JDBC3 with SSL (build 405)).
> 1625 PortfolioData INFO [main] openjpa.Enhance - Creating
> subclass for
> "[class portfolio.data.entities.Category, class
> portfolio.data.entities.Account, class
> portfolio.data.entities.Accounttype,
> class portfolio.data.entities.Owner]". This means that your
> application will
> be less efficient and will consume more memory than it would if you
> ran the
> OpenJPA enhancer. Additionally, lazy loading will not be available for
> one-to-one and many-to-one persistent attributes in types using field
> access; they will be loaded eagerly instead.
> 2578 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type
> "class
> portfolio.data.entities.Category".
> 2938 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type
> "class
> portfolio.data.entities.Account".
> 3328 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type
> "class
> portfolio.data.entities.Accounttype".
> 3594 PortfolioData TRACE [main] openjpa.Enhance - Enhancing type
> "class
> portfolio.data.entities.Owner".
> INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:
> 54) -
> Context is Set, ejb in Context:
> .=
>
> AccountBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .PortfolioCRUD;deployment=AccountBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-8000
>
> AccounttypeBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .AccounttypeManager
> ;deployment=AccounttypeBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-7fff
>
> CategoryBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .PortfolioCRUD;deployment=CategoryBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-7ffd
>
> OwnerBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .PortfolioCRUD;deployment=OwnerBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-7ffc
>
> PortFolioCRUDBeanLocal
> =
> proxy
> =
> portfolio
> .data
> .beans
> .PortfolioCRUD
> ;deployment=PortFolioCRUDBean;pk=2291cc984d5ae5a2:-3af9f98d:
> 119e366778c:-7ffe
> INFO- portfolio.data.junit.suite.InitialTestSetup.suiteSetUp(Line:
> 64) -
> Framework initialization and bean lookup took 8.844
> --
> View this message in context: http://www.nabble.com/Enhancer-annoyance-tp17215212p17215212.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>