Fork me on GitHub

28 Apr 2009

Grails Upgrade

We've just finished upgrading our sites to Grails 1.1 and I thought it would be worth sharing some of the fun we had with the process.

First and foremost was a call site caching bug in Groovy 1.6.0 that caused chaos with our unit and integration tests. Basically any time we mocked a class then demanded behaviour on a static method or any time we used the metaClass to override a static method (among other things that's pretty much any unit test that goes anywhere near a domain class) the behaviour wouldn't get torn down again. This caused symptoms such as stubbed dynamic finders leaking from unit tests and breaking integration tests that would pass when re-run in isolation. We got as far as refactoring a whole bunch of test code that mocked static methods before Burt Beckwith pointed out to me that simply replacing $GRAILS_HOME/lib/groovy-all-1.6.0.jar with the newer version from the Groovy 1.6.1 or 1.6.2 release would fix the problem.

Unfortunately the same bug has another effect that was quite catastrophic for us. Any Hibernate proxy of an instance of a domain class involved in an inheritance hierarchy will throw ClassCastException when you try to access a subclass property or do an instanceof check. I blogged already about the instanceof issue but it's actually wider ranging than I realised at the time. It can cause very unpredictable behaviour because complex relationships between objects and the way they are loaded by a controller before a page is rendered can cause this error to pop up under obscure conditions that are very hard to nail down with test coverage. To solve the problem we've had to use eager fetching in places where associations are typed as the base class of an inheritance hierarchy and to use explicit checks for proxies such as:

if (o instanceof HibernateProxy) {
o = GrailsHibernateUtil.unwrapProxy(o)
}

Hopefully this bug will be fixed in Grails 1.1.1 and we will be able to use the default lazy loading behaviour in all relationships.

Other problems we encountered included:

  • The onLoad Hibernate event handler on domain classes now seems to run at a slightly different time in the object life cycle: before any eager fetched collections are loaded. We had one domain class that was doing some initialisation (calculating the percentage of votes each answer to a poll had received and storing it in a transient property) that no longer worked as the persistent collection it was trying to iterate over was always empty. This was simple to refactor out and in fairness was pretty horrible anyway.

  • Config.groovy and related external config files are no longer loaded when running unit tests so any unit test that excercises code doing ConfigurationHolder.config.some.value.or.other blew up. We solved this by simply adding the following to _Events.groovy to load up config prior to the unit tests running:
    eventTestPhaseStart = { phase ->
    if (phase == 'unit') {
    ConfigSlurper slurper = new ConfigSlurper(GrailsUtil.environment)
    def configClass = getClass().classLoader.loadClass("Config")
    def config = slurper.parse(configClass)
    ConfigurationHelper.initConfig config // this step loads the external environment config file(s)
    ConfigurationHolder.config = config
    }
    }

  • Logger configuration has completely changed (for the better) in Grails 1.1

  • Some of our tests were explicitly setting the level of particular loggers to 'OFF' because the test is deliberately causing an error condition and we didn't want the console polluted with a huge stack trace. This no longer works as the logging abstraction has changed to SLF4J which does not allow you to directly set the level on its Logger class. Having better things to do than unwrapping logging abstractions I just turned logging off altogether in the test Grails environment.
    log4j = {
    root {
    off()
    }
    }

  • It looks like binding errors don't get reported on nullable properties when using DomainClass.properties = params in a controller. I've raised a bug.

  • There's been a minor change to the <g:select> tag. Previously the disabled attribute followed the HTML convention (disabled="disabled") but now the attribute value needs to be a boolean. I guess this actually makes more sense than the goofy HTML convention but I really expect most of the attributes on those sorts of tags to be pure pass-through.

  • The mockDomain method used by unit tests seems to be a little inconsistent when dealing with inheritance heirarchies. If you do mockDomain(BaseClass) then try to use subClassInstance.subClassProperty it fails with a MissingPropertyException. I've raised a bug.

  • We had customised Package.groovy to deploy our app at the root context. It seems this is now directly supported as an option in Grails 1.1 by setting grails.app.context = '/' in Config.groovy. I think this option was already available in Grails 1.0.3 but our patch pre-dated us upgrading to 1.0.3. One of the things I was trying to achieve while upgrading was to ensure we were patching Grails and any plugins as little as possible.

  • I'd upgraded our selenium plugin (not the one in the Grails plugin repository) a while back to cope with Grails 1.1 and upgraded the selenium server it contained at the same time. It turns out the new selenium server will time out attempting to click any anchor that uses the javascript: protocol in its href. Luckily this was only being done in 2 places in our app and was easily fixed by using href="#" instead.

One other thing we decided to do was to replace our existing suite of webtests with functional tests. Webtest has never been popular with the developers on our team and we had made a number of modifications to version 0.4 of the plugin in order to support issues like config loading and running the app at the context root of the server. These modifications caused some headaches when trying to upgrade the plugin so we decided to drop it and port the tests over to the functional test plugin. Generally I'd still rather be writing Selenium tests than using either webtest or functional tests but the functional test syntax is a little nicer and less "pseudo-XML" than webtest's.

55 comments:

Fraaargh said...

Whaou, that is NOT what you would call a trivial upgrade :/ Thanks for all the explanations, it may help.

grandfatha said...

It is things like that which make me think about leaving my current project the way it is (1.0.3) and migrate it to a regular Spring MVC, Hibernate, Maven, GWT app some time in the future. I am so sick of this tiny little issues ALL OVER THE PLACE.

I just dont want to deal with this buggy stuff anymore. Using Grails feels like walking on eggs, you have to be careful all the time (did I use x uncorrectly or is it a bug? did others encounter the same issue -> check mailing list? Is there a bug already-> check JIRA) all the time for stuff that should just work.

Graeme Rocher said...

All I can say is sorry for all the difficulties you had in upgrading. Grails 1.1.1 (out next week) addresses most of the hassles you have had including those related to proxies, the static method Groovy bug, and the unit testing hierarchy issues.

Rob said...

Well, it has been difficult but in my perverse way I actually enjoyed it and learned a lot! I think the upgrade will prove to be worth the effort. For a start we're already seeing an improvement in page response time, which I'm guessing is due to the enhancements to GSP rendering. There is also a small mountain of tech debt around things like form binding, failed save handling, locking, enum persistence, etc. that Grails 1.1 gives us the tools to tackle. I'm looking forward to getting stuck into some of that stuff now that the app is up and running on 1.1.

We'll upgrade to 1.1.1 as soon as it's out barring any blocking issues. I expect that will be a vastly simpler process.

I can sympathise with Daniel K's comments but I'd honestly still rather be using Grails than any other platform. As I see it we've been bitten by; 1) adopting Grails early hence having code written against Grails 0.6 at the core of our app, 2) having a massive application so the sheer weight of code is a problem unto itself and 3) by the fact we have an inheritance hierarchy at the core of our domain which unluckily was the thing that caused us the most pain.

Rob said...

Oh boy here we go again. I just tried Grails 1.1.1 - 110/531 unit tests fail. That's just unit tests, I haven't even tried running integration tests.

michaelvk said...
This comment has been removed by the author.
zcocorporation said...
This comment has been removed by the author.
Fabian Smith said...
This comment has been removed by the author.
Fabian Smith said...
This comment has been removed by the author.
Fabian Smith said...

Excellent is the only word i can give u for this wonderful blog, keep it up. I will come back again to read some more interesting things on this topic. Facebook Timeline Cover Page Designs

Fabian Smith said...
This comment has been removed by the author.
SEO said...

Now I am really thinking what's best for it. Thanks a lot for all the help. It will be just so fine.
Indian wedding footwear

Unknown said...

Nice post. Great blog. Thanks for sharing. It was very interesting and meaningful. Cheap Essay Writing

Unknown said...

Such a nice post. Keep it up. Sell Gold Coins

Unknown said...

This is really a great blog post.Thanks for sharing information good job keep it up. Beauty Reviews

Unknown said...

I really enjoy your blog, keep up that good job! Good luck, smile SEO Company

Unknown said...

Excellent site, keep up the good work my colleagues would love this. Hire a Desktop App Developer

Unknown said...

This site is excellent and so is how the subject matter was explained. I also like some of the comments too.Waiting for next post. Cheap Essay Writing

Unknown said...

Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point. Hire a PHP Developer

Unknown said...

I read your whole blog. Your work is really good and inseparable .Thanks for sharing. iPhone App Marketing

Narayan said...
This comment has been removed by the author.
College Ppaper said...

Comment deleted
This comment has been removed by the author.

cheap Cheap Essay Writers online

Unknown said...

Thank you for sharing these ideas. It amazes me how you manage to choose your favorites. Good luck to the next post. Hire PHP Developers

Unknown said...

Howdy, I actually love reading through your posts, thank you for the truly great post. Paper Writing Services

Unknown said...

Well this is really a informative post and I am glad to read such a great post. I came to your site by mistake but from now I am going to read all of your posts. SEO Packages

Unknown said...

his blog Is very informative, I am really pleased to post my comment on this blog. It helped me with ocean of knowledge so I really believe you will do much better in the future. Good job web master. Free Calls

Unknown said...

The post is interesting. I really never thought I could have a good read by this time until I found out this site.Thanks!
Wholesale Towels

Unknown said...

I'm so enjoyable when reading your post. Thank you for sharing. Used Police Cars

Unknown said...

A very good and informative article indeed . It helps me a lot to enhance my knowledge, I really like the way the writer presented his views. Debt Collector

Unknown said...

I appreciate the write and the real insight of the writer on the subject. well done
Debt Collection

Unknown said...

Great Blog!! That was amazing. Your thought processing is wonderful. The way you tell the thing is awesome. You are really a master. Debt Collector

Unknown said...

Excellent is the only word I can give you for this wonderful blog, keep it up. I will come back again to read some more interesting things on this topic. Debt Collection

Unknown said...

I think that this blog is really cool .so please visit my this site and get collection information. Debt Collection

Unknown said...

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
website designing company

Unknown said...
This comment has been removed by the author.
Unknown said...
This comment has been removed by the author.
Web Development Company said...

This is the Good information you are Sharing:)



