opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 OpenMetaverse.Assets;
38 using OpenSim.Framework;
39 using OpenSim.Region.Framework.Scenes;
40 using OpenSim.Region.Framework.Scenes.Serialization;
41 using OpenSim.Tests.Common;
42 using OpenSim.Tests.Common.Mock;
43  
44 namespace OpenSim.Region.CoreModules.Asset.Tests
45 {
46 /// <summary>
47 /// At the moment we're only test the in-memory part of the FlotsamAssetCache. This is a considerable weakness.
48 /// </summary>
49 [TestFixture]
50 public class FlotsamAssetCacheTests : OpenSimTestCase
51 {
52 protected TestScene m_scene;
53 protected FlotsamAssetCache m_cache;
54  
55 [SetUp]
56 public override void SetUp()
57 {
58 base.SetUp();
59  
60 IConfigSource config = new IniConfigSource();
61  
62 config.AddConfig("Modules");
63 config.Configs["Modules"].Set("AssetCaching", "FlotsamAssetCache");
64 config.AddConfig("AssetCache");
65 config.Configs["AssetCache"].Set("FileCacheEnabled", "false");
66 config.Configs["AssetCache"].Set("MemoryCacheEnabled", "true");
67  
68 m_cache = new FlotsamAssetCache();
69 m_scene = new SceneHelpers().SetupScene();
70 SceneHelpers.SetupSceneModules(m_scene, config, m_cache);
71 }
72  
73 [Test]
74 public void TestCacheAsset()
75 {
76 TestHelpers.InMethod();
77 // log4net.Config.XmlConfigurator.Configure();
78  
79 AssetBase asset = AssetHelpers.CreateNotecardAsset();
80 asset.ID = TestHelpers.ParseTail(0x1).ToString();
81  
82 // Check we don't get anything before the asset is put in the cache
83 AssetBase retrievedAsset = m_cache.Get(asset.ID.ToString());
84 Assert.That(retrievedAsset, Is.Null);
85  
86 m_cache.Store(asset);
87  
88 // Check that asset is now in cache
89 retrievedAsset = m_cache.Get(asset.ID.ToString());
90 Assert.That(retrievedAsset, Is.Not.Null);
91 Assert.That(retrievedAsset.ID, Is.EqualTo(asset.ID));
92 }
93  
94 [Test]
95 public void TestExpireAsset()
96 {
97 TestHelpers.InMethod();
98 // log4net.Config.XmlConfigurator.Configure();
99  
100 AssetBase asset = AssetHelpers.CreateNotecardAsset();
101 asset.ID = TestHelpers.ParseTail(0x2).ToString();
102  
103 m_cache.Store(asset);
104  
105 m_cache.Expire(asset.ID);
106  
107 AssetBase retrievedAsset = m_cache.Get(asset.ID.ToString());
108 Assert.That(retrievedAsset, Is.Null);
109 }
110  
111 [Test]
112 public void TestClearCache()
113 {
114 TestHelpers.InMethod();
115 // log4net.Config.XmlConfigurator.Configure();
116  
117 AssetBase asset = AssetHelpers.CreateNotecardAsset();
118 asset.ID = TestHelpers.ParseTail(0x2).ToString();
119  
120 m_cache.Store(asset);
121  
122 m_cache.Clear();
123  
124 AssetBase retrievedAsset = m_cache.Get(asset.ID.ToString());
125 Assert.That(retrievedAsset, Is.Null);
126 }
127 }
128 }