From e1c449b492a08b95e9f4ea0556b6ec77f32ef0e7 Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Tue, 14 Apr 2009 17:44:10 +0000
Subject: * Change simple asset cache test to manually pump the asset server
rather than relying on another thread
---
.../Communications/Cache/AssetServerBase.cs | 29 ++++++++++++++++------
.../Communications/Tests/Cache/AssetCacheTests.cs | 15 ++++++-----
2 files changed, 28 insertions(+), 16 deletions(-)
(limited to 'OpenSim/Framework/Communications')
diff --git a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
index 343667a..24cb598 100644
--- a/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetServerBase.cs
@@ -138,14 +138,29 @@ namespace OpenSim.Framework.Communications.Cache
/// asset cannot be found.
///
protected abstract AssetBase GetAsset(AssetRequest req);
-
+
+ ///
+ /// Does the asset server have any waiting requests?
+ ///
+ ///
+ /// This does include any request that is currently being handled. This information is not reliable where
+ /// another thread may be processing requests.
+ ///
+ ///
+ /// True if there are waiting requests. False if there are no waiting requests.
+ ///
+ public virtual bool HasWaitingRequests()
+ {
+ return m_assetRequests.Count() != 0;
+ }
+
///
/// Process an asset request. This method will call GetAsset(AssetRequest req)
/// on the subclass.
///
- ///
- protected virtual void ProcessRequest(AssetRequest req)
+ public virtual void ProcessNextRequest()
{
+ AssetRequest req = m_assetRequests.Dequeue();
AssetBase asset;
try
@@ -160,7 +175,7 @@ namespace OpenSim.Framework.Communications.Cache
StatsManager.SimExtraStats.AddAssetServiceRequestFailure();
m_receiver.AssetNotFound(req.AssetID, req.IsTexture);
-
+
return;
}
@@ -190,10 +205,8 @@ namespace OpenSim.Framework.Communications.Cache
while (true) // Since it's a 'blocking queue'
{
try
- {
- AssetRequest req = m_assetRequests.Dequeue();
-
- ProcessRequest(req);
+ {
+ ProcessNextRequest();
}
catch (Exception e)
{
diff --git a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs
index 264bfe1..5d6bc8d 100644
--- a/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs
+++ b/OpenSim/Framework/Communications/Tests/Cache/AssetCacheTests.cs
@@ -62,15 +62,14 @@ namespace OpenSim.Framework.Communications.Tests
TestAssetDataPlugin assetPlugin = new TestAssetDataPlugin();
assetPlugin.CreateAsset(asset);
- IAssetServer assetServer = new SQLAssetServer(assetPlugin);
+ SQLAssetServer assetServer = new SQLAssetServer(assetPlugin);
IAssetCache assetCache = new AssetCache(assetServer);
- assetServer.Start();
-
- lock (this)
- {
- assetCache.GetAsset(assetId, AssetRequestCallback, false);
- Monitor.Wait(this, 60000);
- }
+
+ assetCache.GetAsset(assetId, AssetRequestCallback, false);
+
+ // Manually pump the asset server
+ while (assetServer.HasWaitingRequests())
+ assetServer.ProcessNextRequest();
Assert.That(
assetId, Is.EqualTo(m_assetIdReceived), "Asset id stored differs from asset id received");
--
cgit v1.1