Permalink
Browse files

fixed specs due to Nokogiri addition

NYE cleanup
  • Loading branch information...
1 parent a6f669c commit e608c085d8c64bb7179d32f2a6ff6062262a3608 Alejandro Crosa committed Jan 1, 2011
Showing with 17 additions and 17 deletions.
  1. +13 −16 lib/connection/connection.rb
  2. +2 −1 spec/connection_spec.rb
  3. +2 −0 spec/voldemort_client_spec.rb
View
29 lib/connection/connection.rb
@@ -1,7 +1,5 @@
-require 'json'
require 'nokogiri'
-
class Connection
attr_accessor :hosts # The hosts from where we bootstrapped.
@@ -36,25 +34,25 @@ def initialize(db_name, hosts, request_limit_per_node = DEFAULT_REQUEST_LIMIT_PE
def bootstrap
cluster_response = self.get_from("metadata", "cluster.xml", false)
cluster_xml_doc = Nokogiri::XML(cluster_response[1][0][1])
- self.nodes = self.parse_nodes_from(cluster_xml_doc)
-
+ self.nodes = self.parse_nodes_from(cluster_xml_doc)
+
stores_response = self.get_from("metadata", "stores.xml", false)
stores_xml = stores_response[1][0][1]
-
+
doc = Nokogiri::XML(stores_xml)
-
- self.key_serializer_type = self.parse_schema_type(doc, 'key-serializer')
+
+ self.key_serializer_type = self.parse_schema_type(doc, 'key-serializer')
self.value_serializer_type = self.parse_schema_type(doc, 'value-serializer')
self.key_serializer_schemas = self.parse_schema_from(doc, 'key-serializer')
self.value_serializer_schemas = self.parse_schema_from(doc, 'value-serializer')
-
+
self.connect_to_random_node
-
+
rescue StandardError => e
raise("There was an error trying to bootstrap from the specified servers: #{e}")
end
-
+
def connect_to_random_node
nodes = self.nodes.sort_by { rand }
for node in nodes do
@@ -65,25 +63,24 @@ def connect_to_random_node
end
end
end
-
+
def parse_schema_type(doc, serializer = 'value-serializer')
type_doc = doc.xpath("//stores/store[name = \"#{self.db_name}\"]/#{serializer}/type")
if(type_doc != nil)
return type_doc.text
else
return nil
end
- end
-
+ end
+
def parse_schema_from(doc, serializer = 'value-serializer')
parsed_schemas = {}
doc.xpath("//stores/store[name = \"#{self.db_name}\"]/#{serializer}/schema-info").each do |value_serializer|
parsed_schemas[value_serializer.attributes['version'].text] = value_serializer.text
end
return parsed_schemas
- end
-
-
+ end
+
def parse_nodes_from(doc)
nodes = []
doc.xpath("/cluster/server").each do |n|
View
3 spec/connection_spec.rb
@@ -23,7 +23,8 @@
it "should parse nodes from xml" do
@connection.should respond_to(:parse_nodes_from)
xml = "<cluster>\r\n <name>mycluster</name>\r\n <server>\r\n <id>0</id>\r\n <host>localhost</host>\r\n <http-port>8081</http-port>\r\n <socket-port>6666</socket-port>\r\n <admin-port>6667</admin-port>\r\n <partitions>0, 1</partitions>\r\n </server>\r\n</cluster>"
- nodes = @connection.parse_nodes_from(xml)
+ doc = Nokogiri::XML(xml)
+ nodes = @connection.parse_nodes_from(doc)
nodes.first.host.should eql("localhost")
nodes.first.port.should eql("6666")
nodes.length.should eql(1)
View
2 spec/voldemort_client_spec.rb
@@ -6,6 +6,8 @@
before(:each) do
connection = mock(TCPConnection)
+ connection.stub!(:key_serializer_type).and_return("string")
+ connection.stub!(:value_serializer_type).and_return("string")
node = mock(VoldemortNode)
connection.stub!(:bootstrap).and_return(node)
TCPConnection.stub!(:new).and_return(connection)

0 comments on commit e608c08

Please sign in to comment.