diff options
author | Justin Clark-Casey (justincc) | 2012-09-15 02:12:26 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-09-15 02:12:26 +0100 |
commit | 1ec84ac8b160c1a6ee903b832c75635d1219fe5a (patch) | |
tree | d729f94cdfbfa4a5f26d3127fa61c4ca20b36bd8 /OpenSim | |
parent | For FlotsamAssetCache, always update access times of cached scene assets befo... (diff) | |
download | opensim-SC_OLD-1ec84ac8b160c1a6ee903b832c75635d1219fe5a.zip opensim-SC_OLD-1ec84ac8b160c1a6ee903b832c75635d1219fe5a.tar.gz opensim-SC_OLD-1ec84ac8b160c1a6ee903b832c75635d1219fe5a.tar.bz2 opensim-SC_OLD-1ec84ac8b160c1a6ee903b832c75635d1219fe5a.tar.xz |
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.
Diffstat (limited to 'OpenSim')
3 files changed, 143 insertions, 4 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs index c78915f..449c1f1 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs | |||
@@ -204,8 +204,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset | |||
204 | public byte[] GetData(string id) | 204 | public byte[] GetData(string id) |
205 | { | 205 | { |
206 | // m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Requesting data for asset {0}", id); | 206 | // m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Requesting data for asset {0}", id); |
207 | 207 | ||
208 | AssetBase asset = m_Cache.Get(id); | 208 | AssetBase asset = null; |
209 | |||
210 | if (m_Cache != null) | ||
211 | asset = m_Cache.Get(id); | ||
209 | 212 | ||
210 | if (asset != null) | 213 | if (asset != null) |
211 | return asset.Data; | 214 | return asset.Data; |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/Tests/AssetConnectorTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/Tests/AssetConnectorTests.cs new file mode 100644 index 0000000..1982473 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/Tests/AssetConnectorTests.cs | |||
@@ -0,0 +1,136 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net.Config; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset; | ||
40 | using OpenSim.Tests.Common; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset.Tests | ||
43 | { | ||
44 | [TestFixture] | ||
45 | public class AssetConnectorsTests : OpenSimTestCase | ||
46 | { | ||
47 | [Test] | ||
48 | public void TestAddAsset() | ||
49 | { | ||
50 | TestHelpers.InMethod(); | ||
51 | // TestHelpers.EnableLogging(); | ||
52 | |||
53 | IConfigSource config = new IniConfigSource(); | ||
54 | config.AddConfig("Modules"); | ||
55 | config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector"); | ||
56 | config.AddConfig("AssetService"); | ||
57 | config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService"); | ||
58 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
59 | |||
60 | LocalAssetServicesConnector lasc = new LocalAssetServicesConnector(); | ||
61 | lasc.Initialise(config); | ||
62 | |||
63 | AssetBase a1 = AssetHelpers.CreateNotecardAsset(); | ||
64 | lasc.Store(a1); | ||
65 | |||
66 | AssetBase retreivedA1 = lasc.Get(a1.ID); | ||
67 | Assert.That(retreivedA1.ID, Is.EqualTo(a1.ID)); | ||
68 | Assert.That(retreivedA1.Metadata.ID, Is.EqualTo(a1.Metadata.ID)); | ||
69 | Assert.That(retreivedA1.Data.Length, Is.EqualTo(a1.Data.Length)); | ||
70 | |||
71 | AssetMetadata retrievedA1Metadata = lasc.GetMetadata(a1.ID); | ||
72 | Assert.That(retrievedA1Metadata.ID, Is.EqualTo(a1.ID)); | ||
73 | |||
74 | byte[] retrievedA1Data = lasc.GetData(a1.ID); | ||
75 | Assert.That(retrievedA1Data.Length, Is.EqualTo(a1.Data.Length)); | ||
76 | |||
77 | // TODO: Add cache and check that this does receive a copy of the asset | ||
78 | } | ||
79 | |||
80 | [Test] | ||
81 | public void TestAddTemporaryAsset() | ||
82 | { | ||
83 | TestHelpers.InMethod(); | ||
84 | // TestHelpers.EnableLogging(); | ||
85 | |||
86 | IConfigSource config = new IniConfigSource(); | ||
87 | config.AddConfig("Modules"); | ||
88 | config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector"); | ||
89 | config.AddConfig("AssetService"); | ||
90 | config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService"); | ||
91 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
92 | |||
93 | LocalAssetServicesConnector lasc = new LocalAssetServicesConnector(); | ||
94 | lasc.Initialise(config); | ||
95 | |||
96 | AssetBase a1 = AssetHelpers.CreateNotecardAsset(); | ||
97 | a1.Temporary = true; | ||
98 | |||
99 | lasc.Store(a1); | ||
100 | |||
101 | Assert.That(lasc.Get(a1.ID), Is.Null); | ||
102 | Assert.That(lasc.GetData(a1.ID), Is.Null); | ||
103 | Assert.That(lasc.GetMetadata(a1.ID), Is.Null); | ||
104 | |||
105 | // TODO: Add cache and check that this does receive a copy of the asset | ||
106 | } | ||
107 | |||
108 | [Test] | ||
109 | public void TestAddLocalAsset() | ||
110 | { | ||
111 | TestHelpers.InMethod(); | ||
112 | // TestHelpers.EnableLogging(); | ||
113 | |||
114 | IConfigSource config = new IniConfigSource(); | ||
115 | config.AddConfig("Modules"); | ||
116 | config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector"); | ||
117 | config.AddConfig("AssetService"); | ||
118 | config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService"); | ||
119 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
120 | |||
121 | LocalAssetServicesConnector lasc = new LocalAssetServicesConnector(); | ||
122 | lasc.Initialise(config); | ||
123 | |||
124 | AssetBase a1 = AssetHelpers.CreateNotecardAsset(); | ||
125 | a1.Local = true; | ||
126 | |||
127 | lasc.Store(a1); | ||
128 | |||
129 | Assert.That(lasc.Get(a1.ID), Is.Null); | ||
130 | Assert.That(lasc.GetData(a1.ID), Is.Null); | ||
131 | Assert.That(lasc.GetMetadata(a1.ID), Is.Null); | ||
132 | |||
133 | // TODO: Add cache and check that this does receive a copy of the asset | ||
134 | } | ||
135 | } | ||
136 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/AssetService/AssetServiceBase.cs b/OpenSim/Services/AssetService/AssetServiceBase.cs index 177c565..58ab052 100644 --- a/OpenSim/Services/AssetService/AssetServiceBase.cs +++ b/OpenSim/Services/AssetService/AssetServiceBase.cs | |||
@@ -84,7 +84,7 @@ namespace OpenSim.Services.AssetService | |||
84 | 84 | ||
85 | m_Database = LoadPlugin<IAssetDataPlugin>(dllName); | 85 | m_Database = LoadPlugin<IAssetDataPlugin>(dllName); |
86 | if (m_Database == null) | 86 | if (m_Database == null) |
87 | throw new Exception("Could not find a storage interface in the given module"); | 87 | throw new Exception(string.Format("Could not find a storage interface in the module {0}", dllName)); |
88 | 88 | ||
89 | m_Database.Initialise(connString); | 89 | m_Database.Initialise(connString); |
90 | 90 | ||
@@ -96,7 +96,7 @@ namespace OpenSim.Services.AssetService | |||
96 | m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName); | 96 | m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName); |
97 | 97 | ||
98 | if (m_AssetLoader == null) | 98 | if (m_AssetLoader == null) |
99 | throw new Exception("Asset loader could not be loaded"); | 99 | throw new Exception(string.Format("Asset loader could not be loaded from {0}", loaderName)); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | } | 102 | } |