Skip to content

Commit 3a571fa

Browse files
authored
Merge pull request #213 from datastax/ruby-256_tests
[RUBY-256] Integration tests and cucumber features for execution profiles
2 parents f805228 + fad98f9 commit 3a571fa

File tree

2 files changed

+104
-6
lines changed

2 files changed

+104
-6
lines changed

features/basics/execution_profiles.feature

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,49 @@ Feature: Execution profiles
66
Background:
77
Given a running cassandra cluster
88

9-
Scenario: Configure different load balancing policies with profiles.
9+
Scenario: Creating and inspecting execution profiles
10+
Given the following example:
11+
"""ruby
12+
require 'cassandra'
13+
14+
profile_1 = Cassandra::Execution::Profile.new(load_balancing_policy: Cassandra::LoadBalancing::Policies::RoundRobin.new,
15+
retry_policy: Cassandra::Retry::Policies::DowngradingConsistency.new,
16+
consistency: :all,
17+
timeout: 32
18+
)
19+
20+
cluster = Cassandra.cluster(execution_profiles: {'my_profile' => profile_1})
21+
puts "There are #{cluster.execution_profiles.size} execution profiles in the cluster:"
22+
puts ""
23+
24+
cluster.execution_profiles.each do |name, profile|
25+
puts "Name: #{name}"
26+
puts "Load_balancing_policy: #{profile.load_balancing_policy.class}"
27+
puts "Retry policy: #{profile.retry_policy.class}"
28+
puts "Consistency: #{profile.consistency}"
29+
puts "Timeout: #{profile.timeout}"
30+
puts ""
31+
end
32+
"""
33+
When it is executed
34+
Then its output should contain:
35+
"""
36+
There are 2 execution profiles in the cluster:
37+
38+
Name: __DEFAULT_EXECUTION_PROFILE__
39+
Load_balancing_policy: Cassandra::LoadBalancing::Policies::TokenAware
40+
Retry policy: Cassandra::Retry::Policies::Default
41+
Consistency: local_one
42+
Timeout: 12
43+
44+
Name: my_profile
45+
Load_balancing_policy: Cassandra::LoadBalancing::Policies::RoundRobin
46+
Retry policy: Cassandra::Retry::Policies::DowngradingConsistency
47+
Consistency: all
48+
Timeout: 32
49+
"""
50+
51+
Scenario: Configure different load balancing policies with profiles
1052
Given the following example:
1153
"""ruby
1254
require 'cassandra'
@@ -22,18 +64,15 @@ Feature: Execution profiles
2264
2365
puts "Running with default profile"
2466
25-
# By default, the driver uses a dc-aware, token-aware round-robin load balancing policy that
26-
# is notified of which nodes are available in random order. To make this test's output
27-
# deterministic, we sort the results by ip address.
67+
# By default, the driver uses a token-aware, round-robin load balancing policy.
2868
ip_list = []
2969
3.times do
3070
rs = session.execute('select rpc_address from system.local')
3171
ip_list << rs.first['rpc_address'].to_s
3272
end
3373
puts ip_list.sort.join("\n")
3474
35-
# p2 and p3 set up load-balancing policies that will match only one node, so there's no
36-
# issue of hitting nodes in random order.
75+
# p2 and p3 set up load-balancing policies that will match only one node.
3776
puts "Running with profile p1"
3877
3.times do
3978
rs = session.execute('select rpc_address from system.local', execution_profile: :p1)

integration/session_test.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ def test_cluster_session_inspect
870870
assert_match(/@paging_state=nil/, session_inspect)
871871
assert_match(/@idempotent=false/, session_inspect)
872872
assert_match(/@payload=nil/, session_inspect)
873+
ensure
874+
cluster && cluster.close
873875
end
874876

875877
# Test for cluster options retrieval
@@ -900,5 +902,62 @@ def test_can_retrieve_cluster_options
900902
assert_equal Cassandra::Retry::Policies::Default, execution_profile.retry_policy.class
901903
assert_equal :quorum, execution_profile.consistency
902904
assert_equal 12, execution_profile.timeout
905+
ensure
906+
cluster && cluster.close
907+
end
908+
909+
# Test for execution profile creation and use
910+
#
911+
# test_can_use_execution_profiles tests that execution profiles can be created and used in session execution. It first
912+
# creates two execution profiles: one with all options specified and another with no options specified. It then
913+
# creates a cluster with these two profiles and verifies their options. The 2nd execution profile should be equivalent
914+
# to the DEFAULT_EXECUTION_PROFILE as any missing options are copied over. It then executes a simple query using
915+
# the execution profiles and verifies that the execution info shows their use.
916+
#
917+
# @since 3.1.0
918+
# @jira_ticket RUBY-256
919+
# @expected_result cluster execution profiles should be retrieved and used from the cluster object
920+
#
921+
# @test_category execution_profiles
922+
#
923+
def test_can_use_execution_profiles
924+
setup_schema
925+
926+
profile_1 = Cassandra::Execution::Profile.new(load_balancing_policy: Cassandra::LoadBalancing::Policies::RoundRobin.new,
927+
retry_policy: Cassandra::Retry::Policies::DowngradingConsistency.new,
928+
consistency: :all,
929+
timeout: 32
930+
)
931+
932+
profile_2 = Cassandra::Execution::Profile.new(load_balancing_policy: nil,
933+
retry_policy: nil,
934+
consistency: nil,
935+
)
936+
937+
profiles = {profile_1: profile_1, profile_2: profile_2}
938+
cluster = Cassandra.cluster(execution_profiles: profiles)
939+
assert_equal 3, cluster.execution_profiles.size
940+
941+
execution_profile_1 = cluster.execution_profiles[:profile_1]
942+
assert_equal profile_1, execution_profile_1
943+
944+
execution_profile_2 = cluster.execution_profiles[:profile_2]
945+
assert_equal profile_2, execution_profile_2
946+
assert_equal cluster.execution_profiles['__DEFAULT_EXECUTION_PROFILE__'], execution_profile_2
947+
948+
session = cluster.connect
949+
exec_options = session.execute('select * from system.local').execution_info.options
950+
assert_equal Cassandra::LoadBalancing::Policies::TokenAware, exec_options.load_balancing_policy.class
951+
assert_equal Cassandra::Retry::Policies::Default, exec_options.retry_policy.class
952+
assert_equal :local_one, exec_options.consistency
953+
assert_equal 12, exec_options.timeout
954+
955+
exec_options = session.execute('select * from system.local', execution_profile: :profile_1).execution_info.options
956+
assert_equal Cassandra::LoadBalancing::Policies::RoundRobin, exec_options.load_balancing_policy.class
957+
assert_equal Cassandra::Retry::Policies::DowngradingConsistency, exec_options.retry_policy.class
958+
assert_equal :all, exec_options.consistency
959+
assert_equal 32, exec_options.timeout
960+
ensure
961+
cluster && cluster.close
903962
end
904963
end

0 commit comments

Comments
 (0)