lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r494108 - in /incubator/solr/trunk/client/ruby/solrb: ./ test/ test/functional/ test/unit/
Date Mon, 08 Jan 2007 16:05:03 GMT
Author: ehatcher
Date: Mon Jan  8 08:05:02 2007
New Revision: 494108

URL: http://svn.apache.org/viewvc?view=rev&rev=494108
Log:
SOLR-97: Rakefile now supports functional and unit tests.  Also added partially functioning
test:coverage task

Added:
    incubator/solr/trunk/client/ruby/solrb/test/functional/
    incubator/solr/trunk/client/ruby/solrb/test/functional/server_test.rb
    incubator/solr/trunk/client/ruby/solrb/test/test_solr_server.rb
    incubator/solr/trunk/client/ruby/solrb/test/unit/
    incubator/solr/trunk/client/ruby/solrb/test/unit/connection_test.rb
      - copied unchanged from r492692, incubator/solr/trunk/client/ruby/solrb/test/connection_test.rb
    incubator/solr/trunk/client/ruby/solrb/test/unit/request_test.rb
      - copied unchanged from r492583, incubator/solr/trunk/client/ruby/solrb/test/request_test.rb
    incubator/solr/trunk/client/ruby/solrb/test/unit/solr_mock_base.rb
      - copied unchanged from r492698, incubator/solr/trunk/client/ruby/solrb/test/solr_mock_base.rb
Removed:
    incubator/solr/trunk/client/ruby/solrb/test/connection_test.rb
    incubator/solr/trunk/client/ruby/solrb/test/request_test.rb
    incubator/solr/trunk/client/ruby/solrb/test/solr_mock_base.rb
    incubator/solr/trunk/client/ruby/solrb/test/test_helper.rb
Modified:
    incubator/solr/trunk/client/ruby/solrb/Rakefile

Modified: incubator/solr/trunk/client/ruby/solrb/Rakefile
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/client/ruby/solrb/Rakefile?view=diff&rev=494108&r1=494107&r2=494108
==============================================================================
--- incubator/solr/trunk/client/ruby/solrb/Rakefile (original)
+++ incubator/solr/trunk/client/ruby/solrb/Rakefile Mon Jan  8 08:05:02 2007
@@ -1,3 +1,34 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# the default task is to run both the unit and functional tests
+# functional tests require that a solr test server is running
+# but this Rakefil should take care of starting and stopping it 
+# for you
+# 
+# if you just want to run unit tests:
+#
+#    rake test_units
+#
+# and if you just want to run functional tests
+#
+#    rake test_functionals
+#
+# if you would like to see solr startup messages on STDERR
+# when starting solr test server during functional tests use:
+# 
+#    rake SOLR_CONSOLE=true
+
 SOLRB_VERSION = '0.0.1'
 
 require 'rubygems'
@@ -6,7 +37,7 @@
 require 'rake/rdoctask'
 require 'rake/packagetask'
 require 'rake/gempackagetask'
-require 'test/test_helper.rb'
+require 'test/test_solr_server.rb'
 
 task :default => [:test]
 
@@ -35,19 +66,51 @@
   rd.rdoc_dir = 'doc'
 end
 
-# append to the test task so that we can wrap 
-# Rake::TestTask with a call to start/stop a solr server
-
-task :test do
-  start_solr_server
+Rake::TestTask.new(:test_units) do |t|
+  t.pattern = 'test/unit/*_test.rb'
+  t.verbose = true
+  t.ruby_opts = ['-r solr', '-r test/unit', '-Itest/unit']
 end
 
-Rake::TestTask.new('test') do |t|
-  t.pattern = 'test/*_test.rb'
+Rake::TestTask.new(:test_functionals) do |t|
+  t.pattern = 'test/functional/*_test.rb'
   t.verbose = true
-  t.ruby_opts = ['-r solr', '-r test/unit', '-Itest']
+  t.ruby_opts = ['-r solr', '-r test/unit', '-Itest/functional']
 end
 
 task :test do
-  stop_solr_server
-end
+  # unit tests don't require a solr server
+  Rake::Task[:test_units].invoke rescue got_error = true
+
+  # functional tests do
+  solr_server = TestSolrServer.instance
+  solr_server.quiet = false if ENV['SOLR_CONSOLE']
+
+  begin
+    puts
+    puts "starting solr server for functional tests"
+    solr_server.start
+    sleep 10
+    Rake::Task[:test_functionals].invoke 
+  rescue 
+    got_error = true
+  ensure
+    puts "stopping solr server"
+    solr_server.stop
+  end
+
+  raise "test failures" if got_error
+end
+
+# TODO: fix this so it works, it is not happy with connection_test.rb for some reason
+#       borrowed from here: http://clarkware.com/cgi/blosxom/2007/01/05#RcovRakeTask
+namespace :test do
+  desc 'Measures test coverage'
+  task :coverage do
+    rm_f "coverage"
+    rm_f "coverage.data"
+    system("rcov --text-summary -Ilib test/unit/*_test.rb")
+    system("open coverage/index.html") if PLATFORM['darwin']
+  end
+
+end
\ No newline at end of file

Added: incubator/solr/trunk/client/ruby/solrb/test/functional/server_test.rb
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/client/ruby/solrb/test/functional/server_test.rb?view=auto&rev=494108
==============================================================================
--- incubator/solr/trunk/client/ruby/solrb/test/functional/server_test.rb (added)
+++ incubator/solr/trunk/client/ruby/solrb/test/functional/server_test.rb Mon Jan  8 08:05:02
2007
@@ -0,0 +1,17 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class TestServer < Test::Unit::TestCase
+  def test_ok
+    assert_equal true, true
+  end
+end

Added: incubator/solr/trunk/client/ruby/solrb/test/test_solr_server.rb
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/client/ruby/solrb/test/test_solr_server.rb?view=auto&rev=494108
==============================================================================
--- incubator/solr/trunk/client/ruby/solrb/test/test_solr_server.rb (added)
+++ incubator/solr/trunk/client/ruby/solrb/test/test_solr_server.rb Mon Jan  8 08:05:02 2007
@@ -0,0 +1,48 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A singleton class for starting/stopping a Solr server for testing purposes
+# The behavior of TestSolrServer can be modified prior to start() by changing 
+# port, solr_home, and quiet properties.
+ 
+class TestSolrServer
+  require 'singleton'
+  include Singleton
+  attr_accessor :port, :solr_home, :quiet
+ 
+  # configure the singleton with some defaults
+  def initialize
+    @port = 8888
+    @quiet = true
+    root_dir = File.expand_path(File.dirname(__FILE__) + '/..')
+    @solr_dir = "#{root_dir}/solr"
+    @solr_home = "#{root_dir}/test" 
+    @pid = nil
+  end
+
+  # start the solr server
+  def start
+    Dir.chdir(@solr_dir) do
+      @pid = fork do
+        STDERR.close if @quiet
+        exec "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} " + 
+          "-jar start.jar"
+      end
+    end
+  end
+ 
+  # stop a running solr server
+  def stop
+    Process.kill('TERM', @pid)
+    Process.wait
+  end
+ end



Mime
View raw message