OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
EventQueueTests.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;
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 
47 namespace OpenSim.Region.ClientStack.Linden.Tests
48 {
49  [TestFixture]
51  {
52  private TestScene m_scene;
53  private EventQueueGetModule m_eqgMod;
54  private NPCModule m_npcMod;
55 
56  [SetUp]
57  public override void SetUp()
58  {
59  base.SetUp();
60 
61  uint port = 9999;
62  uint sslPort = 9998;
63 
64  // This is an unfortunate bit of clean up we have to do because MainServer manages things through static
65  // variables and the VM is not restarted between tests.
66  MainServer.RemoveHttpServer(port);
67 
68  BaseHttpServer server = new BaseHttpServer(port, false, sslPort, "");
69  MainServer.AddHttpServer(server);
70  MainServer.Instance = server;
71 
72  IConfigSource config = new IniConfigSource();
73  config.AddConfig("Startup");
74  config.Configs["Startup"].Set("EventQueue", "true");
75 
76  CapabilitiesModule capsModule = new CapabilitiesModule();
77  m_eqgMod = new EventQueueGetModule();
78 
79  // For NPC test support
80  config.AddConfig("NPC");
81  config.Configs["NPC"].Set("Enabled", "true");
82  m_npcMod = new NPCModule();
83 
84  m_scene = new SceneHelpers().SetupScene();
85  SceneHelpers.SetupSceneModules(m_scene, config, capsModule, m_eqgMod, m_npcMod);
86  }
87 
88  [Test]
89  public void TestAddForClient()
90  {
91  TestHelpers.InMethod();
92 // log4net.Config.XmlConfigurator.Configure();
93 
94  SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
95 
96  // TODO: Add more assertions for the other aspects of event queues
97  Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(1));
98  }
99 
100  [Test]
101  public void TestRemoveForClient()
102  {
103  TestHelpers.InMethod();
104 // TestHelpers.EnableLogging();
105 
106  UUID spId = TestHelpers.ParseTail(0x1);
107 
108  SceneHelpers.AddScenePresence(m_scene, spId);
109  m_scene.CloseAgent(spId, false);
110 
111  // TODO: Add more assertions for the other aspects of event queues
112  Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(0));
113  }
114 
115  [Test]
116  public void TestEnqueueMessage()
117  {
118  TestHelpers.InMethod();
119 // log4net.Config.XmlConfigurator.Configure();
120 
121  ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));
122 
123  string messageName = "TestMessage";
124 
125  m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), sp.UUID);
126 
127  Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID);
128 
129  // initial queue as null events
130  eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID);
131  if((int)eventsResponse["int_response_code"] != (int)HttpStatusCode.OK)
132  {
133  eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID);
134  if((int)eventsResponse["int_response_code"] != (int)HttpStatusCode.OK)
135  eventsResponse = m_eqgMod.GetEvents(UUID.Zero, sp.UUID);
136  }
137 
138  Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.OK));
139 
140 // Console.WriteLine("Response [{0}]", (string)eventsResponse["str_response_string"]);
141 
142  OSDMap rawOsd = (OSDMap)OSDParser.DeserializeLLSDXml((string)eventsResponse["str_response_string"]);
143  OSDArray eventsOsd = (OSDArray)rawOsd["events"];
144 
145  bool foundUpdate = false;
146  foreach (OSD osd in eventsOsd)
147  {
148  OSDMap eventOsd = (OSDMap)osd;
149 
150  if (eventOsd["message"] == messageName)
151  foundUpdate = true;
152  }
153 
154  Assert.That(foundUpdate, Is.True, string.Format("Did not find {0} in response", messageName));
155  }
156 
160  [Test]
162  {
163  TestHelpers.InMethod();
164  TestHelpers.EnableLogging();
165 
166  string messageName = "TestMessage";
167 
168  m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), TestHelpers.ParseTail(0x1));
169 
170  Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, TestHelpers.ParseTail(0x1));
171 
172  Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway));
173  }
174 
178  [Test]
180  {
181  TestHelpers.InMethod();
182 // TestHelpers.EnableLogging();
183 
184  UUID npcId
185  = m_npcMod.CreateNPC(
186  "John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, m_scene, new AvatarAppearance());
187 
188  ScenePresence npc = m_scene.GetScenePresence(npcId);
189 
190  string messageName = "TestMessage";
191 
192  m_eqgMod.Enqueue(m_eqgMod.BuildEvent(messageName, new OSDMap()), npc.UUID);
193 
194  Hashtable eventsResponse = m_eqgMod.GetEvents(UUID.Zero, npc.UUID);
195 
196  Assert.That((int)eventsResponse["int_response_code"], Is.EqualTo((int)HttpStatusCode.BadGateway));
197  }
198  }
199 }
void TestEnqueueMessageNoUser()
Test an attempt to put a message on the queue of a user that is not in the region.
OpenMetaverse.StructuredData.OSDArray OSDArray
Contains the Avatar's Appearance and methods to manipulate the appearance.
OpenMetaverse.StructuredData.OSDMap OSDMap
static UUID ParseTail(int tail)
Parse tail section into full UUID.
Definition: TestHelpers.cs:140
OpenMetaverse.StructuredData.OSD OSD
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Interactive OpenSim region server
Definition: OpenSim.cs:55
void TestEnqueueMessageToNpc()
NPCs do not currently have an event queue but a caller may try to send a message anyway, so check behaviour.