diff options
author | Teravus Ovares (Dan Olivares) | 2009-10-30 18:13:58 -0400 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2009-10-30 18:13:58 -0400 |
commit | 2e81acec48c02e54843b2a33ce9c542d0a0fb68d (patch) | |
tree | 37e5de9df59b5e37bd6eed3b1e79a5137868ebe1 /OpenSim/Framework/Tests/CacheTests.cs | |
parent | Merge branch 'master' of ssh://MyConnection/var/git/opensim (diff) | |
download | opensim-SC-2e81acec48c02e54843b2a33ce9c542d0a0fb68d.zip opensim-SC-2e81acec48c02e54843b2a33ce9c542d0a0fb68d.tar.gz opensim-SC-2e81acec48c02e54843b2a33ce9c542d0a0fb68d.tar.bz2 opensim-SC-2e81acec48c02e54843b2a33ce9c542d0a0fb68d.tar.xz |
* Adding Tests for OpenSim.Framework.Cache. Some test cases disabled until mantis resolutions.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Tests/CacheTests.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/OpenSim/Framework/Tests/CacheTests.cs b/OpenSim/Framework/Tests/CacheTests.cs new file mode 100644 index 0000000..8e97232 --- /dev/null +++ b/OpenSim/Framework/Tests/CacheTests.cs | |||
@@ -0,0 +1,75 @@ | |||
1 | using System; | ||
2 | using NUnit.Framework; | ||
3 | using OpenMetaverse; | ||
4 | |||
5 | namespace OpenSim.Framework.Tests | ||
6 | { | ||
7 | [TestFixture] | ||
8 | public class CacheTests | ||
9 | { | ||
10 | private Cache cache; | ||
11 | private UUID cacheItemUUID; | ||
12 | [SetUp] | ||
13 | public void Build() | ||
14 | { | ||
15 | cache = new Cache(); | ||
16 | cacheItemUUID = UUID.Random(); | ||
17 | MemoryCacheItem cachedItem = new MemoryCacheItem(cacheItemUUID.ToString(),DateTime.Now + TimeSpan.FromDays(1)); | ||
18 | byte[] foo = new byte[1]; | ||
19 | foo[0] = 255; | ||
20 | cachedItem.Store(foo); | ||
21 | cache.Store(cacheItemUUID.ToString(), cachedItem); | ||
22 | } | ||
23 | [Test] | ||
24 | public void TestRetreive() | ||
25 | { | ||
26 | CacheItemBase citem = (CacheItemBase)cache.Get(cacheItemUUID.ToString()); | ||
27 | byte[] data = (byte[]) citem.Retrieve(); | ||
28 | Assert.That(data.Length == 1, "Cached Item should have one byte element"); | ||
29 | Assert.That(data[0] == 255, "Cached Item element should be 255"); | ||
30 | } | ||
31 | |||
32 | [Test] | ||
33 | public void TestNotInCache() | ||
34 | { | ||
35 | UUID randomNotIn = UUID.Random(); | ||
36 | while (randomNotIn == cacheItemUUID) | ||
37 | { | ||
38 | randomNotIn = UUID.Random(); | ||
39 | } | ||
40 | object citem = cache.Get(randomNotIn.ToString()); | ||
41 | Assert.That(citem == null, "Item should not be in Cache" ); | ||
42 | } | ||
43 | |||
44 | //NOTE: Test Case disabled until Cache is fixed | ||
45 | [Test] | ||
46 | public void TestTTLExpiredEntry() | ||
47 | { | ||
48 | UUID ImmediateExpiryUUID = UUID.Random(); | ||
49 | MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(-1)); | ||
50 | byte[] foo = new byte[1]; | ||
51 | foo[0] = 1; | ||
52 | cachedItem.Store(foo); | ||
53 | cache.Store(cacheItemUUID.ToString(), cachedItem); | ||
54 | |||
55 | object citem = cache.Get(cacheItemUUID.ToString()); | ||
56 | //Assert.That(citem == null, "Item should not be in Cache because the expiry time was before now"); | ||
57 | } | ||
58 | |||
59 | //NOTE: Test Case disabled until Cache is fixed | ||
60 | [Test] | ||
61 | public void ExpireItemManually() | ||
62 | { | ||
63 | UUID ImmediateExpiryUUID = UUID.Random(); | ||
64 | MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(1)); | ||
65 | byte[] foo = new byte[1]; | ||
66 | foo[0] = 1; | ||
67 | cachedItem.Store(foo); | ||
68 | cache.Store(cacheItemUUID.ToString(), cachedItem); | ||
69 | cache.Invalidate(ImmediateExpiryUUID.ToString()); | ||
70 | object citem = cache.Get(cacheItemUUID.ToString()); | ||
71 | //Assert.That(citem == null, "Item should not be in Cache because we manually invalidated it"); | ||
72 | } | ||
73 | |||
74 | } | ||
75 | } | ||