Skip to content

Commit 9d700f3

Browse files
akeles85OzanCansel
andauthored
Shutdown fix for test cases (#1177)
* client shutdown for test cases * clang format * test fixes * near cache fixes * review fixes --------- Co-authored-by: Ozan Cansel <[email protected]>
1 parent ddd2461 commit 9d700f3

File tree

9 files changed

+268
-39
lines changed

9 files changed

+268
-39
lines changed

hazelcast/test/src/HazelcastTests1.cpp

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ TEST_F(ClientStatisticsTest, testClientStatisticsDisabledByDefault)
285285
ASSERT_TRUE(statsFromServer.success);
286286
ASSERT_TRUE(statsFromServer.message.empty())
287287
<< "Statistics should be disabled by default.";
288+
289+
client.shutdown().get();
288290
}
289291

290292
TEST_F(ClientStatisticsTest, testNoUpdateWhenDisabled)
@@ -296,6 +298,8 @@ TEST_F(ClientStatisticsTest, testNoUpdateWhenDisabled)
296298
auto client = hazelcast::new_client(std::move(clientConfig)).get();
297299

298300
ASSERT_TRUE_ALL_THE_TIME(get_stats().empty(), 2);
301+
302+
client.shutdown().get();
299303
}
300304

301305
TEST_F(ClientStatisticsTest, testClientStatisticsDisabledWithWrongValue)
@@ -314,6 +318,8 @@ TEST_F(ClientStatisticsTest, testClientStatisticsDisabledWithWrongValue)
314318
ASSERT_TRUE(statsFromServer.success);
315319
ASSERT_TRUE(statsFromServer.message.empty())
316320
<< "Statistics should not be enabled with wrong value.";
321+
322+
client.shutdown().get();
317323
}
318324

319325
TEST_F(ClientStatisticsTest, testClientStatisticsContent)
@@ -405,6 +411,8 @@ TEST_F(ClientStatisticsTest, testClientStatisticsContent)
405411
ASSERT_NE(std::string::npos,
406412
statsFromServer.result.find(std::string("nc.") + test_name + "." +
407413
"creationTime"));
414+
415+
client.shutdown().get();
408416
}
409417

410418
TEST_F(ClientStatisticsTest, testStatisticsCollectionNonDefaultPeriod)
@@ -500,6 +508,8 @@ TEST_F(ClientStatisticsTest, testStatisticsCollectionNonDefaultPeriod)
500508
<< mapHitsKey << " stat should exist (" << to_string(statsMap) << ")";
501509
ASSERT_EQ("1", statsMap[mapHitsKey])
502510
<< "Expected 1 map hits (" << to_string(statsMap) << ")";
511+
512+
client->shutdown().get();
503513
}
504514

505515
TEST_F(ClientStatisticsTest, testStatisticsPeriod)
@@ -520,6 +530,8 @@ TEST_F(ClientStatisticsTest, testStatisticsPeriod)
520530

521531
ASSERT_NE(initialStats, get_stats())
522532
<< "initial statistics should not be the same as current stats";
533+
534+
client->shutdown().get();
523535
}
524536
} // namespace test
525537
} // namespace client
@@ -607,8 +619,16 @@ class RingbufferTest : public ClientTest
607619

608620
static void TearDownTestCase()
609621
{
610-
delete client;
611-
delete client2;
622+
if (client) {
623+
client->shutdown().get();
624+
delete client;
625+
}
626+
627+
if (client2) {
628+
client2->shutdown().get();
629+
delete client2;
630+
}
631+
612632
delete instance;
613633

614634
client = nullptr;
@@ -887,6 +907,7 @@ class ssl_test_base : public ClientTest
887907
auto client = new_client(std::move(config)).get();
888908
auto map = client.get_map("test").get();
889909
ASSERT_NO_THROW(map->put(5, std::vector<byte>(1024)).get());
910+
client.shutdown().get();
890911
}
891912

