[ https://issues.apache.org/jira/browse/GEODE-10276?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17534381#comment-17534381 ]
ASF GitHub Bot commented on GEODE-10276: ---------------------------------------- pivotal-jbarrett commented on code in PR #969: URL: https://github.com/apache/geode-native/pull/969#discussion_r869330026 ########## cppcache/integration/test/PdxInstanceTest.cpp: ########## @@ -268,7 +268,7 @@ TEST(PdxInstanceTest, testPdxInstance) { pdxTypeFromPdxTypeInstance->equals(*pdxTypeFromPdxTypeInstanceGet, false)) << "PdxObjects should be equal."; - EXPECT_EQ(-960665662, pdxTypeInstance->hashcode()) + EXPECT_EQ(514863279, pdxTypeInstance->hashcode()) Review Comment: Why did this hash code change? Are we certain it matches the same hash that the server produces for it? If not this can lead to really bad single hop performance. ########## tests/javaobject/PdxTests/DeliveryAddress.java: ########## @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package PdxTests; + +import java.util.Vector; +import org.apache.geode.pdx.PdxReader; +import org.apache.geode.pdx.PdxSerializable; +import org.apache.geode.pdx.PdxWriter; + +public class DeliveryAddress implements PdxSerializable +{ + String _addressLine; Review Comment: Geode's Java conventions come from the Google Java Style Guide. Please don't prefix member variables. Also please make this private. ########## cppcache/integration/test/PdxSerializableTest.cpp: ########## @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <framework/Cluster.h> + +#include <iostream> +#include <memory> + +#include <gtest/gtest.h> + +#include <geode/Cache.hpp> +#include <geode/FunctionService.hpp> +#include <geode/PdxWrapper.hpp> +#include <geode/PoolManager.hpp> +#include <geode/RegionFactory.hpp> +#include <geode/RegionShortcut.hpp> +#include <geode/TypeRegistry.hpp> + +#include "DeliveryAddress.hpp" + +namespace { + +using apache::geode::client::Cache; +using apache::geode::client::Cacheable; +using apache::geode::client::CacheableString; +using apache::geode::client::CacheableVector; +using apache::geode::client::FunctionService; +using apache::geode::client::PdxReader; +using apache::geode::client::PdxSerializable; +using apache::geode::client::PdxWriter; +using apache::geode::client::Region; +using apache::geode::client::RegionShortcut; + +using PdxTests::DeliveryAddress; + +std::shared_ptr<Region> setupRegion(Cache& cache) { + auto region = cache.createRegionFactory(RegionShortcut::PROXY) + .setPoolName("default") + .create("region"); + + return region; +} + +/** + * This test perform the following steps: + * 1. Writes a version 1 entry of DeliveryAddress named 'entry.v1' + * 2. From another cache, fetches the entry 'entry.v1' + * 3. From the same cache as step 2, it call function PutDeliveryAddress that + * writes a version 2 entry of DeliveryAddress named 'entry.v2' + * 4. From another cache, try to fetch the entry 'entry.v2' and it should match + * the entry written in step 3 + * + * The purpose of this test is to verify that even if there are 2 versions of + * the same PdxSerializable class, the right PdxType will be used during + * (de)serialization + */ +TEST(PdxSerializableTest, testRightPdxTypeForDiffPdxVersions) { + Cluster cluster{LocatorCount{1}, ServerCount{1}}; + cluster.start([&]() { + cluster.getGfsh() + .deploy() + .jar(getFrameworkString(FrameworkVariable::JavaObjectJarPath)) + .execute(); + }); + cluster.getGfsh() + .create() + .region() + .withName("region") + .withType("REPLICATE") + .execute(); + + std::shared_ptr<DeliveryAddress> entryV1; + std::shared_ptr<DeliveryAddress> entryV2; + + { + auto cache = cluster.createCache(); + auto region = setupRegion(cache); + cache.getTypeRegistry().registerPdxType( + DeliveryAddress::createDeserializable); + + DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_1); + entryV1 = std::make_shared<DeliveryAddress>( + "Some address line", "Some city", "Some country", std::string{}, + std::shared_ptr<CacheableVector>{}); + + region->put("entry.v1", entryV1); + } + + { + auto cache = cluster.createCache(); + auto region = setupRegion(cache); + cache.getTypeRegistry().registerPdxType( + DeliveryAddress::createDeserializable); + + DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_1); + auto entry = region->get("entry.v1"); + EXPECT_TRUE(entry); + + auto address = std::dynamic_pointer_cast<DeliveryAddress>(entry); + EXPECT_TRUE(address); + EXPECT_EQ(*entryV1, *address); Review Comment: Please use the `EXPECT_THAT` or `ASSERT_THAT` form over the older `EXPECT_*` and `ASSERT_*` macros. ```c++ EXPECT_THAT(*entryV1, Eq(*address)); ``` https://google.github.io/googletest/reference/matchers.html ########## cppcache/src/CacheImpl.hpp: ########## @@ -134,6 +134,12 @@ class APACHE_GEODE_EXPORT CacheImpl { */ DistributedSystem& getDistributedSystem(); Review Comment: Any chance this non `const` version can be refactored out? ########## cppcache/integration/test/PdxSerializableTest.cpp: ########## @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <framework/Cluster.h> + +#include <iostream> +#include <memory> + +#include <gtest/gtest.h> + +#include <geode/Cache.hpp> +#include <geode/FunctionService.hpp> +#include <geode/PdxWrapper.hpp> +#include <geode/PoolManager.hpp> +#include <geode/RegionFactory.hpp> +#include <geode/RegionShortcut.hpp> +#include <geode/TypeRegistry.hpp> + +#include "DeliveryAddress.hpp" + +namespace { + +using apache::geode::client::Cache; +using apache::geode::client::Cacheable; +using apache::geode::client::CacheableString; +using apache::geode::client::CacheableVector; +using apache::geode::client::FunctionService; +using apache::geode::client::PdxReader; +using apache::geode::client::PdxSerializable; +using apache::geode::client::PdxWriter; +using apache::geode::client::Region; +using apache::geode::client::RegionShortcut; + +using PdxTests::DeliveryAddress; + +std::shared_ptr<Region> setupRegion(Cache& cache) { + auto region = cache.createRegionFactory(RegionShortcut::PROXY) + .setPoolName("default") + .create("region"); + + return region; +} + +/** + * This test perform the following steps: + * 1. Writes a version 1 entry of DeliveryAddress named 'entry.v1' + * 2. From another cache, fetches the entry 'entry.v1' + * 3. From the same cache as step 2, it call function PutDeliveryAddress that + * writes a version 2 entry of DeliveryAddress named 'entry.v2' + * 4. From another cache, try to fetch the entry 'entry.v2' and it should match + * the entry written in step 3 + * + * The purpose of this test is to verify that even if there are 2 versions of + * the same PdxSerializable class, the right PdxType will be used during + * (de)serialization + */ +TEST(PdxSerializableTest, testRightPdxTypeForDiffPdxVersions) { + Cluster cluster{LocatorCount{1}, ServerCount{1}}; + cluster.start([&]() { + cluster.getGfsh() + .deploy() + .jar(getFrameworkString(FrameworkVariable::JavaObjectJarPath)) + .execute(); + }); + cluster.getGfsh() + .create() + .region() + .withName("region") + .withType("REPLICATE") + .execute(); + + std::shared_ptr<DeliveryAddress> entryV1; + std::shared_ptr<DeliveryAddress> entryV2; + + { + auto cache = cluster.createCache(); + auto region = setupRegion(cache); + cache.getTypeRegistry().registerPdxType( + DeliveryAddress::createDeserializable); + + DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_1); + entryV1 = std::make_shared<DeliveryAddress>( + "Some address line", "Some city", "Some country", std::string{}, + std::shared_ptr<CacheableVector>{}); + + region->put("entry.v1", entryV1); + } + + { + auto cache = cluster.createCache(); + auto region = setupRegion(cache); + cache.getTypeRegistry().registerPdxType( + DeliveryAddress::createDeserializable); + + DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_1); + auto entry = region->get("entry.v1"); + EXPECT_TRUE(entry); + + auto address = std::dynamic_pointer_cast<DeliveryAddress>(entry); + EXPECT_TRUE(address); + EXPECT_EQ(*entryV1, *address); + + DeliveryAddress::setSerializationVersion(DeliveryAddress::VERSION_2); + entryV2 = std::make_shared<DeliveryAddress>( + "Some address line", "Some city", "Some country", "Some instructions", + std::shared_ptr<CacheableVector>{}); + + auto args = CacheableVector::create(); + args->push_back(CacheableString::create("region")); + args->push_back(CacheableString::create("entry.v2")); + args->push_back(CacheableString::create("Some address line")); + args->push_back(CacheableString::create("Some city")); + args->push_back(CacheableString::create("Some country")); + args->push_back(CacheableString::create("Some instructions")); + + auto collector = FunctionService::onServer(region->getRegionService()) + .withArgs(args) + .execute("PutDeliveryAddress"); + EXPECT_TRUE(collector); + + auto resultSet = collector->getResult(); + EXPECT_TRUE(resultSet); + + auto result = std::dynamic_pointer_cast<CacheableString>((*resultSet)[0]); + std::cerr << result->toString() << std::endl; + } + + { + auto cache = cluster.createCache(); + auto region = setupRegion(cache); + cache.getTypeRegistry().registerPdxType( + DeliveryAddress::createDeserializable); + + auto entry = region->get("entry.v2"); + EXPECT_TRUE(entry); Review Comment: This, and all the other `std::shared_ptr` nullability checks, should be `EXPECT_THAT(entry, IsNotNull())`. > Refactor PDX (de)serialziation code to align it with Java client > ---------------------------------------------------------------- > > Key: GEODE-10276 > URL: https://issues.apache.org/jira/browse/GEODE-10276 > Project: Geode > Issue Type: Improvement > Components: native client > Reporter: Mario Salazar de Torres > Assignee: Mario Salazar de Torres > Priority: Major > Labels: pull-request-available > > Currently there are the following open issues regarding PDX (de)serialization: > * [GEODE-9968 - Fix deserialization for new fields in PdxSerializable > class|https://issues.apache.org/jira/browse/GEODE-9968] > * [GEODE-9753 - Coredump during PdxSerializable object > serialization|https://issues.apache.org/jira/browse/GEODE-9753] > * [GEODE-10220 - Coredump while initializing PdxType > remoteToLocal|https://issues.apache.org/jira/browse/GEODE-10220] > * [GEODE-10255 - PdxSerializable not working correctly for multiple versions > of the same class|https://issues.apache.org/jira/browse/GEODE-10255] > Also, the implementation on this ticket ([GEODE-8212: Reduce connections to > server to get type id|https://issues.apache.org/jira/browse/GEODE-8212]) > poses some issues with PDX entries which fields are a permutation. Thing is > that PdxTypes which fields are a permutation might use the wrong offsets, > leading to a corrupt serialization. This is something that was not taken into > account at the time of getting this PR merged. > So this ticket should be reverted and possibly an alternative solution > proposed. > In order to tackle these issues, a code refactoring is needed to introduce > the following implementations: > * Single type of PdxWriter > * An implementation PdxReader that tracks unread data, and other that don't. > * An implementation for PdxInstances that guarantees that fields are > actually written in alphabetical order, independently of the writeFields call > order. This should tackle the issue described above regarding GEODE-8212. > * Also, it'd be ideal to make it so PDX code is cleaner and easier to > understand, though that's a complex matter, and also, subjective. -- This message was sent by Atlassian Jira (v8.20.7#820007)