Skip to content

Commit a60b137

Browse files
authored
New test cases [API-1812] (#1099)
* test added for load_balancer lvalue config * Test cases for reliable_listener * replicated_map tests are added * test for latch try_wait * fenced_lock assignment operator test * test case for pnCounter decrement_and_get * test case for reliableTopicTest config * test case for item_listener::on_removed * test case for remove_lifecycle_listener * deprecated methods for near_cache_config * test case for set_cache_local_entries * code coverage changes for index_config * test case for set_labels and add_label * debug for testTerminateCaseForLValue * testListenerOnRemoved fail case fixed * bitmap_index_options test error fix * refactor config.cpp * test cases for transcation objects * test fail for bitmap_index_options * test failures fix * test failure fix * new test cases for uncovered api * flakeIDConfig test * test for typed_data * Portable write_null_portable * predicate test * test case for near_cache_config * set_connection_strategy_config for code coverage * test fix * test fix * test fix * variable Name fix * compiler error * load balancer init method * clang format * clang-format * Test case is added * code review changes * code review PR fixs continue * compiler error fix after merge * clang-format * compiler error and missing test * clang format
1 parent bd8b061 commit a60b137

File tree

15 files changed

+770
-41
lines changed

15 files changed

+770
-41
lines changed

hazelcast/include/hazelcast/client/config/index_config.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ struct HAZELCAST_API index_config
112112

113113
static const index_type DEFAULT_TYPE;
114114

115-
index_config();
116-
117115
/**
118116
* Creates an index configuration of the given type.
119117
*
120118
* \param type Index type.
121119
*/
122-
index_config(index_type type);
120+
index_config(index_type type = DEFAULT_TYPE);
123121

124122
/**
125123
* Creates an index configuration of the given type with provided
@@ -130,7 +128,7 @@ struct HAZELCAST_API index_config
130128
*/
131129
template<typename... T>
132130
index_config(index_type t, T... attrs)
133-
: type(t)
131+
: index_config(t)
134132
{
135133
add_attributes(std::forward<T>(attrs)...);
136134
}

hazelcast/include/hazelcast/client/config/near_cache_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class HAZELCAST_API near_cache_config
188188
const in_memory_format& in_memory_format);
189189

190190
/**
191+
* @deprecated This method has no effect on client side.
191192
* If true, cache local entries also.
192193
* This is useful when in-memory-format for Near Cache is different than the
193194
* map's one.
@@ -197,6 +198,7 @@ class HAZELCAST_API near_cache_config
197198
bool is_cache_local_entries() const;
198199

199200
/**
201+
* @deprecated This method has no effect on client side.
200202
* True to cache local entries also.
201203
* This is useful when in-memory-format for Near Cache is different than the
202204
* map's one.
@@ -253,8 +255,6 @@ class HAZELCAST_API near_cache_config
253255
* </ul>
254256
*/
255257
eviction_config eviction_config_;
256-
257-
int32_t calculate_max_size(int32_t max_size);
258258
};
259259

260260
} // namespace config

hazelcast/include/hazelcast/cp/cp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,8 @@ class HAZELCAST_API fenced_lock : public session_aware_proxy
926926
*/
927927
const raft_group_id& get_group_id();
928928

929-
friend bool operator==(const fenced_lock& lhs, const fenced_lock& rhs);
929+
friend HAZELCAST_API bool operator==(const fenced_lock& lhs,
930+
const fenced_lock& rhs);
930931

931932
protected:
932933
void post_destroy();

hazelcast/src/hazelcast/client/config.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,6 @@ index_config::bitmap_index_options::bitmap_index_options()
811811
const index_config::index_type index_config::DEFAULT_TYPE =
812812
index_config::index_type::SORTED;
813813

814-
index_config::index_config()
815-
: type(DEFAULT_TYPE)
816-
{}
817-
818814
index_config::index_config(index_config::index_type type)
819815
: type(type)
820816
{}
@@ -1032,14 +1028,6 @@ near_cache_config::set_eviction_config(const eviction_config& eviction_config)
10321028
return *this;
10331029
}
10341030

