cassandra-driver 3.0.0.beta.1 → 3.0.0.rc.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 (131) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +90 -38
  3. data/ext/cassandra_murmur3/cassandra_murmur3.c +1 -1
  4. data/lib/cassandra.rb +327 -130
  5. data/lib/cassandra/address_resolution.rb +1 -1
  6. data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +1 -1
  7. data/lib/cassandra/address_resolution/policies/none.rb +1 -1
  8. data/lib/cassandra/aggregate.rb +21 -7
  9. data/lib/cassandra/argument.rb +2 -2
  10. data/lib/cassandra/auth.rb +4 -4
  11. data/lib/cassandra/auth/providers.rb +1 -1
  12. data/lib/cassandra/auth/providers/password.rb +9 -5
  13. data/lib/cassandra/cassandra_logger.rb +80 -0
  14. data/lib/cassandra/cluster.rb +38 -9
  15. data/lib/cassandra/cluster/client.rb +801 -205
  16. data/lib/cassandra/cluster/connection_pool.rb +2 -2
  17. data/lib/cassandra/cluster/connector.rb +74 -25
  18. data/lib/cassandra/cluster/control_connection.rb +217 -82
  19. data/lib/cassandra/cluster/failed_connection.rb +1 -1
  20. data/lib/cassandra/cluster/metadata.rb +12 -4
  21. data/lib/cassandra/cluster/options.rb +60 -11
  22. data/lib/cassandra/cluster/registry.rb +69 -16
  23. data/lib/cassandra/cluster/schema.rb +25 -7
  24. data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
  25. data/lib/cassandra/cluster/schema/fetchers.rb +263 -106
  26. data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +41 -36
  27. data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
  28. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +3 -3
  29. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +1 -1
  30. data/lib/cassandra/cluster/schema/partitioners/random.rb +1 -1
  31. data/lib/cassandra/cluster/schema/replication_strategies.rb +1 -1
  32. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +19 -18
  33. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +1 -1
  34. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +1 -1
  35. data/lib/cassandra/column.rb +3 -3
  36. data/lib/cassandra/compression.rb +1 -1
  37. data/lib/cassandra/compression/compressors/lz4.rb +4 -3
  38. data/lib/cassandra/compression/compressors/snappy.rb +4 -3
  39. data/lib/cassandra/driver.rb +103 -41
  40. data/lib/cassandra/errors.rb +265 -30
  41. data/lib/cassandra/execution/info.rb +16 -5
  42. data/lib/cassandra/execution/options.rb +99 -54
  43. data/lib/cassandra/execution/trace.rb +16 -9
  44. data/lib/cassandra/executors.rb +1 -1
  45. data/lib/cassandra/function.rb +19 -13
  46. data/lib/cassandra/function_collection.rb +85 -0
  47. data/lib/cassandra/future.rb +106 -48
  48. data/lib/cassandra/host.rb +10 -4
  49. data/lib/cassandra/keyspace.rb +90 -33
  50. data/lib/cassandra/listener.rb +1 -1
  51. data/lib/cassandra/load_balancing.rb +2 -2
  52. data/lib/cassandra/load_balancing/policies.rb +1 -1
  53. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +18 -18
  54. data/lib/cassandra/load_balancing/policies/round_robin.rb +1 -1
  55. data/lib/cassandra/load_balancing/policies/token_aware.rb +15 -13
  56. data/lib/cassandra/load_balancing/policies/white_list.rb +11 -5
  57. data/lib/cassandra/null_logger.rb +27 -6
  58. data/lib/cassandra/protocol.rb +1 -1
  59. data/lib/cassandra/protocol/coder.rb +78 -39
  60. data/lib/cassandra/protocol/cql_byte_buffer.rb +50 -33
  61. data/lib/cassandra/protocol/cql_protocol_handler.rb +44 -45
  62. data/lib/cassandra/protocol/request.rb +2 -2
  63. data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
  64. data/lib/cassandra/protocol/requests/batch_request.rb +16 -7
  65. data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
  66. data/lib/cassandra/protocol/requests/execute_request.rb +41 -20
  67. data/lib/cassandra/protocol/requests/options_request.rb +1 -1
  68. data/lib/cassandra/protocol/requests/prepare_request.rb +5 -5
  69. data/lib/cassandra/protocol/requests/query_request.rb +27 -22
  70. data/lib/cassandra/protocol/requests/register_request.rb +2 -2
  71. data/lib/cassandra/protocol/requests/startup_request.rb +6 -4
  72. data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
  73. data/lib/cassandra/protocol/response.rb +2 -2
  74. data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
  75. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +1 -1
  76. data/lib/cassandra/protocol/responses/auth_success_response.rb +1 -1
  77. data/lib/cassandra/protocol/responses/authenticate_response.rb +1 -1
  78. data/lib/cassandra/protocol/responses/error_response.rb +101 -13
  79. data/lib/cassandra/protocol/responses/event_response.rb +1 -1
  80. data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
  81. data/lib/cassandra/protocol/responses/prepared_result_response.rb +11 -5
  82. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +14 -9
  83. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +26 -4
  84. data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +22 -3
  85. data/lib/cassandra/protocol/responses/ready_response.rb +3 -3
  86. data/lib/cassandra/protocol/responses/result_response.rb +4 -2
  87. data/lib/cassandra/protocol/responses/rows_result_response.rb +5 -3
  88. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +5 -4
  89. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +16 -9
  90. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
  91. data/lib/cassandra/protocol/responses/status_change_event_response.rb +2 -2
  92. data/lib/cassandra/protocol/responses/supported_response.rb +1 -1
  93. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +1 -1
  94. data/lib/cassandra/protocol/responses/unavailable_error_response.rb +20 -3
  95. data/lib/cassandra/protocol/responses/unprepared_error_response.rb +11 -2
  96. data/lib/cassandra/protocol/responses/void_result_response.rb +1 -1
  97. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +26 -4
  98. data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +22 -3
  99. data/lib/cassandra/protocol/v1.rb +101 -36
  100. data/lib/cassandra/protocol/v3.rb +124 -51
  101. data/lib/cassandra/protocol/v4.rb +172 -68
  102. data/lib/cassandra/reconnection.rb +1 -1
  103. data/lib/cassandra/reconnection/policies.rb +1 -1
  104. data/lib/cassandra/reconnection/policies/constant.rb +2 -4
  105. data/lib/cassandra/reconnection/policies/exponential.rb +6 -6
  106. data/lib/cassandra/result.rb +53 -19
  107. data/lib/cassandra/retry.rb +8 -8
  108. data/lib/cassandra/retry/policies.rb +1 -1
  109. data/lib/cassandra/retry/policies/default.rb +1 -1
  110. data/lib/cassandra/retry/policies/downgrading_consistency.rb +7 -3
  111. data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
  112. data/lib/cassandra/session.rb +22 -16
  113. data/lib/cassandra/statement.rb +1 -1
  114. data/lib/cassandra/statements.rb +1 -1
  115. data/lib/cassandra/statements/batch.rb +16 -10
  116. data/lib/cassandra/statements/bound.rb +10 -3
  117. data/lib/cassandra/statements/prepared.rb +59 -15
  118. data/lib/cassandra/statements/simple.rb +23 -10
  119. data/lib/cassandra/statements/void.rb +1 -1
  120. data/lib/cassandra/table.rb +79 -30
  121. data/lib/cassandra/time.rb +11 -6
  122. data/lib/cassandra/time_uuid.rb +7 -7
  123. data/lib/cassandra/tuple.rb +16 -8
  124. data/lib/cassandra/types.rb +20 -9
  125. data/lib/cassandra/udt.rb +32 -36
  126. data/lib/cassandra/util.rb +20 -13
  127. data/lib/cassandra/uuid.rb +22 -15
  128. data/lib/cassandra/uuid/generator.rb +7 -5
  129. data/lib/cassandra/version.rb +2 -2
  130. data/lib/datastax/cassandra.rb +1 -1
  131. metadata +5 -3
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -26,31 +26,31 @@ module Cassandra
26
26
  Result = Struct.new(:results, :collections)
