From bb92ba97c6952c60f5bdd50b1c6599894bfef501 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 12 Nov 2009 18:26:22 +0000 Subject: [PATCH] Stop iar save failing on corrupt assets Not ideal since one will still have to watch out for big 'corrupt asset' messages in the log, but better than an outright fail --- .../Scenes/Tests/UuidGathererTests.cs | 31 ++++++++++++++++--- .../Region/Framework/Scenes/UuidGatherer.cs | 4 ++- OpenSim/Tests/Common/Mock/TestAssetService.cs | 8 +++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs index cf2b3b3a44..52891f4286 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/UuidGathererTests.cs @@ -26,10 +26,13 @@ */ using System.Collections.Generic; +using System.Text; using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using OpenMetaverse; +using OpenSim.Framework; using OpenSim.Region.Framework.Scenes; +using OpenSim.Services.Interfaces; using OpenSim.Tests.Common; using OpenSim.Tests.Common.Mock; @@ -38,16 +41,36 @@ namespace OpenSim.Region.Framework.Scenes.Tests [TestFixture] public class UuidGathererTests { - protected UuidGatherer m_ug; + protected IAssetService m_assetService; + protected UuidGatherer m_uuidGatherer; [SetUp] public void Init() { - m_ug = new UuidGatherer(new TestAssetService()); + m_assetService = new TestAssetService(); + m_uuidGatherer = new UuidGatherer(m_assetService); + } + + [Test] + public void TestCorruptAsset() + { + TestHelper.InMethod(); + + UUID corruptAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); + AssetBase corruptAsset = new AssetBase(corruptAssetUuid, corruptAssetUuid.ToString(), (sbyte)AssetType.Object); + corruptAsset.Data = Encoding.ASCII.GetBytes("CORRUPT ASSET"); + + m_assetService.Store(corruptAsset); + + IDictionary foundAssetUuids = new Dictionary(); + m_uuidGatherer.GatherAssetUuids(corruptAssetUuid, AssetType.Object, foundAssetUuids); + + // We count the uuid as gathered even if the asset itself is corrupt. + Assert.That(foundAssetUuids.Count, Is.EqualTo(1)); } /// - /// Test requests made for non-existent assets + /// Test requests made for non-existent assets while we're gathering /// [Test] public void TestMissingAsset() @@ -57,7 +80,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests UUID missingAssetUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); IDictionary foundAssetUuids = new Dictionary(); - m_ug.GatherAssetUuids(missingAssetUuid, AssetType.Object, foundAssetUuids); + m_uuidGatherer.GatherAssetUuids(missingAssetUuid, AssetType.Object, foundAssetUuids); // We count the uuid as gathered even if the asset itself is missing. Assert.That(foundAssetUuids.Count, Is.EqualTo(1)); diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 525a93a7fe..930af813c2 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -273,7 +273,9 @@ namespace OpenSim.Region.Framework.Scenes { string xml = Utils.BytesToString(objectAsset.Data); SceneObjectGroup sog = SceneObjectSerializer.FromOriginalXmlFormat(xml); - GatherAssetUuids(sog, assetUuids); + + if (null != sog) + GatherAssetUuids(sog, assetUuids); } } } diff --git a/OpenSim/Tests/Common/Mock/TestAssetService.cs b/OpenSim/Tests/Common/Mock/TestAssetService.cs index ff75d86567..a537b976eb 100644 --- a/OpenSim/Tests/Common/Mock/TestAssetService.cs +++ b/OpenSim/Tests/Common/Mock/TestAssetService.cs @@ -27,6 +27,8 @@ using System; using System.Collections.Generic; +using System.Reflection; +using log4net; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Data; @@ -37,6 +39,8 @@ namespace OpenSim.Tests.Common.Mock { public class TestAssetService : IAssetService { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private readonly Dictionary Assets = new Dictionary(); public TestAssetService() {} @@ -50,6 +54,8 @@ namespace OpenSim.Tests.Common.Mock public AssetBase Get(string id) { + m_log.DebugFormat("[MOCK ASSET SERVICE]: Getting asset with id {0}", id); + AssetBase asset; if (Assets.ContainsKey(id)) asset = Assets[id]; @@ -78,6 +84,8 @@ namespace OpenSim.Tests.Common.Mock public string Store(AssetBase asset) { + m_log.DebugFormat("[MOCK ASSET SERVICE]: Storing asset {0}", asset.ID); + Assets[asset.ID] = asset; return asset.ID;