aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/Tests
diff options
context:
space:
mode:
authorSean Dague2008-12-12 18:33:16 +0000
committerSean Dague2008-12-12 18:33:16 +0000
commit7a4f11b94da2ba2fbe24393ce2804214e199bce7 (patch)
tree106c9d1e745156a100da8bfc352a0997a04062fe /OpenSim/Region/Environment/Scenes/Tests
parentMade the casting of stings to floats more robust and work more like SL. (diff)
downloadopensim-SC-7a4f11b94da2ba2fbe24393ce2804214e199bce7.zip
opensim-SC-7a4f11b94da2ba2fbe24393ce2804214e199bce7.tar.gz
opensim-SC-7a4f11b94da2ba2fbe24393ce2804214e199bce7.tar.bz2
opensim-SC-7a4f11b94da2ba2fbe24393ce2804214e199bce7.tar.xz
* Deleted old EntiyList tests, added new EntityManager tests
* Edited EntityManager to treat Exceptions From: Arthur Rodrigo S Valadares <arthursv@linux.vnet.ibm.com>
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/Tests')
-rw-r--r--OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs (renamed from OpenSim/Region/Environment/Scenes/Tests/EntityListTests.cs)162
1 files changed, 51 insertions, 111 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Tests/EntityListTests.cs b/OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs
index 405eddd..5923a2c 100644
--- a/OpenSim/Region/Environment/Scenes/Tests/EntityListTests.cs
+++ b/OpenSim/Region/Environment/Scenes/Tests/EntityManagerTests.cs
@@ -32,11 +32,10 @@ using System.Text;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using Nini.Config; 33using Nini.Config;
34using NUnit.Framework; 34using NUnit.Framework;
35using OpenMetaverse;
36using OpenSim.Framework; 35using OpenSim.Framework;
37using OpenSim.Framework.Communications; 36using OpenSim.Framework.Communications;
38using OpenSim.Region.Environment.Scenes; 37using OpenSim.Region.Environment.Scenes;
39using OpenSim.Tests.Common.Mock; 38using OpenMetaverse;
40 39
41namespace OpenSim.Region.Environment.Scenes.Tests 40namespace OpenSim.Region.Environment.Scenes.Tests
42{ 41{
@@ -44,7 +43,7 @@ namespace OpenSim.Region.Environment.Scenes.Tests
44 /// Scene oriented tests 43 /// Scene oriented tests
45 /// </summary> 44 /// </summary>
46 [TestFixture] 45 [TestFixture]
47 public class EntityListTests 46 public class EntityManagerTests
48 { 47 {
49 static public Random random; 48 static public Random random;
50 SceneObjectGroup found; 49 SceneObjectGroup found;
@@ -55,116 +54,72 @@ namespace OpenSim.Region.Environment.Scenes.Tests
55 { 54 {
56 random = new Random(); 55 random = new Random();
57 SceneObjectGroup found; 56 SceneObjectGroup found;
58 EntityList entlist = new EntityList(); 57 EntityManager entman = new EntityManager();
59 SceneObjectGroup sog = NewSOG(); 58 SceneObjectGroup sog = NewSOG();
60 UUID obj1 = sog.UUID; 59 UUID obj1 = sog.UUID;
61 uint li1 = sog.LocalId; 60 uint li1 = sog.LocalId;
62 entlist.Add(sog); 61 entman.Add(sog);
63 sog = NewSOG(); 62 sog = NewSOG();
64 UUID obj2 = sog.UUID; 63 UUID obj2 = sog.UUID;
65 uint li2 = sog.LocalId; 64 uint li2 = sog.LocalId;
66 entlist.Add(sog); 65 entman.Add(sog);
67 66
68 found = entlist.FindObject(obj1); 67 found = (SceneObjectGroup)entman[obj1];
69 Assert.That(found.UUID ,Is.EqualTo(obj1) ); 68 Assert.That(found.UUID ,Is.EqualTo(obj1) );
70 found = entlist.FindObject(li1); 69 found = (SceneObjectGroup)entman[li1];
71 Assert.That(found.UUID ,Is.EqualTo(obj1) ); 70 Assert.That(found.UUID ,Is.EqualTo(obj1) );
72 found = entlist.FindObject(obj2); 71 found = (SceneObjectGroup)entman[obj2];
73 Assert.That(found.UUID ,Is.EqualTo(obj2) ); 72 Assert.That(found.UUID ,Is.EqualTo(obj2) );
74 found = entlist.FindObject(li2); 73 found = (SceneObjectGroup)entman[li2];
75 Assert.That(found.UUID ,Is.EqualTo(obj2) ); 74 Assert.That(found.UUID ,Is.EqualTo(obj2) );
76 75
77 entlist.RemoveObject(obj1); 76 entman.Remove(obj1);
78 entlist.RemoveObject(obj2); 77 entman.Remove(li2);
79 78
80 found = entlist.FindObject(obj1); 79 Assert.That(entman.ContainsKey(obj1), Is.False);
81 Assert.That(found, Is.Null); 80 Assert.That(entman.ContainsKey(li1), Is.False);
82 found = entlist.FindObject(obj2); 81 Assert.That(entman.ContainsKey(obj2), Is.False);
83 Assert.That(found, Is.Null); 82 Assert.That(entman.ContainsKey(li2), Is.False);
84 } 83 }
85 84
86 [Test] 85 [Test]
87 public void T011_ThreadAddRemoveTest() 86 public void T011_ThreadAddRemoveTest()
88 { 87 {
89 EntityList entlist = new EntityList(); 88 // This test adds and removes with mutiple threads, attempting to break the
90 Dictionary<UUID, uint> dict = new Dictionary<UUID,uint>(); 89 // uuid and localid dictionary coherence.
91 List<Thread> trdlist = new List<Thread>(); 90 EntityManager entman = new EntityManager();
92 for (int i=0; i<80; i++) 91 SceneObjectGroup sog = NewSOG();
93 { 92 for (int j=0; j<20; j++)
94 SceneObjectGroup sog = NewSOG();
95 TestThreads test = new TestThreads(entlist,sog);
96 Thread start = new Thread(new ThreadStart(test.TestAddSceneObject));
97 start.Start();
98 trdlist.Add(start);
99 dict.Add(sog.UUID, sog.LocalId);
100 }
101 foreach (Thread thread in trdlist)
102 {
103 thread.Join();
104 }
105 foreach (KeyValuePair<UUID, uint> item in dict)
106 { 93 {
107 found = entlist.FindObject(item.Key); 94 List<Thread> trdlist = new List<Thread>();
108 Assert.That(found.UUID,Is.EqualTo(item.Key));
109 found = entlist.FindObject(item.Value);
110 Assert.That(found.UUID,Is.EqualTo(item.Key));
111 95
112 // Start Removing 96 for (int i=0; i<4; i++)
113 TestThreads test = new TestThreads(entlist,found);
114 Thread start = new Thread(new ThreadStart(test.TestRemoveSceneObject));
115 start.Start();
116 trdlist.Add(start);
117 }
118 foreach (Thread thread in trdlist)
119 {
120 thread.Join();
121 }
122 foreach (KeyValuePair<UUID, uint> item in dict)
123 {
124 found = entlist.FindObject(item.Key);
125 Assert.That(found,Is.Null);
126 found = entlist.FindObject(item.Value);
127 Assert.That(found,Is.Null);
128 }
129 }
130
131 [Test]
132 public void T012_MultipleUUIDEntry()
133 {
134 EntityList entlist = new EntityList();
135 UUID id = UUID.Random();
136 //int exceptions = 0;
137 //Dictionary<UUID, uint> dict = new Dictionary<UUID,uint>();
138 List<Thread> trdlist = new List<Thread>();
139 SceneObjectGroup sog = NewSOG(id);
140 uint lid = sog.LocalId;
141 for (int i=0; i<30; i++)
142 {
143 try
144 { 97 {
145 TestThreads test = new TestThreads(entlist,sog); 98 // Adds scene object
99 NewTestThreads test = new NewTestThreads(entman,sog);
146 Thread start = new Thread(new ThreadStart(test.TestAddSceneObject)); 100 Thread start = new Thread(new ThreadStart(test.TestAddSceneObject));
147 start.Start(); 101 start.Start();
148 trdlist.Add(start); 102 trdlist.Add(start);
103
104 // Removes it
105 test = new NewTestThreads(entman,sog);
106 start = new Thread(new ThreadStart(test.TestRemoveSceneObject));
107 start.Start();
108 trdlist.Add(start);
149 } 109 }
150 catch 110 foreach (Thread thread in trdlist)
151 { 111 {
112 thread.Join();
113 }
114 if (entman.ContainsKey(sog.UUID) || entman.ContainsKey(sog.LocalId)) {
115 found = (SceneObjectGroup)entman[sog.UUID];
116 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
117 found = (SceneObjectGroup)entman[sog.LocalId];
118 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
152 } 119 }
153 } 120 }
154 foreach (Thread thread in trdlist)
155 {
156 thread.Join();
157 }
158 found = entlist.FindObject(sog.UUID);
159 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
160 found = entlist.FindObject(lid);
161 Assert.That(found.UUID,Is.EqualTo(sog.UUID));
162
163 entlist.RemoveObject(id);
164 found = entlist.FindObject(id);
165 Assert.That(found,Is.Null);
166 } 121 }
167 122
168 private SceneObjectGroup NewSOG() 123 private SceneObjectGroup NewSOG()
169 { 124 {
170 SceneObjectGroup sog = new SceneObjectGroup(); 125 SceneObjectGroup sog = new SceneObjectGroup();
@@ -182,26 +137,7 @@ namespace OpenSim.Region.Environment.Scenes.Tests
182 137
183 return sog; 138 return sog;
184 } 139 }
185 140
186 private SceneObjectGroup NewSOG(UUID id)
187 {
188 SceneObjectGroup sog = new SceneObjectGroup();
189 SceneObjectPart sop = new SceneObjectPart(UUID.Random(), PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
190 sop.UUID = id;
191 sop.Name = RandomName();
192 sop.Description = sop.Name;
193 sop.Text = RandomName();
194 sop.SitName = RandomName();
195 sop.TouchName = RandomName();
196 sop.ObjectFlags |= (uint)PrimFlags.Phantom;
197
198 sog.SetRootPart(sop);
199
200 scene.AddNewSceneObject(sog, false);
201
202 return sog;
203 }
204
205 private static string RandomName() 141 private static string RandomName()
206 { 142 {
207 StringBuilder name = new StringBuilder(); 143 StringBuilder name = new StringBuilder();
@@ -216,23 +152,27 @@ namespace OpenSim.Region.Environment.Scenes.Tests
216 } 152 }
217 } 153 }
218 154
219 public class TestThreads 155 public class NewTestThreads
220 { 156 {
221 private EntityList entlist; 157 private EntityManager entman;
222 private SceneObjectGroup sog; 158 private SceneObjectGroup sog;
159 private Random random;
223 160
224 public TestThreads(EntityList entlist, SceneObjectGroup sog) 161 public NewTestThreads(EntityManager entman, SceneObjectGroup sog)
225 { 162 {
226 this.entlist = entlist; 163 this.entman = entman;
227 this.sog = sog; 164 this.sog = sog;
165 this.random = new Random();
228 } 166 }
229 public void TestAddSceneObject() 167 public void TestAddSceneObject()
230 { 168 {
231 entlist.Add(sog); 169 Thread.Sleep(random.Next(0,50));
170 entman.Add(sog);
232 } 171 }
233 public void TestRemoveSceneObject() 172 public void TestRemoveSceneObject()
234 { 173 {
235 entlist.RemoveObject(sog.UUID); 174 Thread.Sleep(random.Next(0,50));
175 entman.Remove(sog.UUID);
236 } 176 }
237 } 177 }
238} \ No newline at end of file 178} \ No newline at end of file