Add image not in database test for LLImageManager

iar_mods
Justin Clark-Casey (justincc) 2012-01-19 21:57:12 +00:00
parent 503faaea62
commit d38e2c0c91
4 changed files with 58 additions and 13 deletions

View File

@ -377,6 +377,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private void AssetReceived(string id, Object sender, AssetBase asset) private void AssetReceived(string id, Object sender, AssetBase asset)
{ {
// m_log.DebugFormat(
// "[J2KIMAGE]: Received asset {0} ({1} bytes)", id, asset != null ? asset.Data.Length.ToString() : "n/a");
UUID assetID = UUID.Zero; UUID assetID = UUID.Zero;
if (asset != null) if (asset != null)
{ {

View File

@ -55,18 +55,29 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private bool m_shuttingdown; private bool m_shuttingdown;
private AssetBase m_missingImage; private AssetBase m_missingImage;
private IClientAPI m_client; //Client we're assigned to private IAssetService m_assetCache;
private IAssetService m_assetCache; //Asset Cache private IJ2KDecoder m_j2kDecodeModule;
private IJ2KDecoder m_j2kDecodeModule; //Our J2K module
/// <summary>
/// Priority queue for determining which image to send first.
/// </summary>
private C5.IntervalHeap<J2KImage> m_priorityQueue = new C5.IntervalHeap<J2KImage>(10, new J2KImageComparer()); private C5.IntervalHeap<J2KImage> m_priorityQueue = new C5.IntervalHeap<J2KImage>(10, new J2KImageComparer());
/// <summary>
/// Used to control thread access to the priority queue.
/// </summary>
private object m_syncRoot = new object(); private object m_syncRoot = new object();
public IClientAPI Client { get { return m_client; } } /// <summary>
/// Client served by this image manager
/// </summary>
public IClientAPI Client { get; private set; }
public AssetBase MissingImage { get { return m_missingImage; } } public AssetBase MissingImage { get { return m_missingImage; } }
public LLImageManager(IClientAPI client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule) public LLImageManager(IClientAPI client, IAssetService pAssetCache, IJ2KDecoder pJ2kDecodeModule)
{ {
m_client = client; Client = client;
m_assetCache = pAssetCache; m_assetCache = pAssetCache;
if (pAssetCache != null) if (pAssetCache != null)
@ -90,7 +101,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// Do a linear search for this texture download // Do a linear search for this texture download
lock (m_syncRoot) lock (m_syncRoot)
{
m_priorityQueue.Find(delegate(J2KImage img) { return img.TextureID == newRequest.RequestedAssetID; }, out imgrequest); m_priorityQueue.Find(delegate(J2KImage img) { return img.TextureID == newRequest.RequestedAssetID; }, out imgrequest);
}
if (imgrequest != null) if (imgrequest != null)
{ {
@ -178,8 +191,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
imgrequest = new J2KImage(this); imgrequest = new J2KImage(this);
imgrequest.J2KDecoder = m_j2kDecodeModule; imgrequest.J2KDecoder = m_j2kDecodeModule;
imgrequest.AssetService = m_assetCache; imgrequest.AssetService = m_assetCache;
imgrequest.AgentID = m_client.AgentId; imgrequest.AgentID = Client.AgentId;
imgrequest.InventoryAccessModule = m_client.Scene.RequestModuleInterface<IInventoryAccessModule>(); imgrequest.InventoryAccessModule = Client.Scene.RequestModuleInterface<IInventoryAccessModule>();
imgrequest.DiscardLevel = newRequest.DiscardLevel; imgrequest.DiscardLevel = newRequest.DiscardLevel;
imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber); imgrequest.StartPacket = Math.Max(1, newRequest.PacketNumber);
imgrequest.Priority = newRequest.Priority; imgrequest.Priority = newRequest.Priority;
@ -210,7 +223,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (image.IsDecoded) if (image.IsDecoded)
{ {
int sent; int sent;
bool imageDone = image.SendPackets(m_client, packetsToSend - packetsSent, out sent); bool imageDone = image.SendPackets(Client, packetsToSend - packetsSent, out sent);
packetsSent += sent; packetsSent += sent;
// If the send is complete, destroy any knowledge of this transfer // If the send is complete, destroy any knowledge of this transfer

View File

@ -46,6 +46,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
public class LLImageManagerTests public class LLImageManagerTests
{ {
private AssetBase m_testImageAsset; private AssetBase m_testImageAsset;
private Scene scene;
private LLImageManager llim; private LLImageManager llim;
private TestClient tc; private TestClient tc;
@ -78,21 +79,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
J2KDecoderModule j2kdm = new J2KDecoderModule(); J2KDecoderModule j2kdm = new J2KDecoderModule();
Scene scene = SceneHelpers.SetupScene(); scene = SceneHelpers.SetupScene();
SceneHelpers.SetupSceneModules(scene, j2kdm); SceneHelpers.SetupSceneModules(scene, j2kdm);
scene.AssetService.Store(m_testImageAsset);
tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene); tc = new TestClient(SceneHelpers.GenerateAgentData(userId), scene);
llim = new LLImageManager(tc, scene.AssetService, j2kdm); llim = new LLImageManager(tc, scene.AssetService, j2kdm);
} }
[Test] [Test]
public void TestRequestAndSendImage() public void TestSendImage()
{ {
TestHelpers.InMethod(); TestHelpers.InMethod();
// XmlConfigurator.Configure(); // XmlConfigurator.Configure();
scene.AssetService.Store(m_testImageAsset);
TextureRequestArgs args = new TextureRequestArgs(); TextureRequestArgs args = new TextureRequestArgs();
args.RequestedAssetID = m_testImageAsset.FullID; args.RequestedAssetID = m_testImageAsset.FullID;
args.DiscardLevel = 0; args.DiscardLevel = 0;
@ -107,11 +108,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
} }
[Test] [Test]
public void TestRequestAndDiscardImage() public void TestDiscardImage()
{ {
TestHelpers.InMethod(); TestHelpers.InMethod();
// XmlConfigurator.Configure(); // XmlConfigurator.Configure();
scene.AssetService.Store(m_testImageAsset);
TextureRequestArgs args = new TextureRequestArgs(); TextureRequestArgs args = new TextureRequestArgs();
args.RequestedAssetID = m_testImageAsset.FullID; args.RequestedAssetID = m_testImageAsset.FullID;
args.DiscardLevel = 0; args.DiscardLevel = 0;
@ -133,5 +136,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0)); Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0));
} }
[Test]
public void TestMissingImage()
{
TestHelpers.InMethod();
// XmlConfigurator.Configure();
TextureRequestArgs args = new TextureRequestArgs();
args.RequestedAssetID = m_testImageAsset.FullID;
args.DiscardLevel = 0;
args.PacketNumber = 1;
args.Priority = 5;
args.requestSequence = 1;
llim.EnqueueReq(args);
llim.ProcessImageQueue(20);
Assert.That(tc.SentImageDataPackets.Count, Is.EqualTo(0));
Assert.That(tc.SentImageNotInDatabasePackets.Count, Is.EqualTo(1));
}
} }
} }