27
27
 
28
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
- "org.apache.cassandra.db.marshal.UserType" => :udt,
49
- "org.apache.cassandra.db.marshal.TupleType" => :tuple,
50
- "org.apache.cassandra.db.marshal.ShortType" => :smallint,
51
- "org.apache.cassandra.db.marshal.ByteType" => :tinyint,
52
- "org.apache.cassandra.db.marshal.TimeType" => :time,
53
- "org.apache.cassandra.db.marshal.SimpleDateType" => :date,
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
+ 'org.apache.cassandra.db.marshal.UserType' => :udt,
49
+ 'org.apache.cassandra.db.marshal.TupleType' => :tuple,
50
+ 'org.apache.cassandra.db.marshal.ShortType' => :smallint,
51
+ 'org.apache.cassandra.db.marshal.ByteType' => :tinyint,
52
+ 'org.apache.cassandra.db.marshal.TimeType' => :time,
53
+ 'org.apache.cassandra.db.marshal.SimpleDateType' => :date
54
54
  }.freeze
55
55
 
56
56
  def parse(string)
@@ -63,15 +63,16 @@ module Cassandra
63
63
  collections = nil
64
64
  results = []
65
65
 
66
- if node.name == "org.apache.cassandra.db.marshal.CompositeType"
66
+ if node.name == 'org.apache.cassandra.db.marshal.CompositeType'
67
67
  collections = {}
