* Establish InventoryArchiveSaved event for unit tests

* This is done on the inventory archiver module directly rather than Scene.EventManager - the module seems the more appropriate location
0.6.3-post-fixes
Justin Clarke Casey 2009-02-17 15:39:18 +00:00
parent 2a67c5ec8b
commit 229b69e044
6 changed files with 89 additions and 36 deletions

View File

@ -65,7 +65,7 @@ namespace OpenSim.Framework
/// <summary>
/// The description of the inventory item (must be less than 64 characters)
/// </summary>
private string _description;
private string _description = string.Empty;
/// <summary>
///

View File

@ -42,7 +42,7 @@ namespace OpenSim.Framework
get { return m_name; }
set { m_name = value; }
}
private string m_name;
private string m_name = string.Empty;
/// <summary>
/// A UUID containing the ID for the inventory node itself

View File

@ -45,9 +45,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected TarArchiveWriter archive = new TarArchiveWriter();
protected CommunicationsManager commsManager;
protected Dictionary<UUID, int> assetUuids = new Dictionary<UUID, int>();
private InventoryArchiverModule m_module;
private CachedUserInfo m_userInfo;
private string m_invPath;
@ -60,12 +60,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// Constructor
/// </summary>
public InventoryArchiveWriteRequest(
CachedUserInfo userInfo, string invPath, string savePath, CommunicationsManager commsManager)
InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, string savePath)
: this(
module,
userInfo,
invPath,
new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress),
commsManager)
new GZipStream(new FileStream(savePath, FileMode.Create), CompressionMode.Compress))
{
}
@ -73,20 +73,34 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// Constructor
/// </summary>
public InventoryArchiveWriteRequest(
CachedUserInfo userInfo, string invPath, Stream saveStream, CommunicationsManager commsManager)
InventoryArchiverModule module, CachedUserInfo userInfo, string invPath, Stream saveStream)
{
m_module = module;
m_userInfo = userInfo;
m_invPath = invPath;
m_saveStream = saveStream;
this.commsManager = commsManager;
}
protected void ReceivedAllAssets(IDictionary<UUID, AssetBase> assetsFound, ICollection<UUID> assetsNotFoundUuids)
{
AssetsArchiver assetsArchiver = new AssetsArchiver(assetsFound);
assetsArchiver.Archive(archive);
Exception reportedException = null;
bool succeeded = true;
try
{
archive.WriteTar(m_saveStream);
}
catch (IOException e)
{
reportedException = e;
succeeded = false;
}
m_module.TriggerInventoryArchiveSaved(succeeded, m_userInfo, m_invPath, m_saveStream, reportedException);
}
protected void saveInvItem(InventoryItemBase inventoryItem, string path)
{
@ -115,9 +129,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
writer.WriteString(inventoryItem.Owner.ToString());
writer.WriteEndElement();
writer.WriteStartElement("Description");
if (inventoryItem.Description.Length > 0)
writer.WriteString(inventoryItem.Description);
else writer.WriteString("No Description");
writer.WriteEndElement();
writer.WriteStartElement("AssetType");
writer.WriteString(inventoryItem.AssetType.ToString());
@ -191,7 +203,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
//
// FIXME: FetchInventory should probably be assumed to by async anyway, since even standalones might
// use a remote inventory service, though this is vanishingly rare at the moment.
if (null == commsManager.UserAdminService)
if (null == m_module.CommsManager.UserAdminService)
{
m_log.ErrorFormat(
"[INVENTORY ARCHIVER]: Have not yet received inventory info for user {0} {1}",
@ -242,7 +254,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
else
{
m_log.InfoFormat(
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
inventoryItem.Name, inventoryItem.ID, m_invPath);
@ -252,7 +264,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
}
else
{
m_log.InfoFormat(
m_log.DebugFormat(
"[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
inventoryFolder.Name, inventoryFolder.ID, m_invPath);
@ -260,7 +272,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
saveInvDir(inventoryFolder, "");
}
new AssetsRequest(assetUuids.Keys, commsManager.AssetCache, ReceivedAllAssets).Execute();
new AssetsRequest(assetUuids.Keys, m_module.CommsManager.AssetCache, ReceivedAllAssets).Execute();
}
}
}

View File

@ -25,6 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
@ -50,6 +51,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public bool IsSharedModule { get { return true; } }
public event InventoryArchiveSaved OnInventoryArchiveSaved;
/// <summary>
/// The file to load and save inventory if no filename has been specified
/// </summary>
@ -63,14 +66,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// <value>
/// The comms manager we will use for all comms requests
/// </value>
private CommunicationsManager m_commsManager;
protected internal CommunicationsManager CommsManager;
public void Initialise(Scene scene, IConfigSource source)
{
if (m_scenes.Count == 0)
{
scene.RegisterModuleInterface<IInventoryArchiverModule>(this);
m_commsManager = scene.CommsManager;
CommsManager = scene.CommsManager;
scene.AddCommand(
this, "load iar",
@ -90,6 +93,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
public void Close() {}
/// <summary>
/// Trigger the inventory archive saved event.
/// </summary>
protected internal void TriggerInventoryArchiveSaved(
bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException)
{
InventoryArchiveSaved handlerInventoryArchiveSaved = OnInventoryArchiveSaved;
if (handlerInventoryArchiveSaved != null)
handlerInventoryArchiveSaved(succeeded, userInfo, invPath, saveStream, reportedException);
}
public void DearchiveInventory(string firstName, string lastName, string invPath, Stream loadStream)
{
if (m_scenes.Count > 0)
@ -99,7 +113,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (userInfo != null)
{
InventoryArchiveReadRequest request =
new InventoryArchiveReadRequest(userInfo, invPath, loadStream, m_commsManager);
new InventoryArchiveReadRequest(userInfo, invPath, loadStream, CommsManager);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
}
}
@ -112,7 +126,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
new InventoryArchiveWriteRequest(userInfo, invPath, saveStream, m_commsManager).Execute();
new InventoryArchiveWriteRequest(this, userInfo, invPath, saveStream).Execute();
}
}
@ -125,7 +139,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
if (userInfo != null)
{
InventoryArchiveReadRequest request =
new InventoryArchiveReadRequest(userInfo, invPath, loadPath, m_commsManager);
new InventoryArchiveReadRequest(userInfo, invPath, loadPath, CommsManager);
UpdateClientWithLoadedNodes(userInfo, request.Execute());
}
}
@ -138,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
CachedUserInfo userInfo = GetUserInfo(firstName, lastName);
if (userInfo != null)
new InventoryArchiveWriteRequest(userInfo, invPath, savePath, m_commsManager).Execute();
new InventoryArchiveWriteRequest(this, userInfo, invPath, savePath).Execute();
}
}
@ -208,7 +222,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
/// <returns></returns>
protected CachedUserInfo GetUserInfo(string firstName, string lastName)
{
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(firstName, lastName);
UserProfileData userProfile = CommsManager.UserService.GetUserProfile(firstName, lastName);
if (null == userProfile)
{
@ -216,7 +230,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
return null;
}
CachedUserInfo userInfo = m_commsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(userProfile.ID);
if (null == userInfo)
{
m_log.ErrorFormat(

View File

@ -26,7 +26,9 @@
*/
using System;
using System.IO;
using System.Text;
using System.Threading;
using NUnit.Framework;
using OpenMetaverse;
using OpenSim.Data;
@ -42,6 +44,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
[TestFixture]
public class InventoryArchiverTests
{
private EventWaitHandle m_waitHandle = new AutoResetEvent(false);
private void SaveCompleted(
bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException)
{
m_waitHandle.Set();
}
/// <summary>
/// Test saving a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet).
/// </summary>
@ -96,14 +106,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
item1.Folder = userInfo.RootFolder.FindFolderByPath("Objects").ID;
scene.AddInventoryItem(userId, item1);
/*
MemoryStream archiveWriteStream = new MemoryStream();
archiverModule.OnInventoryArchiveSaved += SaveCompleted;
scene.EventManager.OnOarFileSaved += SaveCompleted;
archiverModule.ArchiveRegion(archiveWriteStream);
archiverModule.ArchiveInventory(userFirstName, userLastName, "Objects", archiveWriteStream);
m_waitHandle.WaitOne(60000, true);
/*
byte[] archive = archiveWriteStream.ToArray();
MemoryStream archiveReadStream = new MemoryStream(archive);
TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

View File

@ -25,12 +25,30 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.IO;
using OpenSim.Framework.Communications.Cache;
namespace OpenSim.Region.Framework.Interfaces
{
/// <summary>
/// Used for the OnInventoryArchiveSaved event.
/// </summary>
/// <param name="succeeded">true if the save succeeded, false otherwise</param>
/// <param name="userInfo">The user for whom the save was conducted</param>
/// <param name="invPath">The inventory path saved</param>
/// <param name="savePath">The stream to which the archive was saved</param>
/// <param name="reportedException">Contains the exception generated if the save did not succeed</param>
public delegate void InventoryArchiveSaved(
bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, Exception reportedException);
public interface IInventoryArchiverModule
{
/// <summary>
/// Fired when an archive inventory save has been completed.
/// </summary>
event InventoryArchiveSaved OnInventoryArchiveSaved;
/// <summary>
/// Dearchive a user's inventory folder from the given stream
/// </summary>