Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hazelcast/include/hazelcast/client/HazelcastJsonValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace hazelcast {

bool operator!=(const HazelcastJsonValue &rhs) const;

bool operator<(const HazelcastJsonValue &rhs) const;

friend std::ostream HAZELCAST_API &operator<<(std::ostream &os, const HazelcastJsonValue &value);

private:
Expand Down
31 changes: 19 additions & 12 deletions hazelcast/include/hazelcast/client/map/ClientMapProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,11 @@ namespace hazelcast {
std::vector<K> keySet() {
std::vector<serialization::pimpl::Data> dataResult = proxy::IMapImpl::keySetData();
size_t size = dataResult.size();
std::vector<K> keys(size);
std::vector<K> keys;
keys.reserve(size);
for (size_t i = 0; i < size; ++i) {
std::unique_ptr<K> key = toObject<K>(dataResult[i]);
keys[i] = *key;
keys.push_back(*key);
}
return keys;
}
Expand Down Expand Up @@ -693,10 +694,11 @@ namespace hazelcast {
std::vector<K> keySet(const query::Predicate &predicate) {
std::vector<serialization::pimpl::Data> dataResult = proxy::IMapImpl::keySetData(predicate);
size_t size = dataResult.size();
std::vector<K> keys(size);
std::vector<K> keys;
keys.reserve(size);
for (size_t i = 0; i < size; ++i) {
std::unique_ptr<K> key = toObject<K>(dataResult[i]);
keys[i] = *key;
keys.push_back(*key);
}
return keys;
}
Expand Down Expand Up @@ -747,10 +749,11 @@ namespace hazelcast {
std::vector<V> values() {
std::vector<serialization::pimpl::Data> dataResult = proxy::IMapImpl::valuesData();
size_t size = dataResult.size();
std::vector<V> values(size);
std::vector<V> values;
values.reserve(size);
for (size_t i = 0; i < size; ++i) {
std::unique_ptr<V> value = toObject<V>(dataResult[i]);
values[i] = *value;
values.push_back(*value);
}
return values;
}
Expand Down Expand Up @@ -782,6 +785,7 @@ namespace hazelcast {
std::vector<serialization::pimpl::Data> dataResult = proxy::IMapImpl::valuesData(predicate);
size_t size = dataResult.size();
std::vector<V> values;
values.reserve(size);
for (size_t i = 0; i < size; ++i) {
std::unique_ptr<V> value = toObject<V>(dataResult[i]);
values.push_back(*value);
Expand Down Expand Up @@ -826,11 +830,12 @@ namespace hazelcast {
std::vector<std::pair<K, V> > entrySet() {
std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > dataResult = proxy::IMapImpl::entrySetData();
size_t size = dataResult.size();
std::vector<std::pair<K, V> > entries(size);
std::vector<std::pair<K, V> > entries;
entries.reserve(size);
for (size_t i = 0; i < size; ++i) {
std::unique_ptr<K> key = toObject<K>(dataResult[i].first);
std::unique_ptr<V> value = toObject<V>(dataResult[i].second);
entries[i] = std::make_pair(*key, *value);
entries.emplace_back(*key, *value);
}
return entries;
}
Expand All @@ -851,11 +856,12 @@ namespace hazelcast {
std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > dataResult = proxy::IMapImpl::entrySetData(
predicate);
size_t size = dataResult.size();
std::vector<std::pair<K, V> > entries(size);
std::vector<std::pair<K, V> > entries;
entries.reserve(size);
for (size_t i = 0; i < size; ++i) {
std::unique_ptr<K> key = toObject<K>(dataResult[i].first);
std::unique_ptr<V> value = toObject<V>(dataResult[i].second);
entries[i] = std::make_pair(*key, *value);
entries.emplace_back(*key, *value);
}
return entries;
}
Expand All @@ -874,11 +880,12 @@ namespace hazelcast {
std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > dataResult = proxy::IMapImpl::entrySetData(
predicate);
size_t size = dataResult.size();
std::vector<std::pair<K, V> > entries(size);
std::vector<std::pair<K, V> > entries;
entries.reserve(size);
for (size_t i = 0; i < size; ++i) {
std::unique_ptr<K> key = toObject<K>(dataResult[i].first);
std::unique_ptr<V> value = toObject<V>(dataResult[i].second);
entries[i] = std::make_pair(*key, *value);
entries.emplace_back(*key, *value);
}
return entries;
}
Expand Down
4 changes: 4 additions & 0 deletions hazelcast/src/hazelcast/client/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ namespace hazelcast {
return jsonString == rhs.jsonString;
}

bool HazelcastJsonValue::operator<(const HazelcastJsonValue &rhs) const {
return jsonString < rhs.jsonString;
}

bool HazelcastJsonValue::operator!=(const HazelcastJsonValue &rhs) const {
return !(rhs == *this);
}
Expand Down
26 changes: 25 additions & 1 deletion hazelcast/test/src/HazelcastTests5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,7 @@ namespace hazelcast {
static const char *intMapName;
static const char *employeesMapName;
static const char *imapName;
static const char *jsonMapName;
static const std::string ONE_SECOND_MAP_NAME;

MapClientConfig() {
Expand All @@ -2403,6 +2404,7 @@ namespace hazelcast {

const char *MapClientConfig::intMapName = "IntMap";
const char *MapClientConfig::employeesMapName = "EmployeesMap";
const char *MapClientConfig::jsonMapName = "jsonMapTest";
const char *MapClientConfig::imapName = "clientMapTest";
const std::string MapClientConfig::ONE_SECOND_MAP_NAME = "OneSecondTtlMap";

Expand Down Expand Up @@ -2450,7 +2452,8 @@ namespace hazelcast {
ClientMapTest() : client(HazelcastClient(GetParam())),
imap(client.getMap<std::string, std::string>(MapClientConfig::imapName)),
intMap(client.getMap<int, int>(MapClientConfig::intMapName)),
employees(client.getMap<int, Employee>(MapClientConfig::employeesMapName)) {
employees(client.getMap<int, Employee>(MapClientConfig::employeesMapName)),
jsonMap(client.getMap<std::string, HazelcastJsonValue>(MapClientConfig::jsonMapName)) {
}

static void SetUpTestCase() {
Expand Down Expand Up @@ -2738,6 +2741,7 @@ namespace hazelcast {
IMap<std::string, std::string> imap;
IMap<int, int> intMap;
IMap<int, Employee> employees;
IMap<std::string, HazelcastJsonValue> jsonMap;

static HazelcastServer *instance;
static HazelcastServer *instance2;
Expand Down Expand Up @@ -3293,6 +3297,26 @@ namespace hazelcast {

}

TEST_P(ClientMapTest, testJsonValues) {
const int numItems = 5;
for (int i = 0; i < numItems; ++i) {
jsonMap.put("key_" + std::to_string(i), HazelcastJsonValue("{ \"value\"=\"value_" + std::to_string(i) + "\"}"));
}
std::vector<HazelcastJsonValue> values = jsonMap.values();
ASSERT_EQ(numItems, (int) values.size());
}

TEST_P(ClientMapTest, testJsonValuesWithPagingPredicate) {
const int numItems = 5;
const int predSize = 3;
for (int i = 0; i < numItems; ++i) {
jsonMap.put("key_" + std::to_string(i), HazelcastJsonValue("{ \"value\"=\"value_" + std::to_string(i) + "\"}"));
}
query::PagingPredicate<std::string, HazelcastJsonValue> predicate((size_t) predSize);
std::vector<HazelcastJsonValue> values = jsonMap.values(predicate);
ASSERT_EQ(predSize, (int) values.size());
}

TEST_P(ClientMapTest, testValues) {
fillMap();
std::vector<std::string> tempVector;
Expand Down