892913
void test_ssl_disabled()
@@ -1429,6 +1450,8 @@ TEST_P(ClusterTest, testAllClientStates)
14291450
ASSERT_OPEN_EVENTUALLY(disconnectedLatch);
14301451
ASSERT_OPEN_EVENTUALLY(shuttingDownLatch);
14311452
ASSERT_OPEN_EVENTUALLY(shutdownLatch);
1453+
1454+
client.shutdown().get();
14321455
}
14331456

14341457
TEST_P(ClusterTest, testConnectionAttemptPeriod)
@@ -1519,6 +1542,8 @@ TEST_F(HeartbeatTest, testPing)
15191542

15201543
// perform a map put
15211544
ASSERT_NO_THROW(hz.get_map("short-heartbeat-map").get()->put(1, 1));
1545+
1546+
hz.shutdown().get();
15221547
}
15231548
} // namespace test
15241549
} // namespace client
@@ -1552,6 +1577,7 @@ TEST_F(SocketInterceptorTest, interceptSSLBasic)
15521577
config.set_socket_interceptor(std::move(interceptor));
15531578
hazelcast_client hz{ hazelcast::new_client(std::move(config)).get() };
15541579
interceptorLatch.wait_for(boost::chrono::seconds(2));
1580+
hz.shutdown().get();
15551581
}
15561582

15571583
#endif
@@ -1565,6 +1591,7 @@ TEST_F(SocketInterceptorTest, interceptBasic)
15651591
config.set_socket_interceptor(std::move(interceptor));
15661592
hazelcast_client hz{ hazelcast::new_client(std::move(config)).get() };
15671593
interceptorLatch.wait_for(boost::chrono::seconds(2));
1594+
hz.shutdown().get();
15681595
}
15691596
} // namespace test
15701597
} // namespace client
@@ -1598,6 +1625,8 @@ TEST_F(SocketOptionsTest, testConfiguration)
15981625
ASSERT_FALSE(socketOptions.is_tcp_no_delay());
15991626
ASSERT_EQ(5, socketOptions.get_linger_seconds());
16001627
ASSERT_EQ(bufferSize, socketOptions.get_buffer_size_in_bytes());
1628+
1629+
client.shutdown().get();
16011630
}
16021631
} // namespace test
16031632
} // namespace client
@@ -1620,6 +1649,8 @@ TEST_F(ClientAuthenticationTest, testUserPasswordCredentials)
16201649
std::make_shared<security::username_password_credentials>("test-user",
16211650
"test-pass"));
16221651
hazelcast_client hz{ hazelcast::new_client(std::move(config)).get() };
1652+
1653+
hz.shutdown().get();
16231654
}
16241655

16251656
TEST_F(ClientAuthenticationTest, testTokenCredentials)
@@ -1632,6 +1663,8 @@ TEST_F(ClientAuthenticationTest, testTokenCredentials)
16321663
config.set_cluster_name("token-credentials-dev")
16331664
.set_credentials(std::make_shared<security::token_credentials>(my_token));
16341665
hazelcast_client hz{ hazelcast::new_client(std::move(config)).get() };
1666+
1667+
hz.shutdown().get();
16351668
}
16361669

16371670
TEST_F(ClientAuthenticationTest, testIncorrectGroupName)
@@ -1677,6 +1710,8 @@ TEST_F(ClientEnpointTest, testConnectedClientEnpoint)
16771710
ASSERT_TRUE(localAddress);
16781711
ASSERT_EQ(*localAddress, *endpointAddress);
16791712
ASSERT_EQ(connectionManager.get_client_uuid(), endpoint.get_uuid());
1713+
1714+
client.shutdown().get();
16801715
}
16811716
} // namespace test
16821717
} // namespace client
@@ -1700,6 +1735,8 @@ TEST_F(MemberAttributeTest, testInitialValues)
17001735
ASSERT_TRUE(member.lookup_attribute(attribute_name));
17011736
ASSERT_EQ("test-member-attribute-value",
17021737
*member.get_attribute(attribute_name));
1738+
1739+
hazelcastClient.shutdown().get();
17031740
}
17041741

17051742
} // namespace test
@@ -1722,7 +1759,11 @@ class BasicPnCounterAPITest : public ClientTest
17221759

