aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs291
1 files changed, 291 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
new file mode 100644
index 0000000..06e6423
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAgentTests.cs
@@ -0,0 +1,291 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using System.Threading;
33using System.Timers;
34using Timer = System.Timers.Timer;
35using Nini.Config;
36using NUnit.Framework;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Communications;
40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.ClientStack.Linden;
43using OpenSim.Region.CoreModules.Framework.EntityTransfer;
44using OpenSim.Region.CoreModules.World.Serialiser;
45using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
46using OpenSim.Tests.Common;
47using GridRegion = OpenSim.Services.Interfaces.GridRegion;
48
49namespace OpenSim.Region.Framework.Scenes.Tests
50{
51 /// <summary>
52 /// Scene presence tests
53 /// </summary>
54 [TestFixture]
55 public class ScenePresenceAgentTests : OpenSimTestCase
56 {
57// public Scene scene, scene2, scene3;
58// public UUID agent1, agent2, agent3;
59// public static Random random;
60// public ulong region1, region2, region3;
61// public AgentCircuitData acd1;
62// public TestClient testclient;
63
64// [TestFixtureSetUp]
65// public void Init()
66// {
67//// TestHelpers.InMethod();
68////
69//// SceneHelpers sh = new SceneHelpers();
70////
71//// scene = sh.SetupScene("Neighbour x", UUID.Random(), 1000, 1000);
72//// scene2 = sh.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000);
73//// scene3 = sh.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000);
74////
75//// ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
76//// interregionComms.Initialise(new IniConfigSource());
77//// interregionComms.PostInitialise();
78//// SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms);
79//// SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), interregionComms);
80//// SceneHelpers.SetupSceneModules(scene3, new IniConfigSource(), interregionComms);
81//
82//// agent1 = UUID.Random();
83//// agent2 = UUID.Random();
84//// agent3 = UUID.Random();
85//
86//// region1 = scene.RegionInfo.RegionHandle;
87//// region2 = scene2.RegionInfo.RegionHandle;
88//// region3 = scene3.RegionInfo.RegionHandle;
89// }
90
91 [Test]
92 public void TestCreateRootScenePresence()
93 {
94 TestHelpers.InMethod();
95// TestHelpers.EnableLogging();
96
97 UUID spUuid = TestHelpers.ParseTail(0x1);
98
99 TestScene scene = new SceneHelpers().SetupScene();
100 SceneHelpers.AddScenePresence(scene, spUuid);
101
102 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
103 Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
104
105 ScenePresence sp = scene.GetScenePresence(spUuid);
106 Assert.That(sp, Is.Not.Null);
107 Assert.That(sp.IsChildAgent, Is.False);
108 Assert.That(sp.UUID, Is.EqualTo(spUuid));
109
110 Assert.That(scene.GetScenePresences().Count, Is.EqualTo(1));
111 }
112
113 /// <summary>
114 /// Test that duplicate complete movement calls are ignored.
115 /// </summary>
116 /// <remarks>
117 /// If duplicate calls are not ignored then there is a risk of race conditions or other unexpected effects.
118 /// </remarks>
119 [Test]
120 public void TestDupeCompleteMovementCalls()
121 {
122 TestHelpers.InMethod();
123// TestHelpers.EnableLogging();
124
125 UUID spUuid = TestHelpers.ParseTail(0x1);
126
127 TestScene scene = new SceneHelpers().SetupScene();
128
129 int makeRootAgentEvents = 0;
130 scene.EventManager.OnMakeRootAgent += spi => makeRootAgentEvents++;
131
132 ScenePresence sp = SceneHelpers.AddScenePresence(scene, spUuid);
133
134 Assert.That(makeRootAgentEvents, Is.EqualTo(1));
135
136 // Normally these would be invoked by a CompleteMovement message coming in to the UDP stack. But for
137 // convenience, here we will invoke it manually.
138 sp.CompleteMovement(sp.ControllingClient, true);
139
140 Assert.That(makeRootAgentEvents, Is.EqualTo(1));
141
142 // Check rest of exepcted parameters.
143 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
144 Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
145
146 Assert.That(sp.IsChildAgent, Is.False);
147 Assert.That(sp.UUID, Is.EqualTo(spUuid));
148
149 Assert.That(scene.GetScenePresences().Count, Is.EqualTo(1));
150 }
151
152 [Test]
153 public void TestCreateDuplicateRootScenePresence()
154 {
155 TestHelpers.InMethod();
156// TestHelpers.EnableLogging();
157
158 UUID spUuid = TestHelpers.ParseTail(0x1);
159
160 // The etm is only invoked by this test to check whether an agent is still in transit if there is a dupe
161 EntityTransferModule etm = new EntityTransferModule();
162
163 IConfigSource config = new IniConfigSource();
164 IConfig modulesConfig = config.AddConfig("Modules");
165 modulesConfig.Set("EntityTransferModule", etm.Name);
166 IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
167
168 // In order to run a single threaded regression test we do not want the entity transfer module waiting
169 // for a callback from the destination scene before removing its avatar data.
170 entityTransferConfig.Set("wait_for_callback", false);
171
172 TestScene scene = new SceneHelpers().SetupScene();
173 SceneHelpers.SetupSceneModules(scene, config, etm);
174 SceneHelpers.AddScenePresence(scene, spUuid);
175 SceneHelpers.AddScenePresence(scene, spUuid);
176
177 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
178 Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
179
180 ScenePresence sp = scene.GetScenePresence(spUuid);
181 Assert.That(sp, Is.Not.Null);
182 Assert.That(sp.IsChildAgent, Is.False);
183 Assert.That(sp.UUID, Is.EqualTo(spUuid));
184 }
185
186 [Test]
187 public void TestCloseClient()
188 {
189 TestHelpers.InMethod();
190// TestHelpers.EnableLogging();
191
192 TestScene scene = new SceneHelpers().SetupScene();
193 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
194
195 scene.CloseAgent(sp.UUID, false);
196
197 Assert.That(scene.GetScenePresence(sp.UUID), Is.Null);
198 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null);
199 Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(0));
200
201// TestHelpers.DisableLogging();
202 }
203
204 [Test]
205 public void TestCreateChildScenePresence()
206 {
207 TestHelpers.InMethod();
208// log4net.Config.XmlConfigurator.Configure();
209
210 LocalSimulationConnectorModule lsc = new LocalSimulationConnectorModule();
211
212 IConfigSource configSource = new IniConfigSource();
213 IConfig config = configSource.AddConfig("Modules");
214 config.Set("SimulationServices", "LocalSimulationConnectorModule");
215
216 SceneHelpers sceneHelpers = new SceneHelpers();
217 TestScene scene = sceneHelpers.SetupScene();
218 SceneHelpers.SetupSceneModules(scene, configSource, lsc);
219
220 UUID agentId = TestHelpers.ParseTail(0x01);
221 AgentCircuitData acd = SceneHelpers.GenerateAgentData(agentId);
222 acd.child = true;
223
224 GridRegion region = scene.GridService.GetRegionByName(UUID.Zero, scene.RegionInfo.RegionName);
225 string reason;
226
227 // *** This is the first stage, when a neighbouring region is told that a viewer is about to try and
228 // establish a child scene presence. We pass in the circuit code that the client has to connect with ***
229 // XXX: ViaLogin may not be correct here.
230 scene.SimulationService.CreateAgent(null, region, acd, (uint)TeleportFlags.ViaLogin, out reason);
231
232 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
233 Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
234
235 // There's no scene presence yet since only an agent circuit has been established.
236 Assert.That(scene.GetScenePresence(agentId), Is.Null);
237
238 // *** This is the second stage, where the client established a child agent/scene presence using the
239 // circuit code given to the scene in stage 1 ***
240 TestClient client = new TestClient(acd, scene);
241 scene.AddNewAgent(client, PresenceType.User);
242
243 Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
244 Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
245
246 ScenePresence sp = scene.GetScenePresence(agentId);
247 Assert.That(sp, Is.Not.Null);
248 Assert.That(sp.UUID, Is.EqualTo(agentId));
249 Assert.That(sp.IsChildAgent, Is.True);
250 }
251
252 /// <summary>
253 /// Test that if a root agent logs into a region, a child agent is also established in the neighbouring region
254 /// </summary>
255 /// <remarks>
256 /// Please note that unlike the other tests here, this doesn't rely on anything set up in the instance fields.
257 /// INCOMPLETE
258 /// </remarks>
259 [Test]
260 public void TestChildAgentEstablishedInNeighbour()
261 {
262 TestHelpers.InMethod();
263// log4net.Config.XmlConfigurator.Configure();
264
265// UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
266
267 TestScene myScene1 = new SceneHelpers().SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
268 TestScene myScene2 = new SceneHelpers().SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
269
270 IConfigSource configSource = new IniConfigSource();
271 IConfig config = configSource.AddConfig("Startup");
272 config.Set("serverside_object_permissions", true);
273 config.Set("EventQueue", true);
274
275 EntityTransferModule etm = new EntityTransferModule();
276
277 EventQueueGetModule eqgm1 = new EventQueueGetModule();
278 SceneHelpers.SetupSceneModules(myScene1, configSource, etm, eqgm1);
279
280 EventQueueGetModule eqgm2 = new EventQueueGetModule();
281 SceneHelpers.SetupSceneModules(myScene2, configSource, etm, eqgm2);
282
283// SceneHelpers.AddScenePresence(myScene1, agent1Id);
284// ScenePresence childPresence = myScene2.GetScenePresence(agent1);
285//
286// // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents
287// Assert.That(childPresence, Is.Not.Null);
288// Assert.That(childPresence.IsChildAgent, Is.True);
289 }
290 }
291} \ No newline at end of file