Monthly Archives: June 2009

Forking JUnit tests in Ant (watch out!)

Turtles are surprisingly fast.

Turtles are surprisingly fast.

I’ve noticed for a while our unit tests run very fast through my IDE but take forever on our build box. At first I attributed this to our severely overloaded build box, but I was wrong.

In our particular case the tests take 5 minutes 3 seconds to run through Ant while forking for each test class. Very not cool.

If you’re using fork to run your JUnit tests in Ant, there are two attributes to be concerned with: fork and forkmode.

The forkmode attribute is the big one here. Possible values are “perTest” (default), “perBatch”, and “once”.

It turns out that because “perTest” is the default; meaning forking is done for each test class. While that might be what you want, it can make your tests significantly slower. Using the “once” option instead means forking happens just once; all your tests will be ran together in a single JVM.

After switching the forkmode to “once”, our test running time plummeted to 33 seconds for a net gain of 4.5 minutes. As Borat would say, “very niiiice”. (In this case 33 seconds is still longer than it should be, but that’s for another post).

There’s some very good technical reasons to run all your tests in the same JVM. As Chris at nominet.org.uk pointed out, it might reveal some issues with your production code or test code:

Having the tests run each in its own JVM also covers up problems. You can create whatever sort of mess you like and it’ll all be swept away before the next test runs. While going through a setting the forkmode to “once” I found a database connection leak in some test code. This sort of problem would be much more visible if all the test code was running in a single JVM and reminded me of Martin Fowler’s advice on testing resource pools.

Of course Martin Fowler comes through again with good advice.

Backing up MySQL Databases with mysqldump

We all know that backing up critical data is very important. Unfortunately, it’s not always very clear how to go about doing that.

Luckily, making back ups of MySQL databases is easy by using mysqldump.

Backing up all databases

Backing up all databases is as easy as as this:

mysqldump -u username -p password –all-databases -c > mysqldump.sql

Did you expect it to be much harder? Sorry to disappoint.

The –all-databases option backs up all databases (genius naming!). The –complete-insert or -c uses complete insert statements in the backup script.

With the above command, mysqldump outputs all the SQL needed to regenerate all databases from scratch with all the data from the time of the dump. Users and other MySQL tables are also included in the dump.

Backing up a specific database or table

Sometimes it’s useful to only backup a small portion of the MySQL instance, either an entire database or a specific set of tables.

Not surprisingly, you can backup a specific database with mysqldump:

mysqldump -u username -p password YourDatabase > yourdatabase.sql

It’s just as easy to backup one or more tables in a database:

mysqldump -u username -p password YourDatabase table1 table2 > yourdatabase.sql

Compressing the backup

If you have a lot of data, compression with gzip will be helpful to eliminate disk space waste:

mysqldump -u username –password=password –all-databases -c | gzip -9 > mysqldump.sql.gz

Automating backups

If you’re dealing with a database of any significant importance, it’s critical to automate the backup process. In the Unix world there is cron. I won’t go into specifics on how to use cron since it is easily worthy of its own posting.

If you ever need your backup, it’ll suck. With backups, it’ll suck less. With automated backups, it’ll suck much much less.

mysqldump isn’t the right tool for all your MySQL backup needs, but its ease of use gives you no excuse. More complicated backup techniques, including incremental backups, can be found in the MySQL reference guide.

First look at Apple’s App Store ratings system – Your iPhone is safe!

I somehow missed the flurry of Apple news today, so I was surprised to see the updates to iTunes Connect when I wanted to check up on the number of downloads for my first iPhone App Store application (it was approved late last night). I haven’t seen much talk on the Apple’s App Store ratings, so here’s the tiny bit of details that I’ve seen about this new feature.

Before an iPhone developer can update an existing app or upload a new app, they must select the ratings for their own applications:

appstore-content-descriptions

iPhone developers are asked to choose the content frequency (None, Infrequent/Mild, and Frequent/Intense) of various types of objectionable content.