17231760
static void TearDownTestCase()
17241761
{
1725-
delete client;
1762+
if (client) {
1763+
client->shutdown().get();
1764+
delete client;
1765+
}
1766+
17261767
delete instance;
17271768

17281769
client = nullptr;
@@ -1880,7 +1921,10 @@ class PnCounterFunctionalityTest : public ClientTest
18801921

18811922
static void TearDownTestCase()
18821923
{
1883-
delete client;
1924+
if (client) {
1925+
client->shutdown().get();
1926+
delete client;
1927+
}
18841928
delete instance;
18851929

18861930
client = nullptr;
@@ -1958,6 +2002,8 @@ TEST_F(ClientPNCounterNoDataMemberTest, noDataMemberExceptionIsThrown)
19582002

19592003
ASSERT_THROW(pnCounter->add_and_get(5).get(),
19602004
exception::no_data_member_in_cluster);
2005+
2006+
hz.shutdown().get();
19612007
}
19622008

19632009
/**
@@ -2012,6 +2058,8 @@ TEST_F(ClientPNCounterConsistencyLostTest,
20122058
terminate_member(*currentTarget, instance, instance2);
20132059

20142060
ASSERT_THROW(pnCounter->add_and_get(5).get(), exception::consistency_lost);
2061+
2062+
hz.shutdown().get();
20152063
}
20162064

20172065
TEST_F(ClientPNCounterConsistencyLostTest,
@@ -2042,6 +2090,8 @@ TEST_F(ClientPNCounterConsistencyLostTest,
20422090
pnCounter->reset().get();
20432091

20442092
pnCounter->add_and_get(5).get();
2093+
2094+
hz.shutdown().get();
20452095
}
20462096
} // namespace pncounter
20472097
} // namespace crdt
@@ -2121,6 +2171,8 @@ TEST_P(SimpleListenerTest, testSharedClusterListeners)
21212171
cluster.remove_membership_listener(initialListenerRegistrationId));
21222172
ASSERT_TRUE(
21232173
cluster.remove_membership_listener(sampleListenerRegistrationId));
2174+
2175+
hazelcastClient.shutdown().get();
21242176
}
21252177

21262178
TEST_P(SimpleListenerTest, testClusterListeners)
@@ -2154,6 +2206,8 @@ TEST_P(SimpleListenerTest, testClusterListeners)
21542206

21552207
ASSERT_TRUE(cluster.remove_membership_listener(init_id));
21562208
ASSERT_TRUE(cluster.remove_membership_listener(id));
2209+
2210+
hazelcastClient.shutdown().get();
21572211
}
21582212

21592213
TEST_P(SimpleListenerTest, testClusterListenersFromConfig)
@@ -2184,6 +2238,8 @@ TEST_P(SimpleListenerTest, testClusterListenersFromConfig)
21842238
ASSERT_OPEN_EVENTUALLY(memberRemovedInit);
21852239

21862240
instance.shutdown();
2241+
2242+
hazelcastClient.shutdown().get();
21872243
}
21882244

21892245
TEST_P(SimpleListenerTest, testDeregisterListener)
@@ -2221,6 +2277,8 @@ TEST_P(SimpleListenerTest, testDeregisterListener)
22212277
map->clear().get();
22222278
ASSERT_OPEN_EVENTUALLY(map_clearedLatch);
22232279
ASSERT_TRUE(map->remove_entry_listener(listenerRegistrationId).get());
2280+
2281+
hazelcastClient.shutdown().get();
22242282
}
22252283

22262284
TEST_P(SimpleListenerTest, testEmptyListener)
@@ -2249,6 +2307,8 @@ TEST_P(SimpleListenerTest, testEmptyListener)
22492307
std::this_thread::sleep_for(std::chrono::milliseconds(500));
22502308

22512309
ASSERT_TRUE(map->remove_entry_listener(listenerRegistrationId).get());
2310+
2311+
hazelcastClient.shutdown().get();
22522312
}
22532313

22542314
INSTANTIATE_TEST_SUITE_P(
@@ -2290,7 +2350,10 @@ class FlakeIdGeneratorApiTest : public ClientTest
22902350

22912351
static void TearDownTestCase()
22922352
{
2293-
delete client;
2353+
if (client) {
2354+
client->shutdown().get();
2355+
delete client;
2356+
}
22942357
delete instance;
22952358

22962359
client = nullptr;
@@ -2400,7 +2463,10 @@ ClientTxnMapTest::ClientTxnMapTest()
24002463
, client_(get_new_client())
24012464
{}
24022465

2403-
ClientTxnMapTest::~ClientTxnMapTest() = default;
2466+
ClientTxnMapTest::~ClientTxnMapTest()
2467+
{
2468+
client_.shutdown().get();
2469+
}
24042470

24052471
TEST_F(ClientTxnMapTest, testPutGet)
24062472
{
@@ -2823,7 +2889,10 @@ ClientTxnSetTest::ClientTxnSetTest()
28232889
, client_(get_new_client())
28242890
{}
28252891

2826-
ClientTxnSetTest::~ClientTxnSetTest() = default;
2892+
ClientTxnSetTest::~ClientTxnSetTest()
2893+
{
2894+
client_.shutdown().get();
2895+
}
28272896

28282897
TEST_F(ClientTxnSetTest, testAddRemove)
28292898
{
@@ -2972,6 +3041,8 @@ TEST_F(ClientTxnTest, testTxnCommitUniSocket)
29723041
auto retrievedElement = q->poll<std::string>().get();
29733042
ASSERT_TRUE(retrievedElement.has_value());
29743043
ASSERT_EQ(value, retrievedElement.value());
3044+
3045+
uniSocketClient.shutdown().get();
29753046
}
29763047

29773048
TEST_F(ClientTxnTest, testTxnCommitWithOptions)
@@ -3100,6 +3171,7 @@ TEST_F(ClientTxnTest, testTxnInitAndNextMethod)
31003171
});
31013172

31023173
clientConfig.set_load_balancer(std::move(tmp_load_balancer));
3174+
client_->shutdown().get();
31033175
client_.reset(
31043176
new hazelcast_client{ new_client(std::move(clientConfig)).get() });
31053177

@@ -3127,6 +3199,8 @@ TEST_F(ClientTxnTest, testTxnInitAndNextMethodRValue)
31273199
}
31283200
return boost::make_optional<member>(std::move(members[0]));
31293201
}));
3202+
3203+
client_->shutdown().get();
31303204
client_.reset(
31313205
new hazelcast_client{ new_client(std::move(clientConfig)).get() });
31323206

@@ -3159,7 +3233,10 @@ ClientTxnListTest::ClientTxnListTest()
31593233
, client_(get_new_client())
31603234
{}
31613235

3162-
ClientTxnListTest::~ClientTxnListTest() = default;
3236+
ClientTxnListTest::~ClientTxnListTest()
3237+
{
3238+
client_.shutdown().get();
3239+
}
31633240

31643241
TEST_F(ClientTxnListTest, testAddRemove)
31653242
{
@@ -3215,7 +3292,10 @@ ClientTxnMultiMapTest::ClientTxnMultiMapTest()
32153292
, client_(get_new_client())
32163293
{}
32173294

3218-
ClientTxnMultiMapTest::~ClientTxnMultiMapTest() = default;
3295+
ClientTxnMultiMapTest::~ClientTxnMultiMapTest()
3296+
{
3297+
client_.shutdown().get();
3298+
};
32193299

32203300
TEST_F(ClientTxnMultiMapTest, testRemoveIfExists)
32213301
{
@@ -3319,7 +3399,10 @@ ClientTxnQueueTest::ClientTxnQueueTest()
33193399
, client_(get_new_client())
33203400
{}
33213401

3322-
ClientTxnQueueTest::~ClientTxnQueueTest() = default;
3402+
ClientTxnQueueTest::~ClientTxnQueueTest()
3403+
{
3404+
client_.shutdown().get();
3405+
};
33233406

33243407
TEST_F(ClientTxnQueueTest, testTransactionalOfferPoll1)
33253408
{

0 commit comments

Comments
 (0)