|
| 1 | +/* |
| 2 | + Copyright (c) DataStax, Inc. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +#include "integration.hpp" |
| 18 | + |
| 19 | +#include <locale> |
| 20 | + |
| 21 | +/** |
| 22 | + * "USE <keyspace>" case-sensitive tests |
| 23 | + */ |
| 24 | +class UseKeyspaceCaseSensitiveTests : public Integration { |
| 25 | +public: |
| 26 | + UseKeyspaceCaseSensitiveTests() {} |
| 27 | + |
| 28 | + // Make a case-sensitive keyspace capitalizing the first char and wrapping in double quotes |
| 29 | + virtual std::string default_keyspace() { |
| 30 | + std::string temp(Integration::default_keyspace()); |
| 31 | + temp[0] = std::toupper(temp[0]); |
| 32 | + return "\"" + temp + "\""; |
| 33 | + } |
| 34 | + |
| 35 | + virtual void SetUp() { |
| 36 | + Integration::SetUp(); |
| 37 | + session_.execute( |
| 38 | + format_string(CASSANDRA_KEY_VALUE_TABLE_FORMAT, table_name_.c_str(), "int", "int")); |
| 39 | + session_.execute( |
| 40 | + format_string(CASSANDRA_KEY_VALUE_INSERT_FORMAT, table_name_.c_str(), "1", "2")); |
| 41 | + } |
| 42 | +}; |
| 43 | + |
| 44 | +/** |
| 45 | + * Verify that case-sensitive keyspaces work when connecting a session with a keyspace. |
| 46 | + */ |
| 47 | +CASSANDRA_INTEGRATION_TEST_F(UseKeyspaceCaseSensitiveTests, ConnectWithKeyspace) { |
| 48 | + CHECK_FAILURE; |
| 49 | + Session session = default_cluster().connect(keyspace_name_); |
| 50 | + |
| 51 | + Result result = |
| 52 | + session.execute(format_string(CASSANDRA_SELECT_VALUE_FORMAT, table_name_.c_str(), "1")); |
| 53 | + |
| 54 | + Row row = result.first_row(); |
| 55 | + EXPECT_EQ(row.column_by_name<Integer>("value"), Integer(2)); |
| 56 | +} |
| 57 | + |
| 58 | +/** |
| 59 | + * Verify that case-sensitive keyspaces work with "USE <keyspace>". |
| 60 | + */ |
| 61 | +CASSANDRA_INTEGRATION_TEST_F(UseKeyspaceCaseSensitiveTests, UseKeyspace) { |
| 62 | + CHECK_FAILURE; |
| 63 | + Session session = default_cluster().connect(); |
| 64 | + |
| 65 | + { // Expect failure there's no keyspace set |
| 66 | + Result result = |
| 67 | + session.execute(format_string(CASSANDRA_SELECT_VALUE_FORMAT, table_name_.c_str(), "1"), |
| 68 | + CASS_CONSISTENCY_ONE, false, false); |
| 69 | + |
| 70 | + EXPECT_EQ(result.error_code(), CASS_ERROR_SERVER_INVALID_QUERY); |
| 71 | + } |
| 72 | + |
| 73 | + session.execute("USE " + keyspace_name_); |
| 74 | + |
| 75 | + { // Success |
| 76 | + Result result = |
| 77 | + session.execute(format_string(CASSANDRA_SELECT_VALUE_FORMAT, table_name_.c_str(), "1")); |
| 78 | + |
| 79 | + Row row = result.first_row(); |
| 80 | + EXPECT_EQ(row.column_by_name<Integer>("value"), Integer(2)); |
| 81 | + } |
| 82 | +} |
0 commit comments