Rcov Update For JRuby 1.1.4

31 08 2008

Just a quick post. An update that makes rcov compatible with JRuby 1.1.4 has been released. Here’s the announcement on the user’s list. Again, I’d like to commend Jay on his work on this. I really have not had the time to work on this at all, and Jay is the only reason anything has been released at all. Thanks Jay!


Rcov for JRuby Gem Available

31 07 2008

It’s been a long time coming, but, thanks to Jay, who’s really kicked some ass to make this happen, the long suffering Rcov port to JRuby finally is bearing fruit. The first gem is now available.

There are a few known issues. Performance isn’t that great. And there is some slight variation between what Rcov reports in JRuby vs. MRI. But Jay’s been using it in his build environment, and so should you. So go ahead and grab the gem and help us make it great!

Time’s Making Changes

26 06 2008

What could be so stupendous as to merit sharing a title with The Best of Tesla?

The paperwork is finally done and everything is official, so I guess I can talk about it. I’ve got a new job with Collaborative Software Initiative. I start the first full week in July. I’m really excited. This is going to be a big change for me in a lot of ways.

First of all, since the company’s in Portland and I’m not, I’ll be working from home. People like to talk about the ups and downs of working from home: how you can never get away from work that way; how it’s hard to keep your personal life and your work separate; how you’re going to miss human contact. I think those people are jealous or nuts. When I’ve gotten to work from home in the past, it has ruled. I really think I’m going to eat it up.

The client is in Utah (well, the client is Utah), so I will be traveling a scosh, which I’ve never done. I’m looking forward to getting to see new places, but this is the aspect of the job that has me the most anxious. Since my daughter’s birth, I don’t think I’ve ever been away from her longer then twenty-four hours.

The product is a JRuby on Rails application, and it’s being developed in a lean/agile manner. I’ve been looking for a chance to work in an environment that was Ruby, or Smalltalk, and was agile. I’m not as fond of Java (the language) as I used to be, and my current company just doesn’t seem to be ready for agile development (if this post is any indicator).

The product is open source (or will be soon). This represents a huge change for me. A few months ago, I don’t think I appreciated how important this would be to me. Back then, I was trying to set up a talk about some work I had done in our software using JRuby for eRubyCon. I thought it would be a good talk and fit right into the eRubyCon concept. I was eventually shut down because there was concern amongst the powers-that-be that I would be exposing too much of our architecture and we’d be giving up a competitive advantage.  That was when I realized that I’m an open source guy, and I need to be making my living writing open source.

That is lot of change for one guy with a family to feed to make. I feel like I should be nervous. I’m not. I’m excited and I can’t wait to get started.

Writing an ActiveRecord-JDBC Adapter

23 04 2008

Rails 2.0 made writing your own ActiveRecord adapters easier. Combine
that with JDBC and you have some really nice tools for creating data
driven ruby applications working against any number of databases.

So, How Do I Write One?

Like a lot of things in the Ruby and Rails world, once you understand
the conventions, everything else is easy. So much so that, once you
know what you are looking for, writing an adapter is about copying the
patterns that have already been laid out in the other adapters.

The key steps for creating an adapter are:

– create a new lib/jdbc_adapter/jdbc_<adaptername>.rb

– update lib/active_record/connection_adapters/jdbc_adapter_spec.rb to
require ‘jdbc_adapter/jdbc_<adaptername>’

– create a new test/<adaptername>_simple_test.rb and an associated

– add test rake task to the Rakefile.

(these were basically stolen from an email on the JRuby Users mailing list).

What Goes Where?

For the most part, you can figure out everything else you need to know
by reading the code. If you aren’t sure how to do something, there’s
probably already an example of it in the code somewhere.
Here are some things I think I’ve figured out:

– Most of the magic happens in the
lib/jdbc_adapter/jdbc_<adaptername>.rb file. The rest of these
points describe points of interest in that file.

– ::JdbcSpec::ActiveRecordExtensions is where you put the connection
method, <adaptername>_connection. This is what Rails will call when
someone sets the adapter name to <adaptername>. You can use this to
turn Rails flavored config hashes into nasty JDBC URLs. Users will
thank you.

– Create a ::JdbcSpec::<AdapterName> module. Make sure you follow the
conventions for self.column_selector and
self.adapter_selector. There’s no reason not to.

– Lots of crazy stuff happens in the ::JdbcSpec::<AdapterName>
module. Write a custom create_table method. Rewrite “LIMIT 1”
queries for dialects that don’t support the LIMIT keyword. Support
migration behaviors that aren’t natively supported by the
database. Many more examples exist.

– Create a ::JdbcSpec::<AdapterName>::Column module. This is where
individual field customization happens. You can customize quoting
and unquoting of fields and column names. You can cast special types
(like bit to boolean). You can modify types on the fly.

Anything Else?

Eh, probably. I can’t think of anything else that you necessarily need
to know. I suppose you could do all of your modules in Java as part of
a Ruby Service. If your database driver has a friendly enough license,
you could distribute that as its own gem. This simplifies distribution
and installation for end users. I haven’t tried that yet, but it looks
simple enough. Leave a comment if can think of something I missed.

Rcov for JRuby Update

19 03 2008

It works well in simple cases. Running from Rake doesn’t work. Running rcov from rspec doesn’t work yet, either.

There are 13 unit tests that fail (12 failures and 1 error). The failures are mostly minor differences in output between MRI and JRuby. The big old up now is the one error. It appears to be a bug in the reset code. Once data collection starts, calling reset clears the callected data (desirable) and prevents new data from being collection (less desirable). I think that’s why running rcov from rspec fails.

JRuby ETL Performance Boost

25 01 2008

I spent today looking for ways to get our JRuby ETL to handle more data. Today’s work was mostly centered around cutting back on reads from the database. I had a lot of luck taking advantage of data already available in the JMS message we receive. The numbers aren’t in, but I think this should make it fast enough. It also looks like upgrading to a newer JRuby release will be fairly painless. That should get us some JIT, too. Sweet.

While I was poking through the code, I realized that it could use some work. It’s not thread safe, for one thing. That’s not a problem in production now, but I’d like to be able to run multiple processes one day and process more messages.

So I had the idea. The current tool uses TestCase, but I thought that I might start writing rspecs based on a) what the ETL does now, and b) what I’d like it to do in version 2.0. Once the specs are solid, I’ll start a rewrite. It’ll be interesting to see what comes of it.

As an aside, I popped into the local RUG. Coincidently, they were talking about rspec. Nothing earth shattering, but it seemed like a good group (if a little heavy with M$ Mono users).

Dear Lazy Web, What’s With Batch Eating Equals?

15 01 2008

Does anyone know why batch eats equal signs in a construct like this?:

jruby -S rake TEST=somefile.rb

More importantly, does anyone know how to make it stop (without resorting to “TEST=somefile.rb”.