Skip to content

Commit 12aa0dc

Browse files
RikeVoltzyemreinci
andauthored
Fix error in get_all imap method with hazelcast_json_value value type (#926)
* Fix error in get_all imap method with hazelcast_json_value value type * Fix redundant copy of value in get_all imap method Co-authored-by: yemreinci <[email protected]>
1 parent 3301fa3 commit 12aa0dc

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

hazelcast/include/hazelcast/client/imap.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,8 @@ namespace hazelcast {
603603
entry.second);
604604
// it is guaranteed that all values are non-null
605605
assert(val.has_value());
606-
result[to_object<K>(
607-
entry.first).value()] = std::move(
608-
val.value());
606+
result.emplace(to_object<K>(
607+
entry.first).value(), std::move(val.value()));
609608
}
610609
}
611610
return result;

hazelcast/test/src/HazelcastTests5.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,26 @@ namespace hazelcast {
10251025

10261026
}
10271027

1028+
TEST_P(ClientMapTest, testPutAllGetAllWithJson) {
1029+
std::unordered_map<std::string, hazelcast_json_value> mapTemp;
1030+
1031+
for (int i = 0; i < 100; i++) {
1032+
mapTemp.emplace(std::to_string(i), hazelcast_json_value("{\"value\":\"value_" + std::to_string(i) + "\"}"));
1033+
}
1034+
ASSERT_EQ(imap_->size().get(), 0);
1035+
imap_->put_all(mapTemp).get();
1036+
ASSERT_EQ(imap_->size().get(), 100);
1037+
1038+
std::unordered_set<std::string> tempSet;
1039+
tempSet.insert(std::to_string(1));
1040+
tempSet.insert(std::to_string(3));
1041+
std::unordered_map<std::string, hazelcast_json_value> m2 = imap_->get_all<std::string, hazelcast_json_value>(tempSet).get();
1042+
1043+
ASSERT_EQ(2U, m2.size());
1044+
ASSERT_EQ(m2.at(std::to_string(1)), hazelcast_json_value("{\"value\":\"value_1\"}"));
1045+
ASSERT_EQ(m2.at(std::to_string(3)), hazelcast_json_value("{\"value\":\"value_3\"}"));
1046+
}
1047+
10281048
TEST_P(ClientMapTest, testTryPutRemove) {
10291049
ASSERT_TRUE(imap_->try_put("key1", "value1", std::chrono::seconds(1)).get());
10301050
ASSERT_TRUE(imap_->try_put("key2", "value2", std::chrono::seconds(1)).get());

0 commit comments

Comments
 (0)