yugabyte-ycql-driver 3.2.3.1

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.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +13 -0
  3. data/README.md +242 -0
  4. data/ext/cassandra_murmur3/cassandra_murmur3.c +178 -0
  5. data/ext/cassandra_murmur3/extconf.rb +2 -0
  6. data/lib/cassandra/address_resolution.rb +36 -0
  7. data/lib/cassandra/address_resolution/policies.rb +2 -0
  8. data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +56 -0
  9. data/lib/cassandra/address_resolution/policies/none.rb +35 -0
  10. data/lib/cassandra/aggregate.rb +123 -0
  11. data/lib/cassandra/argument.rb +51 -0
  12. data/lib/cassandra/attr_boolean.rb +33 -0
  13. data/lib/cassandra/auth.rb +100 -0
  14. data/lib/cassandra/auth/providers.rb +17 -0
  15. data/lib/cassandra/auth/providers/password.rb +65 -0
  16. data/lib/cassandra/cassandra_logger.rb +80 -0
  17. data/lib/cassandra/cluster.rb +331 -0
  18. data/lib/cassandra/cluster/client.rb +1612 -0
  19. data/lib/cassandra/cluster/connection_pool.rb +78 -0
  20. data/lib/cassandra/cluster/connector.rb +372 -0
  21. data/lib/cassandra/cluster/control_connection.rb +962 -0
  22. data/lib/cassandra/cluster/failed_connection.rb +35 -0
  23. data/lib/cassandra/cluster/metadata.rb +142 -0
  24. data/lib/cassandra/cluster/options.rb +145 -0
  25. data/lib/cassandra/cluster/registry.rb +284 -0
  26. data/lib/cassandra/cluster/schema.rb +405 -0
  27. data/lib/cassandra/cluster/schema/cql_type_parser.rb +112 -0
  28. data/lib/cassandra/cluster/schema/fetchers.rb +1627 -0
  29. data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +175 -0
  30. data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
  31. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +45 -0
  32. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
  33. data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
  34. data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
  35. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +102 -0
  36. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
  37. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
  38. data/lib/cassandra/column.rb +66 -0
  39. data/lib/cassandra/column_container.rb +326 -0
  40. data/lib/cassandra/compression.rb +69 -0
  41. data/lib/cassandra/compression/compressors/lz4.rb +73 -0
  42. data/lib/cassandra/compression/compressors/snappy.rb +69 -0
  43. data/lib/cassandra/custom_data.rb +53 -0
  44. data/lib/cassandra/driver.rb +260 -0
  45. data/lib/cassandra/errors.rb +784 -0
  46. data/lib/cassandra/execution/info.rb +69 -0
  47. data/lib/cassandra/execution/options.rb +267 -0
  48. data/lib/cassandra/execution/profile.rb +153 -0
  49. data/lib/cassandra/execution/profile_manager.rb +71 -0
  50. data/lib/cassandra/execution/trace.rb +192 -0
  51. data/lib/cassandra/executors.rb +113 -0
  52. data/lib/cassandra/function.rb +156 -0
  53. data/lib/cassandra/function_collection.rb +85 -0
  54. data/lib/cassandra/future.rb +794 -0
  55. data/lib/cassandra/host.rb +102 -0
  56. data/lib/cassandra/index.rb +118 -0
  57. data/lib/cassandra/keyspace.rb +473 -0
  58. data/lib/cassandra/listener.rb +87 -0
  59. data/lib/cassandra/load_balancing.rb +121 -0
  60. data/lib/cassandra/load_balancing/policies.rb +20 -0
  61. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +172 -0
  62. data/lib/cassandra/load_balancing/policies/round_robin.rb +141 -0
  63. data/lib/cassandra/load_balancing/policies/token_aware.rb +149 -0
  64. data/lib/cassandra/load_balancing/policies/white_list.rb +100 -0
  65. data/lib/cassandra/materialized_view.rb +92 -0
  66. data/lib/cassandra/null_logger.rb +56 -0
  67. data/lib/cassandra/protocol.rb +102 -0
  68. data/lib/cassandra/protocol/coder.rb +1085 -0
  69. data/lib/cassandra/protocol/cql_byte_buffer.rb +418 -0
  70. data/lib/cassandra/protocol/cql_protocol_handler.rb +448 -0
  71. data/lib/cassandra/protocol/request.rb +41 -0
  72. data/lib/cassandra/protocol/requests/auth_response_request.rb +51 -0
  73. data/lib/cassandra/protocol/requests/batch_request.rb +117 -0
  74. data/lib/cassandra/protocol/requests/credentials_request.rb +51 -0
  75. data/lib/cassandra/protocol/requests/execute_request.rb +122 -0
  76. data/lib/cassandra/protocol/requests/options_request.rb +39 -0
  77. data/lib/cassandra/protocol/requests/prepare_request.rb +59 -0
  78. data/lib/cassandra/protocol/requests/query_request.rb +112 -0
  79. data/lib/cassandra/protocol/requests/register_request.rb +38 -0
  80. data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
  81. data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
  82. data/lib/cassandra/protocol/response.rb +28 -0
  83. data/lib/cassandra/protocol/responses/already_exists_error_response.rb +50 -0
  84. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +36 -0
  85. data/lib/cassandra/protocol/responses/auth_success_response.rb +36 -0
  86. data/lib/cassandra/protocol/responses/authenticate_response.rb +36 -0
  87. data/lib/cassandra/protocol/responses/error_response.rb +142 -0
  88. data/lib/cassandra/protocol/responses/event_response.rb +30 -0
  89. data/lib/cassandra/protocol/responses/function_failure_error_response.rb +52 -0
  90. data/lib/cassandra/protocol/responses/prepared_result_response.rb +62 -0
  91. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +59 -0
  92. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +71 -0
  93. data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +61 -0
  94. data/lib/cassandra/protocol/responses/ready_response.rb +43 -0
  95. data/lib/cassandra/protocol/responses/result_response.rb +42 -0
  96. data/lib/cassandra/protocol/responses/rows_result_response.rb +39 -0
  97. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +73 -0
  98. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +70 -0
  99. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +37 -0
  100. data/lib/cassandra/protocol/responses/status_change_event_response.rb +39 -0
  101. data/lib/cassandra/protocol/responses/supported_response.rb +36 -0
  102. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +33 -0
  103. data/lib/cassandra/protocol/responses/unavailable_error_response.rb +58 -0
  104. data/lib/cassandra/protocol/responses/unprepared_error_response.rb +48 -0
  105. data/lib/cassandra/protocol/responses/void_result_response.rb +34 -0
  106. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +73 -0
  107. data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +63 -0
  108. data/lib/cassandra/protocol/v1.rb +326 -0
  109. data/lib/cassandra/protocol/v3.rb +358 -0
  110. data/lib/cassandra/protocol/v4.rb +478 -0
  111. data/lib/cassandra/reconnection.rb +49 -0
  112. data/lib/cassandra/reconnection/policies.rb +20 -0
  113. data/lib/cassandra/reconnection/policies/constant.rb +46 -0
  114. data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
  115. data/lib/cassandra/result.rb +276 -0
  116. data/lib/cassandra/retry.rb +154 -0
  117. data/lib/cassandra/retry/policies.rb +21 -0
  118. data/lib/cassandra/retry/policies/default.rb +53 -0
  119. data/lib/cassandra/retry/policies/downgrading_consistency.rb +73 -0
  120. data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
  121. data/lib/cassandra/session.rb +270 -0
  122. data/lib/cassandra/statement.rb +32 -0
  123. data/lib/cassandra/statements.rb +23 -0
  124. data/lib/cassandra/statements/batch.rb +146 -0
  125. data/lib/cassandra/statements/bound.rb +65 -0
  126. data/lib/cassandra/statements/prepared.rb +235 -0
  127. data/lib/cassandra/statements/simple.rb +118 -0
  128. data/lib/cassandra/statements/void.rb +38 -0
  129. data/lib/cassandra/table.rb +240 -0
  130. data/lib/cassandra/time.rb +103 -0
  131. data/lib/cassandra/time_uuid.rb +78 -0
  132. data/lib/cassandra/timestamp_generator.rb +37 -0
  133. data/lib/cassandra/timestamp_generator/simple.rb +38 -0
  134. data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +58 -0
  135. data/lib/cassandra/trigger.rb +67 -0
  136. data/lib/cassandra/tuple.rb +131 -0
  137. data/lib/cassandra/types.rb +1704 -0
  138. data/lib/cassandra/udt.rb +443 -0
  139. data/lib/cassandra/util.rb +464 -0
  140. data/lib/cassandra/uuid.rb +110 -0
  141. data/lib/cassandra/uuid/generator.rb +212 -0
  142. data/lib/cassandra/version.rb +21 -0
  143. data/lib/datastax/cassandra.rb +47 -0
  144. data/lib/ycql.rb +842 -0
  145. metadata +243 -0
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 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
+ # @abstract Compressors given to {Cassandra.cluster} 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
67
+
68
+ require 'cassandra/compression/compressors/snappy'
69
+ require 'cassandra/compression/compressors/lz4'
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 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
+ module Compressors
22
+ # A compressor that uses the LZ4 compression library.
23
+ #
24
+ # @note This compressor requires the
25
+ # [lz4-ruby](http://rubygems.org/gems/lz4-ruby) gem (v0.3.2 or later
26
+ # required).
27
+ # @note No need to instantiate this class manually, use `compression:
28
+ # :lz4` option when calling {Cassandra.cluster} and one will be created
29
+ # automatically for you.
30
+ class Lz4 < Compressor
31
+ # @private
32
+ BUFFER_FORMAT = 'Na*'.freeze
33
+
34
+ # @return [String] `'lz4'`
35
+ attr_reader :algorithm
36
+
37
+ # @param [Integer] min_size (64) Don't compress frames smaller than
38
+ # this size (see {#compress?}).
39
+ def initialize(min_size = 64)
40
+ unless defined?(::LZ4::Raw)
41
+ begin
42
+ require 'lz4-ruby'
43
+ rescue LoadError => e
44
+ raise LoadError, %(LZ4 support requires the "lz4-ruby" gem: #{e.message}),
45
+ e.backtrace
46
+ end
47
+ end
48
+
49
+ @algorithm = 'lz4'.freeze
50
+ @min_size = min_size
51
+ end
52
+
53
+ # @return [true, false] will return false for frames smaller than the
54
+ # `min_size` given to the constructor.
55
+ # @see Cassandra::Compression::Compressor#compress?
56
+ def compress?(str)
57
+ str.bytesize > @min_size
58
+ end
59
+
60
+ # @see Cassandra::Compression::Compressor#compress
61
+ def compress(str)
62
+ [str.bytesize, ::LZ4::Raw.compress(str.to_s).first].pack(BUFFER_FORMAT)
63
+ end
64
+
65
+ # @see Cassandra::Compression::Compressor#decompress
66
+ def decompress(str)
67
+ decompressed_size, compressed_data = str.to_s.unpack(BUFFER_FORMAT)
68
+ ::LZ4::Raw.decompress(compressed_data, decompressed_size).first
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 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
+ module Compressors
22
+ # A compressor that uses the Snappy compression library.
23
+ #
24
+ # @note This compressor requires the
25
+ # [snappy](http://rubygems.org/gems/snappy) gem (v0.0.10 or later for
26
+ # JRuby support).
27
+ # @note No need to instantiate this class manually, use `compression:
28
+ # :snappy` option when calling {Cassandra.cluster} and one will be
29
+ # created automatically for you.
30
+ class Snappy < Compressor
31
+ # @return [String] `'snappy'`
32
+ attr_reader :algorithm
33
+
34
+ # @param [Integer] min_size (64) Don't compress frames smaller than
35
+ # this size (see {#compress?}).
36
+ def initialize(min_size = 64)
37
+ unless defined?(::Snappy)
38
+ begin
39
+ require 'snappy'
40
+ rescue LoadError => e
41
+ raise LoadError, %(Snappy support requires the "snappy" gem: #{e.message}),
42
+ e.backtrace
43
+ end
44
+ end
45
+
46
+ @algorithm = 'snappy'.freeze
47
+ @min_size = min_size
48
+ end
49
+
50
+ # @return [true, false] will return false for frames smaller than the
51
+ # `min_size` given to the constructor.
52
+ # @see Cassandra::Compression::Compressor#compress?
53
+ def compress?(str)
54
+ str.bytesize > @min_size
55
+ end
56
+
57
+ # @see Cassandra::Compression::Compressor#compress
58
+ def compress(str)
59
+ ::Snappy.deflate(str)
60
+ end
61
+
62
+ # @see Cassandra::Compression::Compressor#decompress
63
+ def decompress(str)
64
+ ::Snappy.inflate(str)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 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
+ # Use this module to mark domain object classes as custom type implementations for custom-type
20
+ # columns in C*. This module has no logic of its own, but indicates that the marked class has
21
+ # certain methods.
22
+ # @private
23
+ module Cassandra
24
+ module CustomData
25
+ def self.included(base)
26
+ base.send :include, InstanceMethods
27
+ base.extend ClassMethods
28
+ end
29
+
30
+ module ClassMethods
31
+ # @return [Cassandra::Types::Custom] the custom type that this class represents.
32
+ def type
33
+ raise NotImplementedError, "#{self.class} must implement the :type class method"
34
+ end
35
+
36
+ # Deserialize the given data into an instance of this domain object class.
37
+ # @param data [String] byte-array representation of a column value of this custom type.
38
+ # @return An instance of the domain object class.
39
+ # @raise [Cassandra::Errors::DecodingError] upon failure.
40
+ def deserialize(data)
41
+ raise NotImplementedError, "#{self.class} must implement the :deserialize class method"
42
+ end
43
+ end
44
+
45
+ module InstanceMethods
46
+ # Serialize this domain object into a byte array to send to C*.
47
+ # @return [String] byte-array representation of this domain object.
48
+ def serialize
49
+ raise NotImplementedError, "#{self.class} must implement the :serialize instance method"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,260 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 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) do
24
+ @instances.key?(name) ?
25
+ @instances[name] :
26
+ @instances[name] = instance_eval(&block)
27
+ end
28
+ define_method(:"#{name}=") { |object| @instances[name] = object }
29
+ end
30
+
31
+ let(:io_reactor) { Ione::Io::IoReactor.new }
32
+ let(:cluster_registry) { Cluster::Registry.new(logger) }
33
+ let(:cluster_schema) { Cluster::Schema.new }
34
+ let(:cluster_metadata) do
35
+ Cluster::Metadata.new(
36
+ cluster_registry,
37
+ cluster_schema,
38
+ {
39
+ 'org.apache.cassandra.dht.Murmur3Partitioner' => murmur3_partitioner,
40
+ 'org.apache.cassandra.dht.ByteOrderedPartitioner' => ordered_partitioner,
41
+ 'org.apache.cassandra.dht.RandomPartitioner' => random_partitioner
42
+ }.freeze,
43
+ {
44
+ 'SimpleStrategy' => simple_replication_strategy,
45
+ 'NetworkTopologyStrategy' => network_topology_replication_strategy
46
+ }.freeze,
47
+ no_replication_strategy
48
+ )
49
+ end
50
+
51
+ let(:executor) { Executors::ThreadPool.new(thread_pool_size) }
52
+ let(:futures_factory) { Future::Factory.new(executor) }
53
+
54
+ let(:schema_fqcn_type_parser) { Cluster::Schema::FQCNTypeParser.new }
55
+ let(:schema_cql_type_parser) { Cluster::Schema::CQLTypeParser.new }
56
+
57
+ let(:simple_replication_strategy) do
58
+ Cluster::Schema::ReplicationStrategies::Simple.new
59
+ end
60
+ let(:network_topology_replication_strategy) do
61
+ Cluster::Schema::ReplicationStrategies::NetworkTopology.new
62
+ end
63
+ let(:no_replication_strategy) do
64
+ Cluster::Schema::ReplicationStrategies::None.new
65
+ end
66
+
67
+ let(:murmur3_partitioner) { Cluster::Schema::Partitioners::Murmur3.new }
68
+ let(:ordered_partitioner) { Cluster::Schema::Partitioners::Ordered.new }
69
+ let(:random_partitioner) { Cluster::Schema::Partitioners::Random.new }
70
+
71
+ let(:connector) do
72
+ Cluster::Connector.new(logger,
73
+ io_reactor,
74
+ cluster_registry,
75
+ connection_options,
76
+ execution_options)
77
+ end
78
+
79
+ let(:schema_fetcher) { create_schema_fetcher_picker }
80
+
81
+ let(:control_connection) do
82
+ Cluster::ControlConnection.new(logger,
83
+ io_reactor,
84
+ cluster_registry,
85
+ cluster_schema,
86
+ cluster_metadata,
87
+ profile_manager.default_profile.load_balancing_policy,
88
+ reconnection_policy,
89
+ address_resolution_policy,
90
+ connector,
91
+ connection_options,
92
+ schema_fetcher)
93
+ end
94
+
95
+ let(:cluster_klass) { Cluster }
96
+
97
+ let(:cluster) do
98
+ cluster_klass.new(logger,
99
+ io_reactor,
100
+ executor,
101
+ control_connection,
102
+ cluster_registry,
103
+ cluster_schema,
104
+ cluster_metadata,
105
+ execution_options,
106
+ connection_options,
107
+ profile_manager,
108
+ reconnection_policy,
109
+ address_resolution_policy,
110
+ connector,
111
+ futures_factory,
112
+ timestamp_generator)
113
+ end
114
+
115
+ let(:execution_options) do
116
+ Execution::Options.new(consistency: profile_manager.default_profile.consistency,
117
+ trace: trace,
118
+ page_size: page_size,
119
+ timeout: profile_manager.default_profile.timeout,
120
+ idempotent: false,
121
+ load_balancing_policy: profile_manager.default_profile.load_balancing_policy,
122
+ retry_policy: profile_manager.default_profile.retry_policy)
123
+ end
124
+
125
+ let(:connection_options) do
126
+ Cluster::Options.new(
127
+ logger,
128
+ protocol_version,
129
+ credentials,
130
+ auth_provider,
131
+ compressor,
132
+ port,
133
+ connect_timeout,
134
+ ssl,
135
+ connections_per_local_node,
136
+ connections_per_remote_node,
137
+ heartbeat_interval,
138
+ idle_timeout,
139
+ synchronize_schema,
140
+ schema_refresh_delay,
141
+ schema_refresh_timeout,
142
+ nodelay,
143
+ requests_per_connection,
144
+ custom_types,
145
+ allow_beta_protocol
146
+ )
147
+ end
148
+
149
+ let(:custom_types) { [] }
150
+ let(:port) { 9042 }
151
+ let(:protocol_version) { nil }
152
+ let(:allow_beta_protocol) { false }
153
+ let(:connect_timeout) { 10 }
154
+ let(:ssl) { false }
155
+ let(:logger) { NullLogger.new }
156
+ let(:compressor) { nil }
157
+ let(:credentials) { nil }
158
+ let(:auth_provider) { nil }
159
+ let(:datacenter) { nil }
160
+ let(:load_balancing_policy) do
161
+ LoadBalancing::Policies::TokenAware.new(
162
+ LoadBalancing::Policies::DCAwareRoundRobin.new(datacenter, 0),
163
+ shuffle_replicas
164
+ )
165
+ end
166
+ let(:reconnection_policy) do
167
+ Reconnection::Policies::Exponential.new(0.5, 30, 2)
168
+ end
169
+ let(:retry_policy) { Retry::Policies::Default.new }
170
+ let(:address_resolution_policy) { AddressResolution::Policies::None.new }
171
+ let(:consistency) { :quorum }
172
+ let(:trace) { false }
173
+ let(:page_size) { 10000 }
174
+ let(:heartbeat_interval) { 30 }
175
+ let(:idle_timeout) { 60 }
176
+ let(:timeout) { 12 }
177
+ let(:synchronize_schema) { true }
178
+ let(:schema_refresh_delay) { 1 }
179
+ let(:schema_refresh_timeout) { 10 }
180
+ let(:thread_pool_size) { 4 }
181
+ let(:shuffle_replicas) { true }
182
+ let(:nodelay) { true }
183
+ let(:timestamp_generator) { nil }
184
+ let(:connections_per_local_node) { nil }
185
+ let(:connections_per_remote_node) { nil }
186
+ let(:requests_per_connection) { nil }
187
+ let(:default_execution_profile) {
188
+ Cassandra::Execution::Profile.new(load_balancing_policy: load_balancing_policy,
189
+ retry_policy: retry_policy,
190
+ consistency: consistency,
191
+ timeout: timeout)
192
+ }
193
+ let(:execution_profiles) { {} }
194
+ let(:profile_manager) { Cassandra::Execution::ProfileManager.new(default_execution_profile, execution_profiles) }
195
+ let(:listeners) { [] }
196
+
197
+ def initialize(defaults = {})
198
+ @instances = defaults
199
+ end
200
+
201
+ def connect(addresses)
202
+ profile_manager.load_balancing_policies.each do |lbp|
203
+ lbp.setup(cluster)
204
+ cluster_registry.add_listener(lbp)
205
+ end
206
+
207
+ cluster_registry.add_listener(control_connection)
208
+ listeners.each do |listener|
209
+ cluster.register(listener)
210
+ end
211
+
212
+ logger.debug('Populating policies and listeners with initial endpoints')
213
+ addresses.each {|address| cluster_registry.host_found(address)}
214
+
215
+ logger.info('Establishing control connection')
216
+
217
+ promise = futures_factory.promise
218
+
219
+ control_connection.connect_async.on_complete do |f|
220
+ if f.resolved?
221
+ promise.fulfill(cluster)
222
+ else
223
+ f.on_failure do |e|
224
+ cluster.close_async
225
+ promise.break(e)
226
+ end
227
+ end
228
+ end
229
+
230
+ promise.future
231
+ end
232
+
233
+ private
234
+
235
+ def create_schema_fetcher_picker
236
+ picker = Cluster::Schema::Fetchers::MultiVersion.new(cluster_registry)
237
+
238
+ picker.when('1.2') do
239
+ Cluster::Schema::Fetchers::V1_2_x.new(schema_fqcn_type_parser, cluster_schema)
240
+ end
241
+ picker.when('2.0') do
242
+ Cluster::Schema::Fetchers::V2_0_x.new(schema_fqcn_type_parser, cluster_schema)
243
+ end
244
+ picker.when('2.1') do
245
+ Cluster::Schema::Fetchers::V2_1_x.new(schema_fqcn_type_parser, cluster_schema)
246
+ end
247
+ picker.when('2.2') do
248
+ Cluster::Schema::Fetchers::V2_2_x.new(schema_fqcn_type_parser, cluster_schema)
249
+ end
250
+ picker.when('3.') do
251
+ Cluster::Schema::Fetchers::V3_0_x.new(schema_cql_type_parser, cluster_schema)
252
+ end
253
+ picker.when('4.') do
254
+ Cluster::Schema::Fetchers::V3_0_x.new(schema_cql_type_parser, cluster_schema)
255
+ end
256
+
257
+ picker
258
+ end
259
+ end
260
+ end