Outsource Web Development India

Unknown said...

I really like this website. This is a great resources, provide you with your free distribution. It gives in depth information. Thank you for this valuable information. Macy's Coupon
JcPenney Coupons
Bluefly Coupon Codes
Target Promo Codes
Barnes & Noble Coupon Code
Groupon Promo Codes
Amazon Promo Codes
Best Buy Coupons
American Eagle Promo Code
AutoZone Coupons
Walmart Coupon Codes
Next Day Flyers Coupon Codes
Overstock Promo Codes
bebe Coupon Codes
Light In The Box Coupons
SmartBargains Coupons
Bed Bath and Beyond Coupon

Unknown said...

thats awsam thanks for sharing.Geo Essay

Unknown said...

Nice information, i hope you keep writing.
Search Strings
SEO Company
Google Adwords
Social Media
Web Analytics
Conversion Optimization
Reputation Management

Unknown said...

thanx for sharing nice info :)
Cheap Essay

Unknown said...

thats the post i've been seeking for. Nice info thanx for sharing keep it up ;)
Cheap Essay

Fabian Smith said...

There are some very good sources here, thanks for being so kind to post here. Hamilton Resourcing
Human Resource Solutions UAE
Psychometrics Tests
Psychometrics Test Dubai
Talent Management
Integrity International
Executive Recruitment UAE
The McQuaig Psychometric System
The McQuaig Job Survey
The McQuaig Word Survey
The McQuaig Self-Development Survey
Executive Search Firms in Dubai
Head Hunters Dubai
Executive Recruitment in Dubai
Emirati Talent Management
Executive Headhunters Dubai
Executive Recruitment Dubai
Executive Search Dubai

