aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-03-09 19:40:32 +0000
committerJustin Clarke Casey2009-03-09 19:40:32 +0000
commitae759f2d060bc53cc0b372d5584fcd4ffdd963b4 (patch)
tree304c4c40fa8be68943a3b5cad0b22a19769b2cf9 /OpenSim
parent* Move method documentation from AssetCache up to IAssetCache (diff)
downloadopensim-SC_OLD-ae759f2d060bc53cc0b372d5584fcd4ffdd963b4.zip
opensim-SC_OLD-ae759f2d060bc53cc0b372d5584fcd4ffdd963b4.tar.gz
opensim-SC_OLD-ae759f2d060bc53cc0b372d5584fcd4ffdd963b4.tar.bz2
opensim-SC_OLD-ae759f2d060bc53cc0b372d5584fcd4ffdd963b4.tar.xz
* Add basic asset cache get test
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Communications/Cache/GridAssetClient.cs5
-rw-r--r--OpenSim/Framework/Communications/Cache/SQLAssetServer.cs7
-rw-r--r--OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs88
-rw-r--r--OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs37
4 files changed, 122 insertions, 15 deletions
diff --git a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs
index 3b6dc52..7131cb5 100644
--- a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs
+++ b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs
@@ -36,7 +36,6 @@ namespace OpenSim.Framework.Communications.Cache
36{ 36{
37 public class GridAssetClient : AssetServerBase 37 public class GridAssetClient : AssetServerBase
38 { 38 {
39
40 #region IPlugin 39 #region IPlugin
41 40
42 public override string Name 41 public override string Name
@@ -51,7 +50,7 @@ namespace OpenSim.Framework.Communications.Cache
51 50
52 public override void Initialise(ConfigSettings p_set, string p_url) 51 public override void Initialise(ConfigSettings p_set, string p_url)
53 { 52 {
54 m_log.Debug("[GRIDASSET] Plugin configured initialisation"); 53 m_log.Debug("[GRID ASSET CLIENT]: Plugin configured initialisation");
55 Initialise(p_url); 54 Initialise(p_url);
56 } 55 }
57 56
@@ -65,7 +64,7 @@ namespace OpenSim.Framework.Communications.Cache
65 64
66 public GridAssetClient(string p_url) 65 public GridAssetClient(string p_url)
67 { 66 {
68 m_log.Debug("[GRIDASSET] Direct constructor"); 67 m_log.Debug("[GRID ASSET CLIENT]: Direct constructor");
69 Initialise(p_url); 68 Initialise(p_url);
70 } 69 }
71 70
diff --git a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
index 5274288..41a9561 100644
--- a/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
+++ b/OpenSim/Framework/Communications/Cache/SQLAssetServer.cs
@@ -34,7 +34,6 @@ namespace OpenSim.Framework.Communications.Cache
34{ 34{
35 public class SQLAssetServer : AssetServerBase 35 public class SQLAssetServer : AssetServerBase
36 { 36 {
37
38 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 37 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
39 38
40 #region IPlugin 39 #region IPlugin
@@ -51,7 +50,7 @@ namespace OpenSim.Framework.Communications.Cache
51 50
52 public override void Initialise(ConfigSettings p_set) 51 public override void Initialise(ConfigSettings p_set)
53 { 52 {
54 m_log.Debug("[SQLASSET] Plugin configured initialisation"); 53 m_log.Debug("[SQLAssetServer]: Plugin configured initialisation");
55 Initialise(p_set.StandaloneAssetPlugin,p_set.StandaloneAssetSource); 54 Initialise(p_set.StandaloneAssetPlugin,p_set.StandaloneAssetSource);
56 } 55 }
57 56
@@ -61,7 +60,7 @@ namespace OpenSim.Framework.Communications.Cache
61 60
62 public SQLAssetServer(string pluginName, string connect) 61 public SQLAssetServer(string pluginName, string connect)
63 { 62 {
64 m_log.Debug("[SQLASSET] Direct constructor"); 63 m_log.Debug("[SQLAssetServer]: Direct constructor");
65 Initialise(pluginName, connect); 64 Initialise(pluginName, connect);
66 } 65 }
67 66
@@ -108,7 +107,7 @@ namespace OpenSim.Framework.Communications.Cache
108 107
109 protected override AssetBase GetAsset(AssetRequest req) 108 protected override AssetBase GetAsset(AssetRequest req)
110 { 109 {
111 return m_assetProvider.FetchAsset(req.AssetID);; 110 return m_assetProvider.FetchAsset(req.AssetID);
112 } 111 }
113 112
114 public override void StoreAsset(AssetBase asset) 113 public override void StoreAsset(AssetBase asset)
diff --git a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs
new file mode 100644
index 0000000..34193b5
--- /dev/null
+++ b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs
@@ -0,0 +1,88 @@
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 OpenSim 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
28using System.Threading;
29using NUnit.Framework;
30using NUnit.Framework.SyntaxHelpers;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Framework.Communications.Cache;
34using OpenSim.Tests.Common.Mock;
35
36namespace OpenSim.Framework.Communications.Tests
37{
38 /// <summary>
39 /// Asset cache tests
40 /// </summary>
41 [TestFixture]
42 public class AssetCacheTests
43 {
44 protected UUID m_assetIdReceived;
45 protected AssetBase m_assetReceived;
46
47 [Test]
48 /// <summary>
49 /// Test the 'asynchronous' get asset mechanism (though this won't be done asynchronously within this test)
50 /// </summary>
51 public void TestGetAsset()
52 {
53 UUID assetId = UUID.Parse("00000000-0000-0000-0000-000000000001");
54 byte[] assetData = new byte[] { 3, 2, 1 };
55
56 AssetBase asset = new AssetBase();
57 asset.FullID = assetId;
58 asset.Data = assetData;
59
60 TestAssetDataPlugin assetPlugin = new TestAssetDataPlugin();
61 assetPlugin.CreateAsset(asset);
62
63 IAssetCache assetCache = new AssetCache(new SQLAssetServer(assetPlugin));
64
65 lock (this)
66 {
67 assetCache.GetAsset(assetId, AssetRequestCallback, false);
68 Monitor.Wait(this, 60000);
69 }
70
71 Assert.That(
72 assetId, Is.EqualTo(m_assetIdReceived), "Asset id stored differs from asset id received");
73 Assert.That(
74 assetData, Is.EqualTo(m_assetReceived.Data), "Asset data stored differs from asset data received");
75 }
76
77 private void AssetRequestCallback(UUID assetId, AssetBase asset)
78 {
79 m_assetIdReceived = assetId;
80 m_assetReceived = asset;
81
82 lock (this)
83 {
84 Monitor.PulseAll(this);
85 }
86 }
87 }
88}
diff --git a/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs
index d6bce5b..80b9ae3 100644
--- a/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/TestAssetDataPlugin.cs
@@ -38,18 +38,39 @@ namespace OpenSim.Tests.Common.Mock
38 /// tests are single threaded. 38 /// tests are single threaded.
39 /// </summary> 39 /// </summary>
40 public class TestAssetDataPlugin : IAssetDataPlugin 40 public class TestAssetDataPlugin : IAssetDataPlugin
41 { 41 {
42 public string Version { get { return "0"; } } 42 public string Version { get { return "0"; } }
43 public string Name { get { return "TestAssetDataPlugin"; } } 43 public string Name { get { return "TestAssetDataPlugin"; } }
44
45 protected Dictionary<UUID, AssetBase> Assets = new Dictionary<UUID, AssetBase>();
44 46
45 public void Initialise() {} 47 public void Initialise() {}
48 public void Initialise(string connect) {}
46 public void Dispose() {} 49 public void Dispose() {}
47 50
48 public AssetBase FetchAsset(UUID uuid) { return null; } 51 public AssetBase FetchAsset(UUID uuid)
49 public void CreateAsset(AssetBase asset) {} 52 {
50 public void UpdateAsset(AssetBase asset) {} 53 if (ExistsAsset(uuid))
51 public bool ExistsAsset(UUID uuid) { return false; } 54 return Assets[uuid];
52 public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); } 55 else
53 public void Initialise(string connect) {} 56 return null;
57 }
58
59 public void CreateAsset(AssetBase asset)
60 {
61 Assets[asset.FullID] = asset;
62 }
63
64 public void UpdateAsset(AssetBase asset)
65 {
66 CreateAsset(asset);
67 }
68
69 public bool ExistsAsset(UUID uuid)
70 {
71 return Assets.ContainsKey(uuid);
72 }
73
74 public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); }
54 } 75 }
55} 76} \ No newline at end of file