View File

@ -60,6 +60,7 @@ namespace OpenSim.Tests.Common.Mock
public List<ImageDataPacket> SentImageDataPackets { get; private set; } public List<ImageDataPacket> SentImageDataPackets { get; private set; }
public List<ImagePacketPacket> SentImagePacketPackets { get; private set; } public List<ImagePacketPacket> SentImagePacketPackets { get; private set; }
public List<ImageNotInDatabasePacket> SentImageNotInDatabasePackets { get; private set; }
// disable warning: public events, part of the public API // disable warning: public events, part of the public API
#pragma warning disable 67 #pragma warning disable 67
@ -455,6 +456,7 @@ namespace OpenSim.Tests.Common.Mock
SentImageDataPackets = new List<ImageDataPacket>(); SentImageDataPackets = new List<ImageDataPacket>();
SentImagePacketPackets = new List<ImagePacketPacket>(); SentImagePacketPackets = new List<ImagePacketPacket>();
SentImageNotInDatabasePackets = new List<ImageNotInDatabasePacket>();
} }
/// <summary> /// <summary>
@ -822,6 +824,10 @@ namespace OpenSim.Tests.Common.Mock
public void SendImageNotFound(UUID imageid) public void SendImageNotFound(UUID imageid)
{ {
ImageNotInDatabasePacket p = new ImageNotInDatabasePacket();
p.ImageID.ID = imageid;
SentImageNotInDatabasePackets.Add(p);
} }
public void SendShutdownConnectionNotice() public void SendShutdownConnectionNotice()