Skip to main content

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

Posted by arungupta on March 4, 2009 at 7:27 AM PST



href="http://docs.codehaus.org/display/JRUBY/2009/02/24/JRuby+1.2.0RC1+Released">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  href="http://rubyforge.org/projects/glassfishgem/">GlassFish
Gem. The steps are described next.



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


style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
cellpadding="2" cellspacing="2">
~/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 href="http://dist.codehaus.org/jruby/1.2.0RC1/jruby-bin-1.2.0RC1.zip">JRuby
    1.2.0 RC1.
  2. Install Rails and GlassFish Gem as:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/tools/jruby-1.2.0RC1 > style="font-weight: bold;">./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:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/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:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/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 href="http://wiki.jruby.org/wiki/Running_Rails_with_ActiveRecord-JDBC">here.

  5. Create a simple scaffold:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/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:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    development:

      adapter: mysql

      encoding: utf8

      database: runner_development

      pool: 5

      username: root

      password:

      socket: /tmp/mysql.sock



    to


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    development:

      adapter: jdbcmysql

      encoding: utf8

      database: runner_development

      pool: 5

      username: duke style="font-weight: bold;">
      password: glassfish

      socket: /tmp/mysql.sock



    The change is highlighted in bold letters.

  7. Create and migrate the
    database as:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/tools/jruby-1.2.0RC1/samples/rails/runner > style="font-weight: bold;">../../../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 > style="font-weight: bold;">../../../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:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/tools/jruby-1.2.0RC1/samples/rails/runner > style="font-weight: bold;">../../../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:



    alt=""
    src="http://blogs.sun.com/arungupta/resource/ror/jruby12-rails222-gem0.92-runners.png">



    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 href="http://blogs.sun.com/arungupta/tags/totd">here.




Technorati: totd
rubyonrails
glassfish
v3 href="http://technorati.com/tag/jruby">jruby href="http://technorati.com/tags/gem">gem
integrationtest

Related Topics >>