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 2018/01/29 23:11:25 UTC
[geode-native] branch develop updated: GEODE-4419: Converts
DiskPolicyType to enum class. (#196)
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 8c26720 GEODE-4419: Converts DiskPolicyType to enum class. (#196)
8c26720 is described below
commit 8c2672006c7ec04e9817b9393cfa73a7618898ae
Author: Jacob Barrett <jb...@pivotal.io>
AuthorDate: Mon Jan 29 15:11:24 2018 -0800
GEODE-4419: Converts DiskPolicyType to enum class. (#196)
---
clicache/src/AttributesFactory.cpp | 2 +-
clicache/src/RegionFactory.cpp | 2 +-
cppcache/include/geode/AttributesFactory.hpp | 2 +-
cppcache/include/geode/DiskPolicyType.hpp | 39 +-----------
cppcache/include/geode/RegionAttributes.hpp | 8 +--
cppcache/include/geode/RegionFactory.hpp | 2 +-
.../integration-test/testOverflowPutGetSqLite.cpp | 2 +-
.../testXmlCacheCreationWithOverFlow.cpp | 2 +-
cppcache/src/AttributesFactory.cpp | 2 +-
cppcache/src/DiskPolicyType.cpp | 46 --------------
cppcache/src/EntriesMapFactory.cpp | 2 +-
cppcache/src/RegionAttributes.cpp | 6 +-
cppcache/src/RegionFactory.cpp | 2 +-
cppcache/test/DiskPolicyTypeTest.cpp | 72 ----------------------
tests/cpp/fwklib/FwkObjects.cpp | 5 --
tests/cpp/fwklib/FwkObjects.hpp | 3 -
16 files changed, 18 insertions(+), 179 deletions(-)
diff --git a/clicache/src/AttributesFactory.cpp b/clicache/src/AttributesFactory.cpp
index 5d9fe0a..e9c71c7 100644
--- a/clicache/src/AttributesFactory.cpp
+++ b/clicache/src/AttributesFactory.cpp
@@ -430,7 +430,7 @@ namespace Apache
{
try
{
- m_nativeptr->get()->setDiskPolicy(static_cast<native::DiskPolicyType::PolicyType>( diskPolicy ) );
+ m_nativeptr->get()->setDiskPolicy(static_cast<native::DiskPolicyType>( diskPolicy ) );
}
finally
{
diff --git a/clicache/src/RegionFactory.cpp b/clicache/src/RegionFactory.cpp
index b292406..07a4c8b 100644
--- a/clicache/src/RegionFactory.cpp
+++ b/clicache/src/RegionFactory.cpp
@@ -303,7 +303,7 @@ namespace Apache
{
try
{
- m_nativeptr->get()->setDiskPolicy(static_cast<native::DiskPolicyType::PolicyType>( diskPolicy ) );
+ m_nativeptr->get()->setDiskPolicy(static_cast<native::DiskPolicyType>( diskPolicy ) );
}
finally
{
diff --git a/cppcache/include/geode/AttributesFactory.hpp b/cppcache/include/geode/AttributesFactory.hpp
index 0f38097..dfa716e 100644
--- a/cppcache/include/geode/AttributesFactory.hpp
+++ b/cppcache/include/geode/AttributesFactory.hpp
@@ -373,7 +373,7 @@ class _GEODE_EXPORT AttributesFactory {
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if diskPolicyType is Invalid
*/
- AttributesFactory& setDiskPolicy(const DiskPolicyType::PolicyType diskPolicy);
+ AttributesFactory& setDiskPolicy(const DiskPolicyType diskPolicy);
/**
* Set caching enabled flag for this region. If set to false, then no data is
diff --git a/cppcache/include/geode/DiskPolicyType.hpp b/cppcache/include/geode/DiskPolicyType.hpp
index 3879278..09102c0 100644
--- a/cppcache/include/geode/DiskPolicyType.hpp
+++ b/cppcache/include/geode/DiskPolicyType.hpp
@@ -32,50 +32,15 @@
namespace apache {
namespace geode {
namespace client {
+
/**
* @class DiskPolicyType DiskPolicyType.hpp
* Enumerated type for disk policy.
* @see RegionAttributes::getDiskPolicy
* @see AttributesFactory::setDiskPolicy
*/
-class _GEODE_EXPORT DiskPolicyType {
- // public static methods
- public:
- /**
- * Values for setting PolicyType.
- */
- typedef enum { NONE = 0, OVERFLOWS, PERSIST } PolicyType;
-
- /** Returns the Name of the Lru action represented by specified ordinal. */
- static const std::string& fromOrdinal(const uint8_t ordinal);
-
- static const std::string& fromEnum(const PolicyType policyType);
-
- /** Returns the type of the Lru action represented by name. */
- static PolicyType fromName(const std::string& name);
-
- /** Returns whether this is one of the overflow to disk type.
- * @return true if this is any action other than NONE
- */
- inline static bool isOverflow(const PolicyType type) {
- return (type == DiskPolicyType::OVERFLOWS);
- }
-
- /** Return whether this is <code>NONE</code>. */
- inline static bool isNone(const PolicyType type) {
- return (type == DiskPolicyType::NONE);
- }
-
- /** Return whether this is <code>persist</code>. */
- inline static bool isPersist(const PolicyType type) {
- return (type == DiskPolicyType::PERSIST);
- }
+enum class DiskPolicyType { NONE = 0, OVERFLOWS, PERSIST };
- private:
- /** No instance allowed. */
- DiskPolicyType() = delete;
- static const std::string names[];
-};
} // namespace client
} // namespace geode
} // namespace apache
diff --git a/cppcache/include/geode/RegionAttributes.hpp b/cppcache/include/geode/RegionAttributes.hpp
index 72af4b1..25bbacb 100644
--- a/cppcache/include/geode/RegionAttributes.hpp
+++ b/cppcache/include/geode/RegionAttributes.hpp
@@ -171,10 +171,10 @@ class _GEODE_EXPORT RegionAttributes : public Serializable {
/** Returns the disk policy type of the region.
*
- * @return the <code>DiskPolicyType::PolicyType</code>, default is
+ * @return the <code>DiskPolicyType</code>, default is
* DiskPolicyType::NONE.
*/
- DiskPolicyType::PolicyType getDiskPolicy() const;
+ DiskPolicyType getDiskPolicy() const;
/**
* Returns the ExpirationAction used for LRU Eviction, default is
@@ -338,7 +338,7 @@ class _GEODE_EXPORT RegionAttributes : public Serializable {
void setCloningEnabled(bool isClonable);
void setCachingEnabled(bool enable);
void setLruEntriesLimit(int limit);
- void setDiskPolicy(DiskPolicyType::PolicyType diskPolicy);
+ void setDiskPolicy(DiskPolicyType diskPolicy);
void setConcurrencyChecksEnabled(bool enable);
inline bool getEntryExpiryEnabled() const {
@@ -382,7 +382,7 @@ class _GEODE_EXPORT RegionAttributes : public Serializable {
std::string m_cacheWriterFactory;
std::string m_cacheListenerFactory;
std::string m_partitionResolverFactory;
- DiskPolicyType::PolicyType m_diskPolicy;
+ DiskPolicyType m_diskPolicy;
std::string m_endpoints;
bool m_clientNotificationEnabled;
std::string m_persistenceLibrary;
diff --git a/cppcache/include/geode/RegionFactory.hpp b/cppcache/include/geode/RegionFactory.hpp
index ca8e82f..7495332 100644
--- a/cppcache/include/geode/RegionFactory.hpp
+++ b/cppcache/include/geode/RegionFactory.hpp
@@ -216,7 +216,7 @@ class _GEODE_EXPORT RegionFactory {
* @return a reference to <code>this</code>
* @throws IllegalArgumentException if diskPolicyType is Invalid
*/
- RegionFactory& setDiskPolicy(const DiskPolicyType::PolicyType diskPolicy);
+ RegionFactory& setDiskPolicy(const DiskPolicyType diskPolicy);
/**
* Set caching enabled flag for this region. If set to false, then no data is
diff --git a/cppcache/integration-test/testOverflowPutGetSqLite.cpp b/cppcache/integration-test/testOverflowPutGetSqLite.cpp
index 47e017b..8da5f44 100644
--- a/cppcache/integration-test/testOverflowPutGetSqLite.cpp
+++ b/cppcache/integration-test/testOverflowPutGetSqLite.cpp
@@ -77,7 +77,7 @@ void validateAttribute(std::shared_ptr<Region>& regionPtr) {
std::shared_ptr<RegionAttributes> regAttr = regionPtr->getAttributes();
int initialCapacity = regAttr->getInitialCapacity();
ASSERT(initialCapacity == 1000, "Expected initial capacity to be 1000");
- const DiskPolicyType::PolicyType type = regAttr->getDiskPolicy();
+ const DiskPolicyType type = regAttr->getDiskPolicy();
ASSERT(type == DiskPolicyType::OVERFLOWS,
"Expected Action should overflow to disk");
}
diff --git a/cppcache/integration-test/testXmlCacheCreationWithOverFlow.cpp b/cppcache/integration-test/testXmlCacheCreationWithOverFlow.cpp
index 7b2d383..860b20e 100644
--- a/cppcache/integration-test/testXmlCacheCreationWithOverFlow.cpp
+++ b/cppcache/integration-test/testXmlCacheCreationWithOverFlow.cpp
@@ -166,7 +166,7 @@ int testXmlCacheCreationWithOverflow() {
if (action1 != ExpirationAction::DESTROY) {
return -1;
}
- const DiskPolicyType::PolicyType type = regAttr->getDiskPolicy();
+ const DiskPolicyType type = regAttr->getDiskPolicy();
std::cout << "DiskPolicy : overflows" << std::endl;
if (type != DiskPolicyType::OVERFLOWS) {
std::cout << " diskpolicy is not overflows " << std::endl;
diff --git a/cppcache/src/AttributesFactory.cpp b/cppcache/src/AttributesFactory.cpp
index ab21e48..51b994f 100644
--- a/cppcache/src/AttributesFactory.cpp
+++ b/cppcache/src/AttributesFactory.cpp
@@ -185,7 +185,7 @@ AttributesFactory& AttributesFactory::setLruEntriesLimit(
}
AttributesFactory& AttributesFactory::setDiskPolicy(
- const DiskPolicyType::PolicyType diskPolicy) {
+ const DiskPolicyType diskPolicy) {
if (diskPolicy == DiskPolicyType::PERSIST) {
throw IllegalStateException("Persistence feature is not supported");
}
diff --git a/cppcache/src/DiskPolicyType.cpp b/cppcache/src/DiskPolicyType.cpp
deleted file mode 100644
index aa940c9..0000000
--- a/cppcache/src/DiskPolicyType.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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 <geode/DiskPolicyType.hpp>
-#include "ace/OS.h"
-
-namespace apache {
-namespace geode {
-namespace client {
-
-const std::string DiskPolicyType::names[] = {"none", "overflows", "persist"};
-
-DiskPolicyType::PolicyType DiskPolicyType::fromName(const std::string& name) {
- for (int i = NONE; i <= PERSIST; i++) {
- if (names[i] == name) {
- return static_cast<PolicyType>(i);
- }
- }
- return DiskPolicyType::NONE;
-}
-
-const std::string& DiskPolicyType::fromOrdinal(const uint8_t ordinal) {
- if (NONE <= ordinal && ordinal <= PERSIST) {
- return names[ordinal];
- }
-
- return names[NONE];
-}
-
-} // namespace client
-} // namespace geode
-} // namespace apache
diff --git a/cppcache/src/EntriesMapFactory.cpp b/cppcache/src/EntriesMapFactory.cpp
index 2ac150e..e355eef 100644
--- a/cppcache/src/EntriesMapFactory.cpp
+++ b/cppcache/src/EntriesMapFactory.cpp
@@ -50,7 +50,7 @@ EntriesMap* EntriesMapFactory::createMap(
if ((lruLimit != 0) || (prop.heapLRULimitEnabled())) { // create LRU map...
LRUAction::Action lruEvictionAction;
- DiskPolicyType::PolicyType dpType = attrs->getDiskPolicy();
+ DiskPolicyType dpType = attrs->getDiskPolicy();
if (dpType == DiskPolicyType::OVERFLOWS) {
lruEvictionAction = LRUAction::OVERFLOW_TO_DISK;
} else if ((dpType == DiskPolicyType::NONE) ||
diff --git a/cppcache/src/RegionAttributes.cpp b/cppcache/src/RegionAttributes.cpp
index c77477d..37cc8d2 100644
--- a/cppcache/src/RegionAttributes.cpp
+++ b/cppcache/src/RegionAttributes.cpp
@@ -265,7 +265,7 @@ uint32_t RegionAttributes::getLruEntriesLimit() const {
return m_lruEntriesLimit;
}
-DiskPolicyType::PolicyType RegionAttributes::getDiskPolicy() const {
+DiskPolicyType RegionAttributes::getDiskPolicy() const {
return m_diskPolicy;
}
const std::string& RegionAttributes::getPoolName() const { return m_poolName; }
@@ -371,7 +371,7 @@ void RegionAttributes::fromData(DataInput& in) {
apache::geode::client::impl::readString(in, m_cacheListenerFactory);
apache::geode::client::impl::readString(in, m_partitionResolverLibrary);
apache::geode::client::impl::readString(in, m_partitionResolverFactory);
- m_diskPolicy = static_cast<DiskPolicyType::PolicyType>(in.readInt32());
+ m_diskPolicy = static_cast<DiskPolicyType>(in.readInt32());
apache::geode::client::impl::readString(in, m_endpoints);
apache::geode::client::impl::readString(in, m_persistenceLibrary);
apache::geode::client::impl::readString(in, m_persistenceFactory);
@@ -537,7 +537,7 @@ void RegionAttributes::setCachingEnabled(bool enable) { m_caching = enable; }
void RegionAttributes::setLruEntriesLimit(int limit) {
m_lruEntriesLimit = limit;
}
-void RegionAttributes::setDiskPolicy(DiskPolicyType::PolicyType diskPolicy) {
+void RegionAttributes::setDiskPolicy(DiskPolicyType diskPolicy) {
m_diskPolicy = diskPolicy;
}
diff --git a/cppcache/src/RegionFactory.cpp b/cppcache/src/RegionFactory.cpp
index 9db0038..0be1fa2 100644
--- a/cppcache/src/RegionFactory.cpp
+++ b/cppcache/src/RegionFactory.cpp
@@ -179,7 +179,7 @@ RegionFactory& RegionFactory::setLruEntriesLimit(const uint32_t entriesLimit) {
}
RegionFactory& RegionFactory::setDiskPolicy(
- const DiskPolicyType::PolicyType diskPolicy) {
+ const DiskPolicyType diskPolicy) {
m_attributeFactory->setDiskPolicy(diskPolicy);
return *this;
}
diff --git a/cppcache/test/DiskPolicyTypeTest.cpp b/cppcache/test/DiskPolicyTypeTest.cpp
deleted file mode 100644
index 21d23dd..0000000
--- a/cppcache/test/DiskPolicyTypeTest.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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 <gtest/gtest.h>
-
-#include <geode/DiskPolicyType.hpp>
-
-using namespace apache::geode::client;
-
-TEST(DiskPolicyTypeTest, VerifyOrdinalAndNameSymmetryForNone) {
- auto&& name = DiskPolicyType::fromOrdinal(0);
- EXPECT_EQ("none", name) << "Correct name for none";
- auto&& policyType = DiskPolicyType::fromName(name);
- EXPECT_EQ(DiskPolicyType::NONE, policyType) << "Correct policy type for none";
-}
-
-TEST(DiskPolicyTypeTest, VerifyOrdinalAndNameSymmetryForOverflows) {
- auto&& name = DiskPolicyType::fromOrdinal(1);
- EXPECT_EQ("overflows", name) << "Correct name for overflows";
- auto&& policyType = DiskPolicyType::fromName(name);
- EXPECT_EQ(DiskPolicyType::OVERFLOWS, policyType)
- << "Correct policy type for overflows";
-}
-
-TEST(DiskPolicyTypeTest, VerifyOrdinalAndNameSymmetryForPersist) {
- auto&& name = DiskPolicyType::fromOrdinal(2);
- EXPECT_EQ("persist", name) << "Correct name for persist";
- auto&& policyType = DiskPolicyType::fromName(name);
- EXPECT_EQ(DiskPolicyType::PERSIST, policyType)
- << "Correct policy type for persist";
-}
-
-TEST(DiskPolicyTypeTest, ValidateIsNone) {
- EXPECT_EQ(true, DiskPolicyType::isNone(DiskPolicyType::NONE))
- << "NONE is none";
- EXPECT_EQ(false, DiskPolicyType::isNone(DiskPolicyType::OVERFLOWS))
- << "OVERFLOWS is not none";
- EXPECT_EQ(false, DiskPolicyType::isNone(DiskPolicyType::PERSIST))
- << "PERSIST is not none";
-}
-
-TEST(DiskPolicyTypeTest, ValidateIsOverflow) {
- EXPECT_EQ(false, DiskPolicyType::isOverflow(DiskPolicyType::NONE))
- << "NONE is not overflow";
- EXPECT_EQ(true, DiskPolicyType::isOverflow(DiskPolicyType::OVERFLOWS))
- << "OVERFLOWS is overflow";
- EXPECT_EQ(false, DiskPolicyType::isOverflow(DiskPolicyType::PERSIST))
- << "PERSIST is not overflow";
-}
-
-TEST(DiskPolicyTypeTest, ValidateIsPersist) {
- EXPECT_EQ(false, DiskPolicyType::isPersist(DiskPolicyType::NONE))
- << "NONE is not persist";
- EXPECT_EQ(false, DiskPolicyType::isPersist(DiskPolicyType::OVERFLOWS))
- << "OVERFLOWS is not persist";
- EXPECT_EQ(true, DiskPolicyType::isPersist(DiskPolicyType::PERSIST))
- << "PERSIST is persist";
-}
diff --git a/tests/cpp/fwklib/FwkObjects.cpp b/tests/cpp/fwklib/FwkObjects.cpp
index 815c629..73ea2e5 100644
--- a/tests/cpp/fwklib/FwkObjects.cpp
+++ b/tests/cpp/fwklib/FwkObjects.cpp
@@ -528,11 +528,6 @@ Attributes::Attributes(const DOMNode* node)
setInitialCapacity(XMLChToStr(nameNode->getNodeValue()));
}
- nameNode = map->getNamedItem(StrToXMLCh("disk-policy"));
- if (nameNode != NULL) {
- setDiskPolicy(XMLChToStr(nameNode->getNodeValue()));
- }
-
nameNode = map->getNamedItem(StrToXMLCh("pool-name"));
if (nameNode != NULL) {
setPoolName(XMLChToStr(nameNode->getNodeValue()));
diff --git a/tests/cpp/fwklib/FwkObjects.hpp b/tests/cpp/fwklib/FwkObjects.hpp
index e8afcbe..a941a6b 100644
--- a/tests/cpp/fwklib/FwkObjects.hpp
+++ b/tests/cpp/fwklib/FwkObjects.hpp
@@ -390,9 +390,6 @@ class Attributes {
m_factory.setInitialCapacity(FwkStrCvt::toInt32(val));
}
- void setDiskPolicy(std::string val) {
- m_factory.setDiskPolicy(DiskPolicyType::fromName(val.c_str()));
- }
void setCloningEnabled(std::string val) {
m_factory.setCloningEnabled(FwkStrCvt::toBool(val));
}
--
To stop receiving notification emails like this one, please contact
jbarrett@apache.org.