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 namespace MonoTests.Remoting
20 public class ActivationTests
22 ActivationServer server;
24 HttpClientChannel http;
31 tcp = new TcpChannel (0);
33 Hashtable options = new Hashtable ();
34 options ["timeout"] = 10000; // 10s
35 http = new HttpClientChannel (options, null);
37 ChannelServices.RegisterChannel (tcp);
38 ChannelServices.RegisterChannel (http);
40 AppDomain domain = BaseCallTest.CreateDomain ("testdomain_activation");
41 server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer");
43 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), "tcp://localhost:9433");
44 RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), "http://localhost:9434");
45 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), "tcp://localhost:9433/wkoSingleCall1");
46 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), "tcp://localhost:9433/wkoSingleton1");
47 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), "http://localhost:9434/wkoSingleCall2");
48 RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), "http://localhost:9434/wkoSingleton2");
52 Console.WriteLine (ex);
57 public void TestCreateTcpCao ()
59 CaObject1 ca = new CaObject1 ();
60 CaObject1 ca2 = new CaObject1 ();
61 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
62 RunTestCreateCao (ca, ca2);
66 public void TestCreateHttpCao ()
68 CaObject2 ca = new CaObject2 ();
69 CaObject2 ca2 = new CaObject2 ();
70 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
71 RunTestCreateCao (ca, ca2);
74 public void RunTestCreateCao (BaseObject ca, BaseObject ca2)
76 Assert.AreEqual (0, ca.counter, "#1");
79 Assert.AreEqual (1, ca.counter, "#2");
81 Assert.AreEqual (0, ca2.counter, "#3");
84 Assert.AreEqual (1, ca2.counter, "#4");
86 Assert.AreEqual (1, ca.counter, "#5");
90 public void TestCreateTcpWkoSingleCall ()
92 WkObjectSinglecall1 ca = new WkObjectSinglecall1 ();
93 WkObjectSinglecall1 ca2 = new WkObjectSinglecall1 ();
94 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
95 RunTestCreateWkoSingleCall (ca, ca2);
99 public void TestCreateTcpWkoSingleton ()
101 WkObjectSingleton1 ca = new WkObjectSingleton1 ();
102 WkObjectSingleton1 ca2 = new WkObjectSingleton1 ();
103 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
104 RunTestCreateWkoSingleton (ca, ca2);
108 [Category ("NotWorking")]
109 public void TestCreateHttpWkoSingleCall ()
111 WkObjectSinglecall2 ca = new WkObjectSinglecall2 ();
112 WkObjectSinglecall2 ca2 = new WkObjectSinglecall2 ();
113 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
114 RunTestCreateWkoSingleCall (ca, ca2);
118 [Category ("NotWorking")]
119 public void TestCreateHttpWkoSingleton ()
121 WkObjectSingleton2 ca = new WkObjectSingleton2 ();
122 WkObjectSingleton2 ca2 = new WkObjectSingleton2 ();
123 Assert.IsTrue (BaseObject.CreationCount == 0, "Objects created locally");
124 RunTestCreateWkoSingleton (ca, ca2);
127 public void RunTestCreateWkoSingleCall (BaseObject ca, BaseObject ca2)
129 Assert.AreEqual (0, ca.counter, "#1");
131 Assert.AreEqual (0, ca.counter, "#2");
133 Assert.AreEqual (0, ca2.counter, "#3");
135 Assert.AreEqual (0, ca2.counter, "#4");
138 public void RunTestCreateWkoSingleton (BaseObject ca, BaseObject ca2)
140 Assert.AreEqual (0, ca.counter, "#1");
142 Assert.AreEqual (1, ca.counter, "#2");
144 Assert.AreEqual (2, ca2.counter, "#3");
146 Assert.AreEqual (3, ca2.counter, "#4");
149 [TestFixtureTearDown]
152 ChannelServices.UnregisterChannel (tcp);
153 ChannelServices.UnregisterChannel (http);
159 public class ActivationServer: MarshalByRefObject
164 public ActivationServer ()
166 tcp = new TcpChannel (9433);
167 http = new HttpChannel (9434);
169 ChannelServices.RegisterChannel (tcp);
170 ChannelServices.RegisterChannel (http);
172 RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject1));
173 RemotingConfiguration.RegisterActivatedServiceType (typeof(CaObject2));
174 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall1), "wkoSingleCall1", WellKnownObjectMode.SingleCall);
175 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton1), "wkoSingleton1", WellKnownObjectMode.Singleton);
176 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSinglecall2), "wkoSingleCall2", WellKnownObjectMode.SingleCall);
177 RemotingConfiguration.RegisterWellKnownServiceType (typeof(WkObjectSingleton2), "wkoSingleton2", WellKnownObjectMode.Singleton);
182 ChannelServices.UnregisterChannel (tcp);
183 ChannelServices.UnregisterChannel (http);
187 public class BaseObject: MarshalByRefObject
190 public static int CreationCount;
198 public class CaObject1: BaseObject
202 public class CaObject2: BaseObject
206 public class WkObjectSinglecall1: BaseObject
210 public class WkObjectSingleton1: BaseObject
214 public class WkObjectSinglecall2: BaseObject
218 public class WkObjectSingleton2: BaseObject