THRIFT-3906 Run C# tests with make check
This closes #1069
diff --git a/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs b/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs
index ccfe21d..c810a08 100644
--- a/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs
+++ b/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs
@@ -26,17 +26,16 @@
using Thrift;
using Test.Multiplex;
-
namespace Test.Multiplex.Client
{
public class TestClient
{
- private void Run()
+ static void Execute(int port)
{
try
{
TTransport trans;
- trans = new TSocket("localhost", 9090);
+ trans = new TSocket("localhost", port);
trans = new TFramedTransport(trans);
trans.Open();
@@ -44,44 +43,40 @@
TMultiplexedProtocol multiplex;
- multiplex = new TMultiplexedProtocol( Protocol, Constants.NAME_BENCHMARKSERVICE);
- BenchmarkService.Iface bench = new BenchmarkService.Client( multiplex);
+ multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_BENCHMARKSERVICE);
+ BenchmarkService.Iface bench = new BenchmarkService.Client(multiplex);
- multiplex = new TMultiplexedProtocol( Protocol, Constants.NAME_AGGR);
- Aggr.Iface aggr = new Aggr.Client( multiplex);
+ multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_AGGR);
+ Aggr.Iface aggr = new Aggr.Client(multiplex);
- sbyte i;
- for( i = 1; 10 >= i; ++i)
+ for (sbyte i = 1; 10 >= i; ++i)
{
- aggr.addValue( bench.fibonacci(i));
+ aggr.addValue(bench.fibonacci(i));
}
- foreach( int k in aggr.getValues())
+ foreach (int k in aggr.getValues())
{
- Console.Write(k.ToString()+" ");
+ Console.Write(k.ToString() + " ");
Console.WriteLine("");
}
+ trans.Close();
}
- catch( Exception e)
+ catch (Exception e)
{
- Console.WriteLine( e.Message);
+ Console.WriteLine(e.Message);
}
}
-
- public static void Execute()
- {
- TestClient client = new TestClient();
- client.Run();
- }
-
static void Main(string[] args)
{
- Execute();
+ int port = 9090;
+ if (args.Length > 0)
+ {
+ port = ushort.Parse(args[0]);
+ }
+ Execute(port);
Console.WriteLine("done.");
- Console.ReadLine();
}
-
}
}
diff --git a/lib/csharp/test/Multiplex/Makefile.am b/lib/csharp/test/Multiplex/Makefile.am
new file mode 100644
index 0000000..57253d6
--- /dev/null
+++ b/lib/csharp/test/Multiplex/Makefile.am
@@ -0,0 +1,52 @@
+#
+# 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.
+#
+
+GENERATED = \
+ gen-csharp/Aggr.cs \
+ gen-csharp/BenchmarkService.cs \
+ gen-csharp/Error.cs
+
+BUILT_SOURCES = $(GENERATED)
+
+THRIFT = $(top_builddir)/compiler/cpp/thrift
+
+gen-csharp/Aggr.cs: $(top_srcdir)/contrib/async-test/aggr.thrift
+ $(THRIFT) --gen csharp $<
+
+gen-csharp/BenchmarkService.cs gen-csharp/Error.cs: $(top_srcdir)/lib/rb/benchmark/Benchmark.thrift
+ $(THRIFT) --gen csharp $<
+
+ThriftImpl.dll: Multiplex.Test.Common.cs $(GENERATED) ../../Thrift.dll
+ $(CSC) $(CSC_DEFINES) -t:library -out:./ThriftImpl.dll -reference:../../Thrift.dll $(GENERATED) $<
+
+MultiplexClient.exe: Client/Multiplex.Test.Client.cs ThriftImpl.dll
+ $(CSC) $(CSC_DEFINES) -out:$@ -reference:../../Thrift.dll -reference:ThriftImpl.dll $<
+
+MultiplexServer.exe: Server/Multiplex.Test.Server.cs ThriftImpl.dll
+ $(CSC) $(CSC_DEFINES) -out:$@ -reference:../../Thrift.dll -reference:ThriftImpl.dll $<
+
+clean-local:
+ $(RM) -rf gen-csharp *.exe *.dll
+
+TESTPORT = 9501
+check-local: MultiplexServer.exe MultiplexClient.exe
+ echo $(TESTPORT)
+ MONO_PATH=../../ timeout 10 mono MultiplexServer.exe $(TESTPORT) &
+ sleep 1
+ MONO_PATH=../../ mono MultiplexClient.exe $(TESTPORT)
diff --git a/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs b/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs
index 61c2d7c..9786189 100644
--- a/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs
+++ b/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs
@@ -30,30 +30,14 @@
{
public class TestServer
{
- public interface ITestHandler
- {
- void SetServer( TServer aServer);
- }
-
- protected class TestHandlerImpl : ITestHandler
- {
- private TServer Server;
-
- public void SetServer( TServer aServer)
- {
- Server = aServer;
- }
- }
-
-
- protected class BenchmarkServiceImpl : TestHandlerImpl, BenchmarkService.Iface
+ class BenchmarkServiceImpl : BenchmarkService.Iface
{
public int fibonacci(sbyte n)
{
int prev, next, result;
prev = 0;
result = 1;
- while( n > 0)
+ while (n > 0)
{
next = result + prev;
prev = result;
@@ -64,14 +48,13 @@
}
}
-
- protected class AggrServiceImpl : TestHandlerImpl, Aggr.Iface
+ class AggrServiceImpl : Aggr.Iface
{
List<int> values = new List<int>();
public void addValue(int value)
{
- values.Add( value);
+ values.Add(value);
}
public List<int> getValues()
@@ -80,52 +63,45 @@
}
}
- static void Execute()
- {
- try
- {
- // create protocol factory, default to BinaryProtocol
- TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true,true);
- TServerTransport servertrans = new TServerSocket( 9090, 0, false);
- TTransportFactory TransportFactory = new TFramedTransport.Factory();
+ static void Execute(int port)
+ {
+ try
+ {
+ // create protocol factory, default to BinaryProtocol
+ TProtocolFactory ProtocolFactory = new TBinaryProtocol.Factory(true,true);
+ TServerTransport servertrans = new TServerSocket(port, 0, false);
+ TTransportFactory TransportFactory = new TFramedTransport.Factory();
- BenchmarkService.Iface benchHandler = new BenchmarkServiceImpl();
- TProcessor benchProcessor = new BenchmarkService.Processor( benchHandler);
+ BenchmarkService.Iface benchHandler = new BenchmarkServiceImpl();
+ TProcessor benchProcessor = new BenchmarkService.Processor(benchHandler);
- Aggr.Iface aggrHandler = new AggrServiceImpl();
- TProcessor aggrProcessor = new Aggr.Processor( aggrHandler);
+ Aggr.Iface aggrHandler = new AggrServiceImpl();
+ TProcessor aggrProcessor = new Aggr.Processor(aggrHandler);
- TMultiplexedProcessor multiplex = new TMultiplexedProcessor();
- multiplex.RegisterProcessor(Constants.NAME_BENCHMARKSERVICE, benchProcessor);
- multiplex.RegisterProcessor(Constants.NAME_AGGR, aggrProcessor);
+ TMultiplexedProcessor multiplex = new TMultiplexedProcessor();
+ multiplex.RegisterProcessor(Constants.NAME_BENCHMARKSERVICE, benchProcessor);
+ multiplex.RegisterProcessor(Constants.NAME_AGGR, aggrProcessor);
- TServer ServerEngine = new TSimpleServer( multiplex, servertrans, TransportFactory, ProtocolFactory);
+ TServer ServerEngine = new TSimpleServer(multiplex, servertrans, TransportFactory, ProtocolFactory);
- (benchHandler as ITestHandler).SetServer( ServerEngine);
- (aggrHandler as ITestHandler).SetServer( ServerEngine);
+ Console.WriteLine("Starting the server ...");
+ ServerEngine.Serve();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
- Console.WriteLine("Starting the server ...");
- ServerEngine.Serve();
-
- (benchHandler as ITestHandler).SetServer(null);
- (aggrHandler as ITestHandler).SetServer(null);
-
- }
- catch( Exception e)
- {
- Console.WriteLine( e.Message);
- }
- Console.WriteLine( "done.");
- }
-
-
- static void Main(string[] args)
- {
- Execute();
- }
+ static void Main(string[] args)
+ {
+ int port = 9090;
+ if (args.Length > 0)
+ {
+ port = ushort.Parse(args[0]);
+ }
+ Execute(port);
+ }
}
-
-
-
}
diff --git a/lib/csharp/test/Multiplex/maketest.sh b/lib/csharp/test/Multiplex/maketest.sh
deleted file mode 100755
index 1f29ee2..0000000
--- a/lib/csharp/test/Multiplex/maketest.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh
-
-#
-# 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.
-#
-
-../../../../compiler/cpp/thrift --gen csharp ../../../../contrib/async-test/aggr.thrift
-../../../../compiler/cpp/thrift --gen csharp ../../../rb/benchmark/Benchmark.thrift
-gmcs /t:library /out:./ThriftImpl.dll /recurse:./gen-csharp/* /reference:../../Thrift.dll Multiplex.Test.Common.cs
-gmcs /out:MultiplexClient.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll Client/Multiplex.Test.Client.cs
-gmcs /out:MultiplexServer.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll Server/Multiplex.Test.Server.cs
-
-
-
-export MONO_PATH=../../
-
-timeout 120 ./MultiplexServer.exe &
-sleep 3;
-./MultiplexClient.exe