[ap4r-devel] [196] trunk/samples/HelloWorld: second trial to make rails integration test with ap4r

shino at rubyforge.org shino at rubyforge.org
Mon May 28 05:04:07 EDT 2007


Revision: 196
Author:   shino
Date:     2007-05-28 05:04:06 -0400 (Mon, 28 May 2007)

Log Message:
-----------
second trial to make rails integration test with ap4r

Added Paths:
-----------
    trunk/samples/HelloWorld/config/ap4r.yml.sample
    trunk/samples/HelloWorld/test/ap4r_test_helper.rb
    trunk/samples/HelloWorld/test/integration/hello_rails_integration_with_ap4r_test.rb

Added: trunk/samples/HelloWorld/config/ap4r.yml.sample
===================================================================
--- trunk/samples/HelloWorld/config/ap4r.yml.sample	                        (rev 0)
+++ trunk/samples/HelloWorld/config/ap4r.yml.sample	2007-05-28 09:04:06 UTC (rev 196)
@@ -0,0 +1,10 @@
+---
+# need development? or production?
+# or consider proper structure for these
+development:
+
+test:
+  root_dir: ~/work/ap4r_project
+  config_file: config/queues_disk.cfg
+
+production:

Added: trunk/samples/HelloWorld/test/ap4r_test_helper.rb
===================================================================
--- trunk/samples/HelloWorld/test/ap4r_test_helper.rb	                        (rev 0)
+++ trunk/samples/HelloWorld/test/ap4r_test_helper.rb	2007-05-28 09:04:06 UTC (rev 196)
@@ -0,0 +1,81 @@
+# Author:: Shunichi Shinohara
+# Copyright:: Copyright (c) 2007 Future Architect Inc.
+# Licence:: MIT Licence
+
+require 'erb'
+require 'yaml'
+require 'reliable-msg'
+require 'ap4r'
+
+class Ap4rTestHelper
+
+  def initialize(config_file = RAILS_ROOT + "/config/ap4r.yml")
+    raise "please create config/ap4r.yml to configure ap4r service." unless File.exist?(config_file)
+
+    config = {}
+    File.open(config_file, "r") do |input|
+      YAML.load_documents(ERB.new(input.read).result) do |doc|
+        config.merge! doc
+      end
+    end
+    @test_config = config["test"]
+    @root_dir = @test_config["root_dir"]
+    @config_file = @test_config["config_file"]
+    @test_server_config = ReliableMsg::Config.new(File.join(@root_dir, @config_file))
+    raise "config file #{@test_server_config.path} NOT exist!" unless @test_server_config.exist?
+    @test_server_config.load_no_create
+  end
+
+  # Starts ap4r service.
+  def start_service(wait_until_started = true)
+
+    command = "ruby #{@test_config["start_ruby_args"]} #{@root_dir}/script/mongrel_ap4r.rb " +
+      "start -d -c #{@root_dir} -A #{@config_file}"
+    print "executing command: #{command} ..."
+    system(command)
+    puts
+
+    @qm = DRbObject.new_with_uri("druby://localhost:#{@test_server_config.drb["port"]}")
+    # TODO: need to wait until ap4r has really started 2007/05/28 by shino
+    puts "ap4r service has started"
+  end
+
+  # Stops ap4r service.
+  def stop_service
+    command = "ruby #{@test_config["stop_ruby_args"]} #{@root_dir}/script/mongrel_ap4r.rb " +
+      "stop -c #{@root_dir}"
+    print "executing command: #{command} ..."
+    system(command)
+    puts
+
+    @qm = nil
+    puts "ap4r service has stopped"
+  end
+
+  def clear(*queues)
+    queues.each do |queue|
+      q = ReliableMsg::Queue.new(queue)
+      loop do
+        break unless q.get
+      end
+    end
+  end
+end
+
+ap4r_test_helper = Ap4rTestHelper.new
+
+at_exit {
+  ap4r_test_helper.stop_service()
+}
+
+ap4r_test_helper.start_service()
+
+class ActionController::IntegrationTest
+  cattr_accessor :ap4r_helper
+
+  def ap4r_helper
+    @@ap4r_helper
+  end
+end
+
+ActionController::IntegrationTest.ap4r_helper = ap4r_test_helper

Added: trunk/samples/HelloWorld/test/integration/hello_rails_integration_with_ap4r_test.rb
===================================================================
--- trunk/samples/HelloWorld/test/integration/hello_rails_integration_with_ap4r_test.rb	                        (rev 0)
+++ trunk/samples/HelloWorld/test/integration/hello_rails_integration_with_ap4r_test.rb	2007-05-28 09:04:06 UTC (rev 196)
@@ -0,0 +1,15 @@
+# Author:: Shunichi Shinohara
+# Copyright:: Copyright (c) 2007 Future Architect Inc.
+# Licence:: MIT Licence
+
+require "#{File.dirname(__FILE__)}/../test_helper"
+require "#{File.dirname(__FILE__)}/../ap4r_test_helper"
+
+class HelloRailsIntegrationWithAp4rTest < ActionController::IntegrationTest
+
+  # Trivial test case to test the ap4r test helper.
+  def test_truth
+    assert true
+    assert_not_nil ap4r_helper()
+  end
+end




More information about the ap4r-devel mailing list