Skip to content

Commit c4ce0d9

Browse files
Parametrise SubscriptionDrainer with a field instead of subclasses
1 parent 731d813 commit c4ce0d9

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ public void TestSubscriptionNack()
106106
Assert.AreEqual(0, ok.MessageCount);
107107
}
108108

109-
private abstract class SubscriptionDrainer
109+
private class SubscriptionDrainer
110110
{
111111
protected Subscription m_subscription;
112+
protected bool m_ack;
112113

113-
public SubscriptionDrainer(Subscription sub)
114+
public SubscriptionDrainer(Subscription sub, bool ack)
114115
{
115116
m_subscription = sub;
117+
m_ack = ack;
116118
}
117119

118120
public void Drain()
@@ -140,26 +142,15 @@ public void Drain()
140142
#pragma warning restore
141143
}
142144

143-
protected abstract void PostProcess();
144-
}
145-
146-
private class AckingDrainer : SubscriptionDrainer
147-
{
148-
public AckingDrainer(Subscription sub) : base(sub) {}
149-
150-
override protected void PostProcess()
145+
protected void PostProcess()
151146
{
152-
m_subscription.Ack();
153-
}
154-
}
155-
156-
private class NackingDrainer : SubscriptionDrainer
157-
{
158-
public NackingDrainer(Subscription sub) : base(sub) {}
159-
160-
override protected void PostProcess()
161-
{
162-
m_subscription.Nack(false, false);
147+
if(m_ack)
148+
{
149+
m_subscription.Ack();
150+
} else
151+
{
152+
m_subscription.Nack(false, false);
153+
}
163154
}
164155
}
165156

@@ -172,7 +163,7 @@ public void TestConcurrentIterationAndAck()
172163
PreparedQueue(q);
173164
for (int i = 0; i < 10; i++)
174165
{
175-
SubscriptionDrainer drainer = new AckingDrainer(sub);
166+
SubscriptionDrainer drainer = new SubscriptionDrainer(sub, true);
176167
Thread t = new Thread(drainer.Drain);
177168
t.Start();
178169
}
@@ -187,7 +178,7 @@ public void TestConcurrentIterationAndNack()
187178
PreparedQueue(q);
188179
for (int i = 0; i < 10; i++)
189180
{
190-
SubscriptionDrainer drainer = new NackingDrainer(sub);
181+
SubscriptionDrainer drainer = new SubscriptionDrainer(sub, false);
191182
Thread t = new Thread(drainer.Drain);
192183
t.Start();
193184
}

0 commit comments

Comments
 (0)