This is an automated email from the ASF dual-hosted git repository.
bbender 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 e1d5223 GEODE-7207: Fix remaining LGTM "Error" level alerts (#526)
e1d5223 is described below
commit e1d52235cf2b3607e522c6c40aa81a4deb6f3ef2
Author: Blake Bender <[email protected]>
AuthorDate: Fri Oct 4 14:51:52 2019 +0000
GEODE-7207: Fix remaining LGTM "Error" level alerts (#526)
* GEODE-7207: Fix LGTM complaints
- Clean up FunctionExecutionTest
- Remove unneeded cast
- remove cast in UnitTestsN.cs
- remove unused servers_ variable
- use System conversion to double, rather than implicit cast
- Fix compilation error
- Convert numOps to double
Co-authored-by: Michael Oleske <[email protected]>
---
clicache/integration-test/ThinClientPdxTests1.cs | 10 +++---
clicache/integration-test/UnitTestsN.cs | 6 ++--
clicache/integration-test2/Cluster.cs | 3 --
.../integration-test2/FunctionExecutionTest.cs | 41 +++++++---------------
cppcache/src/ClientProxyMembershipID.hpp | 11 +++---
cppcache/src/RegionExpiryHandler.cpp | 2 +-
cppcache/src/TcrConnection.cpp | 2 +-
cppcache/src/TcrEndpoint.cpp | 12 +++----
cppcache/src/ThinClientRegion.cpp | 2 +-
cppcache/test/ClientProxyMembershipIDTest.cpp | 5 +++
10 files changed, 41 insertions(+), 53 deletions(-)
diff --git a/clicache/integration-test/ThinClientPdxTests1.cs
b/clicache/integration-test/ThinClientPdxTests1.cs
index d00cb24..8ae2ecd 100755
--- a/clicache/integration-test/ThinClientPdxTests1.cs
+++ b/clicache/integration-test/ThinClientPdxTests1.cs
@@ -1855,7 +1855,7 @@ namespace Apache.Geode.Client.UnitTests
{
[PdxIdentityField] public string Key;
public int SecKey;
- public double ShareQuantity;
+ public long ShareQuantity;
public double Cost;
public double Price;
public int SettleSecKey;
@@ -1872,8 +1872,8 @@ namespace Apache.Geode.Client.UnitTests
{
Key = key.ToString();
SecKey = key;
- ShareQuantity = (double)((long)key * 9278L);
- Cost = ShareQuantity * 100;
+ ShareQuantity = key * 9278L;
+ Cost = Convert.ToDouble(ShareQuantity) * 100;
Price = Cost * 10;
SettleSecKey = SecKey + 100000;
SettleFxRate = Price * 1.5;
@@ -1893,7 +1893,7 @@ namespace Apache.Geode.Client.UnitTests
{
Key = reader.ReadString("Key");
SecKey = reader.ReadInt("SecKey");
- ShareQuantity = reader.ReadDouble("ShareQuantity");
+ ShareQuantity = reader.ReadLong("ShareQuantity");
Cost = reader.ReadDouble("Cost");
Price = reader.ReadDouble("Price");
SettleSecKey = reader.ReadInt("SettleSecKey");
@@ -1907,7 +1907,7 @@ namespace Apache.Geode.Client.UnitTests
{
writer.WriteString("Key", Key);
writer.WriteInt("SecKey", SecKey);
- writer.WriteDouble("ShareQuantity", ShareQuantity);
+ writer.WriteLong("ShareQuantity", ShareQuantity);
writer.WriteDouble("Cost", Cost);
writer.WriteDouble("Price", Price);
writer.WriteInt("SettleSecKey", SettleSecKey);
diff --git a/clicache/integration-test/UnitTestsN.cs
b/clicache/integration-test/UnitTestsN.cs
index 85b147c..69ce614 100644
--- a/clicache/integration-test/UnitTestsN.cs
+++ b/clicache/integration-test/UnitTestsN.cs
@@ -171,10 +171,12 @@ namespace Apache.Geode.Client.UnitTests
public void LogTaskTiming(ClientBase client, string taskName, int numOps)
{
StopTimer();
- TimeSpan elapsed = m_endTime - m_startTime;
+ var elapsed = m_endTime - m_startTime;
+ var milliseconds = Math.Round(elapsed.TotalMilliseconds, 3);
+ milliseconds = (Convert.ToDouble(numOps) * 1000) / milliseconds;
Util.Log("{0}Time taken for task [{1}]: {2}ms {3}ops/sec{4}",
Util.MarkerString, taskName, elapsed.TotalMilliseconds,
- ((long)numOps * 1000) / elapsed.TotalMilliseconds, Util.MarkerString);
+ milliseconds, Util.MarkerString);
}
}
}
diff --git a/clicache/integration-test2/Cluster.cs
b/clicache/integration-test2/Cluster.cs
index 8ceb219..672d302 100644
--- a/clicache/integration-test2/Cluster.cs
+++ b/clicache/integration-test2/Cluster.cs
@@ -32,7 +32,6 @@ namespace Apache.Geode.Client.IntegrationTests
private int serverCount_;
private bool started_;
private List<Locator> locators_;
- private List<Server> servers_;
private string name_;
internal int jmxManagerPort = Framework.FreeTcpPort();
internal string keyStore_ = Environment.CurrentDirectory +
"/ServerSslKeys/server_keystore.jks";
@@ -63,7 +62,6 @@ namespace Apache.Geode.Client.IntegrationTests
locatorCount_ = locatorCount;
serverCount_ = serverCount;
locators_ = new List<Locator>();
- servers_ = new List<Server>();
}
private bool StartLocators()
@@ -88,7 +86,6 @@ namespace Apache.Geode.Client.IntegrationTests
{
var server = new Server(this, locators_,
name_ + "/server/" + i.ToString());
- servers_.Add(server);
var localResult = server.Start();
if (localResult != 0)
{
diff --git a/clicache/integration-test2/FunctionExecutionTest.cs
b/clicache/integration-test2/FunctionExecutionTest.cs
index 81b4018..847354b 100644
--- a/clicache/integration-test2/FunctionExecutionTest.cs
+++ b/clicache/integration-test2/FunctionExecutionTest.cs
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-using System;
using System.Collections;
using System.Collections.Generic;
-using System.IO;
+using System.Linq;
using Xunit;
using Xunit.Abstractions;
@@ -34,7 +33,7 @@ namespace Apache.Geode.Client.IntegrationTests
[Fact]
public void MultiGetFunctionExecutionWithFilter()
{
- int expectedFilteredCount = 34;
+ const int expectedFilteredCount = 34;
using (var cluster = new Cluster(output,
CreateTestCaseDirectoryName(), 1, 1))
{
Assert.True(cluster.Start());
@@ -56,9 +55,9 @@ namespace Apache.Geode.Client.IntegrationTests
region["KEY--" + i] = "VALUE--" + i;
}
- var args = true;
+ const bool args = true;
- var oddKeyFilter = new Object[17];
+ var oddKeyFilter = new object[17];
var j = 0;
for (var i = 0; i < 34; i++)
{
@@ -67,18 +66,11 @@ namespace Apache.Geode.Client.IntegrationTests
j++;
}
- var exc =
Client.FunctionService<List<object>>.OnRegion<object, object>(region);
- var rc =
exc.WithArgs<bool>(args).WithFilter<object>(oddKeyFilter).Execute("MultiGetFunction");
+ var exc = FunctionService<List<object>>.OnRegion(region);
+ var rc =
exc.WithArgs(args).WithFilter(oddKeyFilter).Execute("MultiGetFunction");
var executeFunctionResult = rc.GetResult();
- var resultList = new List<object>();
+ var resultList = executeFunctionResult.SelectMany(item =>
item).ToList();
- foreach (var item in executeFunctionResult)
- {
- foreach (object item2 in item)
- {
- resultList.Add(item2);
- }
- }
Assert.Equal(expectedFilteredCount, resultList.Count);
}
@@ -87,7 +79,7 @@ namespace Apache.Geode.Client.IntegrationTests
[Fact]
public void MultiGetIFunctionExecutionWithArgs()
{
- int expectedResultCount = 17;
+ const int expectedResultCount = 17;
using (var cluster = new Cluster(output,
CreateTestCaseDirectoryName(), 1, 1))
{
Assert.True(cluster.Start());
@@ -117,18 +109,11 @@ namespace Apache.Geode.Client.IntegrationTests
oddKeyArgs.Add("KEY--" + i);
}
- var exc =
Client.FunctionService<List<object>>.OnRegion<object, object>(region);
- var rc =
exc.WithArgs<ArrayList>(oddKeyArgs).Execute("MultiGetFunctionI");
+ var exc = FunctionService<List<object>>.OnRegion(region);
+ var rc = exc.WithArgs(oddKeyArgs).Execute("MultiGetFunctionI");
var executeFunctionResult = rc.GetResult();
- var resultList = new List<object>();
+ var resultList = executeFunctionResult.SelectMany(item =>
item).ToList();
- foreach (var item in executeFunctionResult)
- {
- foreach (var item2 in item)
- {
- resultList.Add(item2);
- }
- }
Assert.Equal(expectedResultCount, resultList.Count);
}
}
@@ -148,12 +133,12 @@ namespace Apache.Geode.Client.IntegrationTests
.execute());
var cache = cluster.CreateCache();
- var pool = cache.GetPoolFactory().AddLocator("localhost",
10334).Create("pool");
+ cache.GetPoolFactory().AddLocator("localhost", 10334).Create("pool");
var region = cache.CreateRegionFactory(RegionShortcut.PROXY)
.SetPoolName("pool")
.Create<object, object>("region");
- var exc = Client.FunctionService<List<object>>.OnRegion<object,
object>(region);
+ var exc = FunctionService<List<object>>.OnRegion(region);
Assert.Throws<FunctionExecutionException>(() =>
exc.Execute("executeFunction_SendObjectWhichCantBeDeserialized"));
}
}
diff --git a/cppcache/src/ClientProxyMembershipID.hpp
b/cppcache/src/ClientProxyMembershipID.hpp
index 2f95ef7..683614a 100644
--- a/cppcache/src/ClientProxyMembershipID.hpp
+++ b/cppcache/src/ClientProxyMembershipID.hpp
@@ -20,6 +20,7 @@
#ifndef GEODE_CLIENTPROXYMEMBERSHIPID_H_
#define GEODE_CLIENTPROXYMEMBERSHIPID_H_
+#include <sstream>
#include <string>
#include <vector>
@@ -95,14 +96,12 @@ class ClientProxyMembershipID : public
DSMemberForVersionStamp {
int16_t compareTo(const DSMemberForVersionStamp&) const override;
int32_t hashcode() const override {
uint32_t result = 0;
- char hostInfo[255] = {0};
- uint32_t offset = 0;
+ std::stringstream hostAddressString;
+ hostAddressString << std::hex;
for (uint32_t i = 0; i < getHostAddrLen(); i++) {
- offset +=
- std::snprintf(hostInfo + offset, 255 - offset, ":%x", m_hostAddr[i]);
+ hostAddressString << ":" << static_cast<int>(m_hostAddr[i]);
}
- result +=
- internal::geode_hash<std::string>{}(std::string(hostInfo, offset));
+ result += internal::geode_hash<std::string>{}(hostAddressString.str());
result += m_hostPort;
return result;
}
diff --git a/cppcache/src/RegionExpiryHandler.cpp
b/cppcache/src/RegionExpiryHandler.cpp
index 58e2348..a10d8cf 100644
--- a/cppcache/src/RegionExpiryHandler.cpp
+++ b/cppcache/src/RegionExpiryHandler.cpp
@@ -66,7 +66,7 @@ int RegionExpiryHandler::handle_timeout(const ACE_Time_Value&
current_time,
auto remaining = m_duration - elapsed;
// reset the task after
// (lastAccessTime + entryExpiryDuration - curr_time) in seconds
- LOGDEBUG("Resetting expiry task for region [%s] after %d sec",
+ LOGDEBUG("Resetting expiry task for region [%s] after %z sec",
m_regionPtr->getFullPath().c_str(), remaining.count());
m_regionPtr->getCacheImpl()->getExpiryTaskManager().resetTask(
m_expiryTaskId, remaining);
diff --git a/cppcache/src/TcrConnection.cpp b/cppcache/src/TcrConnection.cpp
index 8743473..70febbf 100644
--- a/cppcache/src/TcrConnection.cpp
+++ b/cppcache/src/TcrConnection.cpp
@@ -616,7 +616,7 @@ inline ConnErrType TcrConnection::receiveData(
readHandshakeRawData, readHandShakeBytes, readHandShakeInt,
readHandshakeString, all call TcrConnection::receiveData.
*/
- LOGDEBUG("TcrConnection::receiveData length = %d defaultWaitSecs = %z",
+ LOGDEBUG("TcrConnection::receiveData length = %zu defaultWaitSecs = %z",
length, defaultWaitSecs.count());
if (m_poolDM != nullptr) {
LOGDEBUG("TcrConnection::receiveData readBytes = %zu", readBytes);
diff --git a/cppcache/src/TcrEndpoint.cpp b/cppcache/src/TcrEndpoint.cpp
index 2925d64..293a314 100644
--- a/cppcache/src/TcrEndpoint.cpp
+++ b/cppcache/src/TcrEndpoint.cpp
@@ -265,7 +265,7 @@ GfErrType TcrEndpoint::createNewConnection(
void TcrEndpoint::authenticateEndpoint(TcrConnection*& conn) {
LOGDEBUG(
"TcrEndpoint::authenticateEndpoint m_isAuthenticated = %d "
- "m_baseDM = %d, connection = %p",
+ "m_baseDM = %p, connection = %p",
m_isAuthenticated, m_baseDM, conn);
if (!m_isAuthenticated && m_baseDM) {
setConnected();
@@ -275,7 +275,7 @@ void TcrEndpoint::authenticateEndpoint(TcrConnection*&
conn) {
auto creds = getCredentials();
if (creds != nullptr) {
- LOGDEBUG("TcrEndpoint::authenticateEndpoint got creds from app = %d",
+ LOGDEBUG("TcrEndpoint::authenticateEndpoint got creds from app = %zu",
creds->getSize());
} else {
LOGDEBUG("TcrEndpoint::authenticateEndpoint no creds from app ");
@@ -755,7 +755,7 @@ GfErrType TcrEndpoint::sendRequestConn(const TcrMessage&
request,
LOGFINER("Sending request type %d to endpoint [%s] via connection [%p]",
type,
m_name.c_str(), conn);
// TcrMessage * req = const_cast<TcrMessage *>(&request);
- LOGDEBUG("TcrEndpoint::sendRequestConn = %d", m_baseDM);
+ LOGDEBUG("TcrEndpoint::sendRequestConn = %p", m_baseDM);
if (m_baseDM != nullptr) m_baseDM->beforeSendingRequest(request, conn);
if (((type == TcrMessage::EXECUTE_FUNCTION ||
type == TcrMessage::EXECUTE_REGION_FUNCTION) &&
@@ -923,7 +923,7 @@ GfErrType TcrEndpoint::sendRequestWithRetry(
} else if (conn == nullptr && useEPPool) {
LOGFINER(
"sendRequestWithRetry:: looking for connection in queue timeout = "
- "%d ",
+ "%z ",
timeout.count());
// max wait time to get a connection
conn = m_opConnections.getUntil(timeout);
@@ -1051,7 +1051,7 @@ GfErrType TcrEndpoint::sendRequestWithRetry(
} else {
error = GF_NOTCON;
LOGFINE(
- "Returning without connection with %d seconds remaining "
+ "Returning without connection with %z seconds remaining "
"for endpoint %s.",
timeout.count(), m_name.c_str());
}
@@ -1241,7 +1241,7 @@ void TcrEndpoint::stopNotifyReceiverAndCleanup() {
m_numRegionListener = 0;
if (!m_notifyConnectionList.empty()) {
- LOGFINER("TcrEndpoint::stopNotifyReceiverAndCleanup: notifylist size = %d",
+ LOGFINER("TcrEndpoint::stopNotifyReceiverAndCleanup: notifylist size =
%zu",
m_notifyConnectionList.size());
for (auto& it : m_notifyConnectionList) {
LOGFINER(
diff --git a/cppcache/src/ThinClientRegion.cpp
b/cppcache/src/ThinClientRegion.cpp
index 8e0cc35..7444d19 100644
--- a/cppcache/src/ThinClientRegion.cpp
+++ b/cppcache/src/ThinClientRegion.cpp
@@ -1673,7 +1673,7 @@ GfErrType
ThinClientRegion::singleHopRemoveAllNoThrow_remote(
// set this flag that indicates putAll on PR is invoked with singlehop
// enabled.
m_isPRSingleHopEnabled = true;
- LOGDEBUG("locationMap.size() = %d ", locationMap->size());
+ LOGDEBUG("locationMap.size() = %zu ", locationMap->size());
/*Step-2
* a. create vector of RemoveAllWork
diff --git a/cppcache/test/ClientProxyMembershipIDTest.cpp
b/cppcache/test/ClientProxyMembershipIDTest.cpp
index 9af6e9f..fba153e 100644
--- a/cppcache/test/ClientProxyMembershipIDTest.cpp
+++ b/cppcache/test/ClientProxyMembershipIDTest.cpp
@@ -23,6 +23,7 @@
#include <gtest/gtest.h>
#include "ClientProxyMembershipID.hpp"
+#include "geode/internal/functional.hpp"
using apache::geode::client::ClientProxyMembershipID;
@@ -44,6 +45,10 @@ TEST(ClientProxyMembershipIDTest, testCreate) {
ASSERT_NE("", uniqueTag);
EXPECT_EQ(std::string(":0:0:0:1:2:myDs:").append(uniqueTag),
cpmID.getHashKey());
+ EXPECT_EQ(
+ cpmID.hashcode(),
+ apache::geode::client::internal::geode_hash<std::string>{}(":0:0:0:1") +
+ static_cast<int32_t>(cpmID.getHostPort()));
EXPECT_TRUE(std::regex_search(
cpmID.getDSMemberIdForThinClientUse(),
std::regex(