tests/secondary_index_test: Don't catch polymorphic exceptions by value

Don't slice exception by catching them by value. Instead of catching
by reference, use assert_that_failed().

Signed-off-by: Duarte Nunes <duarte@scylladb.com>
Message-Id: <20180506153745.4512-1-duarte@scylladb.com>
This commit is contained in:
Duarte Nunes
2018-05-06 17:37:45 +02:00
committed by Avi Kivity
parent ab5a45b00c
commit eabe471ce8

View File

@@ -80,21 +80,15 @@ SEASTAR_TEST_CASE(test_secondary_index_clustering_key_query) {
SEASTAR_TEST_CASE(test_secondary_index_single_column_partition_key) {
return do_with_cql_env_thread([] (cql_test_env& e) {
e.execute_cql("create table cf (p int primary key, a int)").get();
try {
e.execute_cql("create index on cf (p)").get();
// Expecting exception: "exceptions::invalid_request_exception:
// Cannot create secondary index on partition key column p"
BOOST_FAIL("Exception expected");
} catch (exceptions::invalid_request_exception) { }
// Expecting exception: "exceptions::invalid_request_exception:
// Cannot create secondary index on partition key column p"
assert_that_failed(e.execute_cql("create index on cf (p)"));
// The same happens if we also have a clustering key, but still just
// one partition key column and we want to index it
e.execute_cql("create table cf2 (p int, c1 int, c2 int, a int, primary key (p, c1, c2))").get();
try {
e.execute_cql("create index on cf2 (p)").get();
// Expecting exception: "exceptions::invalid_request_exception:
// Cannot create secondary index on partition key column p"
BOOST_FAIL("Exception expected");
} catch (exceptions::invalid_request_exception) { }
// Expecting exception: "exceptions::invalid_request_exception:
// Cannot create secondary index on partition key column p"
assert_that_failed(e.execute_cql("create index on cf2 (p)"));
});
}
@@ -186,20 +180,14 @@ SEASTAR_TEST_CASE(test_secondary_index_if_exists) {
// Confirm that creating the same index again with "if not exists" is
// fine, but without "if not exists", it's an error.
e.execute_cql("create index if not exists on cf (a)").get();
try {
e.execute_cql("create index on cf (a)").get();
BOOST_FAIL("Exception expected");
} catch (exceptions::invalid_request_exception) { }
assert_that_failed(e.execute_cql("create index on cf (a)"));
// Confirm that after dropping the index, dropping it again with
// "if exists" is fine, but an error without it.
e.execute_cql("drop index cf_a_idx").get();
e.execute_cql("drop index if exists cf_a_idx").get();
try {
e.execute_cql("drop index cf_a_idx").get();
// Expect exceptions::invalid_request_exception: Index 'cf_a_idx'
// could not be found in any of the tables of keyspace 'ks'
BOOST_FAIL("Exception expected");
} catch (exceptions::invalid_request_exception) { }
// Expect exceptions::invalid_request_exception: Index 'cf_a_idx'
// could not be found in any of the tables of keyspace 'ks'
assert_that_failed(seastar::futurize_apply([&e] { return e.execute_cql("drop index cf_a_idx"); }));
});
}