diff options
author | Justin Clarke Casey | 2009-03-09 19:40:32 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-03-09 19:40:32 +0000 |
commit | ae759f2d060bc53cc0b372d5584fcd4ffdd963b4 (patch) | |
tree | 304c4c40fa8be68943a3b5cad0b22a19769b2cf9 /OpenSim/Framework | |
parent | * Move method documentation from AssetCache up to IAssetCache (diff) | |
download | opensim-SC-ae759f2d060bc53cc0b372d5584fcd4ffdd963b4.zip opensim-SC-ae759f2d060bc53cc0b372d5584fcd4ffdd963b4.tar.gz opensim-SC-ae759f2d060bc53cc0b372d5584fcd4ffdd963b4.tar.bz2 opensim-SC-ae759f2d060bc53cc0b372d5584fcd4ffdd963b4.tar.xz |
* Add basic asset cache get test
Diffstat (limited to 'OpenSim/Framework')
3 files changed, 93 insertions, 7 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 | |||
28 | using System.Threading; | ||
29 | using NUnit.Framework; | ||
30 | using NUnit.Framework.SyntaxHelpers; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Framework.Communications.Cache; | ||
34 | using OpenSim.Tests.Common.Mock; | ||
35 | |||
36 | namespace 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 | } | ||