OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SceneObjectCrossingTests.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 Nini.Config;
31 using NUnit.Framework;
32 using OpenMetaverse;
33 using OpenSim.Framework;
34 using OpenSim.Region.CoreModules.Framework;
35 using OpenSim.Region.CoreModules.Framework.EntityTransfer;
36 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
37 using OpenSim.Region.CoreModules.World.Land;
38 using OpenSim.Region.OptionalModules;
39 using OpenSim.Tests.Common;
40 using System.Threading;
41 
42 namespace OpenSim.Region.Framework.Scenes.Tests
43 {
45  {
46  [TestFixtureSetUp]
47  public void FixtureInit()
48  {
49  // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
50  Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
51  }
52 
53  [TestFixtureTearDown]
54  public void TearDown()
55  {
56  // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
57  // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
58  // tests really shouldn't).
59  Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
60  }
61 
65  [Test]
67  {
68 
69  TestHelpers.InMethod();
70 // TestHelpers.EnableLogging();
71 
72  UUID userId = TestHelpers.ParseTail(0x1);
73  int sceneObjectIdTail = 0x2;
74 
78 
79  IConfigSource config = new IniConfigSource();
80  IConfig modulesConfig = config.AddConfig("Modules");
81  modulesConfig.Set("EntityTransferModule", etmA.Name);
82  modulesConfig.Set("SimulationServices", lscm.Name);
83 
84  SceneHelpers sh = new SceneHelpers();
85  TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
86  TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
87 
88  SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
89  SceneHelpers.SetupSceneModules(sceneA, config, etmA);
90  SceneHelpers.SetupSceneModules(sceneB, config, etmB);
91 
92  SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail);
93  UUID so1Id = so1.UUID;
94  so1.AbsolutePosition = new Vector3(128, 10, 20);
95 
96  // Cross with a negative value
97  so1.AbsolutePosition = new Vector3(128, -10, 20);
98 
99  // crossing is async
100  Thread.Sleep(500);
101 
102  Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id));
103  Assert.NotNull(sceneB.GetSceneObjectGroup(so1Id));
104  }
105 
113  [Test]
115  {
116  TestHelpers.InMethod();
117 // TestHelpers.EnableLogging();
118 
119  UUID userId = TestHelpers.ParseTail(0x1);
120  int sceneObjectIdTail = 0x2;
121  Vector3 so1StartPos = new Vector3(128, 10, 20);
122 
126 
127  IConfigSource config = new IniConfigSource();
128  IConfig modulesConfig = config.AddConfig("Modules");
129  modulesConfig.Set("EntityTransferModule", etmA.Name);
130  modulesConfig.Set("SimulationServices", lscm.Name);
131  IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
132 
133  // In order to run a single threaded regression test we do not want the entity transfer module waiting
134  // for a callback from the destination scene before removing its avatar data.
135  entityTransferConfig.Set("wait_for_callback", false);
136 
137  SceneHelpers sh = new SceneHelpers();
138  TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
139  TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
140 
141  SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
142  SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
143  SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
144 
145  SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail);
146  UUID so1Id = so1.UUID;
147  so1.AbsolutePosition = so1StartPos;
148 
149  AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
150  TestClient tc = new TestClient(acd, sceneA);
151  List<TestClient> destinationTestClients = new List<TestClient>();
152  EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
153 
154  ScenePresence sp1SceneA = SceneHelpers.AddScenePresence(sceneA, tc, acd);
155  sp1SceneA.AbsolutePosition = so1StartPos;
156  sp1SceneA.HandleAgentRequestSit(sp1SceneA.ControllingClient, sp1SceneA.UUID, so1.UUID, Vector3.Zero);
157 
158  // Cross
159  sceneA.SceneGraph.UpdatePrimGroupPosition(
160  so1.LocalId, new Vector3(so1StartPos.X, so1StartPos.Y - 20, so1StartPos.Z), userId);
161 
162  // crossing is async
163  Thread.Sleep(500);
164 
165  SceneObjectGroup so1PostCross;
166 
167  {
168  ScenePresence sp1SceneAPostCross = sceneA.GetScenePresence(userId);
169  Assert.IsTrue(sp1SceneAPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly false");
170 
171  ScenePresence sp1SceneBPostCross = sceneB.GetScenePresence(userId);
172  TestClient sceneBTc = ((TestClient)sp1SceneBPostCross.ControllingClient);
173  sceneBTc.CompleteMovement();
174 
175  Assert.IsFalse(sp1SceneBPostCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true");
176  Assert.IsTrue(sp1SceneBPostCross.IsSatOnObject);
177 
178  Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id), "uck");
179  so1PostCross = sceneB.GetSceneObjectGroup(so1Id);
180  Assert.NotNull(so1PostCross);
181  Assert.AreEqual(1, so1PostCross.GetSittingAvatarsCount());
182  }
183 
184  Vector3 so1PostCrossPos = so1PostCross.AbsolutePosition;
185 
186 // Console.WriteLine("CRISSCROSS");
187 
188  // Recross
189  sceneB.SceneGraph.UpdatePrimGroupPosition(
190  so1PostCross.LocalId, new Vector3(so1PostCrossPos.X, so1PostCrossPos.Y + 20, so1PostCrossPos.Z), userId);
191 
192  // crossing is async
193  Thread.Sleep(500);
194 
195  {
196  ScenePresence sp1SceneBPostReCross = sceneB.GetScenePresence(userId);
197  Assert.IsTrue(sp1SceneBPostReCross.IsChildAgent, "sp1SceneBPostReCross.IsChildAgent unexpectedly false");
198 
199  ScenePresence sp1SceneAPostReCross = sceneA.GetScenePresence(userId);
200  TestClient sceneATc = ((TestClient)sp1SceneAPostReCross.ControllingClient);
201  sceneATc.CompleteMovement();
202 
203  Assert.IsFalse(sp1SceneAPostReCross.IsChildAgent, "sp1SceneAPostCross.IsChildAgent unexpectedly true");
204  Assert.IsTrue(sp1SceneAPostReCross.IsSatOnObject);
205 
206  Assert.IsNull(sceneB.GetSceneObjectGroup(so1Id), "uck2");
207  SceneObjectGroup so1PostReCross = sceneA.GetSceneObjectGroup(so1Id);
208  Assert.NotNull(so1PostReCross);
209  Assert.AreEqual(1, so1PostReCross.GetSittingAvatarsCount());
210  }
211  }
212 
220  [Test]
222  {
223  TestHelpers.InMethod();
224 // TestHelpers.EnableLogging();
225 
226  UUID userId = TestHelpers.ParseTail(0x1);
227  int sceneObjectIdTail = 0x2;
228 
234 
235  IConfigSource config = new IniConfigSource();
236  IConfig modulesConfig = config.AddConfig("Modules");
237  modulesConfig.Set("EntityTransferModule", etmA.Name);
238  modulesConfig.Set("SimulationServices", lscm.Name);
239 
240  IConfig permissionsConfig = config.AddConfig("Permissions");
241  permissionsConfig.Set("permissionmodules", "PrimLimitsModule");
242 
243  SceneHelpers sh = new SceneHelpers();
244  TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
245  TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
246 
247  SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
248  SceneHelpers.SetupSceneModules(
249  sceneA, config, etmA, lmmA, new PrimLimitsModule(), new PrimCountModule());
250  SceneHelpers.SetupSceneModules(
251  sceneB, config, etmB, lmmB, new PrimLimitsModule(), new PrimCountModule());
252 
253  // We must set up the parcel for this to work. Normally this is taken care of by OpenSimulator startup
254  // code which is not yet easily invoked by tests.
255  lmmA.EventManagerOnNoLandDataFromStorage();
256  lmmB.EventManagerOnNoLandDataFromStorage();
257 
258  SceneObjectGroup so1 = SceneHelpers.AddSceneObject(sceneA, 1, userId, "", sceneObjectIdTail);
259  UUID so1Id = so1.UUID;
260  so1.AbsolutePosition = new Vector3(128, 10, 20);
261 
262  // Cross with a negative value. We must make this call rather than setting AbsolutePosition directly
263  // because only this will execute permission checks in the source region.
264  sceneA.SceneGraph.UpdatePrimGroupPosition(so1.LocalId, new Vector3(128, -10, 20), userId);
265 
266  // crossing is async
267  Thread.Sleep(500);
268 
269  Assert.IsNull(sceneA.GetSceneObjectGroup(so1Id));
270  Assert.NotNull(sceneB.GetSceneObjectGroup(so1Id));
271  }
272  }
273 }
void TestCrossOnSameSimulatorPrimLimitsOkay()
Test cross with no prim limit module.
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
void TestCrossOnSameSimulator()
Test cross with no prim limit module.
void TestCrossOnSameSimulatorWithSittingAvatar()
Test cross with no prim limit module.