Permalink
Browse files

merged in http_errors branch

fixed conflict with recent forks
  • Loading branch information...
mwmitchell committed Feb 27, 2010
2 parents d2ecccc + 6b72093 commit bd3ef0cf01256c71404b86a0abac12c9a0646d93
Showing with 52 additions and 5 deletions.
  1. +18 −0 lib/rsolr/client.rb
  2. +1 −1 lib/rsolr/connection/requestable.rb
  3. +20 −0 spec/api/client_spec.rb
  4. +13 −4 spec/api/connection/requestable_spec.rb
View
@@ -95,6 +95,24 @@ def delete_by_id(id)
def delete_by_query(query)
update message.delete_by_query(query)
end
+
+ # Ping the server and make sure it is alright
+ # solr.ping?
+ #
+ # It returns true if the server pings and the status is OK
+ # It returns false otherwise -- which probably cannot happen
+ # Or raises an exception if there is a failure to connect or
+ # the ping service is not activated in the solr server
+ #
+ # The default configuration point of the PingRequestHandler
+ # in the solr server of '/admin/ping' is assumed. If it is
+ # some other location, pass that in as the path
+ #
+ def ping?( path = '/admin/ping', params = {} )
+ response = request( path, params )
+ return response['status'] == "OK"
+ end
+
# shortcut to RSolr::Message::Generator
def message
@@ -92,4 +92,4 @@ def prepend_base url
full_url += url
end
-end
+end
View
@@ -91,6 +91,26 @@
and_return(:params=>{})
client.request '/music', :q=>'Coltrane'
end
+
+ end
+
+ context :ping do
+ it 'should forwad #ping? calls to the connection' do
+ client.connection.should_receive(:request).
+ with('/admin/ping', :wt => :ruby ).
+ and_return( :params => { :wt => :ruby },
+ :status_code => 200,
+ :body => "{'responseHeader'=>{'status'=>0,'QTime'=>44,'params'=>{'echoParams'=>'all','echoParams'=>'all','q'=>'solrpingquery','qt'=>'standard','wt'=>'ruby'}},'status'=>'OK'}" )
+ client.ping?
+ end
+
+ it 'should raise an error if the ping service is not available' do
+ client.connection.should_receive(:request).
+ with('/admin/ping', :wt => :ruby ).
+ # the first part of the what the message would really be
+ and_raise( RSolr::RequestError.new("Solr Response: pingQuery_not_configured_consider_registering_PingRequestHandler_with_the_name_adminping_instead__") )
+ lambda { client.ping? }.should raise_error( RSolr::RequestError )
+ end
end
@@ -148,11 +148,20 @@ def self.included base
it 'should send a post to itself when :method=>:post is set even if no POST data is supplied' do
requestable.should_receive(:post).
- with("http://127.0.0.1:8983/solr/blah", "", {"Content-Type"=>"application/x-www-form-urlencoded"}).
+ with("http://127.0.0.1:8983/solr/blah?q=testing", "q=testing", {"Content-Type"=>"application/x-www-form-urlencoded"}).
and_return(["", 200, "OK"])
- requestable.request('/blah', {}, :method => :post)#.should == expected_response
- end
-
+ response = requestable.request('/blah', {:q => "testing"}, :method => :post)#.should == expected_response
+ response[:body].should == ""
+ response[:path].should == "/blah"
+ response[:message].should == "OK"
+ response[:status_code].should == 200
+ response[:params].should == {:q=>"testing"}
+ response[:headers].should == {"Content-Type"=>"application/x-www-form-urlencoded"}
+ response[:data].should == "q=testing"
+ response[:query].should == "q=testing"
+ response[:url].should == "http://127.0.0.1:8983/solr/blah?q=testing"
+ end
+
end
end

0 comments on commit bd3ef0c

Please sign in to comment.