Skip to content

Commit 0a7b30c

Browse files
keichingermichaelklishin
authored andcommitted
Added Persistent property to IBasicProperties and made IBasicProperties.SetPersistent obsolete
Resolves #112
1 parent c72116b commit 0a7b30c

File tree

5 files changed

+143
-21
lines changed

5 files changed

+143
-21
lines changed

projects/client/RabbitMQ.Client/src/client/api/IBasicProperties.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
4040

41+
using System;
4142
using System.Collections.Generic;
4243

4344
namespace RabbitMQ.Client
@@ -105,6 +106,11 @@ public interface IBasicProperties : IContentHeader
105106
/// </summary>
106107
string MessageId { get; set; }
107108

109+
/// <summary>
110+
/// Sets <see cref="DeliveryMode"/> to either persistent (2) or non-persistent (1).
111+
/// </summary>
112+
bool Persistent { get; set; }
113+
108114
/// <summary>
109115
/// Message priority, 0 to 9.
110116
/// </summary>
@@ -290,6 +296,7 @@ public interface IBasicProperties : IContentHeader
290296
/// In order to reset <see cref="DeliveryMode"/> to the default empty condition, call <see cref="ClearDeliveryMode"/> .
291297
/// </para>
292298
/// </remarks>
299+
[Obsolete("Usage of this setter method is deprecated. Use the Persistent property instead.")]
293300
void SetPersistent(bool persistent);
294301
}
295302
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
4040

41+
using System;
4142
using System.Collections.Generic;
4243

4344
namespace RabbitMQ.Client.Impl
@@ -89,6 +90,15 @@ public abstract class BasicProperties : ContentHeaderBase, IBasicProperties
8990
/// </summary>
9091
public abstract string MessageId { get; set; }
9192

93+
/// <summary>
94+
/// Sets <see cref="DeliveryMode"/> to either persistent (2) or non-persistent (1).
95+
/// </summary>
96+
public bool Persistent
97+
{
98+
get { return DeliveryMode == 2; }
99+
set { DeliveryMode = value ? (byte)2 : (byte)1; }
100+
}
101+
92102
/// <summary>
93103
/// Message priority, 0 to 9.
94104
/// </summary>
@@ -278,16 +288,10 @@ public PublicationAddress ReplyToAddress
278288
/// In order to reset <see cref="DeliveryMode"/> to the default empty condition, call <see cref="ClearDeliveryMode"/> .
279289
/// </para>
280290
/// </remarks>
291+
[Obsolete("Usage of this setter method is deprecated. Use the Persistent property instead.")]
281292
public void SetPersistent(bool persistent)
282293
{
283-
if (persistent)
284-
{
285-
DeliveryMode = 2;
286-
}
287-
else
288-
{
289-
DeliveryMode = 1;
290-
}
294+
Persistent = persistent;
291295
}
292296

293297
public override object Clone()

projects/client/Unit/RabbitMQ.Client.Unit.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<!-- Warning! This file contains important customizations. Using Visual Studio to edit project's properties might break things. -->
44
<!-- Props file -->
@@ -85,6 +85,7 @@
8585
<Compile Include="src\unit\TestAmqpUri.cs" />
8686
<Compile Include="src\unit\TestAuth.cs" />
8787
<Compile Include="src\unit\TestBasicGet.cs" />
88+
<Compile Include="src\unit\TestBasicProperties.cs" />
8889
<Compile Include="src\unit\TestBatchingWorkPool.cs" />
8990
<Compile Include="src\unit\TestBlockingCell.cs" />
9091
<Compile Include="src\unit\TestBytesWireFormatting.cs" />
@@ -145,4 +146,4 @@
145146
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
146147
<!-- Custom BeforeClean -->
147148
<Target Name="BeforeClean" DependsOnTargets="CleanTestResults" />
148-
</Project>
149+
</Project>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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) 2011-2014 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) 2011-2014 GoPivotal, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
using NUnit.Framework;
42+
43+
namespace RabbitMQ.Client.Unit
44+
{
45+
46+
[TestFixture]
47+
class TestBasicProperties
48+
{
49+
[Test]
50+
public void TestPersistentPropertyChangesDeliveryMode_PersistentTrueDelivery2()
51+
{
52+
// Arrange
53+
var subject = new Framing.BasicProperties();
54+
55+
// Act
56+
subject.Persistent = true;
57+
58+
// Assert
59+
Assert.AreEqual(2, subject.DeliveryMode);
60+
Assert.AreEqual(true, subject.Persistent);
61+
}
62+
63+
[Test]
64+
public void TestPersistentPropertyChangesDeliveryMode_PersistentFalseDelivery1()
65+
{
66+
// Arrange
67+
var subject = new Framing.BasicProperties();
68+
69+
// Act
70+
subject.Persistent = false;
71+
72+
// Assert
73+
Assert.AreEqual(1, subject.DeliveryMode);
74+
Assert.AreEqual(false, subject.Persistent);
75+
}
76+
77+
78+
#pragma warning disable CS0618 // Type or member is obsolete
79+
[Test]
80+
public void TestSetPersistentMethodChangesDeliveryMode_PersistentTrueDelivery2()
81+
{
82+
// Arrange
83+
var subject = new Framing.BasicProperties();
84+
85+
// Act
86+
subject.SetPersistent(true);
87+
88+
// Assert
89+
Assert.AreEqual(2, subject.DeliveryMode);
90+
Assert.AreEqual(true, subject.Persistent);
91+
}
92+
93+
94+
[Test]
95+
public void TestSetPersistentMethodChangesDeliveryMode_PersistentFalseDelivery1()
96+
{
97+
// Arrange
98+
var subject = new Framing.BasicProperties();
99+
100+
// Act
101+
subject.SetPersistent(false);
102+
103+
// Assert
104+
Assert.AreEqual(1, subject.DeliveryMode);
105+
Assert.AreEqual(false, subject.Persistent);
106+
}
107+
#pragma warning restore CS0618 // Type or member is obsolete
108+
}
109+
}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,14 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System.Collections.Generic;
42-
4342
using NUnit.Framework;
44-
45-
using System;
46-
using System.IO;
47-
using System.Collections;
48-
4943
using RabbitMQ.Client;
5044
using RabbitMQ.Client.Impl;
5145