1035-
int32_t
1036-
near_cache_config::calculate_max_size(int32_t max_size)
1037-
{
1038-
return (max_size == 0) ? INT32_MAX
1039-
: util::Preconditions::check_not_negative(
1040-
max_size, "Max-size cannot be negative!");
1041-
}
1042-
10431031
std::ostream&
10441032
operator<<(std::ostream& out, const near_cache_config& config)
10451033
{
@@ -1262,7 +1250,7 @@ client_config::get_instance_name() const
12621250
client_config&
12631251
client_config::set_instance_name(const std::string& instance_name)
12641252
{
1265-
client_config::instance_name_ = instance_name;
1253+
instance_name_ = instance_name;
12661254
return *this;
12671255
}
12681256

@@ -1275,7 +1263,7 @@ client_config::get_executor_pool_size() const
12751263
void
12761264
client_config::set_executor_pool_size(int32_t executor_pool_size)
12771265
{
1278-
client_config::executor_pool_size_ = executor_pool_size;
1266+
executor_pool_size_ = executor_pool_size;
12791267
}
12801268

12811269
config::client_connection_strategy_config&
@@ -1288,7 +1276,7 @@ client_config&
12881276
client_config::set_connection_strategy_config(
12891277
const config::client_connection_strategy_config& connection_strategy_config)
12901278
{
1291-
client_config::connection_strategy_config_ = connection_strategy_config;
1279+
connection_strategy_config_ = connection_strategy_config;
12921280
return *this;
12931281
}
12941282

hazelcast/src/hazelcast/client/discovery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ ec2_request_signer::hmac_sh_a256_bytes(const void* key_buffer,
296296
delete hmac;
297297
#endif
298298
return len;
299-
#endif
299+
#endif
300300
}
301301

302302
std::string

hazelcast/test/src/HazelcastTests1.cpp

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,19 @@ TEST_F(BasicPnCounterAPITest, testGetAndDecrement)
18251825
ASSERT_EQ(0, pnCounter->get().get());
18261826
}
18271827

1828+
TEST_F(BasicPnCounterAPITest, testDecrementAndGet)
1829+
{
1830+
auto pnCounter =
1831+
client
1832+
->get_pn_counter(
1833+
testing::UnitTest::GetInstance()->current_test_info()->name())
1834+
.get();
1835+
ASSERT_EQ(1, pnCounter->increment_and_get().get());
1836+
ASSERT_EQ(0, pnCounter->decrement_and_get().get());
1837+
ASSERT_EQ(-1, pnCounter->decrement_and_get().get());
1838+
ASSERT_EQ(-1, pnCounter->get().get());
1839+
}
1840+
18281841
TEST_F(BasicPnCounterAPITest, testGetAndSubtract)
18291842
{
18301843
auto pnCounter =
@@ -2330,6 +2343,38 @@ TEST_F(FlakeIdGeneratorApiTest, testSmoke)
23302343
// set than expected
23312344
ASSERT_EQ(4 * NUM_IDS_PER_THREAD, allIds.size());
23322345
}
2346+
2347+
TEST_F(FlakeIdGeneratorApiTest, testAddGetFlakeIdGeneratorIntegrity)
2348+
{
2349+
client_config clientConfig = get_config();
2350+
config::client_flake_id_generator_config flakeIdConfig("flake_config"),
2351+
flakeIdConfig2("flake_config_2");
2352+
2353+
flakeIdConfig.set_prefetch_count(10).set_prefetch_validity_duration(
2354+
std::chrono::seconds(20));
2355+
clientConfig.add_flake_id_generator_config(flakeIdConfig);
2356+
2357+
const config::client_flake_id_generator_config* readed_flake_config =
2358+
clientConfig.get_flake_id_generator_config("flake_config");
2359+
2360+
EXPECT_EQ(readed_flake_config->get_name(), "flake_config");
2361+
EXPECT_EQ(readed_flake_config->get_prefetch_count(), 10);
2362+
EXPECT_EQ(readed_flake_config->get_prefetch_validity_duration(),
2363+
std::chrono::seconds(20));
2364+
2365+
flakeIdConfig2.set_prefetch_count(20).set_prefetch_validity_duration(
2366+
std::chrono::seconds(30));
2367+
2368+
clientConfig.add_flake_id_generator_config(flakeIdConfig2);
2369+
readed_flake_config =
2370+
clientConfig.get_flake_id_generator_config("flake_config_2");
2371+
2372+
EXPECT_EQ(readed_flake_config->get_name(), "flake_config_2");
2373+
EXPECT_EQ(readed_flake_config->get_prefetch_count(), 20);
2374+
EXPECT_EQ(readed_flake_config->get_prefetch_validity_duration(),
2375+
std::chrono::seconds(30));
2376+
}
2377+
23332378
} // namespace test
23342379
} // namespace client
23352380
} // namespace hazelcast
@@ -2740,6 +2785,20 @@ TEST_F(ClientTxnMapTest, testIsEmpty)
27402785
auto regularMap = client_.get_map(name).get();
27412786
ASSERT_FALSE(regularMap->is_empty().get());
27422787
}
2788+
2789+
TEST_F(ClientTxnMapTest, testServiceNameAndDestroy)
2790+
{
2791+
transaction_context context = client_.new_transaction_context();
2792+
context.begin_transaction().get();
2793+
2794+
auto map = context.get_map(get_test_name());
2795+
2796+
ASSERT_EQ(map->get_service_name(), "hz:impl:mapService");
2797+
2798+
// added for test coverage
2799+
ASSERT_NO_THROW(map->destroy().get());
2800+
}
2801+
27432802
} // namespace test
27442803
} // namespace client
27452804
} // namespace hazelcast
@@ -2784,6 +2843,19 @@ TEST_F(ClientTxnSetTest, testAddRemove)
27842843

