THRIFT-847 Test Framework harmonization across all languages
THRIFT-2946 Enhance usability of cross test framework
Patch: Nobuaki Sukegawa
This closes: #358
diff --git a/lib/csharp/test/ThriftTest/Makefile.am b/lib/csharp/test/ThriftTest/Makefile.am
new file mode 100644
index 0000000..fcde6fc
--- /dev/null
+++ b/lib/csharp/test/ThriftTest/Makefile.am
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+CSC=gmcs
+
+stubs: $(top_srcdir)/test/ThriftTest.thrift
+ $(THRIFT) --gen csharp -o . $(top_srcdir)/test/ThriftTest.thrift
+
+precross: TestClientServer.exe
+
+ThriftImpl.dll: stubs
+ $(CSC) /t:library /out:./ThriftImpl.dll /recurse:./gen-csharp/* /reference:../../Thrift.dll
+
+TestClientServer.exe: TestClient.cs TestServer.cs Program.cs ThriftImpl.dll
+ $(CSC) /out:TestClientServer.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll TestClient.cs TestServer.cs Program.cs
diff --git a/lib/csharp/test/ThriftTest/Program.cs b/lib/csharp/test/ThriftTest/Program.cs
index 3bf6796..5a4245b 100644
--- a/lib/csharp/test/ThriftTest/Program.cs
+++ b/lib/csharp/test/ThriftTest/Program.cs
@@ -31,12 +31,12 @@
{
class Program
{
- static void Main(string[] args)
+ static int Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("must provide 'server' or 'client' arg");
- return;
+ return -1;
}
string[] subArgs = new string[args.Length - 1];
@@ -46,16 +46,17 @@
}
if (args[0] == "client")
{
- TestClient.Execute(subArgs);
+ return TestClient.Execute(subArgs) ? 0 : 1;
}
else if (args[0] == "server")
{
- TestServer.Execute(subArgs);
+ return TestServer.Execute(subArgs) ? 0 : 1;
}
else
{
Console.WriteLine("first argument must be 'server' or 'client'");
}
+ return 0;
}
}
}
diff --git a/lib/csharp/test/ThriftTest/TestClient.cs b/lib/csharp/test/ThriftTest/TestClient.cs
index a0ceb15..ec0696a 100644
--- a/lib/csharp/test/ThriftTest/TestClient.cs
+++ b/lib/csharp/test/ThriftTest/TestClient.cs
@@ -32,7 +32,7 @@
private static int numIterations = 1;
private static string protocol = "";
- public static void Execute(string[] args)
+ public static bool Execute(string[] args)
{
try
{
@@ -41,6 +41,7 @@
string url = null, pipe = null;
int numThreads = 1;
bool buffered = false, framed = false, encrypted = false;
+ string certPath = "../../../../../keys/server.pem";
try
{
@@ -96,6 +97,10 @@
encrypted = true;
Console.WriteLine("Using encrypted transport");
}
+ else if (args[i].StartsWith("--cert="))
+ {
+ certPath = args[i].Substring("--cert=".Length);
+ }
}
}
catch (Exception e)
@@ -119,7 +124,7 @@
else
{
if (encrypted)
- trans = new TTLSSocket(host, port, "../../../../../keys/client.pem");
+ trans = new TTLSSocket(host, port, certPath);
else
trans = new TSocket(host, port);
}
@@ -151,10 +156,12 @@
catch (Exception outerEx)
{
Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace);
+ return false;
}
Console.WriteLine();
Console.WriteLine();
+ return true;
}
public static void ClientThread(object obj)
diff --git a/lib/csharp/test/ThriftTest/TestServer.cs b/lib/csharp/test/ThriftTest/TestServer.cs
index 2096cf8..0e9fe05 100644
--- a/lib/csharp/test/ThriftTest/TestServer.cs
+++ b/lib/csharp/test/ThriftTest/TestServer.cs
@@ -358,13 +358,14 @@
} // class TestHandler
- public static void Execute(string[] args)
+ public static bool Execute(string[] args)
{
try
{
bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false;
int port = 9090;
string pipe = null;
+ string certPath = "../../../../../keys/server.pem";
for (int i = 0; i < args.Length; i++)
{
if (args[i] == "-pipe") // -pipe name
@@ -395,6 +396,10 @@
{
useEncryption = true;
}
+ else if (args[i].StartsWith("--cert="))
+ {
+ certPath = args[i].Substring("--cert=".Length);
+ }
}
// Processor
@@ -411,7 +416,7 @@
{
if (useEncryption)
{
- trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2("../../../../../keys/server.pem"));
+ trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath));
}
else
{
@@ -461,8 +466,10 @@
catch (Exception x)
{
Console.Error.Write(x);
+ return false;
}
Console.WriteLine("done.");
+ return true;
}
}
}