diff options
author | Justin Clark-Casey (justincc) | 2014-07-02 23:48:44 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-07-02 23:49:25 +0100 |
commit | 889194db63016ad4b9ecb0c6ae82d3d9c7632c95 (patch) | |
tree | 823eba42a9ce5fcb04b8c7e1ff6e50deedc726f6 /OpenSim/Region | |
parent | minor: Change default max phys prim size in code to match OpenSimDefaults.ini (diff) | |
download | opensim-SC-889194db63016ad4b9ecb0c6ae82d3d9c7632c95.zip opensim-SC-889194db63016ad4b9ecb0c6ae82d3d9c7632c95.tar.gz opensim-SC-889194db63016ad4b9ecb0c6ae82d3d9c7632c95.tar.bz2 opensim-SC-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/Application/OpenSimBase.cs | 44 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs | 9 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Scene.cs | 1 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/SharedRegionModuleTests.cs | 249 |
4 files changed, 290 insertions, 13 deletions
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 4c1914a..d2dce24 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs | |||
@@ -71,6 +71,20 @@ namespace OpenSim | |||
71 | // OpenSim.ini Section name for ESTATES Settings | 71 | // OpenSim.ini Section name for ESTATES Settings |
72 | public const string ESTATE_SECTION_NAME = "Estates"; | 72 | public const string ESTATE_SECTION_NAME = "Estates"; |
73 | 73 | ||
74 | /// <summary> | ||
75 | /// Allow all plugin loading to be disabled for tests/debug. | ||
76 | /// </summary> | ||
77 | /// <remarks> | ||
78 | /// true by default | ||
79 | /// </remarks> | ||
80 | public bool EnableInitialPluginLoad { get; set; } | ||
81 | |||
82 | /// <summary> | ||
83 | /// Control whether we attempt to load an estate data service. | ||
84 | /// </summary> | ||
85 | /// <remarks>For tests/debugging</remarks> | ||
86 | public bool LoadEstateDataService { get; set; } | ||
87 | |||
74 | protected string proxyUrl; | 88 | protected string proxyUrl; |
75 | protected int proxyOffset = 0; | 89 | protected int proxyOffset = 0; |
76 | 90 | ||
@@ -96,7 +110,7 @@ namespace OpenSim | |||
96 | 110 | ||
97 | public ConsoleCommand CreateAccount = null; | 111 | public ConsoleCommand CreateAccount = null; |
98 | 112 | ||
99 | protected List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>(); | 113 | public List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>(); |
100 | 114 | ||
101 | /// <value> | 115 | /// <value> |
102 | /// The config information passed into the OpenSimulator region server. | 116 | /// The config information passed into the OpenSimulator region server. |
@@ -135,6 +149,8 @@ namespace OpenSim | |||
135 | /// <param name="configSource"></param> | 149 | /// <param name="configSource"></param> |
136 | public OpenSimBase(IConfigSource configSource) : base() | 150 | public OpenSimBase(IConfigSource configSource) : base() |
137 | { | 151 | { |
152 | EnableInitialPluginLoad = true; | ||
153 | LoadEstateDataService = true; | ||
138 | LoadConfigSettings(configSource); | 154 | LoadConfigSettings(configSource); |
139 | } | 155 | } |
140 | 156 | ||
@@ -236,20 +252,25 @@ namespace OpenSim | |||
236 | if (String.IsNullOrEmpty(module)) | 252 | if (String.IsNullOrEmpty(module)) |
237 | throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [EstateDataStore] or [EstateService] section"); | 253 | throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [EstateDataStore] or [EstateService] section"); |
238 | 254 | ||
239 | m_estateDataService = ServerUtils.LoadPlugin<IEstateDataService>(module, new object[] { Config }); | 255 | if (LoadEstateDataService) |
240 | if (m_estateDataService == null) | 256 | { |
241 | throw new Exception( | 257 | m_estateDataService = ServerUtils.LoadPlugin<IEstateDataService>(module, new object[] { Config }); |
242 | string.Format( | 258 | if (m_estateDataService == null) |
243 | "Could not load an IEstateDataService implementation from {0}, as configured in the LocalServiceModule parameter of the [EstateDataStore] config section.", | 259 | throw new Exception( |
244 | module)); | 260 | string.Format( |
261 | "Could not load an IEstateDataService implementation from {0}, as configured in the LocalServiceModule parameter of the [EstateDataStore] config section.", | ||
262 | module)); | ||
263 | } | ||
245 | 264 | ||
246 | base.StartupSpecific(); | 265 | base.StartupSpecific(); |
247 | 266 | ||
248 | LoadPlugins(); | 267 | if (EnableInitialPluginLoad) |
268 | LoadPlugins(); | ||
269 | |||
270 | // We still want to post initalize any plugins even if loading has been disabled since a test may have | ||
271 | // inserted them manually. | ||
249 | foreach (IApplicationPlugin plugin in m_plugins) | 272 | foreach (IApplicationPlugin plugin in m_plugins) |
250 | { | ||
251 | plugin.PostInitialise(); | 273 | plugin.PostInitialise(); |
252 | } | ||
253 | 274 | ||
254 | if (m_console != null) | 275 | if (m_console != null) |
255 | AddPluginCommands(m_console); | 276 | AddPluginCommands(m_console); |
@@ -874,6 +895,9 @@ namespace OpenSim | |||
874 | try | 895 | try |
875 | { | 896 | { |
876 | SceneManager.Close(); | 897 | SceneManager.Close(); |
898 | |||
899 | foreach (IApplicationPlugin plugin in m_plugins) | ||
900 | plugin.Dispose(); | ||
877 | } | 901 | } |
878 | catch (Exception e) | 902 | catch (Exception e) |
879 | { | 903 | { |
diff --git a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs index 9b0e1f4..ebec9d2 100644 --- a/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/CenomeAssetCache.cs | |||
@@ -316,9 +316,12 @@ namespace OpenSim.Region.CoreModules.Asset | |||
316 | /// </summary> | 316 | /// </summary> |
317 | public void Close() | 317 | public void Close() |
318 | { | 318 | { |
319 | m_enabled = false; | 319 | if (m_enabled) |
320 | m_cache.Clear(); | 320 | { |
321 | m_cache = null; | 321 | m_enabled = false; |
322 | m_cache.Clear(); | ||
323 | m_cache = null; | ||
324 | } | ||
322 | } | 325 | } |
323 | 326 | ||
324 | /// <summary> | 327 | /// <summary> |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index ca42d5b..3957ba6 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs | |||
@@ -1894,6 +1894,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1894 | RegionInfo.RegionID, | 1894 | RegionInfo.RegionID, |
1895 | RegionInfo.RegionLocX, RegionInfo.RegionLocY, | 1895 | RegionInfo.RegionLocX, RegionInfo.RegionLocY, |
1896 | RegionInfo.RegionSizeX, RegionInfo.RegionSizeY); | 1896 | RegionInfo.RegionSizeX, RegionInfo.RegionSizeY); |
1897 | |||
1897 | if (error != String.Empty) | 1898 | if (error != String.Empty) |
1898 | throw new Exception(error); | 1899 | throw new Exception(error); |
1899 | } | 1900 | } |
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using Mono.Addins; | ||
32 | using Nini.Config; | ||
33 | using NUnit.Framework; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim; | ||
36 | using OpenSim.ApplicationPlugins.RegionModulesController; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Tests.Common; | ||
41 | |||
42 | namespace 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 | ||