Fix tests broken in 88771aeed3

Adds MockUserAccountService and connects it up
Stops services being carried over between tests since this leads to hard to find bugs
Improves information and error reporting when loading plugins
slimupdates
Justin Clark-Casey (justincc) 2010-03-12 19:31:14 +00:00
parent db61d66e74
commit f2de50bb14
7 changed files with 120 additions and 54 deletions

View File

@ -73,33 +73,31 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
IConfig userConfig = source.Configs["UserAccountService"];
if (userConfig == null)
{
m_log.Error("[USER CONNECTOR]: UserAccountService missing from OpenSim.ini");
m_log.Error("[LOCAL USER ACCOUNT SERVICE CONNECTOR]: UserAccountService missing from OpenSim.ini");
return;
}
string serviceDll = userConfig.GetString("LocalServiceModule",
String.Empty);
string serviceDll = userConfig.GetString("LocalServiceModule", String.Empty);
if (serviceDll == String.Empty)
{
m_log.Error("[USER CONNECTOR]: No LocalServiceModule named in section UserService");
m_log.Error("[LOCAL USER ACCOUNT SERVICE CONNECTOR]: No LocalServiceModule named in section UserService");
return;
}
Object[] args = new Object[] { source };
m_UserService =
ServerUtils.LoadPlugin<IUserAccountService>(serviceDll,
args);
m_UserService = ServerUtils.LoadPlugin<IUserAccountService>(serviceDll, args);
if (m_UserService == null)
{
m_log.Error("[USER CONNECTOR]: Can't load user account service");
m_log.ErrorFormat(
"[LOCAL USER ACCOUNT SERVICE CONNECTOR]: Cannot load user account service specified as {0}", serviceDll);
return;
}
m_Enabled = true;
m_Cache = new UserAccountCache();
m_log.Info("[USER CONNECTOR]: Local user connector enabled");
m_log.Info("[LOCAL USER ACCOUNT SERVICE CONNECTOR]: Local user connector enabled");
}
}
}
@ -134,6 +132,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
{
if (!m_Enabled)
return;
m_log.InfoFormat("[LOCAL USER ACCOUNT SERVICE CONNECTOR]: Enabled local user accounts for region {0}", scene.RegionInfo.RegionName);
}
#endregion

View File

@ -86,6 +86,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
public void TestDeleteSceneObjectAsync()
{
TestHelper.InMethod();
//log4net.Config.XmlConfigurator.Configure();
UUID agentId = UUID.Parse("00000000-0000-0000-0000-000000000001");
@ -97,15 +98,9 @@ namespace OpenSim.Region.Framework.Scenes.Tests
SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene);
try
{
IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero);
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.StackTrace);
}
IClientAPI client = SceneSetupHelpers.AddRootAgent(scene, agentId);
scene.DeRezObject(client, part.LocalId, UUID.Zero, DeRezAction.Delete, UUID.Zero);
SceneObjectPart retrievedPart = scene.GetSceneObjectPart(part.LocalId);
Assert.That(retrievedPart, Is.Not.Null);

View File

@ -57,6 +57,12 @@ namespace OpenSim.Server.Base
return ret;
}
/// <summary>
/// Load a plugin from a dll with the given class or interface
/// </summary>
/// <param name="dllName"></param>
/// <param name="args">The arguments which control which constructor is invoked on the plugin</param>
/// <returns></returns>
public static T LoadPlugin<T>(string dllName, Object[] args) where T:class
{
string[] parts = dllName.Split(new char[] {':'});
@ -71,6 +77,13 @@ namespace OpenSim.Server.Base
return LoadPlugin<T>(dllName, className, args);
}
/// <summary>
/// Load a plugin from a dll with the given class or interface
/// </summary>
/// <param name="dllName"></param>
/// <param name="className"></param>
/// <param name="args">The arguments which control which constructor is invoked on the plugin</param>
/// <returns></returns>
public static T LoadPlugin<T>(string dllName, string className, Object[] args) where T:class
{
string interfaceName = typeof(T).ToString();
@ -83,28 +96,15 @@ namespace OpenSim.Server.Base
{
if (pluginType.IsPublic)
{
if (className != String.Empty &&
pluginType.ToString() !=
pluginType.Namespace + "." + className)
if (className != String.Empty
&& pluginType.ToString() != pluginType.Namespace + "." + className)
continue;
Type typeInterface =
pluginType.GetInterface(interfaceName, true);
Type typeInterface = pluginType.GetInterface(interfaceName, true);
if (typeInterface != null)
{
T plug = null;
try
{
plug = (T)Activator.CreateInstance(pluginType,
args);
}
catch (Exception e)
{
if (!(e is System.MissingMethodException))
m_log.ErrorFormat("Error loading plugin from {0}, exception {1}", dllName, e.InnerException);
return null;
}
return plug;
return (T)Activator.CreateInstance(pluginType, args);
}
}
}
@ -113,7 +113,7 @@ namespace OpenSim.Server.Base
}
catch (Exception e)
{
m_log.ErrorFormat("Error loading plugin from {0}, exception {1}", dllName, e);
m_log.Error(string.Format("Error loading plugin from {0}", dllName), e);
return null;
}
}

