Archive for November, 2009

11/21/2009: 1:08 pm: RobertJava, Scala

A few weeks ago I decided to learn Scala in order to develop the website for my latest side project. This led me down the road of trying to learn Google App Engine/Java, Lift, Maven, Git, ScalaTest, Spec and much more, so it’s been pretty slow going. Especially due to diversions into Cassandra, MongoDB, Tokyo Cabinet, Hadoop and HBase.

I’m a huge fan of JUnit for unit testing Java code, so I was happy when Bil Venners announced the release of ScalaTest 1.0 at a BASE meeting at Twitter. I really like being able to quickly run tests in Eclipse, but it wasn’t obvious to me how to do this with ScalaTest, especially when using the BDD styles of testing, like Spec. Creating test runners manually for each class was a deal killer. I finally found some info that mostly clarified things.

A simple example is helpful, so here you go:

import org.scalatest.Spec
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
 
@RunWith(classOf[JUnitRunner])
class MinimalSpec extends Spec {
   describe("My class") {
     it("should have testable behavior like...") {
       assert(true)
     }
   }
}

After creating the class, do one of the following:

  • Right click on file in tree and select Run As -> JUnit Test
  • Select file in tree and press Alt-Command-X + T on OS X or Alt-Shift-X + T on other OSs

After the test completes, the JUnit view should display something like:

Screenshot of JUnit view after running MinimalSpec with ScalaTest

11/12/2009: 2:41 pm: RobertMySQL

After upgrading to the newest version Maatkit, the invaluable toolkit for MySQL, I was no longer able to run any of the Maatkit tools. The problem turned out to be caused by my update to MacPorts after upgrading to Snow Leopard.

By default, Apple provides perl 5.10, which is built in 64-bit mode, though backwards compatible with 32-bit binaries. However, I was seeing a different version.

$ perl --version
 
This is perl, v5.8.9 built for darwin-2level

Trying to run mk-archiver resulted in the following error (again, wrapping some lines for readability):

$ mk-archiver --version
Can't load '/opt/local/lib/perl5/site_perl/5.8.8//darwin-2level/auto/Data/Dumper/Dumper.bundle'
for module Data::Dumper:
dlopen(/opt/local/lib/perl5/site_perl/5.8.8//darwin-2level/auto/Data/Dumper/Dumper.bundle, 1):
no suitable image found.  Did find:
/opt/local/lib/perl5/site_perl/5.8.8//darwin-2level/auto/Data/Dumper/Dumper.bundle:
mach-o, but wrong architecture at
/opt/local/lib/perl5/5.8.9/darwin-2level/XSLoader.pm line 73.
 at /opt/local/lib/perl5/site_perl/5.8.8//darwin-2level/Data/Dumper.pm line 27
Compilation failed in require at /opt/local/bin/mk-archiver line 874.
BEGIN failed--compilation aborted at /opt/local/bin/mk-archiver line 874.

The “wrong architecture” note in the error message led me to eventually find the cause of my troubles. MacPorts added the following to my ~/.bash_profile (I wrapped a line to make it easier to read:

# MacPorts Installer addition on 2009-10-31_at_23:33:12:
# adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

This caused the 32-bit perl 5.8.9 from MacPorts to be used instead of the 64-bit perl 5.10 provided with Snow Leopard. Commenting out the export line above was the first step to fixing the problem.

I also noticed that I wasn’t adding /usr/bin to my path before I added the MacPorts paths. So, I made the following change to my .bash_profile (leaving out some of the path components for clarity).

PATH_PREFIX=/usr/local/bin:/usr/bin:$JDK_HOME/bin:/opt/local/bin:/opt/local/sbin
PATH_SUFFIX=$ANT_HOME/bin:$MYSQL_HOME/bin:$SCALA_HOME/bin:$GIT_HOME/bin
export PATH=$PATH_PREFIX:$PATH:$PATH_SUFFIX

Using source .bash_profile won’t update the PATH variable properly because of the way it is being constructed above. So, start a new console to get a corrected value for the PATH. Then you should get:

$ perl --version
 
This is perl, v5.10.0 built for darwin-thread-multi-2level

and something like

$ mk-archiver --version
mk-archiver  Ver 1.0.20 Distrib 5014 Changeset 5004