You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2020/04/29 14:51:35 UTC

[geode-native] branch develop updated: GEODE-7944: Fix for QueueConnectionRequest message (#593)

This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 92af070  GEODE-7944: Fix for QueueConnectionRequest message (#593)
92af070 is described below

commit 92af070aca9525e3a442715dc7479a2e4d066f76
Author: Jakov Varenina <62...@users.noreply.github.com>
AuthorDate: Wed Apr 29 16:51:25 2020 +0200

    GEODE-7944: Fix for QueueConnectionRequest message (#593)
    
    
    ClientProxyMembershipID correctly encapsulated within QueueConnectionRequest
    to avoid "Unable to deserialize membership id java.io.EOFException" on
    locator when trying to log recevied ClientProxyMembershipID on debug level
    
    
    Return type char* of method getDSMemberId() replaced with std::string&
---
 cppcache/src/ClientProxyMembershipID.cpp     |  5 +-
 cppcache/src/ClientProxyMembershipID.hpp     |  2 +-
 cppcache/src/QueueConnectionRequest.cpp      |  7 ++-
 cppcache/src/TcrConnection.cpp               | 14 +++--
 cppcache/test/CMakeLists.txt                 |  1 +
 cppcache/test/QueueConnectionRequestTest.cpp | 78 ++++++++++++++++++++++++++++
 6 files changed, 91 insertions(+), 16 deletions(-)

diff --git a/cppcache/src/ClientProxyMembershipID.cpp b/cppcache/src/ClientProxyMembershipID.cpp
index 6ebfa36..ed0fc98 100644
--- a/cppcache/src/ClientProxyMembershipID.cpp
+++ b/cppcache/src/ClientProxyMembershipID.cpp
@@ -175,9 +175,8 @@ void ClientProxyMembershipID::initObjectVars(
   LOGDEBUG("GethashKey %s client id: %s ", m_hashKey.c_str(), clientID.c_str());
 }
 
-const char* ClientProxyMembershipID::getDSMemberId(uint32_t& mesgLength) const {
-  mesgLength = static_cast<int32_t>(m_memIDStr.size());
-  return m_memIDStr.c_str();
+const std::string& ClientProxyMembershipID::getDSMemberId() const {
+  return m_memIDStr;
 }
 
 const std::string& ClientProxyMembershipID::getDSMemberIdForThinClientUse() {
diff --git a/cppcache/src/ClientProxyMembershipID.hpp b/cppcache/src/ClientProxyMembershipID.hpp
index 6125e46..201eeac 100644
--- a/cppcache/src/ClientProxyMembershipID.hpp
+++ b/cppcache/src/ClientProxyMembershipID.hpp
@@ -42,7 +42,7 @@ class ClientProxyMembershipID;
 
 class ClientProxyMembershipID : public DSMemberForVersionStamp {
  public:
-  const char* getDSMemberId(uint32_t& mesgLength) const;
+  const std::string& getDSMemberId() const;
 
   ClientProxyMembershipID(std::string dsName, std::string randString,
                           const char* hostname, const ACE_INET_Addr& address,
diff --git a/cppcache/src/QueueConnectionRequest.cpp b/cppcache/src/QueueConnectionRequest.cpp
index 68ab055..98e024d 100644
--- a/cppcache/src/QueueConnectionRequest.cpp
+++ b/cppcache/src/QueueConnectionRequest.cpp
@@ -28,10 +28,9 @@ void QueueConnectionRequest::toData(DataOutput& output) const {
   output.writeString(m_serverGp);
   output.write(static_cast<int8_t>(DSCode::FixedIDByte));
   output.write(static_cast<int8_t>(DSCode::ClientProxyMembershipId));
-  uint32_t buffLen = 0;
-  output.writeBytes(reinterpret_cast<uint8_t*>(const_cast<char*>(
-                        m_membershipID.getDSMemberId(buffLen))),
-                    buffLen);
+  const auto& dsMemberId = m_membershipID.getDSMemberId();
+  output.writeBytes(reinterpret_cast<const uint8_t*>(dsMemberId.c_str()),
+                    dsMemberId.size());
   output.writeInt(static_cast<int32_t>(1));
   output.writeInt(static_cast<int32_t>(m_redundantCopies));
   writeSetOfServerLocation(output);
diff --git a/cppcache/src/TcrConnection.cpp b/cppcache/src/TcrConnection.cpp
index 75ee916..783984f 100644
--- a/cppcache/src/TcrConnection.cpp
+++ b/cppcache/src/TcrConnection.cpp
@@ -158,11 +158,10 @@ bool TcrConnection::initTcrConnection(
   if (endpointObj->getPoolHADM()) {
     ClientProxyMembershipID* memId =
         endpointObj->getPoolHADM()->getMembershipId();
-    uint32_t memIdBufferLength;
-    auto memIdBuffer = memId->getDSMemberId(memIdBufferLength);
+    const auto& dsMemberId = memId->getDSMemberId();
     handShakeMsg.writeBytes(
-        reinterpret_cast<int8_t*>(const_cast<char*>(memIdBuffer)),
-        memIdBufferLength);
+        reinterpret_cast<const uint8_t*>(dsMemberId.c_str()),
+        dsMemberId.size());
   } else {
     ACE_TCHAR hostName[256];
     ACE_OS::hostname(hostName, sizeof(hostName) - 1);
@@ -177,13 +176,12 @@ bool TcrConnection::initTcrConnection(
     auto&& durableTimeOut = sysProp.durableTimeout();
 
     // Write ClientProxyMembershipID serialized object.
-    uint32_t memIdBufferLength;
     auto memId = cacheImpl->getClientProxyMembershipIDFactory().create(
         hostName, driver, hostPort, durableId.c_str(), durableTimeOut);
-    auto memIdBuffer = memId->getDSMemberId(memIdBufferLength);
+    const auto& dsMemberId = memId->getDSMemberId();
     handShakeMsg.writeBytes(
-        reinterpret_cast<int8_t*>(const_cast<char*>(memIdBuffer)),
-        memIdBufferLength);
+        reinterpret_cast<const uint8_t*>(dsMemberId.c_str()),
+        dsMemberId.size());
   }
   handShakeMsg.writeInt(static_cast<int32_t>(1));
 
diff --git a/cppcache/test/CMakeLists.txt b/cppcache/test/CMakeLists.txt
index 9f45707..f13af10 100644
--- a/cppcache/test/CMakeLists.txt
+++ b/cppcache/test/CMakeLists.txt
@@ -41,6 +41,7 @@ add_executable(apache-geode_unittests
   InterestResultPolicyTest.cpp
   LocalRegionTest.cpp
   PdxInstanceImplTest.cpp
+  QueueConnectionRequestTest.cpp
   RegionAttributesFactoryTest.cpp
   SerializableCreateTests.cpp
   StructSetTest.cpp
diff --git a/cppcache/test/QueueConnectionRequestTest.cpp b/cppcache/test/QueueConnectionRequestTest.cpp
new file mode 100644
index 0000000..b5d7053
--- /dev/null
+++ b/cppcache/test/QueueConnectionRequestTest.cpp
@@ -0,0 +1,78 @@
+/*
+ * 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 <QueueConnectionRequest.hpp>
+
+#include <boost/process/environment.hpp>
+
+#include <gtest/gtest.h>
+
+#include <geode/DataOutput.hpp>
+
+#include "ByteArrayFixture.hpp"
+#include "DataOutputInternal.hpp"
+
+namespace apache {
+namespace geode {
+namespace client {
+
+inline std::string to_hex(const uint8_t* bytes, size_t len) {
+  std::stringstream ss;
+  ss << std::setfill('0') << std::hex;
+  for (size_t i(0); i < len; ++i) {
+    ss << std::setw(2) << static_cast<int>(bytes[i]);
+  }
+  return ss.str();
+}
+
+inline std::string to_hex(const DataOutput& out) {
+  return to_hex(out.getBuffer(), out.getBufferLength());
+}
+
+inline std::string int_to_hex_string(const int value) {
+  char hex[10];
+  sprintf(hex, "%x", value);
+  return std::string(hex);
+}
+
+TEST(QueueConnectionRequestTest, testToData) {
+  DataOutputInternal dataOutput;
+  ACE_INET_Addr addr(10, "localhost");
+  ServerLocation srv("server", 10);
+  std::set<ServerLocation> servLoc;
+  servLoc.insert(srv);
+  std::string dsName = "dsName";
+  std::string randNum = "randNum";
+
+  ClientProxyMembershipID qCR(dsName, randNum, "name", addr, 10, "id-1",
+                              std::chrono::seconds(0));
+
+  QueueConnectionRequest queueConnReq(qCR, servLoc, -1, false);
+  queueConnReq.toData(dataOutput);
+
+  auto pid = int_to_hex_string(boost::this_process::get_id());
+  auto expectedQueueConnectionRequest =
+      "2a0000012631015c047f000001000000022a00046e616d65000000302e0000" + pid +
+      "0d002a000664734e616d652a000772616e644e756d2d00000001ffffffff000000012a00"
+      "067365727665720000000a00";
+
+  EXPECT_EQ(expectedQueueConnectionRequest, to_hex(dataOutput));
+}
+
+}  // namespace client
+}  // namespace geode
+}  // namespace apache