コード例 #1
0
        public void PutResponseBackDummyExceptionTest()
        {
            var f = new MockBrokerQueueFactory();

            var ob = new MockBrokerObserver();

            var sampleMessage = Message.CreateMessage(MessageVersion.Default, "SampleAction");

            sampleMessage.Headers.MessageId = new UniqueId(Guid.NewGuid());
            var adapter = new ResponseQueueAdapter(ob, f, 4);
            var item    = new BrokerQueueItem(DummyRequestContext.GetInstance(MessageVersion.Soap11), sampleMessage, Guid.NewGuid(), null);

            DispatchData data = new DispatchData("1", 1, "1")
            {
                BrokerQueueItem = item,
                MessageId       = Guid.NewGuid(),
                DispatchTime    = new DateTime(2000, 1, 1),
                Exception       = new FaultException <RetryOperationError>(new RetryOperationError("Reason")),
            };

            adapter.PutResponseBack(data);

            Assert.IsTrue(ob.Duration > 0, "The call duration should be greater than 0");
            Assert.AreEqual(f.PutMessageDic.Count, 1, "There must be 1 and only 1 instance");
            Assert.AreEqual(f.PutResponseAsyncInvokedTimes, 1, "There must be 1 and only 1 invoke");
            Assert.AreSame(f.PutMessageDic.First().Key, item, "The put back BrokerQueueItem should be the same as the original one.");
            Assert.AreEqual(f.PutMessageDic.First().Value.Count, 1, "The response message should only be one.");
            Assert.AreSame(f.PutMessageDic.First().Value[0].Headers.RelatesTo, item.Message.Headers.MessageId, "The put back Message should be the same as the original one.");
            Assert.IsNull(data.BrokerQueueItem, "BrokerQueueItem property should be set to null after put back.");
            Assert.IsNull(data.ReplyMessage, "The reply message should be null after put back.");
            Assert.IsNull(data.Exception, "The Exception should be null after put back.");
        }
コード例 #2
0
        /// <summary>
        /// AsyncCallback for ReceiveRequest
        /// </summary>
        /// <param name="ar">async result</param>
        private void ReceiveRequest(IAsyncResult ar)
        {
            ChannelClientState state = (ChannelClientState)ar.AsyncState;
            T            channel     = (T)state.Channel;
            BrokerClient client      = state.Client;
            Message      request;

            try
            {
                request = channel.EndReceive(ar);
            }
            catch (TimeoutException)
            {
                BrokerTracing.TraceEvent(TraceEventType.Information, 0, "[RequestReplyFrontEnd] Receive Request timed out");
                if (!ar.CompletedSynchronously)
                {
                    this.TryToBeginReceiveMessagesWithThrottling(state);
                }

                return;
            }
            catch (CommunicationException ce)
            {
                BrokerTracing.TraceEvent(TraceEventType.Information, 0, "[RequestReplyFrontEnd] Exception while receiving requests: {0}", ce.Message);

                // Retry receiving requests
                if (!ar.CompletedSynchronously)
                {
                    this.TryToBeginReceiveMessagesWithThrottling(state);
                }

                return;
            }

            #region Debug Failure Test
            Microsoft.Hpc.ServiceBroker.SimulateFailure.FailOperation(1);
            #endregion

            // After channel timed out, the request will be null if you call channel.ReceiveRequest()
            // Need to end the channel at this time
            if (request == null)
            {
                // Indicate that the channel should be closed
                // Close the channel
                lock (channel)
                {
                    if (channel.State == CommunicationState.Opened)
                    {
                        try
                        {
                            channel.Close();
                        }
                        catch (CommunicationException ce)
                        {
                            BrokerTracing.TraceEvent(TraceEventType.Warning, 0, "[RequestReplyFrontEnd] Exception throwed while close the channel: {0}", ce);
                            channel.Abort();
                        }
                    }
                }

                return;
            }

            // Try to get the client id and the user name
            string callerSID;
            string userName = GetUserName(request, out callerSID);
            string clientId = GetClientId(request, callerSID);

            try
            {
                ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong);
                ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId);
            }
            catch (ArgumentException)
            {
                BrokerTracing.EtwTrace.LogFrontEndRequestRejectedClientIdInvalid(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request));
                return;
            }

            if (client == null || client.State == BrokerClientState.Disconnected || String.Compare(clientId, client.ClientId, StringComparison.OrdinalIgnoreCase) != 0)
            {
                try
                {
                    client = this.ClientManager.GetClient(clientId, userName);
                    client.SingletonInstanceConnected();
                }
                catch (FaultException <SessionFault> e)
                {
                    if (e.Detail.Code == (int)SOAFaultCode.AccessDenied_BrokerQueue)
                    {
                        BrokerTracing.EtwTrace.LogFrontEndRequestRejectedAuthenticationError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request), userName);
                        return;
                    }
                    else
                    {
                        BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request), e.ToString());
                        throw;
                    }
                }
                catch (BrokerQueueException e)
                {
                    BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request), e.ToString());
                    return;
                }
                catch (Exception e)
                {
                    BrokerTracing.EtwTrace.LogFrontEndRequestRejectedGeneralError(this.SessionId, clientId, Utility.GetMessageIdFromMessage(request), e.ToString());
                    throw;
                }

                state.Client = client;
            }

            // Receive new requests
            if (!ar.CompletedSynchronously)
            {
                this.TryToBeginReceiveMessagesWithThrottling(state);
            }

            // Try to get the user info header
            bool userDataFlag = GetUserInfoHeader(request);

            // Create request context
            RequestContextBase requestContext;

            //Message that needs not to reply
            requestContext = DummyRequestContext.GetInstance(request.Version);

            // Check auth
            if (!this.CheckAuth(request))
            {
                return;
            }

            // Bug 15195: Remove security header for https
            TryRemoveSecurityHeaderForHttps(request);

            // Send request to the broker client
            client.RequestReceived(requestContext, request, null);
        }