From eabe471ce896ac80e87cb176241c4e927aa03961 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Sun, 6 May 2018 17:37:45 +0200 Subject: [PATCH] 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 Message-Id: <20180506153745.4512-1-duarte@scylladb.com> --- tests/secondary_index_test.cc | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/tests/secondary_index_test.cc b/tests/secondary_index_test.cc index 54d8190273..c061678c07 100644 --- a/tests/secondary_index_test.cc +++ b/tests/secondary_index_test.cc @@ -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"); })); }); }