aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-07-02 23:48:44 +0100
committerJustin Clark-Casey (justincc)2014-07-02 23:49:25 +0100
commit889194db63016ad4b9ecb0c6ae82d3d9c7632c95 (patch)
tree823eba42a9ce5fcb04b8c7e1ff6e50deedc726f6 /OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs
parentminor: Change default max phys prim size in code to match OpenSimDefaults.ini (diff)
downloadopensim-SC_OLD-889194db63016ad4b9ecb0c6ae82d3d9c7632c95.zip
opensim-SC_OLD-889194db63016ad4b9ecb0c6ae82d3d9c7632c95.tar.gz
opensim-SC_OLD-889194db63016ad4b9ecb0c6ae82d3d9c7632c95.tar.bz2
opensim-SC_OLD-889194db63016ad4b9ecb0c6ae82d3d9c7632c95.tar.xz
Actually call Close() for shared region modules when the simulator is being shutdown.
Adds regression test for this case.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs249
1 files changed, 249 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs
new file mode 100644
index 0000000..d499f87
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs
@@ -0,0 +1,249 @@
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.Collections.Generic;
30using System.Net;
31using Mono.Addins;
32using Nini.Config;
33using NUnit.Framework;
34using OpenMetaverse;
35using OpenSim;
36using OpenSim.ApplicationPlugins.RegionModulesController;
37using OpenSim.Framework;
38using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
39using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Tests.Common;
41
42namespace OpenSim.Region.Framework.Scenes.Tests
43{
44 public class SharedRegionModuleTests : OpenSimTestCase
45 {
46 [Test]
47 public void TestLifecycle()
48 {
49 TestHelpers.InMethod();
50// TestHelpers.EnableLogging();
51
52 UUID estateOwnerId = TestHelpers.ParseTail(0x1);
53 UUID regionId = TestHelpers.ParseTail(0x10);
54
55 IConfigSource configSource = new IniConfigSource();
56 configSource.AddConfig("Startup");
57 configSource.AddConfig("Modules");
58
59// // We use this to skip estate questions
60 // Turns out not to be needed is estate owner id is pre-set in region information.
61// IConfig estateConfig = configSource.AddConfig(OpenSimBase.ESTATE_SECTION_NAME);
62// estateConfig.Set("DefaultEstateOwnerName", "Zaphod Beeblebrox");
63// estateConfig.Set("DefaultEstateOwnerUUID", estateOwnerId);
64// estateConfig.Set("DefaultEstateOwnerEMail", "zaphod@galaxy.com");
65// estateConfig.Set("DefaultEstateOwnerPassword", "two heads");
66
67 // For grid servic
68 configSource.AddConfig("GridService");
69 configSource.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
70 configSource.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
71 configSource.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
72 configSource.Configs["GridService"].Set("ConnectionString", "!static");
73
74 LocalGridServicesConnector gridService = new LocalGridServicesConnector();
75//
76 OpenSim sim = new OpenSim(configSource);
77
78 sim.SuppressExit = true;
79 sim.EnableInitialPluginLoad = false;
80 sim.LoadEstateDataService = false;
81 sim.NetServersInfo.HttpListenerPort = 0;
82
83 IRegistryCore reg = sim.ApplicationRegistry;
84
85 RegionInfo ri = new RegionInfo();
86 ri.RegionID = regionId;
87 ri.EstateSettings.EstateOwner = estateOwnerId;
88 ri.InternalEndPoint = new IPEndPoint(0, 0);
89
90 MockRegionModulesControllerPlugin rmcp = new MockRegionModulesControllerPlugin();
91 sim.m_plugins = new List<IApplicationPlugin>() { rmcp };
92 reg.RegisterInterface<IRegionModulesController>(rmcp);
93
94 // XXX: Have to initialize directly for now
95 rmcp.Initialise(sim);
96
97 rmcp.AddNode(gridService);
98
99 TestSharedRegion tsr = new TestSharedRegion();
100 rmcp.AddNode(tsr);
101
102 // FIXME: Want to use the real one eventually but this is currently directly tied into Mono.Addins
103 // which has been written in such a way that makes it impossible to use for regression tests.
104// RegionModulesControllerPlugin rmcp = new RegionModulesControllerPlugin();
105// rmcp.LoadModulesFromAddins = false;
106//// reg.RegisterInterface<IRegionModulesController>(rmcp);
107// rmcp.Initialise(sim);
108// rmcp.PostInitialise();
109// TypeExtensionNode node = new TypeExtensionNode();
110// node.
111// rmcp.AddNode(node, configSource.Configs["Modules"], new Dictionary<RuntimeAddin, IList<int>>());
112
113 sim.Startup();
114 IScene scene;
115 sim.CreateRegion(ri, out scene);
116
117 sim.Shutdown();
118
119 List<string> co = tsr.CallOrder;
120 int expectedEventCount = 6;
121
122 Assert.AreEqual(
123 expectedEventCount,
124 co.Count,
125 "Expected {0} events but only got {1} ({2})",
126 expectedEventCount, co.Count, string.Join(",", co));
127 Assert.AreEqual("Initialise", co[0]);
128 Assert.AreEqual("PostInitialise", co[1]);
129 Assert.AreEqual("AddRegion", co[2]);
130 Assert.AreEqual("RegionLoaded", co[3]);
131 Assert.AreEqual("RemoveRegion", co[4]);
132 Assert.AreEqual("Close", co[5]);
133 }
134 }
135
136 class TestSharedRegion : ISharedRegionModule
137 {
138 // FIXME: Should really use MethodInfo
139 public List<string> CallOrder = new List<string>();
140
141 public string Name { get { return "TestSharedRegion"; } }
142
143 public Type ReplaceableInterface { get { return null; } }
144
145 public void PostInitialise()
146 {
147 CallOrder.Add("PostInitialise");
148 }
149
150 public void Initialise(IConfigSource source)
151 {
152 CallOrder.Add("Initialise");
153 }
154
155 public void Close()
156 {
157 CallOrder.Add("Close");
158 }
159
160 public void AddRegion(Scene scene)
161 {
162 CallOrder.Add("AddRegion");
163 }
164
165 public void RemoveRegion(Scene scene)
166 {
167 CallOrder.Add("RemoveRegion");
168 }
169
170 public void RegionLoaded(Scene scene)
171 {
172 CallOrder.Add("RegionLoaded");
173 }
174 }
175
176 class MockRegionModulesControllerPlugin : IRegionModulesController, IApplicationPlugin
177 {
178 // List of shared module instances, for adding to Scenes
179 private List<ISharedRegionModule> m_sharedInstances = new List<ISharedRegionModule>();
180
181 // Config access
182 private OpenSimBase m_openSim;
183
184 public string Version { get { return "0"; } }
185 public string Name { get { return "MockRegionModulesControllerPlugin"; } }
186
187 public void Initialise() {}
188
189 public void Initialise(OpenSimBase sim)
190 {
191 m_openSim = sim;
192 }
193
194 /// <summary>
195 /// Called when the application loading is completed
196 /// </summary>
197 public void PostInitialise()
198 {
199 foreach (ISharedRegionModule module in m_sharedInstances)
200 module.PostInitialise();
201 }
202
203 public void AddRegionToModules(Scene scene)
204 {
205 List<ISharedRegionModule> sharedlist = new List<ISharedRegionModule>();
206
207 foreach (ISharedRegionModule module in m_sharedInstances)
208 {
209 module.AddRegion(scene);
210 scene.AddRegionModule(module.Name, module);
211
212 sharedlist.Add(module);
213 }
214
215 foreach (ISharedRegionModule module in sharedlist)
216 {
217 module.RegionLoaded(scene);
218 }
219 }
220
221 public void RemoveRegionFromModules(Scene scene)
222 {
223 foreach (IRegionModuleBase module in scene.RegionModules.Values)
224 {
225// m_log.DebugFormat("[REGIONMODULE]: Removing scene {0} from module {1}",
226// scene.RegionInfo.RegionName, module.Name);
227 module.RemoveRegion(scene);
228 }
229
230 scene.RegionModules.Clear();
231 }
232
233 public void AddNode(ISharedRegionModule module)
234 {
235 m_sharedInstances.Add(module);
236 module.Initialise(m_openSim.ConfigSource.Source);
237 }
238
239 public void Dispose()
240 {
241 // We expect that all regions have been removed already
242 while (m_sharedInstances.Count > 0)
243 {
244 m_sharedInstances[0].Close();
245 m_sharedInstances.RemoveAt(0);
246 }
247 }
248 }
249} \ No newline at end of file