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


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
Comments:

[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...

Posted by Arun Gupta's Blog on March 04, 2009 at 10:07 PM PST #

[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...

Posted by GlassFish on March 08, 2009 at 12:51 PM PDT #

[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...

Posted by Arun Gupta's Blog on March 08, 2009 at 11:39 PM PDT #

[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...

Posted by Arun Gupta's Blog on March 11, 2009 at 06:22 AM PDT #

[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...

Posted by Arun Gupta's Blog on March 16, 2009 at 04:49 AM PDT #

[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...

Posted by Arun Gupta's Blog on March 16, 2009 at 04:53 AM PDT #

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.

Posted by Roy on March 25, 2009 at 09:01 AM PDT #

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

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

Try using SQLite or some other database.

Posted by Arun Gupta on April 06, 2009 at 03:51 AM PDT #

[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...

Posted by Arun Gupta's Blog on April 27, 2009 at 11:16 PM PDT #

[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...

Posted by Arun Gupta's Blog on April 27, 2009 at 11:18 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today