Skip to content

Commit

Permalink
[Java] Add error frames sent counter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Jul 23, 2024
1 parent 31e47bb commit 283400f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public ErrorFlyweight errorCode(final int errorCode)
*/
public String errorMessage()
{
return getStringUtf8(ERROR_STRING_FIELD_OFFSET);
return getStringAscii(ERROR_STRING_FIELD_OFFSET);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.aeron.driver.DataPacketDispatcher;
import io.aeron.driver.DriverConductorProxy;
import io.aeron.driver.MediaDriver;
import io.aeron.driver.status.SystemCounterDescriptor;
import io.aeron.exceptions.AeronException;
import io.aeron.exceptions.ControlProtocolException;
import io.aeron.protocol.*;
Expand Down Expand Up @@ -66,6 +67,7 @@ abstract class ReceiveChannelEndpointLhsPadding extends UdpChannelTransport

abstract class ReceiveChannelEndpointHotFields extends ReceiveChannelEndpointLhsPadding
{
protected final AtomicCounter errorFramesSent;
long timeOfLastActivityNs;

ReceiveChannelEndpointHotFields(
Expand All @@ -76,6 +78,7 @@ abstract class ReceiveChannelEndpointHotFields extends ReceiveChannelEndpointLhs
final MediaDriver.Context context)
{
super(udpChannel, endPointAddress, bindAddress, connectAddress, context);
errorFramesSent = context.systemCounters().get(SystemCounterDescriptor.ERROR_FRAMES_SENT);
}
}

Expand Down Expand Up @@ -958,6 +961,8 @@ public void sendErrorFrame(
final int errorCode,
final String errorMessage)
{
errorFramesSent.increment();

errorBuffer.clear();
errorFlyweight
.sessionId(sessionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ public enum SystemCounterDescriptor
/**
* A count of the number of error frames received by this driver.
*/
ERROR_FRAMES_RECEIVED(38, "Error Frames received");
ERROR_FRAMES_RECEIVED(38, "Error Frames received"),

/**
* A count of the number of error frames sent by this driver.
*/
ERROR_FRAMES_SENT(39, "Error Frames sent");

/**
* All system counters have the same type id, i.e. system counters are the same type. Other types can exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

import static io.aeron.driver.status.SystemCounterDescriptor.ERRORS;
import static io.aeron.driver.status.SystemCounterDescriptor.ERROR_FRAMES_RECEIVED;
import static io.aeron.driver.status.SystemCounterDescriptor.ERROR_FRAMES_SENT;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -61,7 +62,7 @@
import static org.junit.jupiter.api.Assumptions.assumeTrue;

@ExtendWith({ EventLogExtension.class, InterruptingTestCallback.class })
public class ImageInvalidationTest
public class RejectImageTest
{
public static final long A_VALUE_THAT_SHOWS_WE_ARENT_SPAMMING_ERROR_MESSAGES = 1000L;
@RegisterExtension
Expand Down Expand Up @@ -130,6 +131,8 @@ void shouldRejectSubscriptionsImage() throws IOException
final CountersReader countersReader = aeron.countersReader();
final long initialErrorFramesReceived = countersReader
.getCounterValue(ERROR_FRAMES_RECEIVED.id());
final long initialErrorFramesSent = countersReader
.getCounterValue(ERROR_FRAMES_SENT.id());
final long initialErrors = countersReader
.getCounterValue(ERRORS.id());

Expand Down Expand Up @@ -158,8 +161,8 @@ void shouldRejectSubscriptionsImage() throws IOException
final long value = driver.context().publicationConnectionTimeoutNs();
assertThat(t1 - t0, lessThan(value));

while (initialErrorFramesReceived == countersReader
.getCounterValue(ERROR_FRAMES_RECEIVED.id()))
while (initialErrorFramesReceived == countersReader.getCounterValue(ERROR_FRAMES_RECEIVED.id()) ||
initialErrorFramesSent == countersReader.getCounterValue(ERROR_FRAMES_SENT.id()))
{
Tests.yield();
}
Expand Down

0 comments on commit 283400f

Please sign in to comment.