GEODE-8157: Add DropProxy acceptance test for .NET (#674)
* Assert NotConnectedException when proxy is dropped
* Align the C++ and C# code
* Code cleanup: use runProcess for all docker and docker-compose cmds, unused variable gripes
diff --git a/clicache/acceptance-test/SNITests.cs b/clicache/acceptance-test/SNITests.cs
index f459716..9fd2a70 100644
--- a/clicache/acceptance-test/SNITests.cs
+++ b/clicache/acceptance-test/SNITests.cs
@@ -18,9 +18,11 @@
using System;
using System.Diagnostics;
using System.IO;
-using Xunit;
using System.Collections;
using System.Collections.Generic;
+using System.Threading.Tasks;
+
+using Xunit;
using Xunit.Abstractions;
namespace Apache.Geode.Client.IntegrationTests
@@ -29,18 +31,16 @@
public class SNITests : TestBase, IDisposable
{
string currentWorkingDirectory;
- Process dockerProcess;
private readonly Cache cache_;
+ private int proxyPort = -1;
public SNITests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
- CleanupDocker();
+ CleanupDocker();
currentWorkingDirectory = Directory.GetCurrentDirectory();
var clientTruststore = Config.SslClientKeyPath + @"/truststore_sni.pem";
-
-
var cacheFactory = new CacheFactory();
cacheFactory.Set("log-level", "none");
cacheFactory.Set("log-file", "c:/temp/SNITest-csharp.log");
@@ -49,37 +49,36 @@
cache_ = cacheFactory.Create();
- var dc = Process.Start(@"docker-compose.exe", "-f " + Config.SniConfigPath + "/docker-compose.yml" + " up -d");
- dc.WaitForExit();
-
- var d = Process.Start(@"docker.exe", "exec -t geode gfsh run --file=/geode/scripts/geode-starter.gfsh");
- d.WaitForExit();
+ RunProcess("docker-compose",
+ "-f " + Config.SniConfigPath + "/docker-compose.yml" +
+ " up -d");
+ RunProcess("docker",
+ "exec -t geode " +
+ "gfsh run --file=/geode/scripts/geode-starter.gfsh");
}
public void Dispose()
{
- CleanupDocker();
- }
+ CleanupDocker();
+ }
- private void CleanupDocker()
- {
- var dockerComposeProc = Process.Start(@"docker-compose.exe", "-f " + Config.SniConfigPath + "/docker-compose.yml" + " stop");
- dockerComposeProc.WaitForExit();
+ private void CleanupDocker()
+ {
+ RunProcess("docker", "stop geode");
+ RunProcess("docker", "stop haproxy");
+ RunProcess("docker", "container prune -f");
+ }
- var dockerProc = Process.Start(@"docker.exe", "system prune -f");
- dockerProc.WaitForExit();
- }
-
- private string RunDockerCommand(string dockerCommand)
+ private string RunProcess(string processFile, string processArgs)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
- startInfo.FileName = @"docker.exe";
- startInfo.Arguments = dockerCommand;
- dockerProcess = Process.Start(startInfo);
- String rVal = dockerProcess.StandardOutput.ReadToEnd();
- dockerProcess.WaitForExit();
+ startInfo.FileName = processFile;
+ startInfo.Arguments = processArgs;
+ Process process = Process.Start(startInfo);
+ String rVal = process.StandardOutput.ReadToEnd();
+ process.WaitForExit();
return rVal;
}
@@ -93,12 +92,12 @@
[Fact]
public void ConnectViaProxy()
{
- var portString = RunDockerCommand("port haproxy");
- var portNumber = ParseProxyPort(portString);
+ var portString = RunProcess("docker", "port haproxy");
+ proxyPort = ParseProxyPort(portString);
cache_.GetPoolManager()
.CreateFactory()
- .SetSniProxy("localhost", portNumber)
+ .SetSniProxy("localhost", proxyPort)
.AddLocator("locator-maeve", 10334)
.Create("pool");
@@ -127,5 +126,48 @@
Assert.Throws<NotConnectedException>(() => region.Put("1", "one"));
}
+
+ [Fact]
+ public void DropProxy()
+ {
+ var portString = RunProcess("docker", "port haproxy");
+ proxyPort = ParseProxyPort(portString);
+
+ cache_.GetPoolManager()
+ .CreateFactory()
+ .SetSniProxy("localhost", proxyPort)
+ .AddLocator("locator-maeve", 10334)
+ .Create("pool");
+
+ var region = cache_.CreateRegionFactory(RegionShortcut.PROXY)
+ .SetPoolName("pool")
+ .Create<string, string>("jellyfish");
+
+ region.Put("1", "one");
+ var value = region.Get("1");
+
+ Assert.Equal("one", value);
+
+ RunProcess("docker", "stop haproxy");
+ RunProcess("docker", "container prune -f");
+
+ Assert.Throws<NotConnectedException>(() =>
+ {
+ region.Put("2", "two");
+ value = region.Get("2");
+ });
+
+ string startProxyArgs =
+ "-f " + Config.SniConfigPath + "/docker-compose.yml " +
+ "run -d --name haproxy " +
+ "--publish " + proxyPort.ToString() + ":15443 haproxy";
+ RunProcess("docker-compose", startProxyArgs);
+
+ region.Put("3", "three");
+ value = region.Get("3");
+ Assert.Equal("three", value);
+
+ cache_.Close();
+ }
}
}
\ No newline at end of file
diff --git a/cppcache/acceptance-test/SNITest.cpp b/cppcache/acceptance-test/SNITest.cpp
index 52ba88b..219310f 100644
--- a/cppcache/acceptance-test/SNITest.cpp
+++ b/cppcache/acceptance-test/SNITest.cpp
@@ -55,52 +55,34 @@
void SetUp() override {
TearDown();
- auto systemRVal = 0;
std::string dockerComposeCmd = "docker-compose -f " +
sniConfigPath.string() +
"/docker-compose.yml" + " up -d";
- const char* dcc = dockerComposeCmd.c_str();
- systemRVal = std::system(dcc);
- if (systemRVal == -1) {
- BOOST_LOG_TRIVIAL(error)
- << "std::system(\"docker-compose\") returned: " << systemRVal;
- }
+ runProcess(dockerComposeCmd);
- systemRVal = std::system(
+ runProcess(
"docker exec -t geode gfsh run "
"--file=/geode/scripts/geode-starter.gfsh");
- if (systemRVal == -1) {
- BOOST_LOG_TRIVIAL(error)
- << "std::system(\"docker exec -t geode gfsh run\") returned: "
- << systemRVal;
- }
}
void TearDown() override { cleanupDocker(); }
void cleanupDocker() {
- auto dockerComposeStopCommand = "docker-compose -f " +
- sniConfigPath.string() +
- "/docker-compose.yml" + " stop";
- auto systemRVal = std::system(dockerComposeStopCommand.c_str());
- if (systemRVal == -1) {
- BOOST_LOG_TRIVIAL(error) << "std::system returned: " << systemRVal;
- }
-
- systemRVal = std::system("docker system prune -f");
- if (systemRVal == -1) {
- BOOST_LOG_TRIVIAL(error) << "std::system returned: " << systemRVal;
- }
+ runProcess("docker stop geode");
+ runProcess("docker stop haproxy");
+ runProcess("docker container prune -f");
}
- std::string runDockerCommand(const char* command) {
+ std::string runProcess(std::string command) {
+ const char* cstrCommand = command.c_str();
std::string commandOutput;
#if defined(_WIN32)
- std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(command, "r"),
+ std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cstrCommand, "r"),
_pclose);
#else
- std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command, "r"), pclose);
+ std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cStrCommand, "r"),
+ pclose);
#endif
std::array<char, 128> charBuff;
if (!pipe) {
@@ -125,7 +107,7 @@
boost::filesystem::path sniConfigPath;
};
-TEST_F(SNITest, connectViaProxyTest) {
+TEST_F(SNITest, connectViaProxy) {
const auto clientTruststore =
(clientSslKeysDir / boost::filesystem::path("/truststore_sni.pem"));
@@ -136,7 +118,7 @@
.set("ssl-truststore", clientTruststore.string())
.create();
- auto portString = runDockerCommand("docker port haproxy");
+ auto portString = runProcess("docker port haproxy");
auto portNumber = parseProxyPort(portString);
cache.getPoolManager()
@@ -150,6 +132,8 @@
.create("jellyfish");
region->put("1", "one");
+ auto val = std::dynamic_pointer_cast<CacheableString>(region->get("1"));
+ EXPECT_EQ("one", val->value());
cache.close();
}
@@ -179,7 +163,7 @@
cache.close();
}
-TEST_F(SNITest, dropSNIProxyTest) {
+TEST_F(SNITest, dropSNIProxy) {
const auto clientTruststore =
(clientSslKeysDir / boost::filesystem::path("/truststore_sni.pem"));
@@ -190,12 +174,12 @@
.set("ssl-truststore", clientTruststore.string())
.create();
- auto portString = runDockerCommand("docker port haproxy");
- auto portNumber = parseProxyPort(portString);
+ auto portString = runProcess("docker port haproxy");
+ auto proxyPort = parseProxyPort(portString);
cache.getPoolManager()
.createFactory()
- .setSniProxy("localhost", portNumber)
+ .setSniProxy("localhost", proxyPort)
.addLocator("locator-maeve", 10334)
.create("pool");
@@ -203,27 +187,26 @@
.setPoolName("pool")
.create("jellyfish");
- auto systemRVal = std::system("docker pause haproxy");
- if (systemRVal == -1) {
- BOOST_LOG_TRIVIAL(error) << "std::system returned: " << systemRVal;
- }
+ region->put("1", "one");
+ auto val = std::dynamic_pointer_cast<CacheableString>(region->get("1"));
+ EXPECT_EQ("one", val->value());
- auto f =
- std::async(std::launch::async, [®ion] { region->put("1", "one"); });
+ runProcess("docker stop haproxy");
+ runProcess("docker container prune -f");
- // Insure the put times out (default is 15 seconds).
- std::this_thread::sleep_for(std::chrono::seconds(16));
+ EXPECT_THROW(region->put("1", "one"),
+ apache::geode::client::NotConnectedException);
- systemRVal = std::system("docker unpause haproxy");
- if (systemRVal == -1) {
- BOOST_LOG_TRIVIAL(error) << "std::system returned: " << systemRVal;
- }
+ std::string startProxyArgs = "-f " + sniConfigPath.string() +
+ "/docker-compose.yml "
+ "run -d --name haproxy "
+ "--publish " +
+ std::to_string(proxyPort) + ":15443 haproxy";
- f.wait();
+ runProcess("docker-compose " + startProxyArgs);
- EXPECT_EQ(
- std::dynamic_pointer_cast<CacheableString>(region->get("1"))->value(),
- "one");
+ val = std::dynamic_pointer_cast<CacheableString>(region->get("1"));
+ EXPECT_EQ("one", val->value());
cache.close();
}