27852844
ASSERT_EQ(1, s->size().get());
27862845
}
2846+
2847+
TEST_F(ClientTxnSetTest, testServiceNameAndDestroy)
2848+
{
2849+
transaction_context context = client_.new_transaction_context();
2850+
context.begin_transaction().get();
2851+
2852+
auto set = context.get_set(get_test_name());
2853+
2854+
ASSERT_EQ(set->get_service_name(), "hz:impl:setService");
2855+
// added for test coverage
2856+
ASSERT_NO_THROW(set->destroy().get());
2857+
}
2858+
27872859
} // namespace test
27882860
} // namespace client
27892861
} // namespace hazelcast
@@ -3004,6 +3076,63 @@ TEST_F(ClientTxnTest, testTxnRollbackOnServerCrash)
30043076
<< "queue poll should return null";
30053077
ASSERT_EQ(0, q->size().get());
30063078
}
3079+
3080+
TEST_F(ClientTxnTest, testTxnInitAndNextMethod)
3081+
{
3082+
client_config clientConfig = get_config();
3083+
boost::latch init_latch(1);
3084+
3085+
load_balancer tmp_load_balancer;
3086+
tmp_load_balancer
3087+
.init([&init_latch](cluster& c) { init_latch.count_down(); })
3088+
.next([](cluster& c) {
3089+
std::vector<member> members = c.get_members();
3090+
size_t len = members.size();
3091+
if (len == 0) {
3092+
return boost::optional<member>();
3093+
}
3094+
for (size_t i = 0; i < len; i++) {
3095+
if (members[i].get_address().get_port() == 5701) {
3096+
return boost::make_optional<member>(std::move(members[i]));
3097+
}
3098+
}
3099+
return boost::make_optional<member>(std::move(members[0]));
3100+
});
3101+
3102+
clientConfig.set_load_balancer(std::move(tmp_load_balancer));
3103+
client_.reset(
3104+
new hazelcast_client{ new_client(std::move(clientConfig)).get() });
3105+
3106+
ASSERT_OPEN_EVENTUALLY(init_latch);
3107+
}
3108+
3109+
TEST_F(ClientTxnTest, testTxnInitAndNextMethodRValue)
3110+
{
3111+
client_config clientConfig = get_config();
3112+
boost::latch init_latch(1);
3113+
3114+
clientConfig.set_load_balancer(
3115+
load_balancer()
3116+
.init([&init_latch](cluster& c) { init_latch.count_down(); })
3117+
.next([](cluster& c) {
3118+
std::vector<member> members = c.get_members();
3119+
size_t len = members.size();
3120+
if (len == 0) {
3121+
return boost::optional<member>();
3122+
}
3123+
for (size_t i = 0; i < len; i++) {
3124+
if (members[i].get_address().get_port() == 5701) {
3125+
return boost::make_optional<member>(std::move(members[i]));
3126+
}
3127+
}
3128+
return boost::make_optional<member>(std::move(members[0]));
3129+
}));
3130+
client_.reset(
3131+
new hazelcast_client{ new_client(std::move(clientConfig)).get() });
3132+
3133+
ASSERT_OPEN_EVENTUALLY(init_latch);
3134+
}
3135+
30073136
} // namespace test
30083137
} // namespace client
30093138
} // namespace hazelcast
@@ -3050,6 +3179,19 @@ TEST_F(ClientTxnListTest, testAddRemove)
30503179

30513180
ASSERT_EQ(1, l->size().get());
30523181
}
3182+
3183+
TEST_F(ClientTxnListTest, testServiceNameAndDestroy)
3184+
{
3185+
transaction_context context = client_.new_transaction_context();
3186+
context.begin_transaction().get();
3187+
3188+
auto list = context.get_list(get_test_name());
3189+
3190+
ASSERT_EQ(list->get_service_name(), "hz:impl:listService");
3191+
// added for test coverage
3192+
ASSERT_NO_THROW(list->destroy().get());
3193+
}
3194+
30533195
} // namespace test
30543196
} // namespace client
30553197
} // namespace hazelcast
@@ -3141,6 +3283,19 @@ TEST_F(ClientTxnMultiMapTest, testPutGetRemove)
31413283

31423284
boost::wait_for_all(futures.begin(), futures.end());
31433285
}
3286+
3287+
TEST_F(ClientTxnMultiMapTest, testServiceNameAndDestroy)
3288+
{
3289+
transaction_context context = client_.new_transaction_context();
3290+
context.begin_transaction().get();
3291+
3292+
auto multi_map = context.get_multi_map(get_test_name());
3293+
3294+
ASSERT_EQ(multi_map->get_service_name(), "hz:impl:multiMapService");
3295+
// added for test coverage
3296+
ASSERT_NO_THROW(multi_map->destroy().get());
3297+
}
3298+
31443299
} // namespace test
31453300
} // namespace client
31463301
} // namespace hazelcast
@@ -3684,4 +3839,4 @@ TEST_F(HttpsClientTest, testConnectToGithub)
36843839

36853840
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
36863841
#pragma warning(pop)
3687-
#endif
3842+
#endif

0 commit comments

Comments
 (0)