Skip to content

Commit

Permalink
synchronizing access only to FakeResendRequestController
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianoviana committed Oct 7, 2024
1 parent 336909e commit 7b08e9d
Showing 1 changed file with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,39 @@
import static org.junit.Assert.assertNotNull;
import static uk.co.real_logic.artio.dictionary.SessionConstants.RESEND_REQUEST_MESSAGE_TYPE_CHARS;
import static uk.co.real_logic.artio.fields.RejectReason.OTHER;
import static uk.co.real_logic.artio.system_tests.SystemTestUtil.LOCK;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public class FakeResendRequestController implements ResendRequestController
{
public static final String CUSTOM_MESSAGE = "custom message";
private boolean resend = true;
private AtomicBoolean resend = new AtomicBoolean(true);

private int callCount = 0;
private AtomicInteger callCount = new AtomicInteger(0);
private IntArrayList seenReplaysInFlight = new IntArrayList();
private boolean customResend = false;
private int maxResends = Integer.MAX_VALUE;
private AtomicBoolean customResend = new AtomicBoolean(false);
private AtomicInteger maxResends = new AtomicInteger(Integer.MAX_VALUE);

public void onResend(
final Session session,
final AbstractResendRequestDecoder resendRequest,
final int correctedEndSeqNo,
final ResendRequestResponse response)
{
callCount++;
assertNotNull(resendRequest);

if (callCount > maxResends)
if (callCount.incrementAndGet() > maxResends.get())
{
resend = false;
resend.set(false);
}

if (resend)
if (resend.get())
{
response.resend();
}
else if (customResend)
else if (customResend.get())
{
final RejectEncoder rejectEncoder = new RejectEncoder();
rejectEncoder.refTagID(Constants.BEGIN_SEQ_NO);
Expand All @@ -79,36 +82,44 @@ public void onResendComplete(final Session session, final int remainingReplaysIn

public void resend(final boolean resend)
{
this.resend = resend;
this.resend.set(resend);
}

public void maxResends(final int maxResends)
{
this.maxResends = maxResends;
this.maxResends.set(maxResends);
}

public boolean wasCalled()
{
return callCount > 0;
return callCount.get() > 0;
}

public int callCount()
{
return callCount;
return callCount.get();
}

public int completeCount()
{
return seenReplaysInFlight.size();
synchronized (LOCK)
{

return seenReplaysInFlight.size();
}
}

public IntArrayList seenReplaysInFlight()
{
return seenReplaysInFlight;
synchronized (LOCK)
{

return seenReplaysInFlight;
}
}

public void customResend(final boolean customResend)
{
this.customResend = customResend;
this.customResend.set(customResend);
}
}

0 comments on commit 7b08e9d

Please sign in to comment.