Пример #1
0
        public void ClosedCallbackGuaranteeTest()
        {
            this.testListener.RegisterTarget(TestPoint.Open, (stream, channel, fields) =>
            {
                stream.Dispose();
                return(TestOutcome.Continue);
            });

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                ManualResetEvent closed     = new ManualResetEvent(false);
                Connection       connection = new Connection(this.address);
                connection.AddClosedCallback((o, e) => closed.Set());
                Assert.IsTrue(closed.WaitOne(5000), "closed event not fired");
                Assert.AreEqual(ErrorCode.ConnectionForced, (string)connection.Error.Condition);
                closed.Reset();
                connection.AddClosedCallback((o, e) => closed.Set());
                Assert.IsTrue(closed.WaitOne(5000), "closed event not fired again");
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async() =>
            {
                ManualResetEvent closed = new ManualResetEvent(false);
                Connection connection   = await Connection.Factory.CreateAsync(this.address);
                connection.AddClosedCallback((o, e) => closed.Set());
                Assert.IsTrue(closed.WaitOne(5000), "closed event not fired");
                Assert.AreEqual(ErrorCode.ConnectionForced, (string)connection.Error.Condition);
                closed.Reset();
                connection.AddClosedCallback((o, e) => closed.Set());
                Assert.IsTrue(closed.WaitOne(5000), "closed event not fired again");
            }).Unwrap().GetAwaiter().GetResult();
        }
Пример #2
0
        internal async Task Start()
        {
            Address address = UriUtil.ToAddress(remoteUri, Info.UserName, Info.Password);

            this.tsc             = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
            underlyingConnection = await transport.CreateAsync(address, new AmqpHandler(this)).ConfigureAwait(false);

            underlyingConnection.AddClosedCallback(OnClosed);

            // Wait for connection to be opened
            await this.tsc.Task.ConfigureAwait(false);

            // Create a Session for this connection that is used for Temporary Destinations
            // and perhaps later on management and advisory monitoring.
            NmsSessionInfo sessionInfo = new NmsSessionInfo(Info, -1);

            sessionInfo.AcknowledgementMode = AcknowledgementMode.AutoAcknowledge;

            connectionSession = new AmqpConnectionSession(this, sessionInfo);
            await connectionSession.Start().ConfigureAwait(false);
        }
Пример #3
0
        /// <summary>
        /// Start the current host in the address list
        /// </summary>
        async void OpenConnection()
        {
            try
            {
                Trace.WriteLine(TraceLevel.Verbose,
                                "Attempting connection to  {0}:{1}",
                                addresses[aIndex].Host, addresses[aIndex].Port);

                connection = await Connection.Factory.CreateAsync(addresses[aIndex], null, onOpened);

                Trace.WriteLine(TraceLevel.Information,
                                "Success: connecting to {0}:{1}",
                                addresses[aIndex].Host, addresses[aIndex].Port);

                connection.AddClosedCallback(connectionClosed);
            }
            catch (Exception e)
            {
                Trace.WriteLine(TraceLevel.Error,
                                "Failure: exception connecting to '{0}:{1}': {2}",
                                addresses[aIndex].Host, addresses[aIndex].Port, e.Message);
            }
        }