2 // MonoTests.Remoting.TcpCalls.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2003 (C) Copyright, Ximian, Inc.
10 using System.Collections;
11 using System.Runtime.Remoting;
12 using System.Runtime.Remoting.Channels;
13 using System.Runtime.Remoting.Channels.Tcp;
14 using System.Runtime.Remoting.Channels.Http;
15 using NUnit.Framework;
17 using MonoTests.Helpers;
19 namespace MonoTests.Remoting
22 public class ActivationTests
24 ActivationServer server;
26 HttpClientChannel http;
33 tcp = new TcpChannel (0);
35 Hashtable options = new Hashtable ();
36 options ["timeout"] = 10000; // 10s
37 http = new HttpClientChannel (options, null);
39 ChannelServices.RegisterChannel (tcp);
40 ChannelServices.RegisterChannel (http);
42 AppDomain domain = BaseCallTest.CreateDomain ("testdomain_activation");
43 server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer");
45 var tcpUrlPrefix = $"tcp://localhost:{server.TcpPort}";
46 var httpUrlPrefix = $"http://localhost:{server.HttpPort}";
47 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), tcpUrlPrefix);
48 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), httpUrlPrefix);
49 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), tcpUrlPrefix + "/wkoSingleCall1");
50 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), tcpUrlPrefix + "/wkoSingleton1");
51 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), httpUrlPrefix + "/wkoSingleCall2");
52 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), httpUrlPrefix + "/wkoSingleton2");
56 Console.WriteLine (ex);
61 public void TestCreateTcpCao ()
63 CaObject1 ca = new CaObject1 ();
64 CaObject1 ca2 = new CaObject1 ();
65 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
66 RunTestCreateCao (ca, ca2);
70 public void TestCreateHttpCao ()
72 CaObject2 ca = new CaObject2 ();
73 CaObject2 ca2 = new CaObject2 ();
74 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
75 RunTestCreateCao (ca, ca2);
78 public void RunTestCreateCao (BaseObject ca, BaseObject ca2)
80 Assert.AreEqual (0, ca.counter, "#1");
83 Assert.AreEqual (1, ca.counter, "#2");
85 Assert.AreEqual (0, ca2.counter, "#3");
88 Assert.AreEqual (1, ca2.counter, "#4");
90 Assert.AreEqual (1, ca.counter, "#5");
94 public void TestCreateTcpWkoSingleCall ()
96 WkObjectSinglecall1 ca = new WkObjectSinglecall1 ();
97 WkObjectSinglecall1 ca2 = new WkObjectSinglecall1 ();
98 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
99 RunTestCreateWkoSingleCall (ca, ca2);
103 public void TestCreateTcpWkoSingleton ()
105 WkObjectSingleton1 ca = new WkObjectSingleton1 ();
106 WkObjectSingleton1 ca2 = new WkObjectSingleton1 ();
107 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
108 RunTestCreateWkoSingleton (ca, ca2);
112 [Category ("NotWorking")]
113 public void TestCreateHttpWkoSingleCall ()
115 WkObjectSinglecall2 ca = new WkObjectSinglecall2 ();
116 WkObjectSinglecall2 ca2 = new WkObjectSinglecall2 ();
117 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
118 RunTestCreateWkoSingleCall (ca, ca2);
122 [Category ("NotWorking")]
123 public void TestCreateHttpWkoSingleton ()
125 WkObjectSingleton2 ca = new WkObjectSingleton2 ();
126 WkObjectSingleton2 ca2 = new WkObjectSingleton2 ();
127 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
128 RunTestCreateWkoSingleton (ca, ca2);
131 public void RunTestCreateWkoSingleCall (BaseObject ca, BaseObject ca2)
133 Assert.AreEqual (0, ca.counter, "#1");
135 Assert.AreEqual (0, ca.counter, "#2");
137 Assert.AreEqual (0, ca2.counter, "#3");
139 Assert.AreEqual (0, ca2.counter, "#4");
142 public void RunTestCreateWkoSingleton (BaseObject ca, BaseObject ca2)
144 Assert.AreEqual (0, ca.counter, "#1");
146 Assert.AreEqual (1, ca.counter, "#2");
148 Assert.AreEqual (2, ca2.counter, "#3");
150 Assert.AreEqual (3, ca2.counter, "#4");
153 [TestFixtureTearDown]
156 ChannelServices.UnregisterChannel (tcp);
157 ChannelServices.UnregisterChannel (http);
163 public class ActivationServer: MarshalByRefObject
168 public ActivationServer ()
170 TcpPort = NetworkHelpers.FindFreePort ();
171 HttpPort = NetworkHelpers.FindFreePort ();
172 tcp = new TcpChannel (TcpPort);
173 http = new HttpChannel (HttpPort);
175 ChannelServices.RegisterChannel (tcp);
176 ChannelServices.RegisterChannel (http);
178 RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject1));
179 RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject2));
180 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall1), "wkoSingleCall1", WellKnownObjectMode.SingleCall);
181 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton1), "wkoSingleton1", WellKnownObjectMode.Singleton);
182 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall2), "wkoSingleCall2", WellKnownObjectMode.SingleCall);
183 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton2), "wkoSingleton2", WellKnownObjectMode.Singleton);
188 ChannelServices.UnregisterChannel (tcp);
189 ChannelServices.UnregisterChannel (http);
192 public int TcpPort { get; private set; }
193 public int HttpPort { get; private set; }
196 public class BaseObject: MarshalByRefObject
199 public static int CreationCount;
207 public class CaObject1: BaseObject
211 public class CaObject2: BaseObject
215 public class WkObjectSinglecall1: BaseObject
219 public class WkObjectSingleton1: BaseObject
223 public class WkObjectSinglecall2: BaseObject
227 public class WkObjectSingleton2: BaseObject