cassanity 0.3.0 → 0.4.0
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.
- data/Changelog.md +10 -0
- data/Gemfile +5 -3
- data/README.md +22 -15
- data/examples/_shared.rb +5 -1
- data/examples/batch.rb +17 -23
- data/examples/column_families.rb +12 -13
- data/examples/counters.rb +10 -18
- data/examples/keyspaces.rb +12 -17
- data/examples/select_range.rb +29 -19
- data/lib/cassanity/argument_generators/batch.rb +8 -0
- data/lib/cassanity/argument_generators/column_family_alter.rb +1 -1
- data/lib/cassanity/argument_generators/column_family_create.rb +1 -1
- data/lib/cassanity/argument_generators/column_family_delete.rb +2 -22
- data/lib/cassanity/argument_generators/column_family_drop.rb +1 -1
- data/lib/cassanity/argument_generators/column_family_insert.rb +2 -24
- data/lib/cassanity/argument_generators/column_family_select.rb +1 -1
- data/lib/cassanity/argument_generators/column_family_truncate.rb +1 -1
- data/lib/cassanity/argument_generators/column_family_update.rb +2 -24
- data/lib/cassanity/argument_generators/keyspace_create.rb +1 -1
- data/lib/cassanity/argument_generators/keyspace_drop.rb +1 -1
- data/lib/cassanity/argument_generators/keyspace_use.rb +1 -1
- data/lib/cassanity/argument_generators/where_clause.rb +1 -0
- data/lib/cassanity/argument_generators/with_clause.rb +12 -6
- data/lib/cassanity/client.rb +65 -0
- data/lib/cassanity/column_family.rb +70 -17
- data/lib/cassanity/connection.rb +8 -0
- data/lib/cassanity/decrement.rb +2 -15
- data/lib/cassanity/executors/cassandra_cql.rb +37 -11
- data/lib/cassanity/increment.rb +2 -15
- data/lib/cassanity/instrumentation/log_subscriber.rb +27 -0
- data/lib/cassanity/instrumenters/memory.rb +27 -0
- data/lib/cassanity/instrumenters/noop.rb +9 -0
- data/lib/cassanity/keyspace.rb +42 -6
- data/lib/cassanity/operator.rb +9 -0
- data/lib/cassanity/range.rb +4 -0
- data/lib/cassanity/schema.rb +21 -0
- data/lib/cassanity/version.rb +1 -1
- data/lib/cassanity.rb +16 -2
- data/spec/integration/cassanity/column_family_spec.rb +59 -78
- data/spec/integration/cassanity/connection_spec.rb +18 -34
- data/spec/integration/cassanity/keyspace_spec.rb +24 -34
- data/spec/unit/cassanity/argument_generators/batch_spec.rb +51 -3
- data/spec/unit/cassanity/argument_generators/column_family_alter_spec.rb +6 -6
- data/spec/unit/cassanity/argument_generators/column_family_create_spec.rb +6 -6
- data/spec/unit/cassanity/argument_generators/column_family_delete_spec.rb +5 -5
- data/spec/unit/cassanity/argument_generators/column_family_drop_spec.rb +2 -2
- data/spec/unit/cassanity/argument_generators/column_family_insert_spec.rb +5 -5
- data/spec/unit/cassanity/argument_generators/column_family_select_spec.rb +12 -12
- data/spec/unit/cassanity/argument_generators/column_family_truncate_spec.rb +2 -2
- data/spec/unit/cassanity/argument_generators/column_family_update_spec.rb +5 -5
- data/spec/unit/cassanity/argument_generators/keyspace_create_spec.rb +4 -4
- data/spec/unit/cassanity/argument_generators/keyspace_drop_spec.rb +1 -1
- data/spec/unit/cassanity/argument_generators/keyspace_use_spec.rb +1 -1
- data/spec/unit/cassanity/argument_generators/where_clause_spec.rb +26 -0
- data/spec/unit/cassanity/argument_generators/with_clause_spec.rb +26 -0
- data/spec/unit/cassanity/client_spec.rb +159 -0
- data/spec/unit/cassanity/column_family_spec.rb +64 -17
- data/spec/unit/cassanity/connection_spec.rb +8 -0
- data/spec/unit/cassanity/executors/cassandra_cql_spec.rb +35 -19
- data/spec/unit/cassanity/instrumentors/memory_spec.rb +26 -0
- data/spec/unit/cassanity/instrumentors/noop_spec.rb +22 -0
- data/spec/unit/cassanity/keyspace_spec.rb +25 -3
- data/spec/unit/cassanity/operator_spec.rb +10 -0
- data/spec/unit/cassanity/schema_spec.rb +6 -0
- data/spec/unit/cassanity_spec.rb +6 -0
- metadata +15 -4
@@ -18,12 +18,12 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyCreate do
|
|
18
18
|
context "when missing required argument key" do
|
19
19
|
let(:required_arguments) {
|
20
20
|
{
|
21
|
-
|
21
|
+
column_family_name: column_family_name,
|
22
22
|
schema: schema,
|
23
23
|
}
|
24
24
|
}
|
25
25
|
|
26
|
-
[:
|
26
|
+
[:column_family_name, :schema].each do |key|
|
27
27
|
it "raises error if missing :#{key} key" do
|
28
28
|
args = required_arguments.reject { |k, v| k == key }
|
29
29
|
expect { subject.call(args) }.to raise_error(KeyError)
|
@@ -36,7 +36,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyCreate do
|
|
36
36
|
cql = "CREATE COLUMNFAMILY #{column_family_name} (id text, name text, PRIMARY KEY (id))"
|
37
37
|
expected = [cql]
|
38
38
|
subject.call({
|
39
|
-
|
39
|
+
column_family_name: column_family_name,
|
40
40
|
schema: schema,
|
41
41
|
}).should eq(expected)
|
42
42
|
end
|
@@ -48,7 +48,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyCreate do
|
|
48
48
|
expected = [cql]
|
49
49
|
subject.call({
|
50
50
|
keyspace_name: :foo,
|
51
|
-
|
51
|
+
column_family_name: column_family_name,
|
52
52
|
schema: schema,
|
53
53
|
}).should eq(expected)
|
54
54
|
end
|
@@ -67,7 +67,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyCreate do
|
|
67
67
|
cql = "CREATE COLUMNFAMILY #{column_family_name} (segment text, track_id timeuuid, page text, PRIMARY KEY (segment, track_id))"
|
68
68
|
expected = [cql]
|
69
69
|
subject.call({
|
70
|
-
|
70
|
+
column_family_name: column_family_name,
|
71
71
|
schema: schema,
|
72
72
|
}).should eq(expected)
|
73
73
|
end
|
@@ -98,7 +98,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyCreate do
|
|
98
98
|
cql = "CREATE COLUMNFAMILY apps (id text, name text, PRIMARY KEY (id)) WITH comment = ?"
|
99
99
|
expected = [cql, 'Testing']
|
100
100
|
subject.call({
|
101
|
-
|
101
|
+
column_family_name: :apps,
|
102
102
|
schema: schema,
|
103
103
|
}).should eq(expected)
|
104
104
|
end
|
@@ -9,7 +9,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyDelete do
|
|
9
9
|
cql = "DELETE FROM #{column_family_name} WHERE id = ?"
|
10
10
|
expected = [cql, '1']
|
11
11
|
subject.call({
|
12
|
-
|
12
|
+
column_family_name: column_family_name,
|
13
13
|
where: {
|
14
14
|
id: '1',
|
15
15
|
}
|
@@ -22,7 +22,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyDelete do
|
|
22
22
|
expected = [cql, '1']
|
23
23
|
subject.call({
|
24
24
|
keyspace_name: :foo,
|
25
|
-
|
25
|
+
column_family_name: column_family_name,
|
26
26
|
where: {
|
27
27
|
id: '1',
|
28
28
|
}
|
@@ -35,7 +35,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyDelete do
|
|
35
35
|
cql = "DELETE foo, bar FROM #{column_family_name} WHERE id = ?"
|
36
36
|
expected = [cql, '1']
|
37
37
|
subject.call({
|
38
|
-
|
38
|
+
column_family_name: column_family_name,
|
39
39
|
columns: [:foo, :bar],
|
40
40
|
where: {
|
41
41
|
id: '1',
|
@@ -57,7 +57,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyDelete do
|
|
57
57
|
cql = "DELETE FROM #{column_family_name} WHERE id = ?"
|
58
58
|
expected = [cql, '4']
|
59
59
|
subject.call({
|
60
|
-
|
60
|
+
column_family_name: column_family_name,
|
61
61
|
where: {
|
62
62
|
id: '4',
|
63
63
|
}
|
@@ -78,7 +78,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyDelete do
|
|
78
78
|
cql = "DELETE FROM #{column_family_name} USING TTL = 500 WHERE id = ?"
|
79
79
|
expected = [cql, '4']
|
80
80
|
subject.call({
|
81
|
-
|
81
|
+
column_family_name: column_family_name,
|
82
82
|
using: {
|
83
83
|
ttl: 500,
|
84
84
|
},
|
@@ -8,7 +8,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyDrop do
|
|
8
8
|
it "returns array of arguments" do
|
9
9
|
cql = "DROP COLUMNFAMILY #{column_family_name}"
|
10
10
|
expected = [cql]
|
11
|
-
subject.call(
|
11
|
+
subject.call(column_family_name: column_family_name).should eq(expected)
|
12
12
|
end
|
13
13
|
|
14
14
|
context "with :keyspace_name" do
|
@@ -17,7 +17,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyDrop do
|
|
17
17
|
expected = [cql]
|
18
18
|
subject.call({
|
19
19
|
keyspace_name: :foo,
|
20
|
-
|
20
|
+
column_family_name: column_family_name
|
21
21
|
}).should eq(expected)
|
22
22
|
end
|
23
23
|
end
|
@@ -5,10 +5,10 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyInsert do
|
|
5
5
|
let(:column_family_name) { 'apps' }
|
6
6
|
|
7
7
|
describe "#call" do
|
8
|
-
[:
|
8
|
+
[:column_family_name, :data].each do |key|
|
9
9
|
it "raises error if missing :#{key} key" do
|
10
10
|
required_arguments = {
|
11
|
-
|
11
|
+
column_family_name: column_family_name,
|
12
12
|
data: {
|
13
13
|
id: '1',
|
14
14
|
name: 'GitHub',
|
@@ -24,7 +24,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyInsert do
|
|
24
24
|
cql = "INSERT INTO #{column_family_name} (id, name) VALUES (?, ?)"
|
25
25
|
expected = [cql, '1', 'GitHub']
|
26
26
|
subject.call({
|
27
|
-
|
27
|
+
column_family_name: column_family_name,
|
28
28
|
data: {
|
29
29
|
id: '1',
|
30
30
|
name: 'GitHub',
|
@@ -38,7 +38,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyInsert do
|
|
38
38
|
expected = [cql, '1', 'GitHub']
|
39
39
|
subject.call({
|
40
40
|
keyspace_name: :foo,
|
41
|
-
|
41
|
+
column_family_name: column_family_name,
|
42
42
|
data: {
|
43
43
|
id: '1',
|
44
44
|
name: 'GitHub',
|
@@ -53,7 +53,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyInsert do
|
|
53
53
|
cql = "INSERT INTO #{column_family_name} (id, name) VALUES (?, ?) USING TTL 86400 AND TIMESTAMP #{millis} AND CONSISTENCY quorum"
|
54
54
|
expected = [cql, '1', 'GitHub']
|
55
55
|
subject.call({
|
56
|
-
|
56
|
+
column_family_name: column_family_name,
|
57
57
|
data: {
|
58
58
|
id: '1',
|
59
59
|
name: 'GitHub',
|
@@ -8,7 +8,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
8
8
|
it "returns array of arguments" do
|
9
9
|
cql = "SELECT * FROM #{column_family_name}"
|
10
10
|
expected = [cql]
|
11
|
-
subject.call(
|
11
|
+
subject.call(column_family_name: column_family_name).should eq(expected)
|
12
12
|
end
|
13
13
|
|
14
14
|
context "with :keyspace_name" do
|
@@ -17,7 +17,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
17
17
|
expected = [cql]
|
18
18
|
subject.call({
|
19
19
|
keyspace_name: :foo,
|
20
|
-
|
20
|
+
column_family_name: column_family_name
|
21
21
|
}).should eq(expected)
|
22
22
|
end
|
23
23
|
end
|
@@ -27,7 +27,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
27
27
|
cql = "SELECT name FROM #{column_family_name}"
|
28
28
|
expected = [cql]
|
29
29
|
subject.call({
|
30
|
-
|
30
|
+
column_family_name: column_family_name,
|
31
31
|
select: :name,
|
32
32
|
}).should eq(expected)
|
33
33
|
end
|
@@ -38,7 +38,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
38
38
|
cql = "SELECT id, name, created_at FROM #{column_family_name}"
|
39
39
|
expected = [cql]
|
40
40
|
subject.call({
|
41
|
-
|
41
|
+
column_family_name: column_family_name,
|
42
42
|
select: [:id, :name, :created_at],
|
43
43
|
}).should eq(expected)
|
44
44
|
end
|
@@ -49,7 +49,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
49
49
|
cql = "SELECT COUNT(*) FROM #{column_family_name}"
|
50
50
|
expected = [cql]
|
51
51
|
subject.call({
|
52
|
-
|
52
|
+
column_family_name: column_family_name,
|
53
53
|
select: 'COUNT(*)',
|
54
54
|
}).should eq(expected)
|
55
55
|
end
|
@@ -60,7 +60,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
60
60
|
cql = "SELECT COUNT(1) FROM #{column_family_name}"
|
61
61
|
expected = [cql]
|
62
62
|
subject.call({
|
63
|
-
|
63
|
+
column_family_name: column_family_name,
|
64
64
|
select: 'COUNT(1)',
|
65
65
|
}).should eq(expected)
|
66
66
|
end
|
@@ -71,7 +71,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
71
71
|
cql = "SELECT WRITETIME(name) FROM #{column_family_name}"
|
72
72
|
expected = [cql]
|
73
73
|
subject.call({
|
74
|
-
|
74
|
+
column_family_name: column_family_name,
|
75
75
|
select: 'WRITETIME(name)',
|
76
76
|
}).should eq(expected)
|
77
77
|
end
|
@@ -82,7 +82,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
82
82
|
cql = "SELECT TTL(name) FROM #{column_family_name}"
|
83
83
|
expected = [cql]
|
84
84
|
subject.call({
|
85
|
-
|
85
|
+
column_family_name: column_family_name,
|
86
86
|
select: 'TTL(name)',
|
87
87
|
}).should eq(expected)
|
88
88
|
end
|
@@ -100,7 +100,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
100
100
|
cql = "SELECT * FROM #{column_family_name} USING CONSISTENCY BATMAN"
|
101
101
|
expected = [cql]
|
102
102
|
subject.call({
|
103
|
-
|
103
|
+
column_family_name: column_family_name,
|
104
104
|
using: using,
|
105
105
|
}).should eq(expected)
|
106
106
|
end
|
@@ -118,7 +118,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
118
118
|
cql = "SELECT * FROM #{column_family_name} WHERE foo = ?"
|
119
119
|
expected = [cql, 'bar']
|
120
120
|
subject.call({
|
121
|
-
|
121
|
+
column_family_name: column_family_name,
|
122
122
|
where: where,
|
123
123
|
}).should eq(expected)
|
124
124
|
end
|
@@ -135,7 +135,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
135
135
|
cql = "SELECT * FROM #{column_family_name} ORDER BY name"
|
136
136
|
expected = [cql]
|
137
137
|
subject.call({
|
138
|
-
|
138
|
+
column_family_name: column_family_name,
|
139
139
|
order: :name,
|
140
140
|
}).should eq(expected)
|
141
141
|
end
|
@@ -152,7 +152,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilySelect do
|
|
152
152
|
cql = "SELECT * FROM #{column_family_name} LIMIT 50"
|
153
153
|
expected = [cql]
|
154
154
|
subject.call({
|
155
|
-
|
155
|
+
column_family_name: column_family_name,
|
156
156
|
limit: 50,
|
157
157
|
}).should eq(expected)
|
158
158
|
end
|
@@ -8,7 +8,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyTruncate do
|
|
8
8
|
it "returns array of arguments" do
|
9
9
|
cql = "TRUNCATE #{column_family_name}"
|
10
10
|
expected = [cql]
|
11
|
-
subject.call(
|
11
|
+
subject.call(column_family_name: column_family_name).should eq(expected)
|
12
12
|
end
|
13
13
|
|
14
14
|
context "with :keyspace_name" do
|
@@ -17,7 +17,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyTruncate do
|
|
17
17
|
expected = [cql]
|
18
18
|
subject.call({
|
19
19
|
keyspace_name: :foo,
|
20
|
-
|
20
|
+
column_family_name: column_family_name
|
21
21
|
}).should eq(expected)
|
22
22
|
end
|
23
23
|
end
|
@@ -9,7 +9,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyUpdate do
|
|
9
9
|
cql = "UPDATE #{column_family_name} SET name = ? WHERE id = ?"
|
10
10
|
expected = [cql, 'New Name', '1']
|
11
11
|
subject.call({
|
12
|
-
|
12
|
+
column_family_name: column_family_name,
|
13
13
|
set: {
|
14
14
|
name: 'New Name',
|
15
15
|
},
|
@@ -25,7 +25,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyUpdate do
|
|
25
25
|
expected = [cql, 'New Name', '1']
|
26
26
|
subject.call({
|
27
27
|
keyspace_name: :foo,
|
28
|
-
|
28
|
+
column_family_name: column_family_name,
|
29
29
|
set: {
|
30
30
|
name: 'New Name',
|
31
31
|
},
|
@@ -49,7 +49,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyUpdate do
|
|
49
49
|
cql = "UPDATE #{column_family_name} SET name = ? WHERE id = ?"
|
50
50
|
expected = [cql, 'New Name', '4']
|
51
51
|
subject.call({
|
52
|
-
|
52
|
+
column_family_name: column_family_name,
|
53
53
|
set: {
|
54
54
|
name: 'New Name',
|
55
55
|
},
|
@@ -73,7 +73,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyUpdate do
|
|
73
73
|
cql = "UPDATE #{column_family_name} SET name = ? WHERE id = ?"
|
74
74
|
expected = [cql, 'New Name', '4']
|
75
75
|
subject.call({
|
76
|
-
|
76
|
+
column_family_name: column_family_name,
|
77
77
|
set: {
|
78
78
|
name: 'New Name',
|
79
79
|
},
|
@@ -90,7 +90,7 @@ describe Cassanity::ArgumentGenerators::ColumnFamilyUpdate do
|
|
90
90
|
cql = "UPDATE #{column_family_name} USING TTL 86400 AND TIMESTAMP #{millis} AND CONSISTENCY quorum SET name = ? WHERE id = ?"
|
91
91
|
expected = [cql, 'New Name', '1']
|
92
92
|
subject.call({
|
93
|
-
|
93
|
+
column_family_name: column_family_name,
|
94
94
|
using: {
|
95
95
|
ttl: 86400,
|
96
96
|
timestamp: millis,
|
@@ -9,7 +9,7 @@ describe Cassanity::ArgumentGenerators::KeyspaceCreate do
|
|
9
9
|
it "returns array of arguments" do
|
10
10
|
cql = "CREATE KEYSPACE #{keyspace_name} WITH strategy_class = ? AND strategy_options:replication_factor = ?"
|
11
11
|
expected = [cql, 'SimpleStrategy', 1]
|
12
|
-
subject.call(
|
12
|
+
subject.call(keyspace_name: keyspace_name).should eq(expected)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -18,7 +18,7 @@ describe Cassanity::ArgumentGenerators::KeyspaceCreate do
|
|
18
18
|
cql = "CREATE KEYSPACE #{keyspace_name} WITH strategy_class = ? AND strategy_options:replication_factor = ?"
|
19
19
|
expected = [cql, 'FooStrategy', 1]
|
20
20
|
subject.call({
|
21
|
-
|
21
|
+
keyspace_name: keyspace_name,
|
22
22
|
strategy_class: 'FooStrategy',
|
23
23
|
}).should eq(expected)
|
24
24
|
end
|
@@ -29,7 +29,7 @@ describe Cassanity::ArgumentGenerators::KeyspaceCreate do
|
|
29
29
|
cql = "CREATE KEYSPACE #{keyspace_name} WITH strategy_class = ? AND strategy_options:replication_factor = ?"
|
30
30
|
expected = [cql, 'SimpleStrategy', 3]
|
31
31
|
subject.call({
|
32
|
-
|
32
|
+
keyspace_name: keyspace_name,
|
33
33
|
strategy_options: {
|
34
34
|
replication_factor: 3,
|
35
35
|
}
|
@@ -42,7 +42,7 @@ describe Cassanity::ArgumentGenerators::KeyspaceCreate do
|
|
42
42
|
cql = "CREATE KEYSPACE #{keyspace_name} WITH strategy_class = ? AND strategy_options:replication_factor = ? AND strategy_options:batman = ?"
|
43
43
|
expected = [cql, 'SimpleStrategy', 1, 'robin']
|
44
44
|
subject.call({
|
45
|
-
|
45
|
+
keyspace_name: keyspace_name,
|
46
46
|
strategy_options: {
|
47
47
|
batman: 'robin',
|
48
48
|
}
|
@@ -8,7 +8,7 @@ describe Cassanity::ArgumentGenerators::KeyspaceDrop do
|
|
8
8
|
it "returns array of arguments" do
|
9
9
|
cql = "DROP KEYSPACE #{keyspace_name}"
|
10
10
|
expected = [cql]
|
11
|
-
subject.call(
|
11
|
+
subject.call(keyspace_name: keyspace_name).should eq(expected)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -8,7 +8,7 @@ describe Cassanity::ArgumentGenerators::KeyspaceUse do
|
|
8
8
|
it "returns array of arguments" do
|
9
9
|
cql = "USE #{keyspace_name}"
|
10
10
|
expected = [cql]
|
11
|
-
subject.call(
|
11
|
+
subject.call(keyspace_name: keyspace_name).should eq(expected)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -80,6 +80,32 @@ describe Cassanity::ArgumentGenerators::WhereClause do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
context "with inclusive cassanity range value for a where" do
|
84
|
+
it "returns range comparison including end of range" do
|
85
|
+
subject.call({
|
86
|
+
where: {
|
87
|
+
timestamp: Cassanity::Range.new(1, 3)
|
88
|
+
},
|
89
|
+
}).should eq([
|
90
|
+
" WHERE timestamp >= ? AND timestamp <= ?",
|
91
|
+
1, 3
|
92
|
+
])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "with exclusive cassanity range value for a where" do
|
97
|
+
it "returns range comparison including end of range" do
|
98
|
+
subject.call({
|
99
|
+
where: {
|
100
|
+
timestamp: Cassanity::Range.new(1, 3, true)
|
101
|
+
},
|
102
|
+
}).should eq([
|
103
|
+
" WHERE timestamp >= ? AND timestamp < ?",
|
104
|
+
1, 3
|
105
|
+
])
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
83
109
|
context "with a cassanity operator value" do
|
84
110
|
it "returns correct cql" do
|
85
111
|
subject.call({
|
@@ -31,6 +31,32 @@ describe Cassanity::ArgumentGenerators::WithClause do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
context "with :compact_storage option" do
|
35
|
+
context "set to true" do
|
36
|
+
it "returns array of arguments converting compact storage" do
|
37
|
+
subject.call({
|
38
|
+
with: {
|
39
|
+
compact_storage: true,
|
40
|
+
}
|
41
|
+
}).should eq([
|
42
|
+
" WITH COMPACT STORAGE",
|
43
|
+
])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "set to false" do
|
48
|
+
it "returns array of arguments not including compact storage" do
|
49
|
+
subject.call({
|
50
|
+
with: {
|
51
|
+
compact_storage: false,
|
52
|
+
}
|
53
|
+
}).should eq([
|
54
|
+
" WITH ",
|
55
|
+
])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
34
60
|
context "when using :with option that has sub options" do
|
35
61
|
it "returns array of arguments" do
|
36
62
|
subject.call({
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'cassanity/client'
|
3
|
+
|
4
|
+
describe Cassanity::Client do
|
5
|
+
describe "#initialize" do
|
6
|
+
it "passes arguments to cassandra cql database instance" do
|
7
|
+
CassandraCQL::Database.should_receive(:new).
|
8
|
+
with(
|
9
|
+
'localhost:1234',
|
10
|
+
hash_including(some: 'option'),
|
11
|
+
instance_of(Hash)
|
12
|
+
)
|
13
|
+
|
14
|
+
described_class.new('localhost:1234', some: 'option')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "defaults servers if not present" do
|
18
|
+
CassandraCQL::Database.should_receive(:new).
|
19
|
+
with(
|
20
|
+
'127.0.0.1:9160',
|
21
|
+
instance_of(Hash),
|
22
|
+
instance_of(Hash)
|
23
|
+
)
|
24
|
+
|
25
|
+
described_class.new
|
26
|
+
end
|
27
|
+
|
28
|
+
it "defaults servers if nil" do
|
29
|
+
CassandraCQL::Database.should_receive(:new).
|
30
|
+
with(
|
31
|
+
'127.0.0.1:9160',
|
32
|
+
instance_of(Hash),
|
33
|
+
instance_of(Hash)
|
34
|
+
)
|
35
|
+
|
36
|
+
described_class.new(nil)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "defaults cql version in options to 3" do
|
40
|
+
CassandraCQL::Database.should_receive(:new).
|
41
|
+
with(
|
42
|
+
anything,
|
43
|
+
hash_including(cql_version: '3.0.0'),
|
44
|
+
instance_of(Hash)
|
45
|
+
)
|
46
|
+
|
47
|
+
described_class.new
|
48
|
+
end
|
49
|
+
|
50
|
+
it "does not override cql version option if other options are provided" do
|
51
|
+
CassandraCQL::Database.should_receive(:new).
|
52
|
+
with(
|
53
|
+
anything,
|
54
|
+
hash_including(cql_version: '3.0.0', some: 'thing'),
|
55
|
+
instance_of(Hash)
|
56
|
+
)
|
57
|
+
|
58
|
+
described_class.new('localhost:1234', some: 'thing')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "allows passing instrumenter to executor, but does not pass it to driver instance" do
|
62
|
+
instrumenter = double('Instrumenter')
|
63
|
+
driver = double('Driver')
|
64
|
+
executor = double('Executor')
|
65
|
+
|
66
|
+
CassandraCQL::Database.should_receive(:new).
|
67
|
+
with(
|
68
|
+
anything,
|
69
|
+
hash_not_including(instrumenter: instrumenter),
|
70
|
+
instance_of(Hash)
|
71
|
+
).
|
72
|
+
and_return(driver)
|
73
|
+
|
74
|
+
Cassanity::Executors::CassandraCql.should_receive(:new).
|
75
|
+
with(client: driver, instrumenter: instrumenter).
|
76
|
+
and_return(executor)
|
77
|
+
|
78
|
+
described_class.new('localhost:1234', instrumenter: instrumenter)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "sets cassandra cql database instance as driver" do
|
82
|
+
client = described_class.new
|
83
|
+
client.driver.should be_instance_of(CassandraCQL::Database)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "builds driver, executor and connection" do
|
87
|
+
driver = double('Driver')
|
88
|
+
executor = double('Executor')
|
89
|
+
connection = double('Connection')
|
90
|
+
|
91
|
+
CassandraCQL::Database.should_receive(:new).and_return(driver)
|
92
|
+
|
93
|
+
Cassanity::Executors::CassandraCql.should_receive(:new).
|
94
|
+
with(hash_including(client: driver)).
|
95
|
+
and_return(executor)
|
96
|
+
|
97
|
+
Cassanity::Connection.should_receive(:new).
|
98
|
+
with(executor: executor).
|
99
|
+
and_return(connection)
|
100
|
+
|
101
|
+
client = described_class.new
|
102
|
+
|
103
|
+
client.driver.should be(driver)
|
104
|
+
client.executor.should be(executor)
|
105
|
+
client.connection.should be(connection)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#keyspaces" do
|
110
|
+
it "delegates to connection" do
|
111
|
+
keyspace = double('Keyspace')
|
112
|
+
keyspaces = [keyspace]
|
113
|
+
client = described_class.new
|
114
|
+
client.connection.stub(:keyspaces => keyspaces)
|
115
|
+
client.keyspaces.should be(keyspaces)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#keyspace" do
|
120
|
+
it "delegates to connection" do
|
121
|
+
keyspace = double('Keyspace')
|
122
|
+
client = described_class.new
|
123
|
+
client.connection.stub(:keyspace => keyspace)
|
124
|
+
client.keyspace(:foo).should be(keyspace)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#[]" do
|
129
|
+
it "delegates to connection" do
|
130
|
+
keyspace = double('Keyspace')
|
131
|
+
client = described_class.new
|
132
|
+
client.connection.stub(:[] => keyspace)
|
133
|
+
client[:foo].should be(keyspace)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "#batch" do
|
138
|
+
it "delegates to connection" do
|
139
|
+
modifications = [[:insert, :stuff]]
|
140
|
+
|
141
|
+
client = described_class.new
|
142
|
+
client.connection.should_receive(:batch).
|
143
|
+
with(modifications).
|
144
|
+
and_return(:booyeah)
|
145
|
+
|
146
|
+
client.batch(modifications)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#inspect" do
|
151
|
+
it "return representation" do
|
152
|
+
result = subject.inspect
|
153
|
+
result.should match(/#{described_class}/)
|
154
|
+
result.should match(/driver=/)
|
155
|
+
result.should match(/executor=/)
|
156
|
+
result.should match(/connection=/)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|