Skip to content

Commit 3b02ba3

Browse files
author
Tim Watson
committed
Merge bug25895 into default
2 parents 423fdd6 + 4861ee5 commit 3b02ba3

File tree

6 files changed

+94
-69
lines changed

6 files changed

+94
-69
lines changed

projects/client/RabbitMQ.Client/src/client/exceptions/AlreadyClosedException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public class AlreadyClosedException: OperationInterruptedException
4949
///<summary>Construct an instance containing the given
5050
///shutdown reason.</summary>
5151
public AlreadyClosedException(ShutdownEventArgs reason)
52-
: base(reason) { }
52+
: base(reason, "Already closed") { }
5353
}
5454
}

projects/client/RabbitMQ.Client/src/client/exceptions/OperationInterruptedException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public OperationInterruptedException(ShutdownEventArgs reason)
8181
m_shutdownReason = reason;
8282
}
8383

84+
///<summary>Construct an OperationInterruptedException with
85+
///the passed-in explanation and prefix, if any.</summary>
86+
public OperationInterruptedException(ShutdownEventArgs reason, String prefix)
87+
: base(reason == null ? (prefix + ": The AMQP operation was interrupted") :
88+
string.Format("{0}: The AMQP operation was interrupted: {1}",
89+
prefix, reason))
90+
{
91+
m_shutdownReason = reason;
92+
}
93+
8494
///<summary>Retrieves the explanation for the shutdown. May
8595
///return null if no explanation is available.</summary>
8696
public ShutdownEventArgs ShutdownReason { get { return m_shutdownReason; } }

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,7 @@ protected void StartAndTune()
10551055
connectionStartCell.Value;
10561056

10571057
if (connectionStart == null){
1058-
throw new ProtocolVersionMismatchException(Protocol.MajorVersion,
1059-
Protocol.MinorVersion,
1060-
-1, -1);
1058+
throw new IOException("connection.start was never received, likely due to a network timeout");
10611059
}
10621060

10631061
ServerProperties = connectionStart.m_serverProperties;

projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,7 @@ public void Enqueue(IRpcContinuation k)
494494
public void TransmitAndEnqueue(Command cmd, IRpcContinuation k)
495495
{
496496
Enqueue(k);
497-
try
498-
{
499-
m_session.Transmit(cmd);
500-
}
501-
catch (AlreadyClosedException)
502-
{
503-
// Ignored, since the continuation will be told about
504-
// the closure via an OperationInterruptedException because
505-
// of the shutdown event propagation.
506-
}
497+
m_session.Transmit(cmd);
507498
}
508499