I find it very interesting that developers are being asked to provide these details. Presumably the developers themselves would know about any Hot Coffee-eque features to their apps and fess up, right? I assume the game plan is for the employees already swamped with app approvals will be in charge of validating the accuracy of the developer’s own ratings.

App Store Ratings 4+, 9+, 12+, 17+

App Store Ratings

Apple apple appears to have their very own ratings system:

  • 4+, Applications in this category contain no objectionable material.
  • 9+, Applications in this category may contain mild or infrequent occurrences of cartoon, fantasy or realistic violence, and infrequent or mild mature, suggestive, or horror-themed content which may not be suitable for children under the age of 9.
  • 12+, Applications in this category may also contain infrequent mild language, frequent or intense cartoon, fantasy or realistic violence, and mild or infrequent mature or suggestive themes, and simulated gambling which may not be suitable for children under the age of 12.
  • 17+, Applications in this category may also contain frequent and intense offensive language, frequent and intense cartoon, fantasy or realistic violence, frequent and intense mature, horror, and suggestive themes, plus sexual content, nudity, alcohol, tobacco, and drugs which may not be suitable for children under the age of 17.

Interestingly no application will be sold on the App Store that has “Prolonged graphic or sadistic realistic violence” or “Graphic sexual content and nudity” regardless of the frequency or severity. I guess that means we won’t be seeing any porn anytime soon.

Apple also provides a chart showing the app store rating system’s equivalent to the ESRB and PEGI rating systems:

Are these are equivelent?

Are these are equivelent?

Hopefully this will eliminate the controversy surrounding the rejection of apps due to its objectionable content.

More importantly, I hope the ratings system does not delay the approval process anymore.

Enjoy the new iPhone OS 3.0 upgrade in about a week. Since I’m impatient I might finally grab the version already available to developers. If anything is hosed, I’ll be hosed in a about week anyhow.

Solved: Digester.getParser: org.xml.sax. SAXNotRecognizedException: http://apache.org/xml/features/validation/dynamic

I ran into a nice little problem trying to get richfaces deployed on Oracle’s OC4J:

[text]
Digester.getParser:
org.xml.sax.SAXNotRecognizedException: http://apache.org/xml/features/validation/dynamic
at oracle.xml.jaxp.JXSAXParserFactory.setFeature(JXSAXParserFactory.java:128)
at org.apache.commons.digester.parser.XercesParser.configureXerces(XercesParser.java:185)
at org.apache.commons.digester.parser.XercesParser.newSAXParser(XercesParser.java:138)
… snip …
[/text]

From a little bit of googling, I found several people running into this problem or something very similar. Frustratingly, not a whole lot of solutions. One solution that did not work (but was confirmed by some to do the trick) was to run the OC4J standalone server with the following parameters:

[text]
-Dbootclasspath:/somepath/xerces-2.6.2.jar
-Dorg.xml.sax.drive­r=org.apache.xerces.­parsers.SAXParser
-Djavax.xml.parsers­.SAXParserFactory=or­g.apache.xerces.jaxp­.SAXParserFactoryImp­l
-Djavax.xml.parsers­.TransformerFactory=­org.apache.xalan.pro­cessor.TransformerFa­ctoryImpl
-Djavax.xml.transfo­rm.TransformerFactor­y=org.apache.xalan.p­rocessor.Transformer­FactoryImpl
[/text]

Luckily a co-worker (who is waaaaaaay to humble for his own good and won’t let me use his name here) figured out that adding the following to orion-application.xml does the trick:

[xml]
<orion-application>

<imported-shared-libraries>
<remove-inherited name="oracle.xml"/>
<remove-inherited name="oracle.xml.security"/>
<remove-inherited name="oracle.toplink"/>
</imported-shared-libraries>

</orion-application>
[/xml]

Oracle has details on what the above does in their documentation on utilizing the OC4J class loading framework. Good luck reading that, it looks terribly boring. :-)