Beispiel #1
0
        public void CloseConnectionWithEndTest()
        {
            this.testListener.RegisterTarget(TestPoint.Close, (stream, channel, fields) =>
            {
                // send an end
                TestListener.FRM(stream, 0x17UL, 0, channel);
                return(TestOutcome.Continue);
            });

            string testName = "CloseConnectionWithEndTest";

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                Connection connection = new Connection(this.address);
                Session    session    = new Session(connection);
                SenderLink sender     = new SenderLink(session, "sender-" + testName, "any");
                sender.Send(new Message("test")
                {
                    Properties = new Properties()
                    {
                        MessageId = testName
                    }
                });
                connection.Close();
                Assert.IsTrue(connection.Error == null, "connection has error!" + connection.Error);
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async() =>
            {
                Connection connection = await Connection.Factory.CreateAsync(this.address);
                Session session       = new Session(connection);
                SenderLink sender     = new SenderLink(session, "sender-" + testName, "any");
                await sender.SendAsync(new Message("test")
                {
                    Properties = new Properties()
                    {
                        MessageId = testName
                    }
                });
                await connection.CloseAsync();
                Assert.IsTrue(connection.Error == null, "connection has error!" + connection.Error);
            }).Unwrap().GetAwaiter().GetResult();
        }
Beispiel #2
0
        public void ConnectionEventsOnProtocolError()
        {
            ManualResetEvent closeReceived  = null;
            ManualResetEvent closedNotified = null;

            this.testListener.RegisterTarget(TestPoint.Begin, (stream, channel, fields) =>
            {
                // begin with invalid remote channel
                TestListener.FRM(stream, 0x11UL, 0, channel, (ushort)2, 0u, 100u, 100u, 8u);
                return(TestOutcome.Stop);
            });

            this.testListener.RegisterTarget(TestPoint.Close, (stream, channel, fields) =>
            {
                closeReceived.Set();
                return(TestOutcome.Continue);
            });

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                closeReceived  = new ManualResetEvent(false);
                closedNotified = new ManualResetEvent(false);
                Connection connection = new Connection(this.address);
                connection.Closed += (o, e) => closedNotified.Set();
                Session session = new Session(connection);
                Assert.IsTrue(closeReceived.WaitOne(5000), "Close not received");
                Assert.IsTrue(closedNotified.WaitOne(5000), "Closed event not fired");
                Assert.AreEqual(ErrorCode.NotFound, (string)connection.Error.Condition);
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async() =>
            {
                closeReceived         = new ManualResetEvent(false);
                closedNotified        = new ManualResetEvent(false);
                Connection connection = await Connection.Factory.CreateAsync(this.address);
                connection.Closed    += (o, e) => closedNotified.Set();
                Session session       = new Session(connection);
                Assert.IsTrue(closeReceived.WaitOne(5000), "Close not received");
                Assert.IsTrue(closedNotified.WaitOne(5000), "Closed event not fired");
                Assert.AreEqual(ErrorCode.NotFound, (string)connection.Error.Condition);
            }).Unwrap().GetAwaiter().GetResult();
        }
        public void ReceiveWithLinkDetachTest()
        {
            this.testListener.RegisterTarget(TestPoint.Flow, (stream, channel, fields) =>
            {
                // detach link without error. receivers should return null (eof)
                TestListener.FRM(stream, 0x16UL, 0, channel, fields[0], true);
                return(TestOutcome.Stop);
            });
            this.testListener.RegisterTarget(TestPoint.Detach, (stream, channel, fields) =>
            {
                return(TestOutcome.Stop);
            });

            string testName = "ReceiveWithLinkDetachTest";

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                Connection   connection = new Connection(this.address);
                Session      session    = new Session(connection);
                ReceiverLink receiver   = new ReceiverLink(session, "receiver-" + testName, "any");
                DateTime     dt         = DateTime.UtcNow;
                var          message    = receiver.Receive(30000);
                Assert.IsTrue(message == null);
                connection.Close();
                Assert.IsTrue(DateTime.UtcNow.Subtract(dt).TotalMilliseconds < 10000, "receive should return right away");
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async() =>
            {
                Connection connection = await Connection.Factory.CreateAsync(this.address);
                Session session       = new Session(connection);
                ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, "any");
                DateTime dt           = DateTime.UtcNow;
                var message           = await receiver.ReceiveAsync(30000);
                Assert.IsTrue(message == null);
                await connection.CloseAsync();
                Assert.IsTrue(DateTime.UtcNow.Subtract(dt).TotalMilliseconds < 10000, "receive should return right away");
            }).Unwrap().GetAwaiter().GetResult();
        }
        public void ReceiveWithNoCreditTest()
        {
            this.testListener.RegisterTarget(TestPoint.Attach, (stream, channel, fields) =>
            {
                bool role = !(bool)fields[2];
                TestListener.FRM(stream, 0x12UL, 0, channel, fields[0], fields[1], role, fields[3], fields[4], new Source(), new Target());
                TestListener.FRM(stream, 0x14UL, 0, channel, fields[1], 0u, new byte[0], 0u, true, false);  // transfer
                return(TestOutcome.Stop);
            });

            string testName = "ReceiveWithNoCreditTest";

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                ManualResetEvent closed     = new ManualResetEvent(false);
                Connection       connection = new Connection(this.address);
                connection.Closed += (s, a) => closed.Set();
                Session      session  = new Session(connection);
                ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, "any");
                Assert.IsTrue(closed.WaitOne(5000), "Connection not closed");
                Assert.AreEqual(ErrorCode.TransferLimitExceeded, (string)connection.Error.Condition);
                Assert.IsTrue(receiver.IsClosed);
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async() =>
            {
                ManualResetEvent closed = new ManualResetEvent(false);
                Connection connection   = await Connection.Factory.CreateAsync(this.address);
                connection.Closed      += (s, a) => closed.Set();
                Session session         = new Session(connection);
                ReceiverLink receiver   = new ReceiverLink(session, "receiver-" + testName, "any");
                Assert.IsTrue(closed.WaitOne(5000), "Connection not closed");
                Assert.AreEqual(ErrorCode.TransferLimitExceeded, (string)connection.Error.Condition);
                Assert.IsTrue(receiver.IsClosed);
            }).Unwrap().GetAwaiter().GetResult();
        }
        public void SendWithLinkDetachTest()
        {
            this.testListener.RegisterTarget(TestPoint.Transfer, (stream, channel, fields) =>
            {
                // detach the link
                TestListener.FRM(stream, 0x16UL, 0, channel, fields[0], true);
                return(TestOutcome.Stop);
            });
            this.testListener.RegisterTarget(TestPoint.Detach, (stream, channel, fields) =>
            {
                return(TestOutcome.Stop);
            });

            string testName = "SendWithLinkDetachTest";

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                Connection connection = new Connection(this.address);
                Session    session    = new Session(connection);
                SenderLink sender     = new SenderLink(session, "sender-" + testName, "any");
                try
                {
                    sender.Send(new Message("test")
                    {
                        Properties = new Properties()
                        {
                            MessageId = testName
                        }
                    });
                    Assert.IsTrue(false, "Send should throw exception");
                }
                catch (AmqpException exception)
                {
                    Assert.AreEqual(ErrorCode.MessageReleased, (string)exception.Error.Condition);
                }
                connection.Close();
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async() =>
            {
                Connection connection = await Connection.Factory.CreateAsync(this.address);
                Session session       = new Session(connection);
                SenderLink sender     = new SenderLink(session, "sender-" + testName, "any");
                try
                {
                    await sender.SendAsync(new Message("test")
                    {
                        Properties = new Properties()
                        {
                            MessageId = testName
                        }
                    });
                    Assert.IsTrue(false, "Send should throw exception");
                }
                catch (AmqpException exception)
                {
                    Assert.AreEqual(ErrorCode.MessageReleased, (string)exception.Error.Condition);
                }
                await connection.CloseAsync();
            }).Unwrap().GetAwaiter().GetResult();
        }