[ https://issues.apache.org/jira/browse/GEODE-8562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17250402#comment-17250402 ]
ASF GitHub Bot commented on GEODE-8562: --------------------------------------- pivotal-jbarrett commented on a change in pull request #714: URL: https://github.com/apache/geode-native/pull/714#discussion_r544384826 ########## File path: cppcache/integration/test/Position.cpp ########## @@ -0,0 +1,124 @@ +/* + * 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 "Position.hpp" + +#include <wchar.h> + +#include <cwchar> + +#include <geode/DataInput.hpp> +#include <geode/DataOutput.hpp> + +namespace DataSerializableTest { + +int32_t Position::cnt = 0; + +Position::Position() { init(); } + +Position::Position(const char* id, int32_t out) { Review comment: This source smells like it was lifted from somewhere without care to bring it up to our high standards. Can you please: * Use `std::string` rather than `char *`. * Readable and descriptive variable names. (What is `out`?) * Inner class members should not be `CacheableX` types. * Don't use C methods where C++ methods exist, like `sprintf`. ########## File path: cppcache/integration/test/Position.hpp ########## @@ -0,0 +1,100 @@ +/* + * 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. + */ + +#pragma once + +#ifndef POSITION_H +#define POSITION_H + +/* + * @brief User class for testing the put functionality for object. + */ + +#include <string> + +#include <geode/CacheableString.hpp> +#include <geode/DataSerializable.hpp> + +namespace DataSerializableTest { + +using apache::geode::client::CacheableString; +using apache::geode::client::DataInput; +using apache::geode::client::DataOutput; +using apache::geode::client::DataSerializable; + +class Position : public DataSerializable { + private: + int64_t avg20DaysVol; + std::shared_ptr<CacheableString> bondRating; Review comment: Use `std::string`. ########## File path: cppcache/integration/test/Position.hpp ########## @@ -0,0 +1,100 @@ +/* + * 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. + */ + +#pragma once + +#ifndef POSITION_H +#define POSITION_H + +/* + * @brief User class for testing the put functionality for object. + */ + +#include <string> + +#include <geode/CacheableString.hpp> +#include <geode/DataSerializable.hpp> + +namespace DataSerializableTest { + +using apache::geode::client::CacheableString; +using apache::geode::client::DataInput; +using apache::geode::client::DataOutput; +using apache::geode::client::DataSerializable; + +class Position : public DataSerializable { + private: + int64_t avg20DaysVol; + std::shared_ptr<CacheableString> bondRating; + double convRatio; + std::shared_ptr<CacheableString> country; + double delta; + int64_t industry; + int64_t issuer; + double mktValue; + double qty; + std::shared_ptr<CacheableString> secId; + std::shared_ptr<CacheableString> secLinks; + // wchar_t* secType; Review comment: Delete commented code. ########## File path: tests/javaobject/cli/InstantiateDataSerializable.java ########## @@ -32,15 +32,16 @@ public class InstantiateDataSerializable extends FunctionAdapter implements Declarable{ public void execute(FunctionContext context) { - Instantiator.register(new Instantiator(javaobject.cli.Position.class, 22) { + + Instantiator.register(new Instantiator(javaobject.cli.PositionKey.class, 21) { public DataSerializable newInstance() { - return new javaobject.cli.Position(); + return new javaobject.cli.PositionKey(); } }); - Instantiator.register(new Instantiator(javaobject.cli.PositionKey.class, 77) { Review comment: Why change the ID from 77 to 21? Have all the older tests expecting 77 been updated? ########## File path: cppcache/integration/test/PositionKey.cpp ########## @@ -0,0 +1,46 @@ +/* + * 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 "PositionKey.hpp" + +#include <wchar.h> + +#include <cwchar> + +#include <geode/DataInput.hpp> +#include <geode/DataOutput.hpp> + +namespace DataSerializableTest { + +void PositionKey::toData(DataOutput& output) const { + output.writeInt(m_positionId); +} + +void PositionKey::fromData(apache::geode::client::DataInput& input) { + m_positionId = input.readInt64(); +} + +bool PositionKey::operator==(const CacheableKey& other) const { + return m_positionId == ((PositionKey&)other).getPositionId(); +} + +int PositionKey::hashcode() const { + int hash = 11; + hash = 31 * hash + (int)m_positionId; Review comment: This hash function does not match the Java version of this type. This should be fixed or partitioning will be off. Also very odd both just down cast `positionId`. Regardless you should use `static_cast<int32_t>()` not C-style casts. ########## File path: tests/javaobject/cli/PositionKey.java ########## @@ -26,7 +26,7 @@ private long positionId; static { - Instantiator.register(new Instantiator(javaobject.cli.PositionKey.class, (byte) 77) { + Instantiator.register(new Instantiator(javaobject.cli.PositionKey.class, (byte) 21) { Review comment: I don't know why it casts this literal to a `byte`, the method takes an `int`. Remove the cast. ########## File path: cppcache/integration/test/Position.hpp ########## @@ -0,0 +1,100 @@ +/* + * 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. + */ + +#pragma once + +#ifndef POSITION_H +#define POSITION_H + +/* + * @brief User class for testing the put functionality for object. + */ + +#include <string> + +#include <geode/CacheableString.hpp> +#include <geode/DataSerializable.hpp> + +namespace DataSerializableTest { + +using apache::geode::client::CacheableString; +using apache::geode::client::DataInput; +using apache::geode::client::DataOutput; +using apache::geode::client::DataSerializable; + +class Position : public DataSerializable { + private: + int64_t avg20DaysVol; + std::shared_ptr<CacheableString> bondRating; + double convRatio; + std::shared_ptr<CacheableString> country; + double delta; + int64_t industry; + int64_t issuer; + double mktValue; + double qty; + std::shared_ptr<CacheableString> secId; + std::shared_ptr<CacheableString> secLinks; + // wchar_t* secType; + std::wstring secType; + int32_t sharesOutstanding; + std::shared_ptr<CacheableString> underlyer; + int64_t volatility; + int32_t pid; + + inline size_t getObjectSize(const std::shared_ptr<Serializable>& obj) const { + return (obj == nullptr ? 0 : obj->objectSize()); + } + + public: + static int32_t cnt; + + Position(); + Position(const char* id, int32_t out); + // This constructor is just for some internal data validation test + explicit Position(int32_t iForExactVal); + ~Position() override = default; + void toData(DataOutput& output) const override; + void fromData(DataInput& input) override; + std::string toString() const override; + + size_t objectSize() const override { Review comment: Unless this or any other test is using usage based eviction we should eliminate the noise of `objectSize`. ########## File path: cppcache/integration/test/PositionKey.hpp ########## @@ -0,0 +1,58 @@ +/* + * 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. + */ + +#pragma once + +#ifndef POSITIONKEY_H_ +#define POSITIONKEY_H_ + +#include <string> + +#include <geode/CacheableString.hpp> +#include <geode/DataSerializable.hpp> + +namespace DataSerializableTest { + +using apache::geode::client::CacheableKey; +using apache::geode::client::DataInput; +using apache::geode::client::DataOutput; +using apache::geode::client::DataSerializable; + +class PositionKey : public DataSerializable, public CacheableKey { + private: + int64_t m_positionId; + + public: + PositionKey() {} + PositionKey(int64_t positionId) { m_positionId = positionId; } + ~PositionKey() override = default; + + bool operator==(const CacheableKey& other) const; + int32_t hashcode() const; Review comment: Missing `override`. ########## File path: cppcache/integration/test/Position.hpp ########## @@ -0,0 +1,100 @@ +/* + * 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. + */ + +#pragma once + +#ifndef POSITION_H +#define POSITION_H + +/* + * @brief User class for testing the put functionality for object. + */ + +#include <string> + +#include <geode/CacheableString.hpp> +#include <geode/DataSerializable.hpp> + +namespace DataSerializableTest { + +using apache::geode::client::CacheableString; +using apache::geode::client::DataInput; +using apache::geode::client::DataOutput; +using apache::geode::client::DataSerializable; + +class Position : public DataSerializable { + private: + int64_t avg20DaysVol; + std::shared_ptr<CacheableString> bondRating; + double convRatio; + std::shared_ptr<CacheableString> country; + double delta; + int64_t industry; + int64_t issuer; + double mktValue; Review comment: Readable fully qualified variable names please. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add a new serialization test and example that uses a class for the key > ---------------------------------------------------------------------- > > Key: GEODE-8562 > URL: https://issues.apache.org/jira/browse/GEODE-8562 > Project: Geode > Issue Type: Improvement > Components: native client > Reporter: Michael Martell > Priority: Major > Labels: pull-request-available > > There appears to be no native client tests that use a class for the key. > A new DataSerializable test should be added (new framework of course) that > uses a class that implements DataSerializable for both the key and the value. > Also, the test should be added for both C++ and .NET. > Also update the existing put/get examples to include using a class as the > key. Note, this will require Java code that instantiates the key class. > Notes: > * > Using a class as a key requires the equivalent Java class to be deployed, as > well as an Instantiator for that class to be executed by the server on > startup. An example of this is the > QueryTest::DataSerializableQueryHaveCorrectValues which uses Position.cs and > Position.java. > * In this existing test, Position.java needs to be deployed and instantiated > because the test executes queries. In this new test, we need to deploy and > instantiate the java code for the key class because it's a key not a value. -- This message was sent by Atlassian Jira (v8.3.4#803005)