Add basic asset connector tests to check behaviour for normal, local and temporary assets.
Make AssetServiceConnector return more useful data on failure, such as what DLL it was trying to load Allow LocalAssetServiceConnector.GetData() to work without a cache present, as works for the other lasc Get* methods.connector_plugin
parent
d5c8c6bc12
commit
1ec84ac8b1
|
@ -204,8 +204,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
|
||||||
public byte[] GetData(string id)
|
public byte[] GetData(string id)
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Requesting data for asset {0}", id);
|
// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Requesting data for asset {0}", id);
|
||||||
|
|
||||||
AssetBase asset = m_Cache.Get(id);
|
AssetBase asset = null;
|
||||||
|
|
||||||
|
if (m_Cache != null)
|
||||||
|
asset = m_Cache.Get(id);
|
||||||
|
|
||||||
if (asset != null)
|
if (asset != null)
|
||||||
return asset.Data;
|
return asset.Data;
|
||||||
|
|
|
@ -0,0 +1,136 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using log4net.Config;
|
||||||
|
using Nini.Config;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using OpenMetaverse;
|
||||||
|
using OpenSim.Framework;
|
||||||
|
using OpenSim.Region.Framework.Scenes;
|
||||||
|
using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
|
||||||
|
using OpenSim.Tests.Common;
|
||||||
|
|
||||||
|
namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class AssetConnectorsTests : OpenSimTestCase
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestAddAsset()
|
||||||
|
{
|
||||||
|
TestHelpers.InMethod();
|
||||||
|
// TestHelpers.EnableLogging();
|
||||||
|
|
||||||
|
IConfigSource config = new IniConfigSource();
|
||||||
|
config.AddConfig("Modules");
|
||||||
|
config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
|
||||||
|
config.AddConfig("AssetService");
|
||||||
|
config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
|
||||||
|
config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
|
||||||
|
|
||||||
|
LocalAssetServicesConnector lasc = new LocalAssetServicesConnector();
|
||||||
|
lasc.Initialise(config);
|
||||||
|
|
||||||
|
AssetBase a1 = AssetHelpers.CreateNotecardAsset();
|
||||||
|
lasc.Store(a1);
|
||||||
|
|
||||||
|
AssetBase retreivedA1 = lasc.Get(a1.ID);
|
||||||
|
Assert.That(retreivedA1.ID, Is.EqualTo(a1.ID));
|
||||||
|
Assert.That(retreivedA1.Metadata.ID, Is.EqualTo(a1.Metadata.ID));
|
||||||
|
Assert.That(retreivedA1.Data.Length, Is.EqualTo(a1.Data.Length));
|
||||||
|
|
||||||
|
AssetMetadata retrievedA1Metadata = lasc.GetMetadata(a1.ID);
|
||||||
|
Assert.That(retrievedA1Metadata.ID, Is.EqualTo(a1.ID));
|
||||||
|
|
||||||
|
byte[] retrievedA1Data = lasc.GetData(a1.ID);
|
||||||
|
Assert.That(retrievedA1Data.Length, Is.EqualTo(a1.Data.Length));
|
||||||
|
|
||||||
|
// TODO: Add cache and check that this does receive a copy of the asset
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestAddTemporaryAsset()
|
||||||
|
{
|
||||||
|
TestHelpers.InMethod();
|
||||||
|
// TestHelpers.EnableLogging();
|
||||||
|
|
||||||
|
IConfigSource config = new IniConfigSource();
|
||||||
|
config.AddConfig("Modules");
|
||||||
|
config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
|
||||||
|
config.AddConfig("AssetService");
|
||||||
|
config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
|
||||||
|
config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
|
||||||
|
|
||||||
|
LocalAssetServicesConnector lasc = new LocalAssetServicesConnector();
|
||||||
|
lasc.Initialise(config);
|
||||||
|
|
||||||
|
AssetBase a1 = AssetHelpers.CreateNotecardAsset();
|
||||||
|
a1.Temporary = true;
|
||||||
|
|
||||||
|
lasc.Store(a1);
|
||||||
|
|
||||||
|
Assert.That(lasc.Get(a1.ID), Is.Null);
|
||||||
|
Assert.That(lasc.GetData(a1.ID), Is.Null);
|
||||||
|
Assert.That(lasc.GetMetadata(a1.ID), Is.Null);
|
||||||
|
|
||||||
|
// TODO: Add cache and check that this does receive a copy of the asset
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestAddLocalAsset()
|
||||||
|
{
|
||||||
|
TestHelpers.InMethod();
|
||||||
|
// TestHelpers.EnableLogging();
|
||||||
|
|
||||||
|
IConfigSource config = new IniConfigSource();
|
||||||
|
config.AddConfig("Modules");
|
||||||
|
config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
|
||||||
|
config.AddConfig("AssetService");
|
||||||
|
config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
|
||||||
|
config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
|
||||||
|
|
||||||
|
LocalAssetServicesConnector lasc = new LocalAssetServicesConnector();
|
||||||
|
lasc.Initialise(config);
|
||||||
|
|
||||||
|
AssetBase a1 = AssetHelpers.CreateNotecardAsset();
|
||||||
|
a1.Local = true;
|
||||||
|
|
||||||
|
lasc.Store(a1);
|
||||||
|
|
||||||
|
Assert.That(lasc.Get(a1.ID), Is.Null);
|
||||||
|
Assert.That(lasc.GetData(a1.ID), Is.Null);
|
||||||
|
Assert.That(lasc.GetMetadata(a1.ID), Is.Null);
|
||||||
|
|
||||||
|
// TODO: Add cache and check that this does receive a copy of the asset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -84,7 +84,7 @@ namespace OpenSim.Services.AssetService
|
||||||
|
|
||||||
m_Database = LoadPlugin<IAssetDataPlugin>(dllName);
|
m_Database = LoadPlugin<IAssetDataPlugin>(dllName);
|
||||||
if (m_Database == null)
|
if (m_Database == null)
|
||||||
throw new Exception("Could not find a storage interface in the given module");
|
throw new Exception(string.Format("Could not find a storage interface in the module {0}", dllName));
|
||||||
|
|
||||||
m_Database.Initialise(connString);
|
m_Database.Initialise(connString);
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ namespace OpenSim.Services.AssetService
|
||||||
m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName);
|
m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName);
|
||||||
|
|
||||||
if (m_AssetLoader == null)
|
if (m_AssetLoader == null)
|
||||||
throw new Exception("Asset loader could not be loaded");
|
throw new Exception(string.Format("Asset loader could not be loaded from {0}", loaderName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2970,6 +2970,7 @@
|
||||||
<Match path="World/Media/Moap/Tests" pattern="*.cs" recurse="true"/>
|
<Match path="World/Media/Moap/Tests" pattern="*.cs" recurse="true"/>
|
||||||
<Match path="World/Serialiser/Tests" pattern="*.cs" recurse="true"/>
|
<Match path="World/Serialiser/Tests" pattern="*.cs" recurse="true"/>
|
||||||
<Match path="World/Terrain/Tests" pattern="*.cs" recurse="true"/>
|
<Match path="World/Terrain/Tests" pattern="*.cs" recurse="true"/>
|
||||||
|
<Match path="ServiceConnectorsOut/Asset/Tests" pattern="*.cs" recurse="true"/>
|
||||||
<Match path="ServiceConnectorsOut/Grid/Tests" pattern="*.cs" recurse="true"/>
|
<Match path="ServiceConnectorsOut/Grid/Tests" pattern="*.cs" recurse="true"/>
|
||||||
<Match path="ServiceConnectorsOut/Presence/Tests" pattern="*.cs" recurse="true"/>
|
<Match path="ServiceConnectorsOut/Presence/Tests" pattern="*.cs" recurse="true"/>
|
||||||
</Files>
|
</Files>
|
||||||
|
|
Loading…
Reference in New Issue