View File

@ -140,14 +140,20 @@ namespace OpenSim.Services.Interfaces
UserAccount GetUserAccount(UUID scopeID, UUID userID);
UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName);
UserAccount GetUserAccount(UUID scopeID, string Email);
// Returns the list of avatars that matches both the search
// criterion and the scope ID passed
//
/// <summary>
/// Returns the list of avatars that matches both the search criterion and the scope ID passed
/// </summary>
/// <param name="scopeID"></param>
/// <param name="query"></param>
/// <returns></returns>
List<UserAccount> GetUserAccounts(UUID scopeID, string query);
// Store the data given, wich replaces the sotred data, therefore
// must be complete.
//
/// <summary>
/// Store the data given, wich replaces the sotred data, therefore must be complete.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
bool StoreUserAccount(UserAccount data);
}
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Services.Interfaces;
namespace OpenSim.Tests.Common.Mock
{
public class MockUserAccountService : IUserAccountService
{
public MockUserAccountService(IConfigSource config) {}
public UserAccount GetUserAccount(UUID scopeID, UUID userID) { return new UserAccount(); }
public UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName) { return new UserAccount(); }
public UserAccount GetUserAccount(UUID scopeID, string Email) { return new UserAccount(); }
public List<UserAccount> GetUserAccounts(UUID scopeID, string query) { return new List<UserAccount>(); }
public bool StoreUserAccount(UserAccount data) { return true; }
}
}

View File

@ -65,6 +65,6 @@ namespace OpenSim.Tests.Common.Mock
public AsyncSceneObjectGroupDeleter SceneObjectGroupDeleter
{
get { return m_asyncSceneObjectDeleter; }
}
}
}
}
}

View File

@ -128,7 +128,7 @@ namespace OpenSim.Tests.Common.Setup
/// <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, String realServices)
string name, UUID id, uint x, uint y, String realServices)
{
bool newScene = false;
@ -179,15 +179,16 @@ namespace OpenSim.Tests.Common.Setup
StartAssetService(testScene, true);
else
StartAssetService(testScene, false);
if (realServices.Contains("inventory"))
StartInventoryService(testScene, true);
else
StartInventoryService(testScene, false);
if (realServices.Contains("grid"))
StartGridService(testScene, true);
if (realServices.Contains("useraccounts"))
StartUserAccountService(testScene, true);
StartUserAccountService(testScene, realServices.Contains("useraccounts"));
}
// If not, make sure the shared module gets references to this new scene
else
@ -196,9 +197,13 @@ namespace OpenSim.Tests.Common.Setup
m_assetService.RegionLoaded(testScene);
m_inventoryService.AddRegion(testScene);
m_inventoryService.RegionLoaded(testScene);
m_userAccountService.AddRegion(testScene);
m_userAccountService.RegionLoaded(testScene);
}
m_inventoryService.PostInitialise();
m_assetService.PostInitialise();
m_userAccountService.PostInitialise();
testScene.SetModuleInterfaces();
@ -209,6 +214,11 @@ namespace OpenSim.Tests.Common.Setup
physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
testScene.PhysicsScene
= physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test");
m_assetService = null;
m_inventoryService = null;
m_gridService = null;
m_userAccountService = null;
return testScene;
}
@ -273,6 +283,11 @@ namespace OpenSim.Tests.Common.Setup
//testScene.AddRegionModule(m_gridService.Name, m_gridService);
}
/// <summary>
/// Start a user account service, whether real or mock
/// </summary>
/// <param name="testScene"></param>
/// <param name="real">Starts a real service if true, a mock service if not</param>
private static void StartUserAccountService(Scene testScene, bool real)
{
IConfigSource config = new IniConfigSource();
@ -280,8 +295,14 @@ namespace OpenSim.Tests.Common.Setup
config.AddConfig("UserAccountService");
config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
if (real)
config.Configs["UserAccountService"].Set("LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
config.Configs["UserAccountService"].Set(
"LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
else
config.Configs["UserAccountService"].Set(
"LocalServiceModule", "OpenSim.Tests.Common.dll:MockUserAccountService");
if (m_userAccountService == null)
{
ISharedRegionModule userAccountService = new LocalUserAccountServicesConnector();
@ -292,10 +313,9 @@ namespace OpenSim.Tests.Common.Setup
// config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Tests.Common.dll:TestGridService");
m_userAccountService.AddRegion(testScene);
m_userAccountService.RegionLoaded(testScene);
//testScene.AddRegionModule(m_gridService.Name, m_gridService);
testScene.AddRegionModule(m_userAccountService.Name, m_userAccountService);
}
/// <summary>
/// Setup modules for a scene using their default settings.
/// </summary>