|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | #include "integration.hpp" |
| 18 | +#include "testing.hpp" |
| 19 | + |
| 20 | +using namespace datastax::internal::testing; |
18 | 21 |
|
19 | 22 | /** |
20 | 23 | * Prepared integration tests; common operations |
@@ -108,3 +111,89 @@ CASSANDRA_INTEGRATION_TEST_F(PreparedTests, PreparedIDUnchangedDuringReprepare) |
108 | 111 | EXPECT_EQ(CASS_OK, result.error_code()); |
109 | 112 | EXPECT_EQ(1u, logger_.count()); |
110 | 113 | } |
| 114 | + |
| 115 | +/** |
| 116 | + * Verify that a statement is correctly prepared from an existing simple |
| 117 | + * statement. The settings from the original statement should be inherited. |
| 118 | + * |
| 119 | + * @since 2.8 |
| 120 | + */ |
| 121 | +CASSANDRA_INTEGRATION_TEST_F(PreparedTests, PrepareFromExistingSimpleStatement) { |
| 122 | + CHECK_FAILURE; |
| 123 | + |
| 124 | + use_keyspace(keyspace_name_); |
| 125 | + |
| 126 | + session_.execute( |
| 127 | + format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", "int")); |
| 128 | + session_.execute( |
| 129 | + format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "1", "99")); |
| 130 | + |
| 131 | + DowngradingConsistencyRetryPolicy retry_policy; |
| 132 | + Statement statement(format_string(CASSANDRA_SELECT_VALUE_FORMAT, table_name_.c_str(), "?"), 1); |
| 133 | + |
| 134 | + // Set unique settings to validate later |
| 135 | + statement.set_consistency(CASS_CONSISTENCY_LOCAL_QUORUM); |
| 136 | + statement.set_serial_consistency(CASS_CONSISTENCY_SERIAL); |
| 137 | + statement.set_request_timeout(99999u); |
| 138 | + statement.set_retry_policy(retry_policy); |
| 139 | + |
| 140 | + // Prepare from the existing bound statement |
| 141 | + Statement bound_statement = session_.prepare_from_existing(statement).bind(); |
| 142 | + |
| 143 | + // Validate that the bound statement inherited the settings from the original statement |
| 144 | + EXPECT_EQ(get_consistency(bound_statement.get()), CASS_CONSISTENCY_LOCAL_QUORUM); |
| 145 | + EXPECT_EQ(get_serial_consistency(bound_statement.get()), CASS_CONSISTENCY_SERIAL); |
| 146 | + EXPECT_EQ(get_request_timeout_ms(bound_statement.get()), 99999u); |
| 147 | + EXPECT_EQ(get_retry_policy(bound_statement.get()), retry_policy.get()); |
| 148 | + |
| 149 | + bound_statement.bind<Integer>(0, Integer(1)); |
| 150 | + |
| 151 | + Result result = session_.execute(bound_statement); |
| 152 | + ASSERT_EQ(result.row_count(), 1); |
| 153 | + EXPECT_EQ(result.first_row().column_by_name<Integer>("value").value(), 99); |
| 154 | +} |
| 155 | + |
| 156 | +/** |
| 157 | + * Verify that a statement is correctly prepared from an existing bound |
| 158 | + * statement. The settings from the original bound statement should be |
| 159 | + * inherited. |
| 160 | + * |
| 161 | + * @since 2.8 |
| 162 | + */ |
| 163 | +CASSANDRA_INTEGRATION_TEST_F(PreparedTests, PrepareFromExistingBoundStatement) { |
| 164 | + CHECK_FAILURE; |
| 165 | + |
| 166 | + use_keyspace(keyspace_name_); |
| 167 | + |
| 168 | + session_.execute( |
| 169 | + format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", "int")); |
| 170 | + session_.execute( |
| 171 | + format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "1", "99")); |
| 172 | + |
| 173 | + Statement bound_statement1 = |
| 174 | + session_.prepare(format_string(CASSANDRA_SELECT_VALUE_FORMAT, table_name_.c_str(), "?")) |
| 175 | + .bind(); |
| 176 | + |
| 177 | + DowngradingConsistencyRetryPolicy retry_policy; |
| 178 | + |
| 179 | + // Set unique settings to validate later |
| 180 | + bound_statement1.set_consistency(CASS_CONSISTENCY_LOCAL_QUORUM); |
| 181 | + bound_statement1.set_serial_consistency(CASS_CONSISTENCY_SERIAL); |
| 182 | + bound_statement1.set_request_timeout(99999u); |
| 183 | + bound_statement1.set_retry_policy(retry_policy); |
| 184 | + |
| 185 | + // Prepare from the existing bound statement |
| 186 | + Statement bound_statement2 = session_.prepare_from_existing(bound_statement1).bind(); |
| 187 | + |
| 188 | + // Validate that the bound statement inherited the settings from the original statement |
| 189 | + EXPECT_EQ(get_consistency(bound_statement2.get()), CASS_CONSISTENCY_LOCAL_QUORUM); |
| 190 | + EXPECT_EQ(get_serial_consistency(bound_statement2.get()), CASS_CONSISTENCY_SERIAL); |
| 191 | + EXPECT_EQ(get_request_timeout_ms(bound_statement2.get()), 99999u); |
| 192 | + EXPECT_EQ(get_retry_policy(bound_statement2.get()), retry_policy.get()); |
| 193 | + |
| 194 | + bound_statement2.bind<Integer>(0, Integer(1)); |
| 195 | + |
| 196 | + Result result = session_.execute(bound_statement2); |
| 197 | + ASSERT_EQ(result.row_count(), 1); |
| 198 | + EXPECT_EQ(result.first_row().column_by_name<Integer>("value").value(), 99); |
| 199 | +} |
0 commit comments