2010-05-25 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Runtime.Remoting / Test / ActivationTests.cs
blobb70409344f9eb48f580153c3399e6796b87dd082
1 //
2 // MonoTests.Remoting.TcpCalls.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // 2003 (C) Copyright, Ximian, Inc.
7 //
9 using System;
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
19 [TestFixture]
20 public class ActivationTests
22 ActivationServer server;
23 TcpChannel tcp;
24 HttpClientChannel http;
26 [TestFixtureSetUp]
27 public void Run()
29 try
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");
50 catch (Exception ex)
52 Console.WriteLine (ex);
56 [Test]
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);
65 [Test]
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");
78 ca.counter++;
79 Assert.AreEqual (1, ca.counter, "#2");
81 Assert.AreEqual (0, ca2.counter, "#3");
83 ca2.counter++;
84 Assert.AreEqual (1, ca2.counter, "#4");
86 Assert.AreEqual (1, ca.counter, "#5");
89 [Test]
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);
98 [Test]
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);
107 [Test]
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);
117 [Test]
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");
130 ca.counter++;
131 Assert.AreEqual (0, ca.counter, "#2");
133 Assert.AreEqual (0, ca2.counter, "#3");
134 ca2.counter++;
135 Assert.AreEqual (0, ca2.counter, "#4");
138 public void RunTestCreateWkoSingleton (BaseObject ca, BaseObject ca2)
140 Assert.AreEqual (0, ca.counter, "#1");
141 ca.counter++;
142 Assert.AreEqual (1, ca.counter, "#2");
143 ca.counter++;
144 Assert.AreEqual (2, ca2.counter, "#3");
145 ca2.counter++;
146 Assert.AreEqual (3, ca2.counter, "#4");
149 [TestFixtureTearDown]
150 public void End ()
152 ChannelServices.UnregisterChannel (tcp);
153 ChannelServices.UnregisterChannel (http);
154 if (server != null)
155 server.Stop ();
159 public class ActivationServer: MarshalByRefObject
161 TcpChannel tcp;
162 HttpChannel http;
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);
180 public void Stop ()
182 ChannelServices.UnregisterChannel (tcp);
183 ChannelServices.UnregisterChannel (http);
187 public class BaseObject: MarshalByRefObject
189 public int counter;
190 public static int CreationCount;
192 public BaseObject ()
194 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