68
68
 
69
- if node.children.last.name == "org.apache.cassandra.db.marshal.ColumnToCollectionType"
69
+ if node.children.last.name ==
70
+ 'org.apache.cassandra.db.marshal.ColumnToCollectionType'
70
71
  node.children.pop.children.each do |child|
71
- key, name = child.name.split(":")
72
+ key, name = child.name.split(':')
72
73
  key = [key].pack('H*').force_encoding(::Encoding::UTF_8)
73
74
 
74
- if name == "org.apache.cassandra.db.marshal.ReversedType"
75
+ if name == 'org.apache.cassandra.db.marshal.ReversedType'
75
76
  collections[key] = lookup_type(child.children.first)
76
77
  else
77
78
  child.name = name
@@ -94,12 +95,12 @@ module Cassandra
94
95
  order = :asc
95
96
  frozen = false
96
97
 
97
- if node.name == "org.apache.cassandra.db.marshal.ReversedType"
98
+ if node.name == 'org.apache.cassandra.db.marshal.ReversedType'
98
99
  order = :desc
99
100
  node = node.children.first
100
101
  end
101
102
 
102
- if node.name == "org.apache.cassandra.db.marshal.FrozenType"
103
+ if node.name == 'org.apache.cassandra.db.marshal.FrozenType'
103
104
  frozen = true
104
105
  node = node.children.first
105
106
  end
@@ -108,11 +109,13 @@ module Cassandra
108
109
  end
109
110
 
110
111
  def lookup_type(node)
111
- if node.name == "org.apache.cassandra.db.marshal.FrozenType"
112
+ if node.name == 'org.apache.cassandra.db.marshal.FrozenType'
112
113
  return lookup_type(node.children.first)
113
114
  end
114
115
 
115
- type = @@types.fetch(node.name) { return Cassandra::Types.custom(dump_node(node)) }
116
+ type = @@types.fetch(node.name) do
117
+ return Cassandra::Types.custom(dump_node(node))
118
+ end
116
119
 
117
120
  case type
118
121
  when :set, :list
@@ -123,7 +126,7 @@ module Cassandra
123
126
  keyspace = node.children.shift.name
124
127
  name = [node.children.shift.name].pack('H*')
125
128
  fields = node.children.map do |child|
126
- field_name, child_name = child.name.split(":")
129
+ field_name, child_name = child.name.split(':')
127
130
 
128
131
  child.name = child_name
129
132
  field_name = [field_name].pack('H*').force_encoding(::Encoding::UTF_8)
@@ -166,7 +169,9 @@ module Cassandra
166
169
 
167
170
  def dump_node(node)
168
171
  str = node.name
169
- str << '(' + node.children.map {|n| dump_node(n)}.join(',') + ')' unless node.children.empty?
172
+ unless node.children.empty?
173
+ str << '(' + node.children.map { |n| dump_node(n) }.join(',') + ')'
174
+ end
170
175
  str
171
176
  end
172
177
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -37,9 +37,9 @@ module Cassandra
37
37
  private
38
38
 
39
39
  # @private
40
- LONG_MIN = -2 ** 63
40
+ LONG_MIN = -2**63
41
41
  # @private
42
- LONG_MAX = 2 ** 63 - 1
42
+ LONG_MAX = 2**63 - 1
43
43
  end
44
44
  end
45
45
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ module Cassandra
34
34
  racks[host.datacenter] ||= ::Set.new
35
35
  racks[host.datacenter].add(host.rack)
