voldemort-rb 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,5 @@
1
- require 'json'
2
1
  require 'nokogiri'
3
2
 
4
-
5
3
  class Connection
6
4
 
7
5
  attr_accessor :hosts # The hosts from where we bootstrapped.
@@ -36,25 +34,25 @@ class Connection
36
34
  def bootstrap
37
35
  cluster_response = self.get_from("metadata", "cluster.xml", false)
38
36
  cluster_xml_doc = Nokogiri::XML(cluster_response[1][0][1])
39
- self.nodes = self.parse_nodes_from(cluster_xml_doc)
40
-
37
+ self.nodes = self.parse_nodes_from(cluster_xml_doc)
38
+
41
39
  stores_response = self.get_from("metadata", "stores.xml", false)
42
40
 
43
41
  stores_xml = stores_response[1][0][1]
44
-
42
+
45
43
  doc = Nokogiri::XML(stores_xml)
46
-
47
- self.key_serializer_type = self.parse_schema_type(doc, 'key-serializer')
44
+
45
+ self.key_serializer_type = self.parse_schema_type(doc, 'key-serializer')
48
46
  self.value_serializer_type = self.parse_schema_type(doc, 'value-serializer')
49
47
  self.key_serializer_schemas = self.parse_schema_from(doc, 'key-serializer')
50
48
  self.value_serializer_schemas = self.parse_schema_from(doc, 'value-serializer')
51
-
49
+
52
50
  self.connect_to_random_node
53
-
51
+
54
52
  rescue StandardError => e
55
53
  raise("There was an error trying to bootstrap from the specified servers: #{e}")
56
54
  end
57
-
55
+
58
56
  def connect_to_random_node
59
57
  nodes = self.nodes.sort_by { rand }
60
58
  for node in nodes do
@@ -65,7 +63,7 @@ class Connection
65
63
  end
66
64
  end
67
65
  end
68
-
66
+
69
67
  def parse_schema_type(doc, serializer = 'value-serializer')
70
68
  type_doc = doc.xpath("//stores/store[name = \"#{self.db_name}\"]/#{serializer}/type")
71
69
  if(type_doc != nil)
@@ -73,17 +71,16 @@ class Connection
73
71
  else
74
72
  return nil
75
73
  end
76
- end
77
-
74
+ end
75
+
78
76
  def parse_schema_from(doc, serializer = 'value-serializer')
79
77
  parsed_schemas = {}
80
78
  doc.xpath("//stores/store[name = \"#{self.db_name}\"]/#{serializer}/schema-info").each do |value_serializer|
81
79
  parsed_schemas[value_serializer.attributes['version'].text] = value_serializer.text
82
80
  end
83
81
  return parsed_schemas
84
- end
85
-
86
-
82
+ end
83
+
87
84
  def parse_nodes_from(doc)
88
85
  nodes = []
89
86
  doc.xpath("/cluster/server").each do |n|
@@ -83,16 +83,26 @@ class VoldemortJsonBinarySerializer
83
83
  end
84
84
  else
85
85
  case(type)
86
- when 'string': bytes << write_string(object)
87
- when 'int8': bytes << write_int8(object)
88
- when 'int16': bytes << write_int16(object)
89
- when 'int32': bytes << write_int32(object)
90
- when 'int64': bytes << write_int64(object)
91
- when 'float32': bytes << write_float32(object)
92
- when 'float64': bytes << write_float64(object)
93
- when 'date': bytes << write_date(object)
94
- when 'bytes': bytes << write_bytes(object)
95
- when 'boolean': bytes << write_boolean(object)
86
+ when 'string'
87
+ bytes << write_string(object)
88
+ when 'int8'
89
+ bytes << write_int8(object)
90
+ when 'int16'
91
+ bytes << write_int16(object)
92
+ when 'int32'
93
+ bytes << write_int32(object)
94
+ when 'int64'
95
+ bytes << write_int64(object)
96
+ when 'float32'
97
+ bytes << write_float32(object)
98
+ when 'float64'
99
+ bytes << write_float64(object)
100
+ when 'date'
101
+ bytes << write_date(object)
102
+ when 'bytes'
103
+ bytes << write_bytes(object)
104
+ when 'boolean'
105
+ bytes << write_boolean(object)
96
106
  else
97
107
  # TODO throw unsupported type exception
98
108
  end
@@ -329,16 +339,26 @@ class VoldemortJsonBinarySerializer
329
339
  return read_list(bytes, type)
330
340
  else
331
341
  case(type)
332
- when 'string': return read_bytes(bytes)
333
- when 'int8': return read_int8(bytes)
334
- when 'int16': return read_int16(bytes)
335
- when 'int32': return read_int32(bytes)
336
- when 'int64': return read_int64(bytes)
337
- when 'float32': return read_float32(bytes)
338
- when 'float64': return read_float64(bytes)
339
- when 'date': return read_date(bytes)
340
- when 'bytes': return read_bytes(bytes)
341
- when 'boolean': return read_boolean(bytes)
342
+ when 'string'
343
+ return read_bytes(bytes)
344
+ when 'int8'
345
+ return read_int8(bytes)
346
+ when 'int16'
347
+ return read_int16(bytes)
348
+ when 'int32'
349
+ return read_int32(bytes)
350
+ when 'int64'
351
+ return read_int64(bytes)
352
+ when 'float32'
353
+ return read_float32(bytes)
354
+ when 'float64'
355
+ return read_float64(bytes)
356
+ when 'date'
357
+ return read_date(bytes)
358
+ when 'bytes'
359
+ return read_bytes(bytes)
360
+ when 'boolean'
361
+ return read_boolean(bytes)
342
362
  # TODO default throw unknown type exception
343
363
  end
344
364
  end
@@ -23,7 +23,8 @@ describe Connection do
23
23
  it "should parse nodes from xml" do
24
24
  @connection.should respond_to(:parse_nodes_from)
25
25
  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>"
26
- nodes = @connection.parse_nodes_from(xml)
26
+ doc = Nokogiri::XML(xml)
27
+ nodes = @connection.parse_nodes_from(doc)
27
28
  nodes.first.host.should eql("localhost")
28
29
  nodes.first.port.should eql("6666")
29
30
  nodes.length.should eql(1)
@@ -6,6 +6,8 @@ describe VoldemortClient do
6
6
 
7
7
  before(:each) do
8
8
  connection = mock(TCPConnection)
9
+ connection.stub!(:key_serializer_type).and_return("string")
10
+ connection.stub!(:value_serializer_type).and_return("string")
9
11
  node = mock(VoldemortNode)
10
12
  connection.stub!(:bootstrap).and_return(node)
11
13
  TCPConnection.stub!(:new).and_return(connection)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voldemort-rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alejandro Crosa
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-18 00:00:00 -03:00
18
+ date: 2011-05-19 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency