OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SharedRegionModuleTests.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.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 {
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 
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 
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 
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;
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 
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 
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 
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 }
OpenSim.Framework.RegionInfo RegionInfo
OpenSimulator Application Plugin framework interface
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
Interactive OpenSim region server
Definition: OpenSim.cs:55
Common OpenSimulator simulator code
Definition: OpenSimBase.cs:58
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void PostInitialise()
Called when the application loading is completed