36
36
 
37
- datacenter_token_rings[host.datacenter] ||= Hash.new
37
+ datacenter_token_rings[host.datacenter] ||= {}
38
38
  datacenter_token_rings[host.datacenter][i] = token
39
39
  end
40
40
 
@@ -48,8 +48,11 @@ module Cassandra
48
48
  replication_options.each do |datacenter, factor|
49
49
  ring = datacenter_token_rings[datacenter]
50
50
  next unless ring
51
- factor = [Integer(factor), ring.size].min rescue next
52
-
51
+ factor = begin
52
+ [Integer(factor), ring.size].min
53
+ rescue
54
+ next
55
+ end
53
56
 
54
57
  total_racks = racks[datacenter].size
55
58
  visited_racks = visited[datacenter] ||= ::Set.new
@@ -68,21 +71,19 @@ module Cassandra
68
71
  if rack.nil? || visited_racks.size == total_racks
69
72
  replicas << host
70
73
  added_replicas << host
74
+ elsif visited_racks.include?(rack)
75
+ skipped_hosts << host
71
76
  else
72
- if visited_racks.include?(rack)
73
- skipped_hosts << host
74
- else
75
- replicas << host
76
- visited_racks << rack
77
- added_replicas << host
78
-
79
- if visited_racks.size == total_racks
80
- skipped_hosts.each do |skipped_host|
81
- break if added_replicas.size >= factor
82
-
83
- replicas << skipped_host
84
- added_replicas << host
85
- end
77
+ replicas << host
78
+ visited_racks << rack
79
+ added_replicas << host
80
+
81
+ if visited_racks.size == total_racks
82
+ skipped_hosts.each do |skipped_host|
83
+ break if added_replicas.size >= factor
84
+
85
+ replicas << skipped_host
86
+ added_replicas << host
86
87
  end
87
88
  end
88
89
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ module Cassandra
67
67
 
68
68
  # @private
69
69
  def inspect
70
- "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @name=#{@name} @type=#{@type}>"
70
+ "#<#{self.class.name}:0x#{object_id.to_s(16)} @name=#{@name} @type=#{@type}>"
71
71
  end
72
72
 
73
73
  # @private
@@ -80,6 +80,6 @@ module Cassandra
80
80
  @static == other.static? &&
81
81
  @frozen == other.frozen?
82
82
  end
83
- alias :== :eql?
83
+ alias == eql?
84
84
  end
85
85
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -33,12 +33,13 @@ module Cassandra
33
33
 
34
34
  # @param [Integer] min_size (64) Don't compress frames smaller than
35
35
  # this size (see {#compress?}).
36
- def initialize(min_size=64)
36
+ def initialize(min_size = 64)
37
37
  unless defined?(::LZ4::Raw)
38
38
  begin
39
39
  require 'lz4-ruby'
40
40
  rescue LoadError => e
