Skip to content

Commit c09eeba

Browse files
authored
Merge pull request #178 from datastax/ruby-233_tests
[RUBY-233] Integration tests for idempotent statement timeouts
2 parents b7b6ecb + 491a284 commit c09eeba

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cassandra:
77
- 2.1
88
- 2.2
99
- 3.0
10-
- 3.4
10+
- 3.7
1111
os:
1212
- ubuntu/trusty64
1313
build:

integration/idempotency_test.rb

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
class IdempotencyTest < IntegrationTestCase
2222
def self.before_suite
23-
@@ccm_cluster = CCM.setup_cluster(1, 2)
23+
@@ccm_cluster = CCM.setup_cluster(2, 1)
2424
end
2525

2626
def setup
2727
@@ccm_cluster.setup_schema(<<-CQL)
28-
CREATE KEYSPACE simplex WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2};
28+
CREATE KEYSPACE simplex WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': '1', 'dc2': '1'};
2929
USE simplex;
3030
CREATE TABLE test (k int, v int, PRIMARY KEY (k, v));
3131
INSERT INTO test (k, v) VALUES (0, 0)
@@ -37,28 +37,73 @@ def setup
3737
# test_statement_idempotency_on_timeout tests that idempotent statements are retried automatically on the next host.
3838
# It first blocks the first host such that it is unreachable. It then attempts a simple SELECT query and verifies that
3939
# a Cassandra::Errors::TimeoutError is raised, and the next host is not tried. It finally executes the same query
40-
# once more with idempotent: true and verifies that the statement executes successfully.
40+
# once more with idempotent: true and verifies that the statement executes successfully on another host.
4141
#
4242
# @expected_errors [Cassandra::Errors::TimeoutError] When a host is unavailable on a non-idempotent query
4343
#
4444
# @since 3.0.0
4545
# @jira_ticket RUBY-146
4646
# @expected_result Idempotent queries should be retried on the next host automatically
4747
#
48-
# @test_assumptions A 2-node Cassandra cluster with RF=2.
48+
# @test_assumptions A 2-dc Cassandra cluster 1 node in each dc.
4949
# @test_category queries:timeout
5050
#
5151
def test_statement_idempotency_on_timeout
52-
cluster = Cassandra.cluster
53-
session = cluster.connect("simplex")
52+
datacenter = 'dc1'
53+
max_remote_hosts_to_use = 1
54+
policy = Cassandra::LoadBalancing::Policies::DCAwareRoundRobin.new(datacenter, max_remote_hosts_to_use)
55+
cluster = Cassandra.cluster(load_balancing_policy: policy)
56+
session = cluster.connect('simplex')
5457

55-
@@ccm_cluster.block_node("node1")
58+
@@ccm_cluster.block_node('node1')
5659

5760
assert_raises(Cassandra::Errors::TimeoutError) do
58-
session.execute("SELECT * FROM test", consistency: :one)
61+
session.execute('SELECT * FROM test', consistency: :one)
5962
end
6063

61-
session.execute("SELECT * FROM test", consistency: :one, idempotent: true)
64+
info = session.execute('SELECT * FROM test', consistency: :one, idempotent: true).execution_info
65+
assert_equal 2, info.hosts.size
66+
assert_equal '127.0.0.1', info.hosts[0].ip.to_s
67+
assert_equal '127.0.0.2', info.hosts[1].ip.to_s
68+
ensure
69+
@@ccm_cluster.unblock_nodes
70+
cluster && cluster.close
71+
end
72+
73+
# Test for retrying idempotent statements on timeout
74+
#
75+
# test_statement_idempotency_on_timeout tests that idempotent statements are retried automatically on the next host,
76+
# when the keyspace is not predefined. It first blocks the first host such that it is unreachable. It then attempts a
77+
# simple SELECT query and verifies that a Cassandra::Errors::TimeoutError is raised, and the next host is not tried.
78+
# It finally executes the same query once more with idempotent: true and verifies that the statement executes
79+
# successfully on another host.
80+
#
81+
# @expected_errors [Cassandra::Errors::TimeoutError] When a host is unavailable on a non-idempotent query
82+
#
83+
# @since 3.0.1
84+
# @jira_ticket RUBY-233
85+
# @expected_result Idempotent queries should be retried on the next host automatically
86+
#
87+
# @test_assumptions A 2-dc Cassandra cluster 1 node in each dc.
88+
# @test_category queries:timeout
89+
#
90+
def test_statement_idempotency_on_timeout_no_keyspace_predefined
91+
datacenter = 'dc1'
92+
max_remote_hosts_to_use = 1
93+
policy = Cassandra::LoadBalancing::Policies::DCAwareRoundRobin.new(datacenter, max_remote_hosts_to_use)
94+
cluster = Cassandra.cluster(load_balancing_policy: policy)
95+
session = cluster.connect
96+
97+
@@ccm_cluster.block_node('node1')
98+
99+
assert_raises(Cassandra::Errors::TimeoutError) do
100+
session.execute('SELECT * FROM simplex.test', consistency: :one)
101+
end
102+
103+
info = session.execute('SELECT * FROM simplex.test', consistency: :one, idempotent: true).execution_info
104+
assert_equal 2, info.hosts.size
105+
assert_equal '127.0.0.1', info.hosts[0].ip.to_s
106+
assert_equal '127.0.0.2', info.hosts[1].ip.to_s
62107
ensure
63108
@@ccm_cluster.unblock_nodes
64109
cluster && cluster.close

integration/integration_test_case.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class IntegrationTestCase < MiniTest::Unit::TestCase
2929
@@ccm_cluster = nil
3030

3131
def self.before_suite
32-
@@ccm_cluster = CCM.setup_cluster(1, 1)
32+
@@ccm_cluster = CCM.setup_cluster(1, 1) unless self == IntegrationTestCase
3333
end
3434

3535
def self.after_suite

0 commit comments

Comments
 (0)