1
0

SharedRegionModuleTests.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Net;
  30. using Mono.Addins;
  31. using Nini.Config;
  32. using NUnit.Framework;
  33. using OpenMetaverse;
  34. using OpenSim;
  35. using OpenSim.ApplicationPlugins.RegionModulesController;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Tests.Common;
  40. namespace OpenSim.Region.Framework.Scenes.Tests
  41. {
  42. public class SharedRegionModuleTests : OpenSimTestCase
  43. {
  44. // [Test]
  45. public void TestLifecycle()
  46. {
  47. TestHelpers.InMethod();
  48. TestHelpers.EnableLogging();
  49. UUID estateOwnerId = TestHelpers.ParseTail(0x1);
  50. UUID regionId = TestHelpers.ParseTail(0x10);
  51. IConfigSource configSource = new IniConfigSource();
  52. configSource.AddConfig("Startup");
  53. configSource.AddConfig("Modules");
  54. // // We use this to skip estate questions
  55. // Turns out not to be needed is estate owner id is pre-set in region information.
  56. // IConfig estateConfig = configSource.AddConfig(OpenSimBase.ESTATE_SECTION_NAME);
  57. // estateConfig.Set("DefaultEstateOwnerName", "Zaphod Beeblebrox");
  58. // estateConfig.Set("DefaultEstateOwnerUUID", estateOwnerId);
  59. // estateConfig.Set("DefaultEstateOwnerEMail", "[email protected]");
  60. // estateConfig.Set("DefaultEstateOwnerPassword", "two heads");
  61. // For grid servic
  62. configSource.AddConfig("GridService");
  63. configSource.Configs["Modules"].Set("GridServices", "RegionGridServicesConnector");
  64. configSource.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
  65. configSource.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
  66. configSource.Configs["GridService"].Set("ConnectionString", "!static");
  67. RegionGridServicesConnector gridService = new RegionGridServicesConnector();
  68. //
  69. OpenSim sim = new OpenSim(configSource);
  70. sim.SuppressExit = true;
  71. sim.EnableInitialPluginLoad = false;
  72. sim.LoadEstateDataService = false;
  73. sim.NetServersInfo.HttpListenerPort = 0;
  74. IRegistryCore reg = sim.ApplicationRegistry;
  75. RegionInfo ri = new RegionInfo();
  76. ri.RegionID = regionId;
  77. ri.EstateSettings.EstateOwner = estateOwnerId;
  78. ri.InternalEndPoint = new IPEndPoint(0, 0);
  79. MockRegionModulesControllerPlugin rmcp = new MockRegionModulesControllerPlugin();
  80. sim.m_plugins = new List<IApplicationPlugin>() { rmcp };
  81. reg.RegisterInterface<IRegionModulesController>(rmcp);
  82. // XXX: Have to initialize directly for now
  83. rmcp.Initialise(sim);
  84. rmcp.AddNode(gridService);
  85. TestSharedRegion tsr = new TestSharedRegion();
  86. rmcp.AddNode(tsr);
  87. // FIXME: Want to use the real one eventually but this is currently directly tied into Mono.Addins
  88. // which has been written in such a way that makes it impossible to use for regression tests.
  89. // RegionModulesControllerPlugin rmcp = new RegionModulesControllerPlugin();
  90. // rmcp.LoadModulesFromAddins = false;
  91. //// reg.RegisterInterface<IRegionModulesController>(rmcp);
  92. // rmcp.Initialise(sim);
  93. // rmcp.PostInitialise();
  94. // TypeExtensionNode node = new TypeExtensionNode();
  95. // node.
  96. // rmcp.AddNode(node, configSource.Configs["Modules"], new Dictionary<RuntimeAddin, IList<int>>());
  97. sim.Startup();
  98. IScene scene;
  99. sim.CreateRegion(ri, out scene);
  100. sim.Shutdown();
  101. List<string> co = tsr.CallOrder;
  102. int expectedEventCount = 6;
  103. Assert.AreEqual(
  104. expectedEventCount,
  105. co.Count,
  106. "Expected {0} events but only got {1} ({2})",
  107. expectedEventCount, co.Count, string.Join(",", co));
  108. Assert.AreEqual("Initialise", co[0]);
  109. Assert.AreEqual("PostInitialise", co[1]);
  110. Assert.AreEqual("AddRegion", co[2]);
  111. Assert.AreEqual("RegionLoaded", co[3]);
  112. Assert.AreEqual("RemoveRegion", co[4]);
  113. Assert.AreEqual("Close", co[5]);
  114. }
  115. }
  116. class TestSharedRegion : ISharedRegionModule
  117. {
  118. // FIXME: Should really use MethodInfo
  119. public List<string> CallOrder = new List<string>();
  120. public string Name { get { return "TestSharedRegion"; } }
  121. public Type ReplaceableInterface { get { return null; } }
  122. public void PostInitialise()
  123. {
  124. CallOrder.Add("PostInitialise");
  125. }
  126. public void Initialise(IConfigSource source)
  127. {
  128. CallOrder.Add("Initialise");
  129. }
  130. public void Close()
  131. {
  132. CallOrder.Add("Close");
  133. }
  134. public void AddRegion(Scene scene)
  135. {
  136. CallOrder.Add("AddRegion");
  137. }
  138. public void RemoveRegion(Scene scene)
  139. {
  140. CallOrder.Add("RemoveRegion");
  141. }
  142. public void RegionLoaded(Scene scene)
  143. {
  144. CallOrder.Add("RegionLoaded");
  145. }
  146. }
  147. class MockRegionModulesControllerPlugin : IRegionModulesController, IApplicationPlugin
  148. {
  149. // List of shared module instances, for adding to Scenes
  150. private List<ISharedRegionModule> m_sharedInstances = new List<ISharedRegionModule>();
  151. // Config access
  152. private OpenSimBase m_openSim;
  153. public string Version { get { return "0"; } }
  154. public string Name { get { return "MockRegionModulesControllerPlugin"; } }
  155. public void Initialise() {}
  156. public void Initialise(OpenSimBase sim)
  157. {
  158. m_openSim = sim;
  159. }
  160. /// <summary>
  161. /// Called when the application loading is completed
  162. /// </summary>
  163. public void PostInitialise()
  164. {
  165. foreach (ISharedRegionModule module in m_sharedInstances)
  166. module.PostInitialise();
  167. }
  168. public void AddRegionToModules(Scene scene)
  169. {
  170. List<ISharedRegionModule> sharedlist = new List<ISharedRegionModule>();
  171. foreach (ISharedRegionModule module in m_sharedInstances)
  172. {
  173. module.AddRegion(scene);
  174. scene.AddRegionModule(module.Name, module);
  175. sharedlist.Add(module);
  176. }
  177. foreach (ISharedRegionModule module in sharedlist)
  178. {
  179. module.RegionLoaded(scene);
  180. }
  181. }
  182. public void RemoveRegionFromModules(Scene scene)
  183. {
  184. foreach (IRegionModuleBase module in scene.RegionModules.Values)
  185. {
  186. // m_log.DebugFormat("[REGIONMODULE]: Removing scene {0} from module {1}",
  187. // scene.RegionInfo.RegionName, module.Name);
  188. module.RemoveRegion(scene);
  189. }
  190. scene.RegionModules.Clear();
  191. }
  192. public void AddNode(ISharedRegionModule module)
  193. {
  194. m_sharedInstances.Add(module);
  195. module.Initialise(m_openSim.ConfigSource.Source);
  196. }
  197. public void Dispose()
  198. {
  199. // We expect that all regions have been removed already
  200. while (m_sharedInstances.Count > 0)
  201. {
  202. m_sharedInstances[0].Close();
  203. m_sharedInstances.RemoveAt(0);
  204. }
  205. }
  206. }
  207. }