41
- raise LoadError, %[LZ4 support requires the "lz4-ruby" gem: #{e.message}], e.backtrace
41
+ raise LoadError, %(LZ4 support requires the "lz4-ruby" gem: #{e.message}),
42
+ e.backtrace
42
43
  end
43
44
  end
44
45
 
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -33,12 +33,13 @@ module Cassandra
33
33
 
34
34
  # @param [Integer] min_size (64) Don't compress frames smaller than
35
35
  # this size (see {#compress?}).
36
- def initialize(min_size=64)
36
+ def initialize(min_size = 64)
37
37
  unless defined?(::Snappy)
38
38
  begin
39
39
  require 'snappy'
40
40
  rescue LoadError => e
41
- raise LoadError, %[Snappy support requires the "snappy" gem: #{e.message}], e.backtrace
41
+ raise LoadError, %(Snappy support requires the "snappy" gem: #{e.message}),
42
+ e.backtrace
42
43
  end
43
44
  end
44
45
 
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -20,28 +20,33 @@ module Cassandra
20
20
  # @private
21
21
  class Driver
22
22
  def self.let(name, &block)
23
- define_method(name) { @instances.has_key?(name) ? @instances[name] : @instances[name] = instance_eval(&block) }
23
+ define_method(name) do
24
+ @instances.key?(name) ?
25
+ @instances[name] :
26
+ @instances[name] = instance_eval(&block)
27
+ end
24
28
  define_method(:"#{name}=") { |object| @instances[name] = object }
25
29
  end
26
30
 
27
31
  let(:io_reactor) { Ione::Io::IoReactor.new }
28
32
  let(:cluster_registry) { Cluster::Registry.new(logger) }
29
33
  let(:cluster_schema) { Cluster::Schema.new }
30
- let(:cluster_metadata) { Cluster::Metadata.new(
31
- cluster_registry,
32
- cluster_schema,
33
- {
34
- 'org.apache.cassandra.dht.Murmur3Partitioner' => murmur3_partitioner,
35
- 'org.apache.cassandra.dht.ByteOrderedPartitioner' => ordered_partitioner,
36
- 'org.apache.cassandra.dht.RandomPartitioner' => random_partitioner
37
- }.freeze,
38
- {
39
- 'SimpleStrategy' => simple_replication_strategy,
40
- 'NetworkTopologyStrategy' => network_topology_replication_strategy
41
- }.freeze,
42
- no_replication_strategy
43
- )
44
- }
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
45
50
 
46
51
  let(:executor) { Executors::ThreadPool.new(thread_pool_size) }
47
52
  let(:futures_factory) { Future::Factory.new(executor) }
@@ -49,34 +54,73 @@ module Cassandra
49
54
  let(:schema_fqcn_type_parser) { Cluster::Schema::FQCNTypeParser.new }
50
55
  let(:schema_cql_type_parser) { Cluster::Schema::CQLTypeParser.new }
51
56
 
52
- let(:simple_replication_strategy) { Cluster::Schema::ReplicationStrategies::Simple.new }
53
- let(:network_topology_replication_strategy) { Cluster::Schema::ReplicationStrategies::NetworkTopology.new }
54
- let(:no_replication_strategy) { Cluster::Schema::ReplicationStrategies::None.new }
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
55
66
 
56
67
  let(:murmur3_partitioner) { Cluster::Schema::Partitioners::Murmur3.new }
57
68
  let(:ordered_partitioner) { Cluster::Schema::Partitioners::Ordered.new }
58
69
  let(:random_partitioner) { Cluster::Schema::Partitioners::Random.new }
59
70
 
60
- let(:connector) { Cluster::Connector.new(logger, io_reactor, cluster_registry, connection_options, execution_options) }
71
+ let(:connector) do
72
+ Cluster::Connector.new(logger,
73
+ io_reactor,
74
+ cluster_registry,
75
+ connection_options,
76
+ execution_options)
77
+ end
61
78
 
62
79
  let(:schema_fetcher) { create_schema_fetcher_picker }
63
80
 
64
- let(:control_connection) { Cluster::ControlConnection.new(logger, io_reactor, cluster_registry, cluster_schema, cluster_metadata, load_balancing_policy, reconnection_policy, address_resolution_policy, connector, connection_options, schema_fetcher) }
81
+ let(:control_connection) do
82
+ Cluster::ControlConnection.new(logger,
83
+ io_reactor,
84
+ cluster_registry,
85
+ cluster_schema,
86
+ cluster_metadata,
87
+ load_balancing_policy,
88
+ reconnection_policy,
89
+ address_resolution_policy,
90
+ connector,
91
+ connection_options,
92
+ schema_fetcher)
93
+ end
65
94
 
66
- let(:cluster) { Cluster.new(logger, io_reactor, executor, control_connection, cluster_registry, cluster_schema, cluster_metadata, execution_options, connection_options, load_balancing_policy, reconnection_policy, retry_policy, address_resolution_policy, connector, futures_factory) }
95
+ let(:cluster) do
96
+ Cluster.new(logger,
97
+ io_reactor,
98
+ executor,
99
+ control_connection,
100
+ cluster_registry,
101
+ cluster_schema,
102
+ cluster_metadata,
103
+ execution_options,
104
+ connection_options,
105
+ load_balancing_policy,
106
+ reconnection_policy,
107
+ retry_policy,
108
+ address_resolution_policy,
109
+ connector,
110
+ futures_factory)
111
+ end
67
112
 
68
113
  let(:execution_options) do
69
- Execution::Options.new({
70
- :consistency => consistency,
71
- :trace => trace,
72
- :page_size => page_size,
73
- :timeout => timeout,
74
- :idempotent => false
75
- })
114
+ Execution::Options.new(consistency: consistency,
115
+ trace: trace,
116
+ page_size: page_size,
117
+ timeout: timeout,
118
+ idempotent: false)
76
119
  end
77
120
 
78
121
  let(:connection_options) do
79
122
  Cluster::Options.new(
123
+ logger,
80
124
  protocol_version,
81
125
  credentials,
82
126
  auth_provider,
@@ -92,7 +136,8 @@ module Cassandra
92
136
  schema_refresh_delay,
93
137
  schema_refresh_timeout,
94
138
  client_timestamps,
95
- nodelay
139
+ nodelay,
140
+ requests_per_connection
96
141
  )
97
142
  end
98
143
 
@@ -100,13 +145,19 @@ module Cassandra
100
145
  let(:protocol_version) { 4 }
101
146
  let(:connect_timeout) { 10 }
102
147
  let(:ssl) { false }
103
- let(:logger) { NullLogger.new }
148
+ let(:logger) { NullLogger.new }
104
149
  let(:compressor) { nil }
105
150
  let(:credentials) { nil }
106
151
  let(:auth_provider) { nil }
107
152
  let(:datacenter) { nil }
108
- let(:load_balancing_policy) { LoadBalancing::Policies::TokenAware.new(LoadBalancing::Policies::DCAwareRoundRobin.new(datacenter, 0), shuffle_replicas) }
109
- let(:reconnection_policy) { Reconnection::Policies::Exponential.new(0.5, 30, 2) }
153
+ let(:load_balancing_policy) do
154
+ LoadBalancing::Policies::TokenAware.new(
155
+ LoadBalancing::Policies::DCAwareRoundRobin.new(datacenter, 0),
156
+ shuffle_replicas)
157
+ end
158
+ let(:reconnection_policy) do
159
+ Reconnection::Policies::Exponential.new(0.5, 30, 2)
160
+ end
110
161
  let(:retry_policy) { Retry::Policies::Default.new }
111
162
  let(:address_resolution_policy) { AddressResolution::Policies::None.new }
112
163
  let(:consistency) { :local_one }
@@ -123,8 +174,9 @@ module Cassandra
123
174
  let(:client_timestamps) { false }
124
175
  let(:nodelay) { true }
125
176
 
126
- let(:connections_per_local_node) { 2 }
127
- let(:connections_per_remote_node) { 1 }
177
+ let(:connections_per_local_node) { nil }
178
+ let(:connections_per_remote_node) { nil }
179
+ let(:requests_per_connection) { nil }
128
180
 
129
181
  let(:listeners) { [] }
130
182
 
@@ -166,11 +218,21 @@ module Cassandra
166
218
  def create_schema_fetcher_picker
167
219
  picker = Cluster::Schema::Fetchers::MultiVersion.new(cluster_registry)
168
220
 
169
- picker.when('1.2') { Cluster::Schema::Fetchers::V1_2_x.new(schema_fqcn_type_parser, cluster_schema) }
170
- picker.when('2.0') { Cluster::Schema::Fetchers::V2_0_x.new(schema_fqcn_type_parser, cluster_schema) }
171
- picker.when('2.1') { Cluster::Schema::Fetchers::V2_1_x.new(schema_fqcn_type_parser, cluster_schema) }
172
- picker.when('2.2') { Cluster::Schema::Fetchers::V2_2_x.new(schema_fqcn_type_parser, cluster_schema) }
173
- picker.when('3.0') { Cluster::Schema::Fetchers::V3_0_x.new(schema_cql_type_parser, cluster_schema) }
221
+ picker.when('1.2') do
222
+ Cluster::Schema::Fetchers::V1_2_x.new(schema_fqcn_type_parser, cluster_schema)
223
+ end
224
+ picker.when('2.0') do
225
+ Cluster::Schema::Fetchers::V2_0_x.new(schema_fqcn_type_parser, cluster_schema)
226
+ end
227
+ picker.when('2.1') do
228
+ Cluster::Schema::Fetchers::V2_1_x.new(schema_fqcn_type_parser, cluster_schema)
229
+ end
230
+ picker.when('2.2') do
231
+ Cluster::Schema::Fetchers::V2_2_x.new(schema_fqcn_type_parser, cluster_schema)
232
+ end
233
+ picker.when('3.') do
234
+ Cluster::Schema::Fetchers::V3_0_x.new(schema_cql_type_parser, cluster_schema)
235
+ end
174
236
 
175
237
  picker
176
238
  end