gotime-cassandra_object 4.11.5 → 4.11.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/adapters/abstract_adapter.rb +47 -0
- data/lib/cassandra_object/adapters/cassandra_adapter.rb +158 -0
- data/lib/cassandra_object/adapters/dynamo_adapter.rb +6 -0
- data/lib/cassandra_object/adapters/hstore_adapter.rb +6 -0
- data/lib/cassandra_object/connection.rb +4 -0
- data/lib/cassandra_object/consistency.rb +7 -3
- data/lib/cassandra_object/log_subscriber.rb +15 -0
- data/lib/cassandra_object/persistence.rb +10 -47
- data/lib/cassandra_object/railtie.rb +8 -0
- data/lib/cassandra_object/railties/controller_runtime.rb +45 -0
- data/lib/cassandra_object/scope.rb +3 -11
- data/lib/cassandra_object/scope/batches.rb +1 -1
- data/lib/cassandra_object/scope/finder_methods.rb +3 -2
- data/lib/cassandra_object/scope/query_methods.rb +2 -69
- data/lib/gotime-cassandra_object.rb +16 -8
- data/test/unit/log_subscriber_test.rb +4 -0
- data/test/unit/persistence_test.rb +1 -1
- data/test/unit/railties/controller_runtime_test.rb +48 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fcf2ed65ff6d08d1702f76e7836b583ba931efb
|
4
|
+
data.tar.gz: 92826ba8e10ab9bf7c5adcbd3b91e8aa4fa1b588
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efcb74eb7565da59f852cabf98bbff6576522711baed4e7606bc176e7ff7274b77a07613cced49800566e79492b514a25eccaf1012c878db02637a8f1a6ebd50
|
7
|
+
data.tar.gz: 5719eb66e60d9b435869d774e6f39fa31db7a0650233626ffbcdf4899ec5c1dbef5f8cc394c6fc5f511251b2da2983ceb0aeb45e0ddeb78574acf399b11c6e84
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CassandraObject
|
2
|
+
module Adapters
|
3
|
+
class AbstractAdapter
|
4
|
+
attr_reader :config
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
# === Options
|
10
|
+
# [:select]
|
11
|
+
# Only select certain fields
|
12
|
+
# [:limit]
|
13
|
+
# Limit the results
|
14
|
+
def select(ids, options ={}) # abstract
|
15
|
+
end
|
16
|
+
|
17
|
+
def write(id, attributes) # abstract
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(ids) # abstract
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute_batch(statements) # abstract
|
24
|
+
end
|
25
|
+
|
26
|
+
def batching?
|
27
|
+
!@batch_statements.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def batch
|
31
|
+
@batch_statements = []
|
32
|
+
yield
|
33
|
+
execute_batch(@batch_statements) if @batch_statements.any?
|
34
|
+
ensure
|
35
|
+
@batch_statements = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute_batchable(statement)
|
39
|
+
if @batch_statements
|
40
|
+
@batch_statements << statement
|
41
|
+
else
|
42
|
+
execute statement
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module CassandraObject
|
2
|
+
module Adapters
|
3
|
+
class CassandraAdapter < AbstractAdapter
|
4
|
+
def cql
|
5
|
+
@cql ||= CassandraCQL::Database.new(config.servers, {keyspace: config.keyspace}, config.thrift_options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute(statement)
|
9
|
+
ActiveSupport::Notifications.instrument("cql.cassandra_object", cql: statement) do
|
10
|
+
cql.execute statement
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def select(statement)
|
15
|
+
execute(statement).fetch do |cql_row|
|
16
|
+
attributes = cql_row.to_hash
|
17
|
+
key = attributes.delete(primary_key_column)
|
18
|
+
yield(key, attributes) unless attributes.empty?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_query(scope)
|
23
|
+
QueryBuilder.new(self, scope).to_query
|
24
|
+
end
|
25
|
+
|
26
|
+
class QueryBuilder
|
27
|
+
def initialize(adapter, scope)
|
28
|
+
@adapter = adapter
|
29
|
+
@scope = scope
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_query
|
33
|
+
[
|
34
|
+
"SELECT #{select_string} FROM #{@scope.klass.column_family}",
|
35
|
+
@adapter.write_option_string,
|
36
|
+
where_string,
|
37
|
+
limit_string
|
38
|
+
].delete_if(&:blank?) * ' '
|
39
|
+
end
|
40
|
+
|
41
|
+
def select_string
|
42
|
+
if @scope.select_values.any?
|
43
|
+
(['KEY'] | @scope.select_values) * ','
|
44
|
+
else
|
45
|
+
'*'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def where_string
|
50
|
+
if @scope.where_values.any?
|
51
|
+
wheres = []
|
52
|
+
|
53
|
+
@scope.where_values.map do |where_value|
|
54
|
+
wheres.concat format_where_statement(where_value)
|
55
|
+
end
|
56
|
+
|
57
|
+
"WHERE #{wheres * ' AND '}"
|
58
|
+
else
|
59
|
+
''
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def format_where_statement(where_value)
|
64
|
+
if where_value.is_a?(String)
|
65
|
+
[where_value]
|
66
|
+
elsif where_value.is_a?(Hash)
|
67
|
+
where_value.map do |column, value|
|
68
|
+
if value.is_a?(Array)
|
69
|
+
"#{column} IN (#{escape_where_value(value)})"
|
70
|
+
else
|
71
|
+
"#{column} = #{escape_where_value(value)}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def escape_where_value(value)
|
78
|
+
if value.is_a?(Array)
|
79
|
+
value.map { |v| escape_where_value(v) }.join(",")
|
80
|
+
elsif value.is_a?(String)
|
81
|
+
value = value.gsub("'", "''")
|
82
|
+
"'#{value}'"
|
83
|
+
else
|
84
|
+
value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def limit_string
|
89
|
+
if @scope.limit_value
|
90
|
+
"LIMIT #{@scope.limit_value}"
|
91
|
+
else
|
92
|
+
""
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def write(table, id, attributes)
|
98
|
+
if (not_nil_attributes = attributes.reject { |key, value| value.nil? }).any?
|
99
|
+
insert_attributes = {primary_key_column => id}.update(not_nil_attributes)
|
100
|
+
statement = "INSERT INTO #{table} (#{quote_columns(insert_attributes.keys) * ','}) VALUES (#{Array.new(insert_attributes.size, '?') * ','})#{write_option_string}"
|
101
|
+
execute_batchable sanitize(statement, *insert_attributes.values)
|
102
|
+
end
|
103
|
+
|
104
|
+
if (nil_attributes = attributes.select { |key, value| value.nil? }).any?
|
105
|
+
execute_batchable sanitize("DELETE #{quote_columns(nil_attributes.keys) * ','} FROM #{table}#{write_option_string} WHERE #{primary_key_column} = ?", id)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def delete(table, ids)
|
110
|
+
statement = "DELETE FROM #{table}#{write_option_string} WHERE "
|
111
|
+
statement += ids.is_a?(Array) ? "#{primary_key_column} IN (?)" : "#{primary_key_column} = ?"
|
112
|
+
|
113
|
+
execute_batchable sanitize(statement, ids)
|
114
|
+
end
|
115
|
+
|
116
|
+
def execute_batch(statements)
|
117
|
+
raise 'No can do' if statements.empty?
|
118
|
+
|
119
|
+
stmt = [
|
120
|
+
"BEGIN BATCH#{write_option_string(true)}",
|
121
|
+
statements * "\n",
|
122
|
+
'APPLY BATCH'
|
123
|
+
] * "\n"
|
124
|
+
|
125
|
+
execute stmt
|
126
|
+
end
|
127
|
+
|
128
|
+
def consistency
|
129
|
+
@consistency
|
130
|
+
end
|
131
|
+
|
132
|
+
def consistency=(val)
|
133
|
+
@consistency = val
|
134
|
+
end
|
135
|
+
|
136
|
+
def primary_key_column
|
137
|
+
'KEY'
|
138
|
+
end
|
139
|
+
|
140
|
+
def write_option_string(ignore_batching = false)
|
141
|
+
if (ignore_batching || !batching?) && consistency
|
142
|
+
" USING CONSISTENCY #{consistency}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
def sanitize(statement, *bind_vars)
|
149
|
+
CassandraCQL::Statement.sanitize(statement, bind_vars).force_encoding(Encoding::UTF_8)
|
150
|
+
end
|
151
|
+
|
152
|
+
def quote_columns(column_names)
|
153
|
+
column_names.map { |name| "'#{name}'" }
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -24,6 +24,10 @@ module CassandraObject
|
|
24
24
|
@@cql ||= CassandraCQL::Database.new(config.servers, {keyspace: config.keyspace}, config.thrift_options)
|
25
25
|
end
|
26
26
|
|
27
|
+
def adapter
|
28
|
+
@@adapter ||= CassandraObject::Adapters::CassandraAdapter.new(config)
|
29
|
+
end
|
30
|
+
|
27
31
|
def execute_cql(cql_string, *bind_vars)
|
28
32
|
statement = CassandraCQL::Statement.sanitize(cql_string, bind_vars).force_encoding(Encoding::UTF_8)
|
29
33
|
|
@@ -9,10 +9,14 @@ module CassandraObject
|
|
9
9
|
ensure
|
10
10
|
self.default_consistency = previous
|
11
11
|
end
|
12
|
-
end
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
def default_consistency=(value)
|
14
|
+
adapter.consistency = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_consistency
|
18
|
+
adapter.consistency
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -1,11 +1,26 @@
|
|
1
1
|
module CassandraObject
|
2
2
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
3
|
+
def self.runtime=(value)
|
4
|
+
Thread.current["cassandra_object_request_runtime"] = value
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.runtime
|
8
|
+
Thread.current["cassandra_object_request_runtime"] ||= 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.reset_runtime
|
12
|
+
rt, self.runtime = runtime, 0
|
13
|
+
rt
|
14
|
+
end
|
15
|
+
|
3
16
|
def initialize
|
4
17
|
super
|
5
18
|
@odd_or_even = false
|
6
19
|
end
|
7
20
|
|
8
21
|
def cql(event)
|
22
|
+
self.class.runtime += event.duration
|
23
|
+
|
9
24
|
payload = event.payload
|
10
25
|
name = '%s (%.1fms)' % [payload[:name], event.duration]
|
11
26
|
cql = payload[:cql].squeeze(' ')
|
@@ -7,15 +7,12 @@ module CassandraObject
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
-
def remove(
|
11
|
-
|
12
|
-
statement += id.is_a?(Array) ? "KEY IN (?)" : "KEY = ?"
|
13
|
-
|
14
|
-
execute_batchable_cql statement, id
|
10
|
+
def remove(ids)
|
11
|
+
adapter.delete column_family, ids
|
15
12
|
end
|
16
13
|
|
17
14
|
def delete_all
|
18
|
-
|
15
|
+
adapter.execute "TRUNCATE #{column_family}"
|
19
16
|
end
|
20
17
|
|
21
18
|
def create(attributes = {}, &block)
|
@@ -25,27 +22,15 @@ module CassandraObject
|
|
25
22
|
end
|
26
23
|
|
27
24
|
def write(id, attributes)
|
28
|
-
|
29
|
-
insert_attributes = {'KEY' => id}.update(encoded)
|
30
|
-
statement = "INSERT INTO #{column_family} (#{quote_columns(insert_attributes.keys) * ','}) VALUES (#{Array.new(insert_attributes.size, '?') * ','})#{write_option_string}"
|
31
|
-
execute_batchable_cql statement, *insert_attributes.values
|
32
|
-
end
|
33
|
-
|
34
|
-
if (nil_attributes = attributes.select { |key, value| value.nil? }).any?
|
35
|
-
execute_batchable_cql "DELETE #{quote_columns(nil_attributes.keys) * ','} FROM #{column_family}#{write_option_string} WHERE KEY = ?", id
|
36
|
-
end
|
25
|
+
adapter.write column_family, id, encode_attributes(attributes)
|
37
26
|
end
|
38
27
|
|
39
28
|
def batching?
|
40
|
-
|
29
|
+
adapter.batching?
|
41
30
|
end
|
42
31
|
|
43
|
-
def batch
|
44
|
-
|
45
|
-
yield
|
46
|
-
execute_cql(batch_statement) if batch_statements.any?
|
47
|
-
ensure
|
48
|
-
self.batch_statements = nil
|
32
|
+
def batch(&block)
|
33
|
+
adapter.batch(&block)
|
49
34
|
end
|
50
35
|
|
51
36
|
def instantiate(id, attributes)
|
@@ -60,7 +45,9 @@ module CassandraObject
|
|
60
45
|
def encode_attributes(attributes)
|
61
46
|
encoded = {}
|
62
47
|
attributes.each do |column_name, value|
|
63
|
-
|
48
|
+
if value.nil?
|
49
|
+
encoded[column_name] = nil
|
50
|
+
else
|
64
51
|
encoded[column_name] = attribute_definitions[column_name].coder.encode(value)
|
65
52
|
end
|
66
53
|
end
|
@@ -73,24 +60,6 @@ module CassandraObject
|
|
73
60
|
column_names.map { |name| "'#{name}'" }
|
74
61
|
end
|
75
62
|
|
76
|
-
def batch_statement
|
77
|
-
return nil unless batch_statements.any?
|
78
|
-
|
79
|
-
[
|
80
|
-
"BEGIN BATCH#{write_option_string(true)}",
|
81
|
-
batch_statements * "\n",
|
82
|
-
'APPLY BATCH'
|
83
|
-
] * "\n"
|
84
|
-
end
|
85
|
-
|
86
|
-
def execute_batchable_cql(cql_string, *bind_vars)
|
87
|
-
if batch_statements
|
88
|
-
batch_statements << CassandraCQL::Statement.sanitize(cql_string, bind_vars)
|
89
|
-
else
|
90
|
-
execute_cql cql_string, *bind_vars
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
63
|
def typecast_persisted_attributes(object, attributes)
|
95
64
|
attributes.each do |key, value|
|
96
65
|
if definition = attribute_definitions[key]
|
@@ -108,12 +77,6 @@ module CassandraObject
|
|
108
77
|
|
109
78
|
attributes
|
110
79
|
end
|
111
|
-
|
112
|
-
def write_option_string(ignore_batching = false)
|
113
|
-
if (ignore_batching || !batching?) && base_class.default_consistency
|
114
|
-
" USING CONSISTENCY #{base_class.default_consistency}"
|
115
|
-
end
|
116
|
-
end
|
117
80
|
end
|
118
81
|
|
119
82
|
def new_record?
|
@@ -3,5 +3,13 @@ module CassandraObject
|
|
3
3
|
rake_tasks do
|
4
4
|
load 'cassandra_object/tasks/ks.rake'
|
5
5
|
end
|
6
|
+
|
7
|
+
# Expose database runtime to controller for logging.
|
8
|
+
initializer "cassandra_object.log_runtime" do |app|
|
9
|
+
require "cassandra_object/railties/controller_runtime"
|
10
|
+
ActiveSupport.on_load(:action_controller) do
|
11
|
+
include CassandraObject::Railties::ControllerRuntime
|
12
|
+
end
|
13
|
+
end
|
6
14
|
end
|
7
15
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'active_support/core_ext/module/attr_internal'
|
2
|
+
require 'cassandra_object/log_subscriber'
|
3
|
+
|
4
|
+
module CassandraObject
|
5
|
+
module Railties # :nodoc:
|
6
|
+
module ControllerRuntime #:nodoc:
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
module ClassMethods # :nodoc:
|
10
|
+
def log_process_action(payload)
|
11
|
+
messages, cassandra_object_runtime = super, payload[:cassandra_object_runtime]
|
12
|
+
if cassandra_object_runtime.to_i > 0
|
13
|
+
messages << ("CassandraObject: %.1fms" % cassandra_object_runtime.to_f)
|
14
|
+
end
|
15
|
+
messages
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#private
|
20
|
+
|
21
|
+
attr_internal :cassandra_object_runtime
|
22
|
+
|
23
|
+
def process_action(action, *args)
|
24
|
+
# We also need to reset the runtime before each action
|
25
|
+
# because of queries in middleware or in cases we are streaming
|
26
|
+
# and it won't be cleaned up by the method below.
|
27
|
+
CassandraObject::LogSubscriber.reset_runtime
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def cleanup_view_runtime
|
32
|
+
runtime_before_render = CassandraObject::LogSubscriber.reset_runtime
|
33
|
+
runtime = super
|
34
|
+
runtime_after_render = CassandraObject::LogSubscriber.reset_runtime
|
35
|
+
self.cassandra_object_runtime = runtime_before_render + runtime_after_render
|
36
|
+
runtime - runtime_after_render
|
37
|
+
end
|
38
|
+
|
39
|
+
def append_info_to_payload(payload)
|
40
|
+
super
|
41
|
+
payload[:cassandra_object_runtime] = (cassandra_object_runtime || 0) + CassandraObject::LogSubscriber.reset_runtime
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -36,21 +36,13 @@ module CassandraObject
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def instantiate_from_cql(cql_string
|
39
|
+
def instantiate_from_cql(cql_string)
|
40
40
|
results = []
|
41
|
-
klass.
|
42
|
-
results <<
|
41
|
+
klass.adapter.select(cql_string) do |key, attributes|
|
42
|
+
results << klass.instantiate(key, attributes)
|
43
43
|
end
|
44
44
|
results.compact!
|
45
45
|
results
|
46
46
|
end
|
47
|
-
|
48
|
-
def instantiate_cql_row(cql_row)
|
49
|
-
attributes = cql_row.to_hash
|
50
|
-
key = attributes.delete('KEY')
|
51
|
-
if attributes.any?
|
52
|
-
klass.instantiate(key, attributes)
|
53
|
-
end
|
54
|
-
end
|
55
47
|
end
|
56
48
|
end
|
@@ -24,10 +24,11 @@ module CassandraObject
|
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
27
|
+
|
27
28
|
def find_one(id)
|
28
29
|
if id.blank?
|
29
30
|
raise CassandraObject::RecordNotFound, "Couldn't find #{self.name} with key #{id.inspect}"
|
30
|
-
elsif record = where(
|
31
|
+
elsif record = where(adapter.primary_key_column => id).first
|
31
32
|
record
|
32
33
|
else
|
33
34
|
raise CassandraObject::RecordNotFound
|
@@ -40,7 +41,7 @@ module CassandraObject
|
|
40
41
|
|
41
42
|
ids = ids.compact.map(&:to_s).uniq
|
42
43
|
|
43
|
-
where(
|
44
|
+
where(adapter.primary_key_column => ids).to_a
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
@@ -33,79 +33,12 @@ module CassandraObject
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def to_cql
|
36
|
-
|
37
|
-
"SELECT #{select_string} FROM #{klass.column_family}",
|
38
|
-
consistency_string,
|
39
|
-
where_string,
|
40
|
-
limit_string
|
41
|
-
].delete_if(&:blank?) * ' '
|
36
|
+
adapter.build_query(self)
|
42
37
|
end
|
43
38
|
|
44
39
|
def to_a
|
45
|
-
instantiate_from_cql(
|
40
|
+
instantiate_from_cql(adapter.build_query(self))
|
46
41
|
end
|
47
|
-
|
48
|
-
private
|
49
|
-
def select_string
|
50
|
-
if select_values.any?
|
51
|
-
(['KEY'] | select_values) * ','
|
52
|
-
else
|
53
|
-
'*'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def where_string
|
58
|
-
if where_values.any?
|
59
|
-
wheres = []
|
60
|
-
|
61
|
-
where_values.map do |where_value|
|
62
|
-
wheres.concat format_where_statement(where_value)
|
63
|
-
end
|
64
|
-
|
65
|
-
"WHERE #{wheres * ' AND '}"
|
66
|
-
else
|
67
|
-
''
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def format_where_statement(where_value)
|
72
|
-
if where_value.is_a?(String)
|
73
|
-
[where_value]
|
74
|
-
elsif where_value.is_a?(Hash)
|
75
|
-
where_value.map do |column, value|
|
76
|
-
if value.is_a?(Array)
|
77
|
-
"#{column} IN (#{escape_where_value(value)})"
|
78
|
-
else
|
79
|
-
"#{column} = #{escape_where_value(value)}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def escape_where_value(value)
|
86
|
-
if value.is_a?(Array)
|
87
|
-
value.map { |v| escape_where_value(v) }.join(",")
|
88
|
-
elsif value.is_a?(String)
|
89
|
-
value = value.gsub("'", "''")
|
90
|
-
"'#{value}'"
|
91
|
-
else
|
92
|
-
value
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def limit_string
|
97
|
-
if limit_value
|
98
|
-
"LIMIT #{limit_value}"
|
99
|
-
else
|
100
|
-
""
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def consistency_string
|
105
|
-
if klass.default_consistency
|
106
|
-
"USING CONSISTENCY #{klass.default_consistency}"
|
107
|
-
end
|
108
|
-
end
|
109
42
|
end
|
110
43
|
end
|
111
44
|
end
|
@@ -27,14 +27,6 @@ module CassandraObject
|
|
27
27
|
autoload :Type
|
28
28
|
autoload :Validations
|
29
29
|
|
30
|
-
module BelongsTo
|
31
|
-
extend ActiveSupport::Autoload
|
32
|
-
|
33
|
-
autoload :Association
|
34
|
-
autoload :Builder
|
35
|
-
autoload :Reflection
|
36
|
-
end
|
37
|
-
|
38
30
|
module AttributeMethods
|
39
31
|
extend ActiveSupport::Autoload
|
40
32
|
|
@@ -46,6 +38,22 @@ module CassandraObject
|
|
46
38
|
end
|
47
39
|
end
|
48
40
|
|
41
|
+
module Adapters
|
42
|
+
extend ActiveSupport::Autoload
|
43
|
+
|
44
|
+
autoload :AbstractAdapter
|
45
|
+
autoload :CassandraAdapter
|
46
|
+
autoload :HstoreAdapter
|
47
|
+
end
|
48
|
+
|
49
|
+
module BelongsTo
|
50
|
+
extend ActiveSupport::Autoload
|
51
|
+
|
52
|
+
autoload :Association
|
53
|
+
autoload :Builder
|
54
|
+
autoload :Reflection
|
55
|
+
end
|
56
|
+
|
49
57
|
module Types
|
50
58
|
extend ActiveSupport::Autoload
|
51
59
|
|
@@ -19,4 +19,8 @@ class CassandraObject::LogSubscriberTest < CassandraObject::TestCase
|
|
19
19
|
assert_equal 1, @logger.logged(:debug).size
|
20
20
|
assert_match "SELECT * FROM Issues", @logger.logged(:debug)[0]
|
21
21
|
end
|
22
|
+
|
23
|
+
def test_initializes_runtime
|
24
|
+
Thread.new { assert_equal 0, CassandraObject::LogSubscriber.runtime }.join
|
25
|
+
end
|
22
26
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require "cassandra_object/railties/controller_runtime"
|
3
|
+
|
4
|
+
class CassandraObject::Railties::ControllerRuntimeTest < MiniTest::Unit::TestCase
|
5
|
+
class TestRuntime
|
6
|
+
def self.log_process_action(payload)
|
7
|
+
['sweet']
|
8
|
+
end
|
9
|
+
|
10
|
+
def cleanup_view_runtime
|
11
|
+
12
|
12
|
+
end
|
13
|
+
|
14
|
+
def append_info_to_payload(payload)
|
15
|
+
payload[:foo] = 42
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class CassandraRuntime < TestRuntime
|
20
|
+
include CassandraObject::Railties::ControllerRuntime
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_cleanup_view_runtime
|
24
|
+
runtime = CassandraRuntime.new
|
25
|
+
CassandraObject::LogSubscriber.runtime = 10
|
26
|
+
|
27
|
+
runtime.cleanup_view_runtime
|
28
|
+
|
29
|
+
assert_equal 0, CassandraObject::LogSubscriber.runtime
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_append_info_to_payload
|
33
|
+
runtime = CassandraRuntime.new
|
34
|
+
payload = {}
|
35
|
+
runtime.append_info_to_payload(payload)
|
36
|
+
|
37
|
+
assert_equal 42, payload[:foo]
|
38
|
+
assert payload.key?(:cassandra_object_runtime)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_log_process_action
|
42
|
+
payload = {cassandra_object_runtime: 12.3}
|
43
|
+
messages = CassandraRuntime.log_process_action(payload)
|
44
|
+
|
45
|
+
assert_equal 2, messages.size
|
46
|
+
assert_equal "CassandraObject: 12.3ms", messages.last
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotime-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.11.
|
4
|
+
version: 4.11.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Koziarski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -83,6 +83,10 @@ files:
|
|
83
83
|
- README.rdoc
|
84
84
|
- Rakefile
|
85
85
|
- gotime-cassandra_object.gemspec
|
86
|
+
- lib/cassandra_object/adapters/abstract_adapter.rb
|
87
|
+
- lib/cassandra_object/adapters/cassandra_adapter.rb
|
88
|
+
- lib/cassandra_object/adapters/dynamo_adapter.rb
|
89
|
+
- lib/cassandra_object/adapters/hstore_adapter.rb
|
86
90
|
- lib/cassandra_object/attribute_methods.rb
|
87
91
|
- lib/cassandra_object/attribute_methods/definition.rb
|
88
92
|
- lib/cassandra_object/attribute_methods/dirty.rb
|
@@ -106,6 +110,7 @@ files:
|
|
106
110
|
- lib/cassandra_object/model.rb
|
107
111
|
- lib/cassandra_object/persistence.rb
|
108
112
|
- lib/cassandra_object/railtie.rb
|
113
|
+
- lib/cassandra_object/railties/controller_runtime.rb
|
109
114
|
- lib/cassandra_object/schema.rb
|
110
115
|
- lib/cassandra_object/schema/tasks.rb
|
111
116
|
- lib/cassandra_object/scope.rb
|
@@ -153,6 +158,7 @@ files:
|
|
153
158
|
- test/unit/inspect_test.rb
|
154
159
|
- test/unit/log_subscriber_test.rb
|
155
160
|
- test/unit/persistence_test.rb
|
161
|
+
- test/unit/railties/controller_runtime_test.rb
|
156
162
|
- test/unit/schema/tasks_test.rb
|
157
163
|
- test/unit/schema_test.rb
|
158
164
|
- test/unit/scope/batches_test.rb
|