using System;
using NUnit.Framework;
using grof;
using System.Threading;
using System.Diagnostics;
// TODO: implement Testcases
namespace grof.protocols{
[TestFixture]
public class ProtocolTest : AbstractTest
{
private TestProtocol upperProt;
private TestProtocol midProt;
private TestProtocol lowerProt;
private MessageCreator creator;
[SetUp]
protected void SetUp()
{
base.SetUp();
this.creator = new MessageCreator( "Foo", "localhost", 5807 );
this.upperProt = new TestProtocol( "upper protocol" );
this.midProt = new TestProtocol( "middle protocol" );
this.lowerProt = new TestProtocol( "lower protocol" );
this.upperProt.UpperProtocol = null;
this.upperProt.LowerProtocol = this.midProt;
this.midProt.UpperProtocol = this.upperProt;
this.midProt.LowerProtocol = this.lowerProt;
this.lowerProt.UpperProtocol = this.midProt;
this.lowerProt.LowerProtocol = null;
this.upperProt.Start();
this.midProt.Start();
this.lowerProt.Start();
}
[TearDown]
protected void TearDown()
{
base.TearDown();
this.lowerProt.Stop();
this.midProt.Stop();
this.upperProt.Stop();
this.upperProt = null;
this.midProt = null;
this.lowerProt = null;
}
[Test]
public void TestMethod()
{
for ( int i=0; i<10; i++ )
{
this.lowerProt.IncomingQueue.Put(
this.creator.CreateApplicationMessage( null ) );
}
this.WaitForProcessedMessages();
}
private void WaitForProcessedMessages()
{
lock( this )
{
while( this.upperProt.IncomingQueue.Size() != 10 )
{
Monitor.Wait( this, 200 );
}
}
}
class TestProtocol : AbstractProtocol
{
public TestProtocol( string name ) : base( name )
{
}
public override GroupMemberInfo[] GetGroupMembers()
{
return null;
}
public override bool ProcessIncomingMessage( Message msg )
{
return true;
}
public override bool ProcessOutgoingMessage( Message msg )
{
return true;
}
}
}
}
|