cassandra-driver 0.1.0.alpha1 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.yardopts +4 -0
  2. data/README.md +117 -0
  3. data/lib/cassandra.rb +320 -0
  4. data/lib/cassandra/auth.rb +97 -0
  5. data/lib/cassandra/auth/providers.rb +16 -0
  6. data/lib/cassandra/auth/providers/password.rb +73 -0
  7. data/lib/cassandra/client.rb +144 -0
  8. data/lib/cassandra/client/batch.rb +212 -0
  9. data/lib/cassandra/client/client.rb +591 -0
  10. data/lib/cassandra/client/column_metadata.rb +54 -0
  11. data/lib/cassandra/client/connection_manager.rb +72 -0
  12. data/lib/cassandra/client/connector.rb +272 -0
  13. data/lib/cassandra/client/execute_options_decoder.rb +59 -0
  14. data/lib/cassandra/client/null_logger.rb +37 -0
  15. data/lib/cassandra/client/peer_discovery.rb +50 -0
  16. data/lib/cassandra/client/prepared_statement.rb +314 -0
  17. data/lib/cassandra/client/query_result.rb +230 -0
  18. data/lib/cassandra/client/request_runner.rb +71 -0
  19. data/lib/cassandra/client/result_metadata.rb +48 -0
  20. data/lib/cassandra/client/void_result.rb +78 -0
  21. data/lib/cassandra/cluster.rb +191 -0
  22. data/lib/cassandra/cluster/client.rb +767 -0
  23. data/lib/cassandra/cluster/connector.rb +231 -0
  24. data/lib/cassandra/cluster/control_connection.rb +420 -0
  25. data/lib/cassandra/cluster/options.rb +40 -0
  26. data/lib/cassandra/cluster/registry.rb +181 -0
  27. data/lib/cassandra/cluster/schema.rb +321 -0
  28. data/lib/cassandra/cluster/schema/type_parser.rb +138 -0
  29. data/lib/cassandra/column.rb +92 -0
  30. data/lib/cassandra/compression.rb +66 -0
  31. data/lib/cassandra/compression/compressors/lz4.rb +72 -0
  32. data/lib/cassandra/compression/compressors/snappy.rb +66 -0
  33. data/lib/cassandra/driver.rb +86 -0
  34. data/lib/cassandra/errors.rb +79 -0
  35. data/lib/cassandra/execution/info.rb +51 -0
  36. data/lib/cassandra/execution/options.rb +77 -0
  37. data/lib/cassandra/execution/trace.rb +152 -0
  38. data/lib/cassandra/future.rb +675 -0
  39. data/lib/cassandra/host.rb +75 -0
  40. data/lib/cassandra/keyspace.rb +120 -0
  41. data/lib/cassandra/listener.rb +87 -0
  42. data/lib/cassandra/load_balancing.rb +112 -0
  43. data/lib/cassandra/load_balancing/policies.rb +18 -0
  44. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +149 -0
  45. data/lib/cassandra/load_balancing/policies/round_robin.rb +95 -0
  46. data/lib/cassandra/load_balancing/policies/white_list.rb +90 -0
  47. data/lib/cassandra/protocol.rb +93 -0
  48. data/lib/cassandra/protocol/cql_byte_buffer.rb +307 -0
  49. data/lib/cassandra/protocol/cql_protocol_handler.rb +323 -0
  50. data/lib/cassandra/protocol/frame_decoder.rb +128 -0
  51. data/lib/cassandra/protocol/frame_encoder.rb +48 -0
  52. data/lib/cassandra/protocol/request.rb +38 -0
  53. data/lib/cassandra/protocol/requests/auth_response_request.rb +47 -0
  54. data/lib/cassandra/protocol/requests/batch_request.rb +76 -0
  55. data/lib/cassandra/protocol/requests/credentials_request.rb +47 -0
  56. data/lib/cassandra/protocol/requests/execute_request.rb +103 -0
  57. data/lib/cassandra/protocol/requests/options_request.rb +39 -0
  58. data/lib/cassandra/protocol/requests/prepare_request.rb +50 -0
  59. data/lib/cassandra/protocol/requests/query_request.rb +153 -0
  60. data/lib/cassandra/protocol/requests/register_request.rb +38 -0
  61. data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
  62. data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
  63. data/lib/cassandra/protocol/response.rb +38 -0
  64. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +41 -0
  65. data/lib/cassandra/protocol/responses/auth_success_response.rb +41 -0
  66. data/lib/cassandra/protocol/responses/authenticate_response.rb +41 -0
  67. data/lib/cassandra/protocol/responses/detailed_error_response.rb +60 -0
  68. data/lib/cassandra/protocol/responses/error_response.rb +50 -0
  69. data/lib/cassandra/protocol/responses/event_response.rb +39 -0
  70. data/lib/cassandra/protocol/responses/prepared_result_response.rb +64 -0
  71. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +43 -0
  72. data/lib/cassandra/protocol/responses/ready_response.rb +44 -0
  73. data/lib/cassandra/protocol/responses/result_response.rb +48 -0
  74. data/lib/cassandra/protocol/responses/rows_result_response.rb +139 -0
  75. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +60 -0
  76. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +57 -0
  77. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +42 -0
  78. data/lib/cassandra/protocol/responses/status_change_event_response.rb +44 -0
  79. data/lib/cassandra/protocol/responses/supported_response.rb +41 -0
  80. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +34 -0
  81. data/lib/cassandra/protocol/responses/void_result_response.rb +39 -0
  82. data/lib/cassandra/protocol/type_converter.rb +384 -0
  83. data/lib/cassandra/reconnection.rb +49 -0
  84. data/lib/cassandra/reconnection/policies.rb +20 -0
  85. data/lib/cassandra/reconnection/policies/constant.rb +48 -0
  86. data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
  87. data/lib/cassandra/result.rb +215 -0
  88. data/lib/cassandra/retry.rb +142 -0
  89. data/lib/cassandra/retry/policies.rb +21 -0
  90. data/lib/cassandra/retry/policies/default.rb +47 -0
  91. data/lib/cassandra/retry/policies/downgrading_consistency.rb +71 -0
  92. data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
  93. data/lib/cassandra/session.rb +195 -0
  94. data/lib/cassandra/statement.rb +22 -0
  95. data/lib/cassandra/statements.rb +23 -0
  96. data/lib/cassandra/statements/batch.rb +95 -0
  97. data/lib/cassandra/statements/bound.rb +46 -0
  98. data/lib/cassandra/statements/prepared.rb +59 -0
  99. data/lib/cassandra/statements/simple.rb +58 -0
  100. data/lib/cassandra/statements/void.rb +33 -0
  101. data/lib/cassandra/table.rb +254 -0
  102. data/lib/cassandra/time_uuid.rb +141 -0
  103. data/lib/cassandra/util.rb +169 -0
  104. data/lib/cassandra/uuid.rb +104 -0
  105. data/lib/cassandra/version.rb +17 -1
  106. metadata +134 -8
