Skip to content

Commit

Permalink
[Java] Fix CodeQL and add test to RejectImageTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Sep 2, 2024
1 parent 42bc837 commit a8d3c6f
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion aeron-system-tests/src/test/java/io/aeron/RejectImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,25 @@ private TestMediaDriver launch()

private static final class QueuedErrorFrameHandler implements PublicationErrorFrameHandler
{
private final AtomicInteger counter = new AtomicInteger(0);
private final OneToOneConcurrentArrayQueue<PublicationErrorFrame> errorFrameQueue =
new OneToOneConcurrentArrayQueue<>(512);

public void onPublicationError(final PublicationErrorFrame errorFrame)
{
errorFrameQueue.offer(errorFrame.clone());
if (!errorFrameQueue.offer(errorFrame.clone()))
{
counter.incrementAndGet();
}
}

PublicationErrorFrame poll()
{
if (counter.get() > 0)
{
throw new RuntimeException("Failed to offer to the errorFrameQueue in the test");
}

return errorFrameQueue.poll();
}
}
Expand Down Expand Up @@ -429,6 +438,32 @@ void shouldErrorIfRejectionReasonIsTooLong()
}
}


@Test
@InterruptAfter(10)
void shouldErrorIfRejectionReasonIsTooLongForLocalBuffer()
{
context.imageLivenessTimeoutNs(TimeUnit.SECONDS.toNanos(3));
final byte[] bytes = new byte[1024 * 1024];
Arrays.fill(bytes, (byte)'x');
final String tooLongReason = new String(bytes, US_ASCII);

final TestMediaDriver driver = launch();

final Aeron.Context ctx = new Aeron.Context()
.aeronDirectoryName(driver.aeronDirectoryName());

try (Aeron aeron = Aeron.connect(ctx);
Publication pub = aeron.addPublication(channel, streamId);
Subscription sub = aeron.addSubscription(channel, streamId))
{
Tests.awaitConnected(pub);
Tests.awaitConnected(sub);

assertThrows(IllegalArgumentException.class, () -> sub.imageAtIndex(0).reject(tooLongReason));
}
}

@Test
@InterruptAfter(10)
void shouldErrorIfUsingAndIpcChannel()
Expand Down

0 comments on commit a8d3c6f

Please sign in to comment.