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 2017/02/14 21:05:31 UTC
geode-native git commit: GEODE-2470: Replace sed dependency with
standard C++.
Repository: geode-native
Updated Branches:
refs/heads/develop 87b6e0355 -> 21c050f94
GEODE-2470: Replace sed dependency with standard C++.
- sed is used in CacheHelper to do string replacement of port number
variables in the input xml configuration files.
This closes #6.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/21c050f9
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/21c050f9
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/21c050f9
Branch: refs/heads/develop
Commit: 21c050f942706c7ab61df55802c4a6476d383700
Parents: 87b6e03
Author: Mike Martell <mm...@pivotal.io>
Authored: Sun Feb 12 09:54:55 2017 -0800
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Tue Feb 14 13:04:39 2017 -0800
----------------------------------------------------------------------
src/cppcache/integration-test/CacheHelper.cpp | 40 ++++++++++++++++------
src/cppcache/integration-test/CacheHelper.hpp | 7 +++-
2 files changed, 35 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/21c050f9/src/cppcache/integration-test/CacheHelper.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/CacheHelper.cpp b/src/cppcache/integration-test/CacheHelper.cpp
index 2e8890e..4d90ee2 100644
--- a/src/cppcache/integration-test/CacheHelper.cpp
+++ b/src/cppcache/integration-test/CacheHelper.cpp
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
#include <gfcpp/GeodeCppCache.hpp>
#include <stdlib.h>
#include <gfcpp/SystemProperties.hpp>
@@ -21,6 +22,7 @@
#include <ace/INET_Addr.h>
#include <ace/SOCK_Acceptor.h>
#include <fstream>
+#include <regex>
#include "TimeBomb.hpp"
#include <list>
@@ -1360,18 +1362,11 @@ void CacheHelper::createDuplicateXMLFile(std::string& originalFile,
testSrc += PATH_SEP;
// file name will have hostport1.xml(i.e. CacheHelper::staticHostPort1) as
// suffix
- sprintf(cmd,
- "sed -e s/HOST_PORT1/%d/g -e s/HOST_PORT2/%d/g -e s/HOST_PORT3/%d/g "
- "-e s/HOST_PORT4/%d/g -e s/LOC_PORT1/%d/g -e s/LOC_PORT2/%d/g <%s%s> "
- "%s%s%d.xml",
- hostport1, hostport2, CacheHelper::staticHostPort3,
- CacheHelper::staticHostPort4, locport1, locport2, testSrc.c_str(),
- originalFile.c_str(), currDir.c_str(), originalFile.c_str(),
- hostport1);
- LOG(cmd);
- int e = ACE_OS::system(cmd);
- ASSERT(0 == e, "cmd failed");
+ replacePortsInFile(
+ hostport1, hostport2, CacheHelper::staticHostPort3,
+ CacheHelper::staticHostPort4, locport1, locport2, testSrc + originalFile,
+ currDir + originalFile + std::to_string(hostport1) + ".xml");
// this file need to delete
sprintf(cmd, "%s%s%d.xml", currDir.c_str(), originalFile.c_str(), hostport1);
@@ -1382,6 +1377,29 @@ void CacheHelper::createDuplicateXMLFile(std::string& originalFile,
CacheHelper::staticConfigFileList.size());
}
+void CacheHelper::replacePortsInFile(int hostPort1, int hostPort2,
+ int hostPort3, int hostPort4, int locPort1,
+ int locPort2, const std::string& inFile,
+ const std::string& outFile) {
+ std::ifstream in(inFile, std::ios::in | std::ios::binary);
+ if (in) {
+ std::string contents;
+ contents.assign(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
+ in.close();
+
+ contents = std::regex_replace(contents, std::regex("HOST_PORT1"), std::to_string(hostPort1));
+ contents = std::regex_replace(contents, std::regex("HOST_PORT2"), std::to_string(hostPort2));
+ contents = std::regex_replace(contents, std::regex("HOST_PORT3"), std::to_string(hostPort3));
+ contents = std::regex_replace(contents, std::regex("HOST_PORT4"), std::to_string(hostPort4));
+ contents = std::regex_replace(contents, std::regex("LOC_PORT1"), std::to_string(locPort1));
+ contents = std::regex_replace(contents, std::regex("LOC_PORT2"), std::to_string(locPort2));
+
+ std::ofstream out(outFile, std::ios::out);
+ out << contents;
+ out.close();
+ }
+}
+
void CacheHelper::createDuplicateXMLFile(std::string& duplicateFile,
std::string& originalFile) {
CacheHelper::createDuplicateXMLFile(
http://git-wip-us.apache.org/repos/asf/geode-native/blob/21c050f9/src/cppcache/integration-test/CacheHelper.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/CacheHelper.hpp b/src/cppcache/integration-test/CacheHelper.hpp
index 7c9b086..b7780be 100644
--- a/src/cppcache/integration-test/CacheHelper.hpp
+++ b/src/cppcache/integration-test/CacheHelper.hpp
@@ -279,6 +279,11 @@ class CacheHelper {
static void cleanupTmpConfigFiles();
+ static void replacePortsInFile(int hostPort1, int hostPort2, int hostPort3,
+ int hostPort4, int locPort1, int locPort2,
+ const std::string& inFile,
+ const std::string& outFile);
+
static std::list<int> staticLocatorInstanceList;
static bool isLocatorCleanupCallbackRegistered;
static void cleanupLocatorInstances();
@@ -331,4 +336,4 @@ int CacheHelper::staticLocatorHostPort2 = CacheHelper::getRandomAvailablePort();
int CacheHelper::staticLocatorHostPort3 = CacheHelper::getRandomAvailablePort();
#endif
-#endif // GEODE_INTEGRATION_TEST_CACHEHELPER_H_
+#endif // GEODE_INTEGRATION_TEST_CACHEHELPER_H_