* 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.
arthursv
Arthur Valadares 2009-08-11 12:07:54 -03:00
parent eba23048ca
commit 18aa2ea0c5
9 changed files with 248 additions and 171 deletions

View File

@ -54,6 +54,7 @@ namespace OpenSim.Framework.Communications.Tests
CachedUserInfo nonExistingUserInfo;
TestCommunicationsManager commsManager = new TestCommunicationsManager();
Scene myScene = SceneSetupHelpers.SetupScene(commsManager, "");
// Check we can't retrieve info before it exists by uuid
nonExistingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
@ -116,7 +117,7 @@ namespace OpenSim.Framework.Communications.Tests
{
TestHelper.InMethod();
Scene myScene = SceneSetupHelpers.SetupScene();
Scene myScene = SceneSetupHelpers.SetupScene("inventory");
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager);
for (int i = 0 ; i < 50 ; i++)
{
@ -132,7 +133,7 @@ namespace OpenSim.Framework.Communications.Tests
{
TestHelper.InMethod();
Scene myScene = SceneSetupHelpers.SetupScene();
Scene myScene = SceneSetupHelpers.SetupScene("inventory");
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager);
for (int i = 0 ; i < 50 ; i++)
{
@ -154,7 +155,7 @@ namespace OpenSim.Framework.Communications.Tests
{
TestHelper.InMethod();
Scene myScene = SceneSetupHelpers.SetupScene();
Scene myScene = SceneSetupHelpers.SetupScene("inventory");
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager);
for (int i = 0 ; i < 50 ; i++)
{
@ -190,7 +191,7 @@ namespace OpenSim.Framework.Communications.Tests
{
TestHelper.InMethod();
Scene myScene = SceneSetupHelpers.SetupScene();
Scene myScene = SceneSetupHelpers.SetupScene("inventory");
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager);
for (int i = 0 ; i < 50 ; i++)
{
@ -256,7 +257,7 @@ namespace OpenSim.Framework.Communications.Tests
{
TestHelper.InMethod();
Scene myScene = SceneSetupHelpers.SetupScene();
Scene myScene = SceneSetupHelpers.SetupScene("inventory");
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager);
for (int i = 0 ; i < 50 ; i++)
{
@ -297,7 +298,7 @@ namespace OpenSim.Framework.Communications.Tests
TestHelper.InMethod();
//log4net.Config.XmlConfigurator.Configure();
Scene myScene = SceneSetupHelpers.SetupScene();
Scene myScene = SceneSetupHelpers.SetupScene("inventory");
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager);
for (int i = 0 ; i < 50 ; i++)
{

View File

@ -36,6 +36,7 @@ using Nwc.XmlRpc;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Communications.Services;
using OpenSim.Region.Communications.Local;
using OpenSim.Tests.Common.Setup;
using OpenSim.Tests.Common.Mock;
using OpenSim.Client.Linden;
using OpenSim.Tests.Common;
@ -57,11 +58,12 @@ namespace OpenSim.Framework.Communications.Tests
private string m_regionExternalName = "localhost";
private IPEndPoint m_capsEndPoint;
private CommunicationsManager m_commsManager;
private TestCommunicationsManager m_commsManager;
private TestLoginToRegionConnector m_regionConnector;
private LocalUserServices m_localUserServices;
private LoginService m_loginService;
private UserProfileData m_userProfileData;
private TestScene m_testScene;
[SetUp]
public void SetUpLoginEnviroment()
@ -69,13 +71,16 @@ namespace OpenSim.Framework.Communications.Tests
m_capsEndPoint = new IPEndPoint(IPAddress.Loopback, 9123);
m_commsManager = new TestCommunicationsManager(new NetworkServersInfo(42, 43));
m_regionConnector = new TestLoginToRegionConnector();
m_testScene = SceneSetupHelpers.SetupScene(m_commsManager, "");
m_regionConnector.AddRegion(new RegionInfo(42, 43, m_capsEndPoint, m_regionExternalName));
//IInventoryService m_inventoryService = new TestInventoryService();
m_localUserServices = (LocalUserServices) m_commsManager.UserService;
m_localUserServices.AddUser(m_firstName,m_lastName,"boingboing","abc@ftw.com",42,43);
m_loginService = new LLStandaloneLoginService((UserManagerBase) m_localUserServices, "Hello folks", new TestInventoryService(),
m_loginService = new LLStandaloneLoginService((UserManagerBase) m_localUserServices, "Hello folks", m_testScene.InventoryService,
m_commsManager.NetworkServersInfo, true, new LibraryRootFolder(String.Empty), m_regionConnector);
m_userProfileData = m_localUserServices.GetUserProfile(m_firstName, m_lastName);
@ -442,123 +447,4 @@ namespace OpenSim.Framework.Communications.Tests
#endregion
}
}
class TestInventoryService : IInventoryService
{
public TestInventoryService()
{
}
/// <summary>
/// <see cref="OpenSim.Framework.Communications.IInterServiceInventoryServices"/>
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public bool CreateUserInventory(UUID userId)
{
return false;
}
/// <summary>
/// <see cref="OpenSim.Framework.Communications.IInterServiceInventoryServices"/>
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
{
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
InventoryFolderBase folder = new InventoryFolderBase();
folder.ID = UUID.Random();
folder.Owner = userId;
folders.Add(folder);
return folders;
}
/// <summary>
/// Returns a list of all the active gestures in a user's inventory.
/// </summary>
/// <param name="userId">
/// The <see cref="UUID"/> of the user
/// </param>
/// <returns>
/// A flat list of the gesture items.
/// </returns>
public List<InventoryItemBase> GetActiveGestures(UUID userId)
{
return null;
}
public InventoryCollection GetUserInventory(UUID userID)
{
return null;
}
public void GetUserInventory(UUID userID, OpenSim.Services.Interfaces.InventoryReceiptCallback callback)
{
}
public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
{
return null;
}
public bool AddFolder(InventoryFolderBase folder)
{
return false;
}
public bool UpdateFolder(InventoryFolderBase folder)
{
return false;
}
public bool MoveFolder(InventoryFolderBase folder)
{
return false;
}
public bool PurgeFolder(InventoryFolderBase folder)
{
return false;
}
public bool AddItem(InventoryItemBase item)
{
return false;
}
public bool UpdateItem(InventoryItemBase item)
{
return false;
}
public bool DeleteItem(InventoryItemBase item)
{
return false;
}
public InventoryItemBase QueryItem(InventoryItemBase item)
{
return null;
}
public InventoryFolderBase QueryFolder(InventoryFolderBase folder)
{
return null;
}
public bool HasInventoryForUser(UUID userID)
{
return false;
}
public InventoryFolderBase RequestRootFolder(UUID userID)
{
InventoryFolderBase root = new InventoryFolderBase();
root.ID = UUID.Random();
root.Owner = userID;
root.ParentID = UUID.Zero;
return root;
}
}
}

View File

@ -698,7 +698,7 @@ namespace OpenSim.Framework.Communications
if (rootfolder != null)
userProf.RootInventoryFolderID = rootfolder.ID;
}
else if (m_commsManager.InterServiceInventoryService != null)
else
{
// used by the user server
m_log.Debug("[USERSTORAGE]: using m_commsManager.InterServiceInventoryService to create user's inventory");

View File

@ -74,7 +74,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
InventoryArchiverModule archiverModule = new InventoryArchiverModule();
Scene scene = SceneSetupHelpers.SetupScene(false);
Scene scene = SceneSetupHelpers.SetupScene("");
SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
CommunicationsManager cm = scene.CommsManager;
@ -363,7 +363,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
public void TestReplicateArchivePathToUserInventory()
{
TestHelper.InMethod();
Scene scene = SceneSetupHelpers.SetupScene(false);
Scene scene = SceneSetupHelpers.SetupScene("");
CommunicationsManager commsManager = scene.CommsManager;
CachedUserInfo userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager);

View File

@ -87,7 +87,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
SerialiserModule serialiserModule = new SerialiserModule();
TerrainModule terrainModule = new TerrainModule();
Scene scene = SceneSetupHelpers.SetupScene(false);
Scene scene = SceneSetupHelpers.SetupScene("asset");
SceneSetupHelpers.SetupSceneModules(scene, archiverModule, serialiserModule, terrainModule);
SceneObjectPart part1;

View File

@ -237,7 +237,7 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests
public void Init()
{
m_serialiserModule = new SerialiserModule();
m_scene = SceneSetupHelpers.SetupScene(false);
m_scene = SceneSetupHelpers.SetupScene("");
SceneSetupHelpers.SetupSceneModules(m_scene, m_serialiserModule);
}

View File

@ -31,13 +31,18 @@ using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Data;
using OpenSim.Services.Interfaces;
using Nini.Config;
namespace OpenSim.Tests.Common.Mock
{
public class TestAssetService : IAssetService
{
private readonly Dictionary<string, AssetBase> Assets = new Dictionary<string, AssetBase>();
private readonly Dictionary<string, AssetBase> Assets = new Dictionary<string, AssetBase>();
public TestAssetService(IConfigSource config)
{
}
public AssetBase Get(string id)
{
return Assets[ id ];

View File

@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Framework;
using OpenMetaverse;
using OpenSim.Services.Interfaces;
using Nini.Config;
namespace OpenSim.Tests.Common.Mock
{
public class TestInventoryService : IInventoryService
{
public TestInventoryService()
{
}
public TestInventoryService(IConfigSource config)
{
}
/// <summary>
/// <see cref="OpenSim.Framework.Communications.IInterServiceInventoryServices"/>
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public bool CreateUserInventory(UUID userId)
{
return false;
}
/// <summary>
/// <see cref="OpenSim.Framework.Communications.IInterServiceInventoryServices"/>
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
{
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
InventoryFolderBase folder = new InventoryFolderBase();
folder.ID = UUID.Random();
folder.Owner = userId;
folders.Add(folder);
return folders;
}
/// <summary>
/// Returns a list of all the active gestures in a user's inventory.
/// </summary>
/// <param name="userId">
/// The <see cref="UUID"/> of the user
/// </param>
/// <returns>
/// A flat list of the gesture items.
/// </returns>
public List<InventoryItemBase> GetActiveGestures(UUID userId)
{
return null;
}
public InventoryCollection GetUserInventory(UUID userID)
{
return null;
}
public void GetUserInventory(UUID userID, OpenSim.Services.Interfaces.InventoryReceiptCallback callback)
{
}
public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
{
return null;
}
public bool AddFolder(InventoryFolderBase folder)
{
return false;
}
public bool UpdateFolder(InventoryFolderBase folder)
{
return false;
}
public bool MoveFolder(InventoryFolderBase folder)
{
return false;
}
public bool PurgeFolder(InventoryFolderBase folder)
{
return false;
}
public bool AddItem(InventoryItemBase item)
{
return false;
}
public bool UpdateItem(InventoryItemBase item)
{
return false;
}
public bool DeleteItem(InventoryItemBase item)
{
return false;
}
public InventoryItemBase QueryItem(InventoryItemBase item)
{
return null;
}
public InventoryFolderBase QueryFolder(InventoryFolderBase folder)
{
return null;
}
public bool HasInventoryForUser(UUID userID)
{
return false;
}
public InventoryFolderBase RequestRootFolder(UUID userID)
{
InventoryFolderBase root = new InventoryFolderBase();
root.ID = UUID.Random();
root.Owner = userID;
root.ParentID = UUID.Zero;
return root;
}
}
}

View File

@ -54,6 +54,10 @@ namespace OpenSim.Tests.Common.Setup
/// </summary>
public class SceneSetupHelpers
{
private static ISharedRegionModule m_assetService = null;
private static ISharedRegionModule m_inventoryService = null;
private static TestCommunicationsManager commsManager = null;
/// <summary>
/// Set up a test scene
/// </summary>
@ -63,7 +67,7 @@ namespace OpenSim.Tests.Common.Setup
/// <returns></returns>
public static TestScene SetupScene()
{
return SetupScene(true);
return SetupScene("");
}
/// <summary>
@ -72,12 +76,17 @@ namespace OpenSim.Tests.Common.Setup
///
/// <param name="startServices">Start associated service threads for the scene</param>
/// <returns></returns>
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, "");
}
/// <summary>
/// Set up a test scene
/// </summary>
@ -89,28 +98,35 @@ namespace OpenSim.Tests.Common.Setup
/// <returns></returns>
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, "");
}
/// <summary>
/// Set up a test scene
/// Set up a scene.
/// </summary>
/// <param name="name">Name of the region</param>
/// <param name="id">ID of the region</param>
/// <param name="x">X co-ordinate of the region</param>
/// <param name="y">Y co-ordinate of the region</param>
/// <param name="cm">This should be the same if simulating two scenes within a standalone</param>
/// <param name="startServices">Start associated threads for the services used by the scene</param>
/// <param name="realServices">Starts real inventory and asset services, as opposed to mock ones, if true</param>
/// <returns></returns>
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,33 +148,31 @@ namespace OpenSim.Tests.Common.Setup
IRegionModule godsModule = new GodsModule();
godsModule.Initialise(testScene, new IniConfigSource());
testScene.AddModule(godsModule.Name, godsModule);
ISharedRegionModule assetService = new LocalAssetServicesConnector();
realServices = realServices.ToLower();
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");
config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
assetService.Initialise(config);
assetService.AddRegion(testScene);
assetService.RegionLoaded(testScene);
testScene.AddRegionModule(assetService.Name, assetService);
assetService.PostInitialise();
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);
ISharedRegionModule inventoryService = new LocalInventoryServicesConnector();
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");
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();
@ -168,10 +182,48 @@ namespace OpenSim.Tests.Common.Setup
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");
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.AddRegion(testScene);
assetService.RegionLoaded(testScene);
testScene.AddRegionModule(assetService.Name, assetService);
m_assetService = assetService;
}
private static void StartInventoryService(Scene testScene, bool real)
{
ISharedRegionModule inventoryService = new LocalInventoryServicesConnector();
IniConfigSource config = new IniConfigSource();
config.AddConfig("Modules");
config.AddConfig("InventoryService");
config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
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);
m_inventoryService = inventoryService;
}
/// <summary>
/// Setup modules for a scene using their default settings.
/// </summary>