From fba961c63f2168eb560eec84b66203b1a875b952 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 1 Jul 2011 23:06:46 +0100 Subject: Make default serverside_object_permissions = true since this better matches user expectations. It also matches the default setting in the OpenSim.ini.example file --- OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs index d7324c6..a40517c 100644 --- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs @@ -134,7 +134,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions return; m_allowGridGods = myConfig.GetBoolean("allow_grid_gods", false); - m_bypassPermissions = !myConfig.GetBoolean("serverside_object_permissions", false); + m_bypassPermissions = !myConfig.GetBoolean("serverside_object_permissions", true); m_propagatePermissions = myConfig.GetBoolean("propagate_permissions", true); m_RegionOwnerIsGod = myConfig.GetBoolean("region_owner_is_god", true); m_RegionManagerIsGod = myConfig.GetBoolean("region_manager_is_god", false); -- cgit v1.1 From 513d63455ed7cf1a7a859e9e8abaeff7e7c7ad4f Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 2 Jul 2011 01:01:40 +0100 Subject: Create a very basic initial test which just creates an 'npc' and tests that the scene presence exists --- .../Region/CoreModules/Avatar/NPC/INPCModule.cs | 40 ---------------------- 1 file changed, 40 deletions(-) delete mode 100644 OpenSim/Region/CoreModules/Avatar/NPC/INPCModule.cs (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Avatar/NPC/INPCModule.cs b/OpenSim/Region/CoreModules/Avatar/NPC/INPCModule.cs deleted file mode 100644 index cd2fe4f..0000000 --- a/OpenSim/Region/CoreModules/Avatar/NPC/INPCModule.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using OpenMetaverse; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.CoreModules.Avatar.NPC -{ - public interface INPCModule - { - UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom); - void Autopilot(UUID agentID, Scene scene, Vector3 pos); - void Say(UUID agentID, Scene scene, string text); - void DeleteNPC(UUID agentID, Scene scene); - } -} \ No newline at end of file -- cgit v1.1 From b8e7258051abab3e1310dd8b08cb1d2e09fa21e3 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 2 Jul 2011 01:14:29 +0100 Subject: If a user has the rights to edit a parcel's properties, then also allow them always to enter that parcel. This is patch http://opensimulator.org/mantis/view.php?id=5567 Thanks Snoopy! --- OpenSim/Region/CoreModules/World/Land/LandObject.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index 560b862..8c40171 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs @@ -418,7 +418,7 @@ namespace OpenSim.Region.CoreModules.World.Land public bool IsBannedFromLand(UUID avatar) { - if (m_scene.Permissions.IsAdministrator(avatar)) + if (m_scene.Permissions.CanEditParcelProperties(avatar, this, 0)) return false; if ((LandData.Flags & (uint) ParcelFlags.UseBanList) > 0) @@ -429,7 +429,7 @@ namespace OpenSim.Region.CoreModules.World.Land if (e.AgentID == avatar && e.Flags == AccessList.Ban) return true; return false; - }) != -1 && LandData.OwnerID != avatar) + }) != -1) { return true; } @@ -439,7 +439,7 @@ namespace OpenSim.Region.CoreModules.World.Land public bool IsRestrictedFromLand(UUID avatar) { - if (m_scene.Permissions.IsAdministrator(avatar)) + if (m_scene.Permissions.CanEditParcelProperties(avatar, this, 0)) return false; if ((LandData.Flags & (uint) ParcelFlags.UseAccessList) > 0) @@ -450,7 +450,7 @@ namespace OpenSim.Region.CoreModules.World.Land if (e.AgentID == avatar && e.Flags == AccessList.Access) return true; return false; - }) == -1 && LandData.OwnerID != avatar) + }) == -1) { return true; } -- cgit v1.1 From 46f5893d559f87982e510d02a37856951eb1e088 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 4 Jul 2011 21:35:15 +0100 Subject: Add basic flotsam asset cache test for retrieved cached asset. Disabled temporarily since file system caching disrupts subsequent test runs --- .../Region/CoreModules/Asset/FlotsamAssetCache.cs | 2 + .../Asset/Tests/FlotsamAssetCacheTests.cs | 82 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index 48ee277..a8f5c99 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -259,6 +259,8 @@ namespace Flotsam.RegionModules.AssetCache // TODO: Spawn this off to some seperate thread to do the actual writing if (asset != null) { + m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Caching asset with id {0}", asset.ID); + UpdateMemoryCache(asset.ID, asset); string filename = GetFileName(asset.ID); diff --git a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs new file mode 100644 index 0000000..3498969 --- /dev/null +++ b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs @@ -0,0 +1,82 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Threading; +using log4net.Config; +using Nini.Config; +using NUnit.Framework; +using OpenMetaverse; +using OpenMetaverse.Assets; +using Flotsam.RegionModules.AssetCache; +using OpenSim.Framework; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Scenes.Serialization; +using OpenSim.Tests.Common; +using OpenSim.Tests.Common.Mock; + +namespace OpenSim.Region.CoreModules.Asset.Tests +{ + [TestFixture] + public class FlotsamAssetCacheTests + { +// [Test] + public void TestCacheAsset() + { + TestHelper.InMethod(); + log4net.Config.XmlConfigurator.Configure(); + + IConfigSource config = new IniConfigSource(); + + config.AddConfig("Modules"); + config.Configs["Modules"].Set("AssetCaching", "FlotsamAssetCache"); + config.AddConfig("AssetCache"); + config.Configs["AssetCache"].Set("MemoryCacheEnabled", "true"); + + FlotsamAssetCache cache = new FlotsamAssetCache(); + TestScene scene = SceneSetupHelpers.SetupScene(); + SceneSetupHelpers.SetupSceneModules(scene, config, cache); + + AssetBase asset = AssetHelpers.CreateAsset(); + asset.ID = TestHelper.ParseTail(0x1).ToString(); + + // Check we don't get anything before the asset is put in the cache + AssetBase retrievedAsset = cache.Get(asset.ID.ToString()); + Assert.That(retrievedAsset, Is.Null); + + cache.Store(asset); + + // Check that asset is now in cache + retrievedAsset = cache.Get(asset.ID.ToString()); + Assert.That(retrievedAsset, Is.Not.Null); + Assert.That(retrievedAsset.ID, Is.EqualTo(asset.ID)); + } + } +} \ No newline at end of file -- cgit v1.1 From 5dc785bbf2a0197b560e94b2aa8858ad33d58504 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 4 Jul 2011 22:30:18 +0100 Subject: refactor: Split file cache manipulation code into separate methods, as has already been done for the memory cache --- .../Region/CoreModules/Asset/FlotsamAssetCache.cs | 233 ++++++++++++--------- 1 file changed, 131 insertions(+), 102 deletions(-) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index a8f5c99..a72cf83 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -226,7 +226,6 @@ namespace Flotsam.RegionModules.AssetCache if (m_AssetService == null) { m_AssetService = scene.RequestModuleInterface(); - } } } @@ -250,140 +249,170 @@ namespace Flotsam.RegionModules.AssetCache private void UpdateMemoryCache(string key, AssetBase asset) { - if (m_MemoryCacheEnabled) - m_MemoryCache.AddOrUpdate(key, asset, m_MemoryExpiration); + m_MemoryCache.AddOrUpdate(key, asset, m_MemoryExpiration); } - public void Cache(AssetBase asset) + private void UpdateFileCache(string key, AssetBase asset) { - // TODO: Spawn this off to some seperate thread to do the actual writing - if (asset != null) - { - m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Caching asset with id {0}", asset.ID); - - UpdateMemoryCache(asset.ID, asset); - - string filename = GetFileName(asset.ID); + string filename = GetFileName(asset.ID); - try + try + { + // If the file is already cached, don't cache it, just touch it so access time is updated + if (File.Exists(filename)) { - // If the file is already cached, don't cache it, just touch it so access time is updated - if (File.Exists(filename)) + File.SetLastAccessTime(filename, DateTime.Now); + } + else + { + // Once we start writing, make sure we flag that we're writing + // that object to the cache so that we don't try to write the + // same file multiple times. + lock (m_CurrentlyWriting) { - File.SetLastAccessTime(filename, DateTime.Now); - } else { - - // Once we start writing, make sure we flag that we're writing - // that object to the cache so that we don't try to write the - // same file multiple times. - lock (m_CurrentlyWriting) - { #if WAIT_ON_INPROGRESS_REQUESTS - if (m_CurrentlyWriting.ContainsKey(filename)) - { - return; - } - else - { - m_CurrentlyWriting.Add(filename, new ManualResetEvent(false)); - } + if (m_CurrentlyWriting.ContainsKey(filename)) + { + return; + } + else + { + m_CurrentlyWriting.Add(filename, new ManualResetEvent(false)); + } #else - if (m_CurrentlyWriting.Contains(filename)) - { - return; - } - else - { - m_CurrentlyWriting.Add(filename); - } -#endif - + if (m_CurrentlyWriting.Contains(filename)) + { + return; } - - Util.FireAndForget( - delegate { WriteFileCache(filename, asset); }); + else + { + m_CurrentlyWriting.Add(filename); + } +#endif } - } - catch (Exception e) - { - LogException(e); + + Util.FireAndForget( + delegate { WriteFileCache(filename, asset); }); } } + catch (Exception e) + { + LogException(e); + } } - public AssetBase Get(string id) + public void Cache(AssetBase asset) { - m_Requests++; + // TODO: Spawn this off to some seperate thread to do the actual writing + if (asset != null) + { + //m_log.DebugFormat("[FLOTSAM ASSET CACHE]: Caching asset with id {0}", asset.ID); + if (m_MemoryCacheEnabled) + UpdateMemoryCache(asset.ID, asset); + + UpdateFileCache(asset.ID, asset); + } + } + + /// + /// Try to get an asset from the in-memory cache. + /// + /// + /// + private AssetBase GetFromMemoryCache(string id) + { AssetBase asset = null; - if (m_MemoryCacheEnabled && m_MemoryCache.TryGetValue(id, out asset)) - { + if (m_MemoryCache.TryGetValue(id, out asset)) m_MemoryHits++; - } - else + + return asset; + } + + /// + /// Try to get an asset from the file cache. + /// + /// + /// + private AssetBase GetFromFileCache(string id) + { + AssetBase asset = null; + + string filename = GetFileName(id); + if (File.Exists(filename)) { - string filename = GetFileName(id); - if (File.Exists(filename)) + FileStream stream = null; + try { - FileStream stream = null; - try - { - stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); - BinaryFormatter bformatter = new BinaryFormatter(); + stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); + BinaryFormatter bformatter = new BinaryFormatter(); - asset = (AssetBase)bformatter.Deserialize(stream); + asset = (AssetBase)bformatter.Deserialize(stream); - UpdateMemoryCache(id, asset); + UpdateMemoryCache(id, asset); - m_DiskHits++; - } - catch (System.Runtime.Serialization.SerializationException e) - { - LogException(e); + m_DiskHits++; + } + catch (System.Runtime.Serialization.SerializationException e) + { + LogException(e); - // If there was a problem deserializing the asset, the asset may - // either be corrupted OR was serialized under an old format - // {different version of AssetBase} -- we should attempt to - // delete it and re-cache - File.Delete(filename); - } - catch (Exception e) - { - LogException(e); - } - finally - { - if (stream != null) - stream.Close(); - } + // If there was a problem deserializing the asset, the asset may + // either be corrupted OR was serialized under an old format + // {different version of AssetBase} -- we should attempt to + // delete it and re-cache + File.Delete(filename); + } + catch (Exception e) + { + LogException(e); } + finally + { + if (stream != null) + stream.Close(); + } + } #if WAIT_ON_INPROGRESS_REQUESTS - // Check if we're already downloading this asset. If so, try to wait for it to - // download. - if (m_WaitOnInprogressTimeout > 0) - { - m_RequestsForInprogress++; + // Check if we're already downloading this asset. If so, try to wait for it to + // download. + if (m_WaitOnInprogressTimeout > 0) + { + m_RequestsForInprogress++; - ManualResetEvent waitEvent; - if (m_CurrentlyWriting.TryGetValue(filename, out waitEvent)) - { - waitEvent.WaitOne(m_WaitOnInprogressTimeout); - return Get(id); - } - } -#else - // Track how often we have the problem that an asset is requested while - // it is still being downloaded by a previous request. - if (m_CurrentlyWriting.Contains(filename)) + ManualResetEvent waitEvent; + if (m_CurrentlyWriting.TryGetValue(filename, out waitEvent)) { - m_RequestsForInprogress++; + waitEvent.WaitOne(m_WaitOnInprogressTimeout); + return Get(id); } -#endif } +#else + // Track how often we have the problem that an asset is requested while + // it is still being downloaded by a previous request. + if (m_CurrentlyWriting.Contains(filename)) + { + m_RequestsForInprogress++; + } +#endif + + return asset; + } + + public AssetBase Get(string id) + { + m_Requests++; + + AssetBase asset = null; + + if (m_MemoryCacheEnabled) + asset = GetFromMemoryCache(id); + else + asset = GetFromFileCache(id); if (((m_LogLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0)) { @@ -474,9 +503,9 @@ namespace Flotsam.RegionModules.AssetCache /// removes empty tier directories. /// /// + /// private void CleanExpiredFiles(string dir, DateTime purgeLine) { - foreach (string file in Directory.GetFiles(dir)) { if (File.GetLastAccessTime(file) < purgeLine) -- cgit v1.1 From bebc51a6e041d2bcd8fef110ea5b178ac614c59d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 4 Jul 2011 22:51:47 +0100 Subject: Make it possible to disable the file part of the flotsam asset cache This matches the ability to disable the memory part This is controlled through the FileCacheEnabled parameter in FlotsamCache.ini Default is true, so existing installations are not affected. Improved fcache command feedback when various caches are disabled. Re-enabled test for flotsam cache with file caching disabled. --- .../Region/CoreModules/Asset/FlotsamAssetCache.cs | 110 ++++++++++++++------- .../Asset/Tests/FlotsamAssetCacheTests.cs | 3 +- 2 files changed, 74 insertions(+), 39 deletions(-) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs index a72cf83..2b3f7f5 100644 --- a/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs +++ b/OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs @@ -86,6 +86,8 @@ namespace Flotsam.RegionModules.AssetCache private List m_CurrentlyWriting = new List(); #endif + private bool m_FileCacheEnabled = true; + private ExpiringCache m_MemoryCache; private bool m_MemoryCacheEnabled = false; @@ -146,6 +148,7 @@ namespace Flotsam.RegionModules.AssetCache } else { + m_FileCacheEnabled = assetConfig.GetBoolean("FileCacheEnabled", m_FileCacheEnabled); m_CacheDirectory = assetConfig.GetString("CacheDirectory", m_DefaultCacheDirectory); m_MemoryCacheEnabled = assetConfig.GetBoolean("MemoryCacheEnabled", m_MemoryCacheEnabled); @@ -173,7 +176,7 @@ namespace Flotsam.RegionModules.AssetCache m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Directory {0}", m_CacheDirectory); - if ((m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero)) + if (m_FileCacheEnabled && (m_FileExpiration > TimeSpan.Zero) && (m_FileExpirationCleanupTimer > TimeSpan.Zero)) { m_CacheCleanTimer = new System.Timers.Timer(m_FileExpirationCleanupTimer.TotalMilliseconds); m_CacheCleanTimer.AutoReset = true; @@ -312,7 +315,8 @@ namespace Flotsam.RegionModules.AssetCache if (m_MemoryCacheEnabled) UpdateMemoryCache(asset.ID, asset); - UpdateFileCache(asset.ID, asset); + if (m_FileCacheEnabled) + UpdateFileCache(asset.ID, asset); } } @@ -411,7 +415,7 @@ namespace Flotsam.RegionModules.AssetCache if (m_MemoryCacheEnabled) asset = GetFromMemoryCache(id); - else + else if (m_FileCacheEnabled) asset = GetFromFileCache(id); if (((m_LogLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0)) @@ -446,10 +450,13 @@ namespace Flotsam.RegionModules.AssetCache try { - string filename = GetFileName(id); - if (File.Exists(filename)) + if (m_FileCacheEnabled) { - File.Delete(filename); + string filename = GetFileName(id); + if (File.Exists(filename)) + { + File.Delete(filename); + } } if (m_MemoryCacheEnabled) @@ -464,11 +471,14 @@ namespace Flotsam.RegionModules.AssetCache public void Clear() { if (m_LogLevel >= 2) - m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing Cache."); + m_log.Debug("[FLOTSAM ASSET CACHE]: Clearing caches."); - foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) + if (m_FileCacheEnabled) { - Directory.Delete(dir); + foreach (string dir in Directory.GetDirectories(m_CacheDirectory)) + { + Directory.Delete(dir); + } } if (m_MemoryCacheEnabled) @@ -743,18 +753,28 @@ namespace Flotsam.RegionModules.AssetCache switch (cmd) { case "status": - m_log.InfoFormat("[FLOTSAM ASSET CACHE] Memory Cache : {0} assets", m_MemoryCache.Count); - - int fileCount = GetFileCacheCount(m_CacheDirectory); - m_log.InfoFormat("[FLOTSAM ASSET CACHE] File Cache : {0} assets", fileCount); + if (m_MemoryCacheEnabled) + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory Cache : {0} assets", m_MemoryCache.Count); + else + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Memory cache disabled"); - foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac")) + if (m_FileCacheEnabled) { - m_log.Info("[FLOTSAM ASSET CACHE] Deep Scans were performed on the following regions:"); - - string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac",""); - DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s); - m_log.InfoFormat("[FLOTSAM ASSET CACHE] Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss")); + int fileCount = GetFileCacheCount(m_CacheDirectory); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File Cache : {0} assets", fileCount); + + foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac")) + { + m_log.Info("[FLOTSAM ASSET CACHE]: Deep Scans were performed on the following regions:"); + + string RegionID = s.Remove(0,s.IndexOf("_")).Replace(".fac",""); + DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss")); + } + } + else + { + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File cache disabled"); } break; @@ -762,7 +782,7 @@ namespace Flotsam.RegionModules.AssetCache case "clear": if (cmdparams.Length < 2) { - m_log.Warn("[FLOTSAM ASSET CACHE] Usage is fcache clear [file] [memory]"); + m_log.Warn("[FLOTSAM ASSET CACHE]: Usage is fcache clear [file] [memory]"); break; } @@ -783,36 +803,48 @@ namespace Flotsam.RegionModules.AssetCache if (clearMemory) { - m_MemoryCache.Clear(); - m_log.Info("[FLOTSAM ASSET CACHE] Memory cache cleared."); + if (m_MemoryCacheEnabled) + { + m_MemoryCache.Clear(); + m_log.Info("[FLOTSAM ASSET CACHE]: Memory cache cleared."); + } + else + { + m_log.Info("[FLOTSAM ASSET CACHE]: Memory cache not enabled."); + } } if (clearFile) { - ClearFileCache(); - m_log.Info("[FLOTSAM ASSET CACHE] File cache cleared."); + if (m_FileCacheEnabled) + { + ClearFileCache(); + m_log.Info("[FLOTSAM ASSET CACHE]: File cache cleared."); + } + else + { + m_log.Info("[FLOTSAM ASSET CACHE]: File cache not enabled."); + } } break; case "assets": - m_log.Info("[FLOTSAM ASSET CACHE] Caching all assets, in all scenes."); + m_log.Info("[FLOTSAM ASSET CACHE]: Caching all assets, in all scenes."); Util.FireAndForget(delegate { int assetsCached = CacheScenes(); - m_log.InfoFormat("[FLOTSAM ASSET CACHE] Completed Scene Caching, {0} assets found.", assetsCached); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Completed Scene Caching, {0} assets found.", assetsCached); }); break; case "expire": - - if (cmdparams.Length < 3) { - m_log.InfoFormat("[FLOTSAM ASSET CACHE] Invalid parameters for Expire, please specify a valid date & time", cmd); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Invalid parameters for Expire, please specify a valid date & time", cmd); break; } @@ -830,26 +862,28 @@ namespace Flotsam.RegionModules.AssetCache if (!DateTime.TryParse(s_expirationDate, out expirationDate)) { - m_log.InfoFormat("[FLOTSAM ASSET CACHE] {0} is not a valid date & time", cmd); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0} is not a valid date & time", cmd); break; } - CleanExpiredFiles(m_CacheDirectory, expirationDate); + if (m_FileCacheEnabled) + CleanExpiredFiles(m_CacheDirectory, expirationDate); + else + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: File cache not active, not clearing."); break; default: - m_log.InfoFormat("[FLOTSAM ASSET CACHE] Unknown command {0}", cmd); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Unknown command {0}", cmd); break; } } else if (cmdparams.Length == 1) { - m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache status - Display cache status"); - m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearmem - Remove all assets cached in memory"); - m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache clearfile - Remove all assets cached on disk"); - m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache cachescenes - Attempt a deep cache of all assets in all scenes"); - m_log.InfoFormat("[FLOTSAM ASSET CACHE] flotsamcache - Purge assets older then the specified date & time"); - + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache status - Display cache status"); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache clearmem - Remove all assets cached in memory"); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache clearfile - Remove all assets cached on disk"); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache cachescenes - Attempt a deep cache of all assets in all scenes"); + m_log.InfoFormat("[FLOTSAM ASSET CACHE]: fcache - Purge assets older then the specified date & time"); } } diff --git a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs index 3498969..a4aeeda 100644 --- a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs +++ b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs @@ -47,7 +47,7 @@ namespace OpenSim.Region.CoreModules.Asset.Tests [TestFixture] public class FlotsamAssetCacheTests { -// [Test] + [Test] public void TestCacheAsset() { TestHelper.InMethod(); @@ -58,6 +58,7 @@ namespace OpenSim.Region.CoreModules.Asset.Tests config.AddConfig("Modules"); config.Configs["Modules"].Set("AssetCaching", "FlotsamAssetCache"); config.AddConfig("AssetCache"); + config.Configs["AssetCache"].Set("FileCacheEnabled", "false"); config.Configs["AssetCache"].Set("MemoryCacheEnabled", "true"); FlotsamAssetCache cache = new FlotsamAssetCache(); -- cgit v1.1 From f58de55c843843775886a6227acbecd249a59e96 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 4 Jul 2011 22:59:36 +0100 Subject: refactor: Move test setup code into setup method --- .../Asset/Tests/FlotsamAssetCacheTests.cs | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs index a4aeeda..36cffd0 100644 --- a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs +++ b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs @@ -47,35 +47,42 @@ namespace OpenSim.Region.CoreModules.Asset.Tests [TestFixture] public class FlotsamAssetCacheTests { - [Test] - public void TestCacheAsset() - { - TestHelper.InMethod(); - log4net.Config.XmlConfigurator.Configure(); + protected TestScene m_scene; + protected FlotsamAssetCache m_cache; + [SetUp] + public void SetUp() + { IConfigSource config = new IniConfigSource(); - - config.AddConfig("Modules"); + + config.AddConfig("Modules"); config.Configs["Modules"].Set("AssetCaching", "FlotsamAssetCache"); config.AddConfig("AssetCache"); config.Configs["AssetCache"].Set("FileCacheEnabled", "false"); config.Configs["AssetCache"].Set("MemoryCacheEnabled", "true"); - FlotsamAssetCache cache = new FlotsamAssetCache(); - TestScene scene = SceneSetupHelpers.SetupScene(); - SceneSetupHelpers.SetupSceneModules(scene, config, cache); + m_cache = new FlotsamAssetCache(); + m_scene = SceneSetupHelpers.SetupScene(); + SceneSetupHelpers.SetupSceneModules(m_scene, config, m_cache); + } + + [Test] + public void TestCacheAsset() + { + TestHelper.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); AssetBase asset = AssetHelpers.CreateAsset(); asset.ID = TestHelper.ParseTail(0x1).ToString(); // Check we don't get anything before the asset is put in the cache - AssetBase retrievedAsset = cache.Get(asset.ID.ToString()); + AssetBase retrievedAsset = m_cache.Get(asset.ID.ToString()); Assert.That(retrievedAsset, Is.Null); - cache.Store(asset); + m_cache.Store(asset); // Check that asset is now in cache - retrievedAsset = cache.Get(asset.ID.ToString()); + retrievedAsset = m_cache.Get(asset.ID.ToString()); Assert.That(retrievedAsset, Is.Not.Null); Assert.That(retrievedAsset.ID, Is.EqualTo(asset.ID)); } -- cgit v1.1 From cb02fc44f5f80fce8fe9e1b87bcfa09df7960a13 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 4 Jul 2011 23:03:05 +0100 Subject: add TestExpireAsset() --- .../Asset/Tests/FlotsamAssetCacheTests.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs index 36cffd0..bbe40d1 100644 --- a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs +++ b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs @@ -44,6 +44,9 @@ using OpenSim.Tests.Common.Mock; namespace OpenSim.Region.CoreModules.Asset.Tests { + /// + /// At the moment we're only test the in-memory part of the FlotsamAssetCache. This is a considerable weakness. + /// [TestFixture] public class FlotsamAssetCacheTests { @@ -86,5 +89,22 @@ namespace OpenSim.Region.CoreModules.Asset.Tests Assert.That(retrievedAsset, Is.Not.Null); Assert.That(retrievedAsset.ID, Is.EqualTo(asset.ID)); } + + [Test] + public void TestExpireAsset() + { + TestHelper.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + AssetBase asset = AssetHelpers.CreateAsset(); + asset.ID = TestHelper.ParseTail(0x2).ToString(); + + m_cache.Store(asset); + + m_cache.Expire(asset.ID); + + AssetBase retrievedAsset = m_cache.Get(asset.ID.ToString()); + Assert.That(retrievedAsset, Is.Null); + } } } \ No newline at end of file -- cgit v1.1 From af8773d6d076f5d74133857a5074bd9e9504dd64 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 4 Jul 2011 23:05:31 +0100 Subject: Add TestClearCache() --- .../CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'OpenSim/Region/CoreModules') diff --git a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs index bbe40d1..63b0c31 100644 --- a/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs +++ b/OpenSim/Region/CoreModules/Asset/Tests/FlotsamAssetCacheTests.cs @@ -106,5 +106,22 @@ namespace OpenSim.Region.CoreModules.Asset.Tests AssetBase retrievedAsset = m_cache.Get(asset.ID.ToString()); Assert.That(retrievedAsset, Is.Null); } + + [Test] + public void TestClearCache() + { + TestHelper.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + AssetBase asset = AssetHelpers.CreateAsset(); + asset.ID = TestHelper.ParseTail(0x2).ToString(); + + m_cache.Store(asset); + + m_cache.Clear(); + + AssetBase retrievedAsset = m_cache.Get(asset.ID.ToString()); + Assert.That(retrievedAsset, Is.Null); + } } } \ No newline at end of file -- cgit v1.1