Skip to content

Commit c7c3957

Browse files
Make IModel throw AlreadyClosedException when already closed
This is how Java client works.
1 parent d8daaa2 commit c7c3957

File tree

2 files changed

+80
-64
lines changed

2 files changed

+80
-64
lines changed

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)