Unknown said...

I Like Ur Post thanks for the shareing with Us.Find Assignment Writing Help

Julia Smith said...

I don't know what to say except that I have enjoyed reading. Nice blog.I will keep visiting this blog very often. Research Paper Writing Services
Thesis Writing Services
Admission Essay Writing Services
Assignment Writing Services
Book Report Writing Services
Power Point Presentation Services
Paper Writing Service
Letter Writing Services
Editing Services
Proof Reading Services
Proposal Writing Services

Maya Angelou said...

Amazing post
Storage services dubai
Furniture Installation In Dubai
Moving and Storage
Movers And Packers
International relocation companies in Dubai
Mover companies in dubai

rehan said...

The info you provided in the blog that was really unique I love it!!!
Dermstore Coupon Code
6pm Coupon Code
Walgreens Coupon Code

Jacky said...

Wow.. Awesome This is Great.. Wonderful information.. I am impressing Thanks..


Ecommerce Web Development Company

Unknown said...

I'm so amazed together with you that will make your blog like this to be really great so we truly wanted to have a nice and interesting blogs such as this. Cheap Essays

Curtis said...

It is great of you to share with us the fun you had when you were upgrading your site to Grails 1.1. This is incredible and indeed you had a lot of fun. Thanks a lot for sharing.
Letter of Reference Writing Help

Unknown said...

I am glad to see that people are actually writing about this issue in such a smart way, showing us all different sides to it. Thanks for sharing, please keep it up.

Also checkout our happy new year 2017 Wishes new collections.

Tristar Traders said...

Ultimate article post in this blog.Thanks for sharing these useful information.
Gone are the days when a business laid down an annual sum to have its information listed in the Yellow Pages. These days it’s crucial for all businesses to instead prominently list themselves in online directories.AIR pros is a directory of service companies in your area with a geolocation system, automatic translation of the content.The site is optimized to facilitate the referencing of referenced companies.You can search for companies by department or city and look at their profile before contacting them.

لمار للتسويق الالكتروني said...

شركة تنظيف بنجران
شركة تنظيف المنازل بنجران
شركة نظافة عامة بنجران
أفضل شركة تنظيف فلل بنجران
شركة نظافة الأسطح بنجران
شركات النظافة  بنجران
شركة نظافة عامة بنجران
أرخص شركة تنظيف شقق بنجران
شركة تنظيف منازل بنجران
شركة تنظيف فلل وقصور بنجران
شركة تنظيف اثاث و مجالس بنجران
شركة تنظيف سجاد و موكيت بنجران

top research papers said...

I have gone through your post and I must admit that it’s quite commendable. I have been thinking and reading so much about research and I have had help from research paper helper and this has helped me so much in regards to attaining top grades. I also study so much about people who offer nursing assignment help and they have really helped me through my studies.

NuVista said...

What a fantastic post! This is so full of useful information I can’t wait to dig deep and start utilizing the resources you have given me. Your exuberance is refreshing.

NetSuite Partners in India
NetSuite Implementation Partner