509500
public ShutdownEventArgs CloseReason
@@ -894,16 +885,7 @@ private QueueDeclareOk QueueDeclare(string queue, bool passive, bool durable, bo
894885
{
895886
QueueDeclareRpcContinuation k = new QueueDeclareRpcContinuation();
896887
Enqueue(k);
897-
try
898-
{
899-
_Private_QueueDeclare(queue, passive, durable, exclusive, autoDelete, false, arguments);
900-
}
901-
catch (AlreadyClosedException)
902-
{
903-
// Ignored, since the continuation will be told about
904-
// the closure via an OperationInterruptedException because
905-
// of the shutdown event propagation.
906-
}
888+
_Private_QueueDeclare(queue, passive, durable, exclusive, autoDelete, false, arguments);
907889
k.GetReply();
908890
return k.m_result;
909891
}
@@ -988,7 +970,7 @@ public bool WaitForConfirms(TimeSpan timeout, out bool timedOut)
988970
{
989971
while (true)
990972
{
991-
if (CloseReason != null)
973+
if (!IsOpen)
992974
throw new AlreadyClosedException(CloseReason);
993975

994976
if (m_unconfirmedSet.Count == 0)
@@ -1095,17 +1077,8 @@ public string BasicConsume(string queue,
10951077
Enqueue(k);
10961078
// Non-nowait. We have an unconventional means of getting
10971079
// the RPC response, but a response is still expected.
1098-
try
1099-
{
1100-
_Private_BasicConsume(queue, consumerTag, noLocal, noAck, exclusive,
1080+
_Private_BasicConsume(queue, consumerTag, noLocal, noAck, exclusive,
11011081
/*nowait:*/ false, arguments);
1102-
}
1103-
catch (AlreadyClosedException)
1104-
{
1105-
// Ignored, since the continuation will be told about
1106-
// the closure via an OperationInterruptedException because
1107-
// of the shutdown event propagation.
1108-
}
11091082
k.GetReply();
11101083
string actualConsumerTag = k.m_consumerTag;
11111084

@@ -1141,17 +1114,7 @@ public void BasicCancel(string consumerTag)
11411114

11421115
Enqueue(k);
11431116

1144-
try
1145-
{
1146-
_Private_BasicCancel(consumerTag, false);
1147-
}
1148-
catch (AlreadyClosedException)
1149-
{
1150-
// Ignored, since the continuation will be told about
1151-
// the closure via an OperationInterruptedException because
1152-
// of the shutdown event propagation.
1153-
}
1154-
1117+
_Private_BasicCancel(consumerTag, false);
11551118
k.GetReply();
11561119

11571120
ModelShutdown -= new ModelShutdownEventHandler(k.m_consumer.HandleModelShutdown);
@@ -1197,16 +1160,7 @@ public BasicGetResult BasicGet(string queue,
11971160
{
11981161
BasicGetRpcContinuation k = new BasicGetRpcContinuation();
11991162
Enqueue(k);
1200-
try
1201-
{
1202-
_Private_BasicGet(queue, noAck);
1203-
}
1204-
catch (AlreadyClosedException)
1205-
{
1206-
// Ignored, since the continuation will be told about
1207-
// the closure via an OperationInterruptedException because
1208-
// of the shutdown event propagation.
1209-
}
1163+
_Private_BasicGet(queue, noAck);
12101164
k.GetReply();
12111165
return k.m_result;
12121166
}
@@ -1218,18 +1172,7 @@ public void BasicRecover(bool requeue)
12181172
SimpleBlockingRpcContinuation k = new SimpleBlockingRpcContinuation();
12191173

12201174
Enqueue(k);
1221-
1222-
try
1223-
{
1224-
_Private_BasicRecover(requeue);
1225-
}
1226-
catch (AlreadyClosedException)
1227-
{
1228-
// Ignored, since the continuation will be told about
1229-
// the closure via an OperationInterruptedException because
1230-
// of the shutdown event propagation.
1231-
}
1232-
1175+
_Private_BasicRecover(requeue);
12331176
k.GetReply();
12341177
}
12351178

projects/client/Unit/src/unit/TestConnectionBlocked.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static bool IsRunningOnMono()
162162
protected void Publish(IConnection conn)
163163
{
164164
IModel ch = conn.CreateModel();
165-
ch.BasicPublish("", "amq.fanout", null, enc.GetBytes("message"));
165+
ch.BasicPublish("amq.fanout", "", null, enc.GetBytes("message"));
166166
}
167167

168168
protected override void ReleaseResources()
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 1.1.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (C) 2007-2013 GoPivotal, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// http://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v1.1:
23+
//
24+
//---------------------------------------------------------------------------
25+
// The contents of this file are subject to the Mozilla Public License
26+
// Version 1.1 (the "License"); you may not use this file except in
27+
// compliance with the License. You may obtain a copy of the License
28+
// at http://www.mozilla.org/MPL/
29+
//
30+
// Software distributed under the License is distributed on an "AS IS"
31+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32+
// the License for the specific language governing rights and
33+
// limitations under the License.
34+
//
35+
// The Original Code is RabbitMQ.
36+
//
37+
// The Initial Developer of the Original Code is GoPivotal, Inc.
38+
// Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
using NUnit.Framework;
42+
using System;
43+
using RabbitMQ.Client.Exceptions;
44+
45+
namespace RabbitMQ.Client.Unit
46+
{
47+
[TestFixture]
48+
public class TestExceptionMessages : IntegrationFixture
49+
{
50+
[Test]
51+
public void TestAlreadyClosedExceptionMessage()
52+
{
53+
var uuid = System.Guid.NewGuid().ToString();
54+
try
55+
{
56+
Model.QueueDeclarePassive(uuid);
57+
} catch (Exception e)
58+
{
59+
Assert.That(e, Is.TypeOf(typeof(OperationInterruptedException)));
60+
}
61+
62+
Assert.IsFalse(Model.IsOpen);
63+
64+
try
65+
{
66+
Model.QueueDeclarePassive(uuid);
67+
} catch (AlreadyClosedException e)
68+
{
69+
Assert.That(e, Is.TypeOf(typeof(AlreadyClosedException)));
70+
Assert.IsTrue(e.Message.StartsWith("Already closed"));
71+
}
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)