Skip to content

Commit

Permalink
synchronizing access only to FakeResendRequestController and applying…
Browse files Browse the repository at this point in the history
… yield idle strategy to framer
  • Loading branch information
lucianoviana committed Oct 3, 2024
1 parent 49152c8 commit 38a0018
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public final class SystemTestUtil

private static final int TEST_COMPACTION_SIZE = 1024 * 1024;

public static final IdleStrategy IDLE_STRATEGY = new YieldingIdleStrategy();

public static final Object LOCK = new Object();

static
{
final File parentDirectory = new File(optimalTmpDirName());
Expand Down Expand Up @@ -132,7 +136,11 @@ public static long sendTestRequest(final TestSystem testSystem, final Session se
static long sendTestRequest(
final TestSystem testSystem, final Session session, final String testReqID, final FixDictionary fixDictionary)
{
assertEventuallyTrue("Session not connected", session::isConnected);
assertEventuallyTrue("Session not connected",
() ->
{
session.isConnected();
});

return alwaysSendTestRequest(testSystem, session, testReqID, fixDictionary);
}
Expand Down Expand Up @@ -260,6 +268,7 @@ static EngineConfiguration initiatingConfig(final int libraryAeronPort, final Ep
.monitoringFile(optimalTmpDirName() + File.separator + "fix-client" + File.separator + "engineCounters")
.logFileDir(CLIENT_LOGS)
.scheduler(new LowResourceEngineScheduler())
.framerIdleStrategy(IDLE_STRATEGY)
.slowConsumerTimeoutInMs(TEST_REPLY_TIMEOUT_IN_MS)
.replyTimeoutInMs(TEST_REPLY_TIMEOUT_IN_MS);
configuration.epochNanoClock(nanoClock);
Expand Down Expand Up @@ -309,6 +318,7 @@ static EngineConfiguration acceptingConfig(
.logFileDir(acceptorLogs)
.scheduler(new LowResourceEngineScheduler())
.slowConsumerTimeoutInMs(TEST_REPLY_TIMEOUT_IN_MS)
.framerIdleStrategy(IDLE_STRATEGY)
.replyTimeoutInMs(TEST_REPLY_TIMEOUT_IN_MS);
}

Expand Down

0 comments on commit 38a0018

Please sign in to comment.