clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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;
30 using System.Collections.Generic;
31 using System.Net;
32 using log4net.Config;
33 using Nini.Config;
34 using NUnit.Framework;
35 using OpenMetaverse;
36 using OpenMetaverse.Packets;
37 using OpenMetaverse.StructuredData;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Servers;
40 using OpenSim.Framework.Servers.HttpServer;
41 using OpenSim.Region.ClientStack.Linden;
42 using OpenSim.Region.CoreModules.Framework;
43 using OpenSim.Region.Framework.Scenes;
44 using OpenSim.Region.OptionalModules.World.NPC;
45 using OpenSim.Tests.Common;
46 using OpenSim.Tests.Common.Mock;
47  
48 namespace OpenSim.Region.ClientStack.Linden.Tests
49 {
50 [TestFixture]
51 public class EventQueueTests : OpenSimTestCase
52 {
53 private TestScene m_scene;
54 private EventQueueGetModule m_eqgMod;
55 private NPCModule m_npcMod;
56  
57 [SetUp]
58 public override void SetUp()
59 {
60 base.SetUp();
61  
62 uint port = 9999;
63 uint sslPort = 9998;
64  
65 // This is an unfortunate bit of clean up we have to do because MainServer manages things through static
66 // variables and the VM is not restarted between tests.
67 MainServer.RemoveHttpServer(port);
68  
69 BaseHttpServer server = new BaseHttpServer(port, false, sslPort, "");
70 MainServer.AddHttpServer(server);
71 MainServer.Instance = server;
72  
73 IConfigSource config = new IniConfigSource();
74 config.AddConfig("Startup");
75 config.Configs["Startup"].Set("EventQueue", "true");
76  
77 CapabilitiesModule capsModule = new CapabilitiesModule();
78 m_eqgMod = new EventQueueGetModule();
79  
80 // For NPC test support
81 config.AddConfig("NPC");
82 config.Configs["NPC"].Set("Enabled", "true");
83 m_npcMod = new NPCModule();
84  
85 m_scene = new SceneHelpers().SetupScene();
86 SceneHelpers.SetupSceneModules(m_scene, config, capsModule, m_eqgMod, m_npcMod);
87 }
88  
89 [Test]
90 public void TestAddForClient()
91 {
92 TestHelpers.InMethod();
93 // log4net.Config.XmlConfigurator.Configure();
94  
95 SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
96  
97 // TODO: Add more assertions for the other aspects of event queues
98 Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(1));
99 }
100  
101 [Test]
102 public void TestRemoveForClient()
103 {
104 TestHelpers.InMethod();
105 // TestHelpers.EnableLogging();
106  
107 UUID spId = TestHelpers.ParseTail(0x1);
108  
109 SceneHelpers.AddScenePresence(m_scene, spId);
110 m_scene.CloseAgent(spId, false);
111  
112 // TODO: Add more assertions for the other aspects of event queues
113 Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(0));
114 }
115  
116 [Test]
117 public void TestEnqueueMessage()
118 {
119 TestHelpers.InMethod();
120 // log4net.Config.XmlConfigurator.Configure();
121  
122 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
123  
124 string messageName = "TestMessage";
125  
126 m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), sp.UUID);
127  
128 Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID);
129  
130 Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK));
131  
132 // Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]);
133  
134 OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]);
135 OSDArray eventsOsd = (OSDArray)rawOsd["events"];
136  
137 bool foundUpdate = false;
138 foreach (OSD osd in eventsOsd)
139 {
140 OSDMap eventOsd = (OSDMap)osd;
141  
142 if (eventOsd["message"] == messageName)
143 foundUpdate = true;
144 }
145  
146 Assert.That(foundUpdate, Is.True, string.Format("Did not find {0} in response", messageName));
147 }
148  
149 /// <summary>
150 /// Test an attempt to put a message on the queue of a user that is not in the region.
151 /// </summary>
152 [Test]
153 public void TestEnqueueMessageNoUser()
154 {
155 TestHelpers.InMethod();
156 TestHelpers.EnableLogging();
157  
158 string messageName = "TestMessage";
159  
160 m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), TestHelpers.ParseTail(0x1));
161  
162 Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, TestHelpers.ParseTail(0x1));
163  
164 Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway));
165 }
166  
167 /// <summary>
168 /// NPCs do not currently have an event queue but a caller may try to send a message anyway, so check behaviour.
169 /// </summary>
170 [Test]
171 public void TestEnqueueMessageToNpc()
172 {
173 TestHelpers.InMethod();
174 // TestHelpers.EnableLogging();
175  
176 UUID npcId
177 = m_npcMod.CreateNPC(
178 "John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, new AvatarAppearance());
179  
180 ScenePresence npc = m_scene.GetScenePresence(npcId);
181  
182 string messageName = "TestMessage";
183  
184 m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), npc.UUID);
185  
186 Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, npc.UUID);
187  
188 Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway));
189 }
190 }
191 }