From 18aa2ea0c5ebd8d5131902ed9856e68f46e76e11 Mon Sep 17 00:00:00 2001 From: Arthur Valadares Date: Tue, 11 Aug 2009 12:07:54 -0300 Subject: * Improves SceneSetupHelper to allow the tester to choose a real or mock, inventory and asset, service modules. The boolean startServices was replaced with realServices string. If the string contains the word asset, it will start a real asset module, if it contains inventory, it starts a real inventory. Otherwise, it use mock (NullPlugin-like) objects, for tests that don't really need functionality. * SetupScene is now actually sharing the asset and inventory modules if the tester wishes to have multiple regions connected. To link regions, just start SetupScene with the same CommunicationManager for all scenes. SceneSetupHelper will hold a static reference to the modules and won't initialize them again, just run the scenes through the modules AddRegion, RegionLoaded and PostInitialize. * With the recent changes, both asset and inventory (and in the future, user) services should always be asked from the scene, not instantiated alone. The tests should reflect this new behavior and always start a scene. --- OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs | 110 +++++++++++++++++------- 1 file changed, 81 insertions(+), 29 deletions(-) (limited to 'OpenSim/Tests/Common/Setup') diff --git a/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs b/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs index c11691f..fbe0e46 100644 --- a/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs +++ b/OpenSim/Tests/Common/Setup/SceneSetupHelpers.cs @@ -54,6 +54,10 @@ namespace OpenSim.Tests.Common.Setup /// public class SceneSetupHelpers { + private static ISharedRegionModule m_assetService = null; + private static ISharedRegionModule m_inventoryService = null; + private static TestCommunicationsManager commsManager = null; + /// /// Set up a test scene /// @@ -63,7 +67,7 @@ namespace OpenSim.Tests.Common.Setup /// public static TestScene SetupScene() { - return SetupScene(true); + return SetupScene(""); } /// @@ -72,12 +76,17 @@ namespace OpenSim.Tests.Common.Setup /// /// Start associated service threads for the scene /// - public static TestScene SetupScene(bool startServices) + public static TestScene SetupScene(String realServices) { return SetupScene( - "Unit test region", UUID.Random(), 1000, 1000, new TestCommunicationsManager(), startServices); + "Unit test region", UUID.Random(), 1000, 1000, new TestCommunicationsManager(), realServices); + } + + public static TestScene SetupScene(TestCommunicationsManager cm, String realServices) + { + return SetupScene( + "Unit test region", UUID.Random(), 1000, 1000, cm, ""); } - /// /// Set up a test scene /// @@ -89,28 +98,35 @@ namespace OpenSim.Tests.Common.Setup /// public static TestScene SetupScene(string name, UUID id, uint x, uint y, TestCommunicationsManager cm) { - return SetupScene(name, id, x, y, cm, true); + return SetupScene(name, id, x, y, cm, ""); } /// - /// Set up a test scene + /// Set up a scene. /// /// Name of the region /// ID of the region /// X co-ordinate of the region /// Y co-ordinate of the region /// This should be the same if simulating two scenes within a standalone - /// Start associated threads for the services used by the scene + /// Starts real inventory and asset services, as opposed to mock ones, if true /// public static TestScene SetupScene( - string name, UUID id, uint x, uint y, TestCommunicationsManager cm, bool startServices) + string name, UUID id, uint x, uint y, TestCommunicationsManager cm, String realServices) { + bool newScene= false; + Console.WriteLine("Setting up test scene {0}", name); + if (cm == null || cm != commsManager) + { + System.Console.WriteLine("Starting a brand new scene"); + newScene = true; + MainConsole.Instance = new LocalConsole("TEST PROMPT"); + MainServer.Instance = new BaseHttpServer(980); + commsManager = cm; + } // We must set up a console otherwise setup of some modules may fail - MainConsole.Instance = new LocalConsole("TEST PROMPT"); - - MainServer.Instance = new BaseHttpServer(980); RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1"); regInfo.RegionName = name; regInfo.RegionID = id; @@ -132,44 +148,80 @@ namespace OpenSim.Tests.Common.Setup IRegionModule godsModule = new GodsModule(); godsModule.Initialise(testScene, new IniConfigSource()); testScene.AddModule(godsModule.Name, godsModule); + realServices = realServices.ToLower(); + IniConfigSource config = new IniConfigSource(); + if ((m_assetService == null && m_inventoryService == null) || newScene) + { + if (realServices.Contains("asset")) + StartAssetService(testScene, true); + else + StartAssetService(testScene, false); + if (realServices.Contains("inventory")) + StartInventoryService(testScene, true); + else + StartInventoryService(testScene, false); + } + else + { + m_assetService.AddRegion(testScene); + m_assetService.RegionLoaded(testScene); + m_inventoryService.AddRegion(testScene); + m_inventoryService.RegionLoaded(testScene); + } + m_inventoryService.PostInitialise(); + m_assetService.PostInitialise(); + + testScene.CommsManager.UserService.SetInventoryService(testScene.InventoryService); + testScene.SetModuleInterfaces(); + + testScene.LandChannel = new TestLandChannel(); + testScene.LoadWorldMap(); + + PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager(); + physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll"); + testScene.PhysicsScene + = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test"); + + return testScene; + } + + private static void StartAssetService(Scene testScene, bool real) + { ISharedRegionModule assetService = new LocalAssetServicesConnector(); IniConfigSource config = new IniConfigSource(); config.AddConfig("Modules"); config.AddConfig("AssetService"); config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector"); - config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService"); + if (real) + config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService"); + else + config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Tests.Common.dll:TestAssetService"); config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); - assetService.Initialise(config); + assetService.Initialise(config); assetService.AddRegion(testScene); assetService.RegionLoaded(testScene); testScene.AddRegionModule(assetService.Name, assetService); - assetService.PostInitialise(); + m_assetService = assetService; + } + private static void StartInventoryService(Scene testScene, bool real) + { ISharedRegionModule inventoryService = new LocalInventoryServicesConnector(); - config = new IniConfigSource(); + IniConfigSource config = new IniConfigSource(); config.AddConfig("Modules"); config.AddConfig("InventoryService"); config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector"); - config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:InventoryService"); + if (real) + config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:InventoryService"); + else + config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Tests.Common.dll:TestInventoryService"); config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); inventoryService.Initialise(config); inventoryService.AddRegion(testScene); inventoryService.RegionLoaded(testScene); testScene.AddRegionModule(inventoryService.Name, inventoryService); - inventoryService.PostInitialise(); - - testScene.SetModuleInterfaces(); - - testScene.LandChannel = new TestLandChannel(); - testScene.LoadWorldMap(); - - PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager(); - physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll"); - testScene.PhysicsScene - = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test"); - - return testScene; + m_inventoryService = inventoryService; } /// -- cgit v1.1