5246
[TestFixture]
5347
public class TestPropertiesClone
5448
{
55-
[Test]
49+
[Test]
5650
public void TestBasicPropertiesCloneV0_9_1()
5751
{
5852
TestBasicPropertiesClone(new RabbitMQ.Client.Framing.BasicProperties());
@@ -72,7 +66,9 @@ private void TestBasicPropertiesClone(BasicProperties bp)
7266
bp.Headers = new Dictionary<string, object>();
7367
bp.Headers.Add("foo_3", "foo_4");
7468
bp.Headers.Add("foo_5", "foo_6");
75-
bp.DeliveryMode = 12;
69+
bp.DeliveryMode = 2;
70+
// Persistent also changes DeliveryMode's value to 2
71+
bp.Persistent = true;
7672
bp.Priority = 12;
7773
bp.CorrelationId = "foo_7";
7874
bp.ReplyTo = "foo_8";
@@ -94,7 +90,9 @@ private void TestBasicPropertiesClone(BasicProperties bp)
9490
bp.Headers.Remove("foo_5");
9591
bp.Headers.Add("foo_17", "foo_18");
9692
bp.Headers.Add("foo_19", "foo_20");
97-
bp.DeliveryMode = 23;
93+
bp.DeliveryMode = 1;
94+
// Persistent also changes DeliveryMode's value to 1
95+
bp.Persistent = false;
9896
bp.Priority = 23;
9997
bp.CorrelationId = "foo_21";
10098
bp.ReplyTo = "foo_22";
@@ -114,7 +112,8 @@ private void TestBasicPropertiesClone(BasicProperties bp)
114112
Assert.AreEqual("foo_4", bpClone.Headers["foo_3"]);
115113
Assert.AreEqual(true, bpClone.Headers.ContainsKey("foo_5"));
116114
Assert.AreEqual("foo_6", bpClone.Headers["foo_5"]);
117-
Assert.AreEqual(12, bpClone.DeliveryMode);
115+
Assert.AreEqual(2, bpClone.DeliveryMode);
116+
Assert.AreEqual(true, bpClone.Persistent);
118117
Assert.AreEqual(12, bpClone.Priority);
119118
Assert.AreEqual("foo_7", bpClone.CorrelationId);
120119
Assert.AreEqual("foo_8", bpClone.ReplyTo);
@@ -138,7 +137,9 @@ private void TestBasicPropertiesNoneClone(BasicProperties bp)
138137
bp.Headers = new Dictionary<string, object>();
139138
bp.Headers.Add("foo_3", "foo_4");
140139
bp.Headers.Add("foo_5", "foo_6");
141-
bp.DeliveryMode = 12;
140+
bp.DeliveryMode = 2;
141+
// Persistent also changes DeliveryMode's value to 2
142+
bp.Persistent = true;
142143
bp.Priority = 12;
143144
bp.CorrelationId = "foo_7";
144145
bp.ReplyTo = "foo_8";

0 commit comments

Comments
 (0)