aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs
diff options
context:
space:
mode:
authorlbsa712009-06-05 06:22:08 +0000
committerlbsa712009-06-05 06:22:08 +0000
commitfd5e45733c0f9912117ed2c151896f62f8265586 (patch)
tree0fe057eb9853e8bf1448f91a34e549fcb2b4412e /OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs
parentCommitting mcortez's FlotsamAssetCache after several positive reviews. (diff)
downloadopensim-SC-fd5e45733c0f9912117ed2c151896f62f8265586.zip
opensim-SC-fd5e45733c0f9912117ed2c151896f62f8265586.tar.gz
opensim-SC-fd5e45733c0f9912117ed2c151896f62f8265586.tar.bz2
opensim-SC-fd5e45733c0f9912117ed2c151896f62f8265586.tar.xz
* Restructured Scenes Tests to follow (what I conceive of as being) current directory standards. (pt 1 - thank you, svn. not.)
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs184
1 files changed, 0 insertions, 184 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs b/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs
deleted file mode 100644
index dae095f..0000000
--- a/OpenSim/Region/Framework/Scenes/Tests/EntityManagerTests.cs
+++ /dev/null
@@ -1,184 +0,0 @@
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.Reflection;
30using System.Threading;
31using System.Text;
32using System.Collections.Generic;
33using Nini.Config;
34using NUnit.Framework;
35using NUnit.Framework.SyntaxHelpers;
36using OpenMetaverse;
37using OpenSim.Framework;
38using OpenSim.Framework.Communications;
39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Tests.Common;
41using OpenSim.Tests.Common.Setup;
42
43namespace OpenSim.Region.Framework.Scenes.Tests
44{
45 [TestFixture, LongRunning]
46 public class EntityManagerTests
47 {
48 static public Random random;
49 SceneObjectGroup found;
50 Scene scene = SceneSetupHelpers.SetupScene();
51
52 [Test]
53 public void T010_AddObjects()
54 {
55 TestHelper.InMethod();
56 // Console.WriteLine("Beginning test {0}", MethodBase.GetCurrentMethod());
57
58 random = new Random();
59 SceneObjectGroup found;
60 EntityManager entman = new EntityManager();
61 SceneObjectGroup sog = NewSOG();
62 UUID obj1 = sog.UUID;
63 uint li1 = sog.LocalId;
64 entman.Add(sog);
65 sog = NewSOG();
66 UUID obj2 = sog.UUID;
67 uint li2 = sog.LocalId;
68 entman.Add(sog);
69
70 found = (SceneObjectGroup)entman[obj1];
71 Assert.That(found.UUID ,Is.EqualTo(obj1) );
72 found = (SceneObjectGroup)entman[li1];
73 Assert.That(found.UUID ,Is.EqualTo(obj1) );
74 found = (SceneObjectGroup)entman[obj2];
75 Assert.That(found.UUID ,Is.EqualTo(obj2) );
76 found = (SceneObjectGroup)entman[li2];
77 Assert.That(found.UUID ,Is.EqualTo(obj2) );
78
79 entman.Remove(obj1);
80 entman.Remove(li2);
81
82 Assert.That(entman.ContainsKey(obj1), Is.False);
83 Assert.That(entman.ContainsKey(li1), Is.False);
84 Assert.That(entman.ContainsKey(obj2), Is.False);
85 Assert.That(entman.ContainsKey(li2), Is.False);
86 }
87
88 [Test]
89 public void T011_ThreadAddRemoveTest()
90 {
91 TestHelper.InMethod();
92 // Console.WriteLine("Beginning test {0}", MethodBase.GetCurrentMethod());
93
94 // This test adds and removes with mutiple threads, attempting to break the
95 // uuid and localid dictionary coherence.
96 EntityManager entman = new EntityManager();
97 SceneObjectGroup sog = NewSOG();
98 for (int j=0; j<20; j++)
99 {
100 List<Thread> trdlist = new List<Thread>();
101
102 for (int i=0; i<4; i++)
103 {
104 // Adds scene object
105 NewTestThreads test = new NewTestThreads(entman,sog);
106 Thread start = new Thread(new ThreadStart(test.TestAddSceneObject));
107 start.Start();
108 trdlist.Add(start);
109
110 // Removes it
111 test = new NewTestThreads(entman,sog);
112 start = new Thread(new ThreadStart(test.TestRemoveSceneObject));
113 start.Start();
114 trdlist.Add(start);
115 }
116 foreach (Thread thread in trdlist)
117 {
118 thread.Join();
119 }
120 if (entman.ContainsKey(sog.UUID) || entman.ContainsKey(sog.LocalId)) {
121 found = (SceneObjectGroup)entman[sog.UUID];
122 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
123 found = (SceneObjectGroup)entman[sog.LocalId];
124 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
125 }
126 }
127 }
128
129 private SceneObjectGroup NewSOG()
130 {
131 SceneObjectGroup sog = new SceneObjectGroup();
132 SceneObjectPart sop = new SceneObjectPart(UUID.Random(), PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
133 sop.Name = RandomName();
134 sop.Description = sop.Name;
135 sop.Text = RandomName();
136 sop.SitName = RandomName();
137 sop.TouchName = RandomName();
138 sop.ObjectFlags |= (uint)PrimFlags.Phantom;
139
140 sog.SetRootPart(sop);
141
142 scene.AddNewSceneObject(sog, false);
143
144 return sog;
145 }
146
147 private static string RandomName()
148 {
149 StringBuilder name = new StringBuilder();
150 int size = random.Next(40,80);
151 char ch ;
152 for (int i=0; i<size; i++)
153 {
154 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
155 name.Append(ch);
156 }
157 return name.ToString();
158 }
159 }
160
161 public class NewTestThreads
162 {
163 private EntityManager entman;
164 private SceneObjectGroup sog;
165 private Random random;
166
167 public NewTestThreads(EntityManager entman, SceneObjectGroup sog)
168 {
169 this.entman = entman;
170 this.sog = sog;
171 this.random = new Random();
172 }
173 public void TestAddSceneObject()
174 {
175 Thread.Sleep(random.Next(0,50));
176 entman.Add(sog);
177 }
178 public void TestRemoveSceneObject()
179 {
180 Thread.Sleep(random.Next(0,50));
181 entman.Remove(sog.UUID);
182 }
183 }
184} \ No newline at end of file