OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
ScenePresenceAgentTests.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Text;
32 using System.Threading;
33 using System.Timers;
35 using Nini.Config;
36 using NUnit.Framework;
37 using OpenMetaverse;
38 using OpenSim.Framework;
39 using OpenSim.Region.Framework.Scenes;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.ClientStack.Linden;
42 using OpenSim.Region.CoreModules.Framework.EntityTransfer;
43 using OpenSim.Region.CoreModules.World.Serialiser;
44 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
45 using OpenSim.Tests.Common;
47 using OpenSim.Services.Interfaces;
48 
49 namespace OpenSim.Region.Framework.Scenes.Tests
50 {
54  [TestFixture]
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 // {
81 //
85 //
89 // }
90 
91  [Test]
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 
119  [Test]
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]
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
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]
206  {
207  TestHelpers.InMethod();
208 // log4net.Config.XmlConfigurator.Configure();
209 
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.
231  scene.SimulationService.CreateAgent(null, region, acd, (uint)TeleportFlags.ViaLogin, ctx, out reason);
232 
233  Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
234  Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
235 
236  // There's no scene presence yet since only an agent circuit has been established.
237  Assert.That(scene.GetScenePresence(agentId), Is.Null);
238 
239  // *** This is the second stage, where the client established a child agent/scene presence using the
240  // circuit code given to the scene in stage 1 ***
241  TestClient client = new TestClient(acd, scene);
242  scene.AddNewAgent(client, PresenceType.User);
243 
244  Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
245  Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
246 
247  ScenePresence sp = scene.GetScenePresence(agentId);
248  Assert.That(sp, Is.Not.Null);
249  Assert.That(sp.UUID, Is.EqualTo(agentId));
250  Assert.That(sp.IsChildAgent, Is.True);
251  }
252 
260  [Test]
262  {
263  TestHelpers.InMethod();
264 // log4net.Config.XmlConfigurator.Configure();
265 
266 // UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
267 
268  TestScene myScene1 = new SceneHelpers().SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
269  TestScene myScene2 = new SceneHelpers().SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
270 
271  IConfigSource configSource = new IniConfigSource();
272  IConfig config = configSource.AddConfig("Startup");
273  config.Set("serverside_object_permissions", true);
274  config.Set("EventQueue", true);
275 
277 
279  SceneHelpers.SetupSceneModules(myScene1, configSource, etm, eqgm1);
280 
282  SceneHelpers.SetupSceneModules(myScene2, configSource, etm, eqgm2);
283 
284 // SceneHelpers.AddScenePresence(myScene1, agent1Id);
285 // ScenePresence childPresence = myScene2.GetScenePresence(agent1);
286 //
287 // // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents
288 // Assert.That(childPresence, Is.Not.Null);
289 // Assert.That(childPresence.IsChildAgent, Is.True);
290  }
291  }
292 }
void TestChildAgentEstablishedInNeighbour()
Test that if a root agent logs into a region, a child agent is also established in the neighbouring r...
OpenSim.Framework.Constants.TeleportFlags TeleportFlags
System.Timers.Timer Timer
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
OpenSim.Services.Interfaces.GridRegion GridRegion
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
System.Timers.Timer Timer
void TestDupeCompleteMovementCalls()
Test that duplicate complete movement calls are ignored.