Miles to go …

March 3, 2009

TOTD #70: JRuby and GlassFish Integration Test# 1: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish Gem

Filed under: glassfish, rails, totd — arungupta @ 11:45 pm

JRuby 1.2.0 RC1 is out for a while!

I typically run a series of tests to ensure that any publicly released version of JRuby works nicely with GlassFish. The main goal of running these tests is to discover any blocking bugs before users do. This particular set of tests are being run little late as RC1 was released on Feb 24th. But I’ll describe all the steps clearly in the next few blog entries so that you can try them out yourself.

JRuby team runs a whole slew of tests before releasing any bits. Similarly we run a bunch of tests before releasing GlassFish Gem. These tests, as mentioned earlier, are only to ensure that the latest release of JRuby works nicely with the latest bits of GlassFish.

The first basic test is to check if a simple Rails application can be run using the latest GlassFish Gem. The steps are described next.

First, lets create a database user and grant privileges required by our application:

~/tools >sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.1.30 MySQL Community Server (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> create user duke@localhost identified by ‘glassfish’;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on runner_development.* to duke@localhost identified by ’glassfish’;
Query OK, 0 rows affected (0.03 sec)

mysql> grant all on runner_production.* to duke@localhost identified by ’glassfish’;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

The “runner_development” and “runner_production” databases will be created later. And the database are dropped and created fresh for every test run.

Now lets try to create our first Rails application using JRuby and run it using GlassFish gem:

  1. Download and unzip JRuby 1.2.0 RC1.
  2. Install Rails and GlassFish Gem as:
    ~/tools/jruby-1.2.0RC1 >./bin/jruby -S gem install rails glassfish
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Successfully installed activesupport-2.2.2
    Successfully installed activerecord-2.2.2
    Successfully installed actionpack-2.2.2
    Successfully installed actionmailer-2.2.2
    Successfully installed activeresource-2.2.2
    Successfully installed rails-2.2.2
    Successfully installed rack-0.9.1
    Successfully installed glassfish-0.9.2-universal-java
    8 gems installed
    Installing ri documentation for activesupport-2.2.2…
    Installing ri documentation for activerecord-2.2.2…
    Installing ri documentation for actionpack-2.2.2…
    Installing ri documentation for actionmailer-2.2.2…
    Installing ri documentation for activeresource-2.2.2…
    Installing ri documentation for rack-0.9.1…
    Installing ri documentation for glassfish-0.9.2-universal-java…
    Installing RDoc documentation for activesupport-2.2.2…
    Installing RDoc documentation for activerecord-2.2.2…
    Installing RDoc documentation for actionpack-2.2.2…
    Installing RDoc documentation for actionmailer-2.2.2…
    Installing RDoc documentation for activeresource-2.2.2…
    Installing RDoc documentation for rack-0.9.1…
    Installing RDoc documentation for glassfish-0.9.2-universal-java…
  3. Create a new app as:
    ~/tools/jruby-1.2.0RC1/samples/rails >../../bin/jruby -S rails runner -d mysql
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
          create 
          create  app/controllers
          create  app/helpers
          . . .
          create  log/server.log
          create  log/production.log
          create  log/development.log
          create  log/test.log
  4. Install MySQL JDBC ActiveRecord adapter as:
    ~/tools/jruby-1.2.0RC1/samples/rails >../../bin/jruby -S gem install activerecord-jdbcmysql-adapter
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Successfully installed activerecord-jdbc-adapter-0.9
    Successfully installed jdbc-mysql-5.0.4
    Successfully installed activerecord-jdbcmysql-adapter-0.9
    3 gems installed
    Installing ri documentation for activerecord-jdbc-adapter-0.9…
    Installing ri documentation for jdbc-mysql-5.0.4…
    Installing ri documentation for activerecord-jdbcmysql-adapter-0.9…
    Installing RDoc documentation for activerecord-jdbc-adapter-0.9…
    Installing RDoc documentation for jdbc-mysql-5.0.4…
    Installing RDoc documentation for activerecord-jdbcmysql-adapter-0.9…

    More details on configuring this adapter here.

  5. Create a simple scaffold:
    ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby script/generate scaffold runner distance:float time:integer
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
          exists  app/models/
          exists  app/controllers/
          . . .
          create    test/fixtures/runners.yml
          create    db/migrate
          create    db/migrate/20090226171752_create_runners.rb
  6. Edit “config/database.yml” to use the JDBC adapter and specify database username/password. Change:
    development:
      adapter: mysql
      encoding: utf8
      database: runner_development
      pool: 5
      username: root
    >   password:
      socket: /tmp/mysql.sock

    to

    development:
      adapter: jdbcmysql
      encoding: utf8
      database: runner_development
      pool: 5
      username: duke
      password: glassfish
      socket: /tmp/mysql.sock

    The change is highlighted in bold letters.

  7. Create and migrate the database as:
    ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S rake db:create
    (in /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner)
    ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S rake db:migrate
    (in /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner)
    ==  CreateRunners: migrating ==================================================
    — create_table(:runners)
       -> 0.1330s
       -> 0 rows
    ==  CreateRunners: migrated (0.1340s) =========================================

    The default RAILS_ENV is DEVELOPMENT so there is no need to specify any addtional arguments.

  8. And then run the application as:
    ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S glassfish
    Feb 26, 2009 10:30:10 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic start
    INFO: Cache not present, will revert to less efficient algorithm
    Feb 26, 2009 10:30:10 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic findDerbyClient
    INFO: Cannot find javadb client jar file, jdbc driver not available
    Feb 26, 2009 10:30:10 AM APIClassLoaderService createAPIClassLoader
    INFO: APIClassLoader = java.net.URLClassLoader@14a66e3f
    no resource bundle found for version, using default GlassFish version
    Feb 26, 2009 10:30:11 AM AppServerStartup run
    INFO: [Thread[GlassFish Kernel Main Thread,5,main]] started
    Feb 26, 2009 10:30:11 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3000
    Feb 26, 2009 10:30:11 AM com.sun.enterprise.v3.admin.adapter.AdminEndpointDecider setGuiContextRoot
    INFO: Admin Console Adapter: context root: /_____admingui
    Feb 26, 2009 10:30:11 AM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setStateMsg
    INFO: The Admin Console Application is not yet installed.
    Feb 26, 2009 10:30:11 AM com.sun.enterprise.v3.admin.adapter.AdminEndpointDecider setGuiContextRoot
    INFO: Admin Console Adapter: context root: /_____admingui
    Feb 26, 2009 10:30:11 AM org.glassfish.scripting.rails.RailsDeployer load
    INFO: Loading application runner at /
    Feb 26, 2009 10:30:11 AM com.sun.grizzly.jruby.RailsAdapter <init>
    INFO: Jruby version is: 1.2.0RC1
    Feb 26, 2009 10:30:11 AM com.sun.grizzly.jruby.rack.RackApplicationChooser detectRails
    INFO: Detected Rails application
    Feb 26, 2009 10:30:11 AM com.sun.grizzly.jruby.rack.RackApplicationChooser detectRails
    INFO: Rails not in thread-safe mode, starting in single-thread mode
    Feb 26, 2009 10:30:11 AM com.sun.grizzly.pool.DynamicPool logDynamicStatus
    INFO: Pool started without dynamic resizing enabled. Pool will not attempt to determine the upper and lower bounds that it should be using, and will stay at 1
    Feb 26, 2009 10:30:16 AM  
    SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Feb 26, 2009 10:30:18 AM  
    INFO: RAILS_ROOT /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner
    Feb 26, 2009 10:30:18 AM  
    INFO: PUBLIC_ROOT /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner/public
    Feb 26, 2009 10:30:19 AM com.sun.grizzly.pool.DynamicPool$1 run
    INFO: New instance created in 7,074 milliseconds
    Feb 26, 2009 10:30:19 AM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: GlassFish v3  startup time : Static(525ms) startup services(7962ms) total(8487ms)
    Feb 26, 2009 10:30:19 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic start
    INFO: Started cache creation
    Feb 26, 2009 10:30:20 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic start
    INFO: Finished cache creation
    Feb 26, 2009 10:30:34 AM sun.reflect.NativeMethodAccessorImpl invoke0
    INFO: 

    After adding few entries, the output at “http://localhost:3000/runners” looks like:

    So we are able to create a trivial Rails application and run it using GlassFish Gem, that passes Test#1.

The subsequent blogs will show the remainder of tests.

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive of all tips is available here.

Technorati: totd rubyonrails glassfish v3 jruby gem integrationtest

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #71: JRuby and GlassFish Integration Test #2: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish v3 Prelude
  2. TOTD #73: JRuby and GlassFish Integration Test #4: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v2 + Warbler
  3. TOTD #72: JRuby and GlassFish Integration Test #3: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v3
  4. TOTD #74: JRuby and GlassFish Integration Test #5: JRuby 1.2.0 RC2 + Rails 2.x.x + GlassFish + Redmine
  5. TOTD #110: JRuby on Rails application using Oracle on GlassFish

11 Comments »

  1. [Trackback] TOTD #70&nbsp;shows the first integration integration tests that I typically run to ensure that the latest JRuby and GlassFish versions work nicely with each other. &nbsp;The second test (explained in this blog) ensures that the same application can b…

    Comment by Arun Gupta's Blog — March 5, 2009 @ 6:07 am

  2. [Trackback] TOTD #70 shows the first integration integration tests that I typically run to ensure that the latest JRuby and GlassFish versions work nicely with each other.  The second test (explained in this blog) ensures that the same application can be deployed…

    Comment by GlassFish — March 8, 2009 @ 7:51 pm

  3. [Trackback] TOTD #70&nbsp;and #71 shows the first two integration tests that I typically run to ensure that the latest JRuby and GlassFish versions work nicely with each other. &nbsp;#70 showed how to create a trivial Rails application and run it…

    Comment by Arun Gupta's Blog — March 9, 2009 @ 6:39 am

  4. [Trackback] TOTD #70, #71, #72 shows the first three integration tests that I typically run to ensure that the latest JRuby and GlassFish versions work nicely with each other. &nbsp;#70 showed how to create a trivial Rails application and run…

    Comment by Arun Gupta's Blog — March 11, 2009 @ 1:22 pm

  5. [Trackback] TOTD #70, #71, #72, #73 shows four integration tests that can ensure that the latest JRuby and GlassFish versions work nicely with each other. #70 showed how to create a trivial Rails application and run it using GlassFish Gem.&nbsp;#71…

    Comment by Arun Gupta's Blog — March 16, 2009 @ 11:49 am

  6. [Trackback] TOTD #70, #71, #72, #73 shows four integration tests that can ensure that the latest JRuby and GlassFish versions work nicely with each other. #70 showed how to create a trivial Rails application and run it using GlassFish Gem.&nbsp;#71…

    Comment by Arun Gupta's Blog — March 16, 2009 @ 11:53 am

  7. I get this error during the db:migrate

    $ ../../../bin/jruby -S rake db:migrate
    rake aborted!
    The driver encountered an error: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown database ‘runner_development’

    I have run db:create before migrate but doesn’t look like it creates the database which I can confirm from MySQL explorer. However, if I pre-create the database through explorer for user duke, it works.

    Comment by Roy — March 25, 2009 @ 4:01 pm

  8. Roy, db:create not working with MySQL is filed as:

    http://jira.codehaus.org/browse/JRUBY-3502

    Try using SQLite or some other database.

    Comment by Arun Gupta — April 6, 2009 @ 10:51 am

  9. [Trackback] Sinatra is a DSL for quickly creating web-applications in Ruby with minimal effort. Like Rails and Merb, Sinatra is not an MVC framework and basically follows a flat-file structure instead. The framework define conventions such as location of static…

    Comment by Arun Gupta's Blog — April 28, 2009 @ 6:16 am

  10. [Trackback] Sinatra is a DSL for quickly creating web-applications in Ruby with minimal effort. Like Rails and Merb, Sinatra is not an MVC framework and basically follows a flat-file structure instead. The framework define conventions such as location of static…

    Comment by Arun Gupta's Blog — April 28, 2009 @ 6:18 am

  11. [...] TOTD #70: Deploying Rails application on GlassFish Gem [...]

    Pingback by TOTD #110: JRuby on Rails application using Oracle on GlassFish « Miles to go … — October 8, 2009 @ 3:42 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress