spec/integration/riak/test_server_spec.rb in riak-client-0.9.8 vs spec/integration/riak/test_server_spec.rb in riak-client-1.0.0.beta

- old
+ new

@@ -1,174 +1,38 @@ -# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc. -# -# Licensed 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. -require File.expand_path("../../spec_helper", File.dirname(__FILE__)) +require 'spec_helper' +require 'riak/test_server' -if $test_server - describe Riak::TestServer do - before do - @server = $test_server - end +describe Riak::TestServer do + subject { $test_server } + let(:app_config) { (subject.etc + 'app.config').read } - after do - @server.stop - @server.cleanup - end + it "should add the test backends to the code path" do + erl_src = File.expand_path("../../../../erl_src", __FILE__) + subject.env[:riak_kv][:add_paths].should include(erl_src) + app_config.should match(/\{add_paths, \[.*#{erl_src.inspect}.*\]\}/) + end - describe "isolation from and modification of the existing install" do - before do - @server.prepare! - @riak_bin = "#{@server.temp_dir}/bin/riak" - @vm_args = "#{@server.temp_dir}/etc/vm.args" - @app_config = "#{@server.temp_dir}/etc/app.config" - end + it "should use the KV test backend" do + subject.kv_backend.should == :riak_kv_test_backend + subject.env[:riak_kv][:storage_backend].should == :riak_kv_test_backend + app_config.should include("{storage_backend, riak_kv_test_backend}") + end - describe "for app.config" do - it "should create the app.config file in the temporary directory" do - File.should be_exist(File.expand_path(@app_config)) - end + it "should use the Search test backend" do + subject.search_backend.should == :riak_search_test_backend + subject.env[:riak_search][:search_backend].should == :riak_search_test_backend + app_config.should include("{search_backend, riak_search_test_backend}") + end - it "should be a correct Erlang config" do - config = File.read(@app_config) - config[-2..-1].should == '].' - config[0..0].should == '[' - end + it "should clear stored data" do + # TODO: use $test_server.to_host when client/host split is finished. + client = Riak::Client.new(:http_port => subject.http_port) + obj = client['test_bucket'].new("test_item") + obj.data = {"data" => "testing"} + obj.store # rescue nil - it "should set the backend to use the test backend" do - File.readlines(@app_config).should be_any do |line| - line =~ /\{storage_backend\s*,\s*(.*)\}/ && $1 == "riak_kv_test_backend" - end - end - - it "should set the default ports to 9000-9002" do - config = File.readlines(@app_config) - config.should be_any do |line| - line =~ /\{web_port\s*,\s*(.*)\}/ && $1 == "9000" - end - config.should be_any do |line| - line =~ /\{handoff_port\s*,\s*(.*)\}/ && $1 == "9001" - end - config.should be_any do |line| - line =~ /\{pb_port\s*,\s*(.*)\}/ && $1 == "9002" - end - end - - it "should set the ring directory to point to the temporary directory" do - config = File.readlines(@app_config) - config.should be_any do |line| - line =~ /\{ring_state_dir\s*,\s*(.*)\}/ && $1 == File.join(@server.temp_dir, "data", "ring") - end - end - end - - describe "for vm.args" do - it "should create the vm.args file in the temporary directory" do - File.should be_exist(File.expand_path(@vm_args)) - end - - it "should set a quasi-random node name" do - File.readlines(@vm_args).should be_any do |line| - line =~ /^-name (.*)/ && $1 =~ /riaktest\d+@/ - end - end - - it "should set a quasi-random cookie" do - File.readlines(@vm_args).should be_any do |line| - line =~ /^-setcookie (.*)/ && $1 != "riak" - end - end - end - - describe "for the riak script" do - it "should create the script in the temporary directory" do - File.should be_exist(File.expand_path(@riak_bin)) - end - - it "should modify the RUNNER_SCRIPT_DIR to point to the temporary directory" do - File.readlines(@riak_bin).should be_any do |line| - line =~ /RUNNER_SCRIPT_DIR=(.*)/ && $1 == File.expand_path("#{@server.temp_dir}/bin") - - end - end - - it "should modify the RUNNER_ETC_DIR to point to the temporary directory" do - File.readlines(@riak_bin).should be_any do |line| - line =~ /RUNNER_ETC_DIR=(.*)/ && $1 == File.expand_path("#{@server.temp_dir}/etc") - end - end - - it "should modify the RUNNER_USER to point to the current user" do - File.readlines(@riak_bin).should be_any do |line| - line =~ /RUNNER_USER=(.*)/ && $1 == (ENV['USER'] || `whoami`) - end - end - - it "should modify the RUNNER_LOG_DIR to point to the temporary directory" do - File.readlines(@riak_bin).should be_any do |line| - line =~ /RUNNER_LOG_DIR=(.*)/ && $1 == File.expand_path("#{@server.temp_dir}/log") - end - end - - it "should modify the RUNNER_BASE_DIR so that it is not relative" do - File.readlines(@riak_bin).should be_any do |line| - line =~ /RUNNER_BASE_DIR=(.*)/ && $1.strip != "${RUNNER_SCRIPT_DIR%/*}" && File.directory?($1) - end - end - - it "should modify the PIPE_DIR to point to the temporary directory" do - File.readlines(@riak_bin).should be_any do |line| - line =~ /PIPE_DIR=(.*)/ && $1 == File.expand_path("#{@server.temp_dir}/pipe") && File.directory?($1) - end - end - end - end - - it "should cleanup the existing config" do - @server.prepare! - @server.cleanup - File.should_not be_directory(@server.temp_dir) - end - - it "should start Riak in the background" do - @server.prepare! - @server.start.should be_true - @server.should be_started - end - - it "should stop a started test server" do - @server.prepare! - @server.start.should be_true - @server.stop - @server.should_not be_started - end - - it "should recycle the server contents" do - begin - @server.prepare! - @server.start.should be_true - - client = Riak::Client.new(:http_port => 9000) - obj = client['test_bucket'].new("test_item") - obj.data = {"data" => "testing"} - obj.store rescue nil - - @server.recycle - @server.should be_started - lambda do - client['test_bucket']['test_item'] - end.should raise_error(Riak::FailedRequest) - ensure - @server.stop - end - end + subject.drop + expect { + client['test_bucket']['test_item'] + }.to raise_error(Riak::FailedRequest) end end