@@ -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
904963end
0 commit comments