* Change simple asset cache test to manually pump the asset server rather than relying on another thread

0.6.5-rc1
Justin Clarke Casey 2009-04-14 17:44:10 +00:00
parent 2a49272b62
commit e1c449b492
2 changed files with 28 additions and 16 deletions

View File

@ -138,14 +138,29 @@ namespace OpenSim.Framework.Communications.Cache
/// asset cannot be found. /// asset cannot be found.
/// </exception> /// </exception>
protected abstract AssetBase GetAsset(AssetRequest req); protected abstract AssetBase GetAsset(AssetRequest req);
/// <summary>
/// Does the asset server have any waiting requests?
/// </summary>
///
/// This does include any request that is currently being handled. This information is not reliable where
/// another thread may be processing requests.
///
/// <returns>
/// True if there are waiting requests. False if there are no waiting requests.
/// </returns>
public virtual bool HasWaitingRequests()
{
return m_assetRequests.Count() != 0;
}
/// <summary> /// <summary>
/// Process an asset request. This method will call GetAsset(AssetRequest req) /// Process an asset request. This method will call GetAsset(AssetRequest req)
/// on the subclass. /// on the subclass.
/// </summary> /// </summary>
/// <param name="req"></param> public virtual void ProcessNextRequest()
protected virtual void ProcessRequest(AssetRequest req)
{ {
AssetRequest req = m_assetRequests.Dequeue();
AssetBase asset; AssetBase asset;
try try
@ -160,7 +175,7 @@ namespace OpenSim.Framework.Communications.Cache
StatsManager.SimExtraStats.AddAssetServiceRequestFailure(); StatsManager.SimExtraStats.AddAssetServiceRequestFailure();
m_receiver.AssetNotFound(req.AssetID, req.IsTexture); m_receiver.AssetNotFound(req.AssetID, req.IsTexture);
return; return;
} }
@ -190,10 +205,8 @@ namespace OpenSim.Framework.Communications.Cache
while (true) // Since it's a 'blocking queue' while (true) // Since it's a 'blocking queue'
{ {
try try
{ {
AssetRequest req = m_assetRequests.Dequeue(); ProcessNextRequest();
ProcessRequest(req);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -62,15 +62,14 @@ namespace OpenSim.Framework.Communications.Tests
TestAssetDataPlugin assetPlugin = new TestAssetDataPlugin(); TestAssetDataPlugin assetPlugin = new TestAssetDataPlugin();
assetPlugin.CreateAsset(asset); assetPlugin.CreateAsset(asset);
IAssetServer assetServer = new SQLAssetServer(assetPlugin); SQLAssetServer assetServer = new SQLAssetServer(assetPlugin);
IAssetCache assetCache = new AssetCache(assetServer); IAssetCache assetCache = new AssetCache(assetServer);
assetServer.Start();
assetCache.GetAsset(assetId, AssetRequestCallback, false);
lock (this)
{ // Manually pump the asset server
assetCache.GetAsset(assetId, AssetRequestCallback, false); while (assetServer.HasWaitingRequests())
Monitor.Wait(this, 60000); assetServer.ProcessNextRequest();
}
Assert.That( Assert.That(
assetId, Is.EqualTo(m_assetIdReceived), "Asset id stored differs from asset id received"); assetId, Is.EqualTo(m_assetIdReceived), "Asset id stored differs from asset id received");