@@ -0,0 +1,138 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ class Cluster
21
+ class Schema
22
+ class TypeParser
23
+ # @private
24
+ Node = Struct.new(:parent, :name, :children)
25
+ # @private
26
+ Result = Struct.new(:results, :collections)
27
+
28
+ @@types = {
29
+ "org.apache.cassandra.db.marshal.AsciiType" => :ascii,
30
+ "org.apache.cassandra.db.marshal.LongType" => :bigint,
31
+ "org.apache.cassandra.db.marshal.BytesType" => :blob,
32
+ "org.apache.cassandra.db.marshal.BooleanType" => :boolean,
33
+ "org.apache.cassandra.db.marshal.CounterColumnType" => :counter,
34
+ "org.apache.cassandra.db.marshal.DecimalType" => :decimal,
35
+ "org.apache.cassandra.db.marshal.DoubleType" => :double,
36
+ "org.apache.cassandra.db.marshal.FloatType" => :float,
37
+ "org.apache.cassandra.db.marshal.InetAddressType" => :inet,
38
+ "org.apache.cassandra.db.marshal.Int32Type" => :int,
39
+ "org.apache.cassandra.db.marshal.UTF8Type" => :text,
40
+ "org.apache.cassandra.db.marshal.TimestampType" => :timestamp,
41
+ "org.apache.cassandra.db.marshal.DateType" => :timestamp,
42
+ "org.apache.cassandra.db.marshal.UUIDType" => :uuid,
43
+ "org.apache.cassandra.db.marshal.IntegerType" => :varint,
44
+ "org.apache.cassandra.db.marshal.TimeUUIDType" => :timeuuid,
45
+ "org.apache.cassandra.db.marshal.MapType" => :map,
46
+ "org.apache.cassandra.db.marshal.SetType" => :set,
47
+ "org.apache.cassandra.db.marshal.ListType" => :list
48
+ }
49
+
50
+ def parse(string)
51
+ create_result(parse_node(string))
52
+ end
53
+
54
+ private
55
+
56
+ def create_result(node)
57
+ collections = nil
58
+ results = []
59
+
60
+ if node.name == "org.apache.cassandra.db.marshal.CompositeType"
61
+ collections = {}
62
+
63
+ if node.children.last.name == "org.apache.cassandra.db.marshal.ColumnToCollectionType"
64
+ node.children.pop.children.each do |child|
65
+ key, name = child.name.split(":")
66
+ key = [key].pack('H*').force_encoding(::Encoding::UTF_8)
67
+
68
+ if name == "org.apache.cassandra.db.marshal.ReversedType"
69
+ collections[key] = lookup_type(child.children.first)
70
+ else
71
+ child.name = name
72
+ collections[key] = lookup_type(child)
73
+ end
74
+ end
75
+ end
76
+
77
+ node.children.each do |child|
78
+ results << create_type(child)
79
+ end
80
+ else
81
+ results << create_type(node)
82
+ end
83
+
84
+ Result.new(results, collections)
85
+ end
86
+
87
+ def create_type(node)
88
+ order = :asc
89
+
90
+ if node.name == "org.apache.cassandra.db.marshal.ReversedType"
91
+ order = :desc
92
+ node = node.children.first
93
+ end
94
+
95
+ [lookup_type(node), order]
96
+ end
97
+
98
+ def lookup_type(node)
99
+ type = @@types[node.name]
100
+
101
+ case type
102
+ when :set, :list
103
+ [type, lookup_type(node.children.first)]
104
+ when :map
105
+ [type, *node.children.map {|child| lookup_type(child)}]
106
+ else
107
+ type
108
+ end
109
+ end
110
+
111
+ def parse_node(string)
112
+ root = node = Node.new(nil, '', [])
113
+
114
+ string.each_char do |char|
115
+ case char
116
+ when '(' # starting type params
117
+ child = Node.new(node, '', [])
118
+ node.children << child
119
+ node = child
120
+ when ','
121
+ child = Node.new(node.parent, '', [])
122
+ node.parent.children << child
123
+ node = child
124
+ when ')'
125
+ node = node.parent
126
+ when ' '
127
+ next
128
+ else
129
+ node.name << char
130
+ end
131
+ end
132
+
133
+ root
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ # Represents a cassandra column
21
+ # @see Cassandra::Table#each_column
22
+ # @see Cassandra::Table#column
23
+ class Column
24
+ # @private
25
+ class Index
26
+ # @return [String] index name
27
+ attr_reader :name
28
+ # @return [String] custom index class name
29
+ attr_reader :custom_class_name
30
+
31
+ # @private
32
+ def initialize(name, custom_class_name = nil)
33
+ @name = name
34
+ @custom_class_name = custom_class_name
35
+ end
36
+ end
37
+
38
+ # @return [String] column name
39
+ attr_reader :name
40
+ # @private
41
+ # @return [Symbol, Array(Symbol, Symbol)] column type
42
+ attr_reader :type
43
+ # @return [Symbol] column order (`:asc` or `:desc`)
44
+ attr_reader :order
45
+ # @private
46
+ # @return [Cassandra::Column::Index, nil] column index
47
+ attr_reader :index
48
+ # @private
49
+ # @return [Boolean] whether the column is static
50
+ attr_reader :static
51
+
52
+ # @private
53
+ def initialize(name, type, order, index = nil, is_static = false)
54
+ @name = name
55
+ @type = type
56
+ @order = order
57
+ @index = index
58
+ @static = is_static
59
+ end
60
+
61
+ # @return [Boolean] whether the column is static
62
+ def static?
63
+ @static
64
+ end
65
+
66
+ # @return [String] a cql representation of this column
67
+ def to_cql
68
+ type = case @type
69
+ when Array
70
+ type, *args = @type
71
+ "#{type.to_s}<#{args.map(&:to_s).join(', ')}>"
72
+ else
73
+ @type.to_s
74
+ end
75
+
76
+ cql = "#{@name} #{type}"
77
+ cql << ' static' if @static
78
+ cql
79
+ end
80
+
81
+ # @return [Boolean] whether this column is equal to the other
82
+ def eql?(other)
83
+ other.is_a?(Column) &&
84
+ @name == other.name &&
85
+ @type == other.type &&
86
+ @order == other.order &&
87
+ @index == other.index &&
88
+ @static == other.static?
89
+ end
90
+ alias :== :eql?
91
+ end
92
+ end
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module Compression
21
+ # @note Compressors given to {Cassandra.connect} as the `:compressor`
22
+ # option don't need to be subclasses of this class, but need to implement
23
+ # the same methods. This class exists only for documentation purposes.
24
+ class Compressor
25
+ # @!method algorithm
26
+ #
27
+ # Returns the name of the algorithm this compressor supports,
28
+ # e.g. "snappy" or "lz4".
29
+ #
30
+ # @return [String] algorithm
31
+
32
+ # @!method compress?(frame)
33
+ #
34
+ # Before compressing a frame the compressor will be asked if it wants
35
+ # to compress it or not. One reason it could say no is if the frame is
36
+ # small enough that compression would be unlikely to decrease its size.
37
+ #
38
+ # If your operations consist mostly of small prepared statement
39
+ # executions it might not be useful to compress the frames being sent
40
+ # _to_ Cassandra, but enabling compression can still be useful on the
41
+ # frames coming _from_ Cassandra. Making this method always return
42
+ # false disables request compression, but will still make the client
43
+ # tell Cassandra that it supports compressed frames.
44
+ #
45
+ # The bytes given to {#compress?} are the same as to {#compress}
46
+ #
47
+ # @param frame [String] the bytes of the frame to be compressed
48
+ # @return [true, false] whether to perform compression or not
49
+
50
+ # @!method compress(frame)
51
+ #
52
+ # Compresses the raw bytes of a frame.
53
+ #
54
+ # @param frame [String] the bytes of the frame to be compressed
55
+ # @return [String] the compressed frame
56
+
57
+ # @!method decompress(compressed_frame)
58
+ #
59
+ # Decompresses the raw bytes of a compressed frame.
60
+ #
61
+ # @param compressed_frame [String] the bytes of the compressed frame to
62
+ # be uncompressed
63
+ # @return [String] uncompressed bytes
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ begin
20
+ require 'lz4-ruby'
21
+ rescue LoadError => e
22
+ raise LoadError, %[LZ4 support requires the "lz4-ruby" gem: #{e.message}], e.backtrace
23
+ end
24
+
25
+ module Cassandra
26
+ module Compression
27
+ module Compressors
28
+ # A compressor that uses the LZ4 compression library.
29
+ #
30
+ # @note This compressor requires the
31
+ # [lz4-ruby](http://rubygems.org/gems/lz4-ruby) gem (v0.3.2 or later
32
+ # required).
33
+ # @note No need to instantiate this class manually, use `compression:
34
+ # :lz4` option when calling {Cassandra.connect} and one will be created
35
+ # automatically for you.
36
+ class Lz4 < Compressor
37
+ # @return [String] `'lz4'`
38
+ attr_reader :algorithm
39
+
40
+ # @param [Integer] min_size (64) Don't compress frames smaller than
41
+ # this size (see {#compress?}).
42
+ def initialize(min_size=64)
43
+ @algorithm = 'lz4'.freeze
44
+ @min_size = min_size
45
+ end
46
+
47
+ # @return [true, false] will return false for frames smaller than the
48
+ # `min_size` given to the constructor.
49
+ # @see Cassandra::Compression::Compressor#compress?
50
+ def compress?(str)
51
+ str.bytesize > @min_size
52
+ end
53
+
54
+ # @see Cassandra::Compression::Compressor#compress
55
+ def compress(str)
56
+ [str.bytesize, ::LZ4::Raw.compress(str.to_s).first].pack(BUFFER_FORMAT)
57
+ end
58
+
59
+ # @see Cassandra::Compression::Compressor#decompress
60
+ def decompress(str)
61
+ decompressed_size, compressed_data = str.to_s.unpack(BUFFER_FORMAT)
62
+ ::LZ4::Raw.decompress(compressed_data, decompressed_size).first
63
+ end
64
+
65
+ private
66
+
67
+ # @private
68
+ BUFFER_FORMAT = 'Na*'.freeze
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ begin
20
+ require 'snappy'
21
+ rescue LoadError => e
22
+ raise LoadError, %[Snappy support requires the "snappy" gem: #{e.message}], e.backtrace
23
+ end
24
+
25
+ module Cassandra
26
+ module Compression
27
+ module Compressors
28
+ # A compressor that uses the Snappy compression library.
29
+ #
30
+ # @note This compressor requires the
31
+ # [snappy](http://rubygems.org/gems/snappy) gem (v0.0.10 or later for
32
+ # JRuby support).
33
+ # @note No need to instantiate this class manually, use `compression:
34
+ # :snappy` option when calling {Cassandra.connect} and one will be
35
+ # created automatically for you.
36
+ class Snappy < Compressor
37
+ # @return [String] `'snappy'`
38
+ attr_reader :algorithm
39
+
40
+ # @param [Integer] min_size (64) Don't compress frames smaller than
41
+ # this size (see {#compress?}).
42
+ def initialize(min_size=64)
43
+ @algorithm = 'snappy'.freeze
44
+ @min_size = min_size
45
+ end
46
+
47
+ # @return [true, false] will return false for frames smaller than the
48
+ # `min_size` given to the constructor.
49
+ # @see Cassandra::Compression::Compressor#compress?
50
+ def compress?(str)
51
+ str.bytesize > @min_size
52
+ end
53
+
54
+ # @see Cassandra::Compression::Compressor#compress
55
+ def compress(str)
56
+ ::Snappy.deflate(str)
57
+ end
58
+
59
+ # @see Cassandra::Compression::Compressor#decompress
60
+ def decompress(str)
61
+ ::Snappy.inflate(str)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2014 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ # @private
21
+ class Driver
22
+ def self.let(name, &block)
23
+ define_method(name) { @instances[name] ||= @defaults.fetch(name) { instance_eval(&block) } }
24
+ define_method(:"#{name}=") { |object| @instances[name] = object }
25
+ end
26
+
27
+ let(:io_reactor) { Io::IoReactor.new }
28
+ let(:cluster_registry) { Cluster::Registry.new(logger) }
29
+ let(:cluster_schema) { Cluster::Schema.new(schema_type_parser) }
30
+ let(:futures_factory) { Future }
31
+
32
+ let(:schema_type_parser) { Cluster::Schema::TypeParser.new }
33
+
34
+ let(:connector) { Cluster::Connector.new(logger, io_reactor, cluster_registry, connection_options) }
35
+
36
+ let(:control_connection) { Cluster::ControlConnection.new(logger, io_reactor, cluster_registry, cluster_schema, load_balancing_policy, reconnection_policy, connector) }
37
+
38
+ let(:cluster) { Cluster.new(logger, io_reactor, control_connection, cluster_registry, cluster_schema, execution_options, connection_options, load_balancing_policy, reconnection_policy, retry_policy, connector, futures_factory) }
39
+
40
+ let(:execution_options) do
41
+ Execution::Options.new({
42
+ :consistency => consistency,
43
+ :trace => trace,
44
+ :page_size => page_size
45
+ })
46
+ end
47
+
48
+ let(:connection_options) { Cluster::Options.new(protocol_version, credentials, auth_provider, compressor, port, connection_timeout, connections_per_local_node, connections_per_remote_node) }
49
+
50
+ let(:port) { 9042 }
51
+ let(:protocol_version) { 2 }
52
+ let(:connection_timeout) { 10 }
53
+ let(:logger) { Client::NullLogger.new }
54
+ let(:compressor) { nil }
55
+ let(:credentials) { nil }
56
+ let(:auth_provider) { nil }
57
+ let(:load_balancing_policy) { LoadBalancing::Policies::RoundRobin.new }
58
+ let(:reconnection_policy) { Reconnection::Policies::Exponential.new(0.5, 30, 2) }
59
+ let(:retry_policy) { Retry::Policies::Default.new }
60
+ let(:consistency) { :quorum }
61
+ let(:trace) { false }
62
+ let(:page_size) { nil }
63
+
64
+ let(:connections_per_local_node) { 2 }
65
+ let(:connections_per_remote_node) { 1 }
66
+
67
+ let(:listeners) { [] }
68
+
69
+ def initialize(defaults = {})
70
+ @defaults = defaults
71
+ @instances = {}
72
+ end
73
+
74
+ def connect(addresses)
75
+ cluster_registry.add_listener(load_balancing_policy)
76
+ cluster_registry.add_listener(control_connection)
77
+ listeners.each do |listener|
78
+ cluster.register(listener)
79
+ end
80
+
81
+ addresses.each {|address| cluster_registry.host_found(address)}
82
+
83
+ control_connection.connect_async.map(cluster)
84
+ end
85
+ end
86
+ end