use of org.agrona.collections.MutableBoolean in project aeron by real-logic.
the class BufferClaimMessageTest method shouldTransferReservedValue.
@ParameterizedTest
@MethodSource("channels")
@InterruptAfter(10)
void shouldTransferReservedValue(final String channel) {
final BufferClaim bufferClaim = new BufferClaim();
try (Subscription subscription = aeron.addSubscription(channel, STREAM_ID);
Publication publication = aeron.addPublication(channel, STREAM_ID)) {
while (publication.tryClaim(MESSAGE_LENGTH, bufferClaim) < 0L) {
Tests.yield();
}
final long reservedValue = System.currentTimeMillis();
bufferClaim.reservedValue(reservedValue);
bufferClaim.commit();
final MutableBoolean done = new MutableBoolean();
while (!done.get()) {
final int fragments = subscription.poll((buffer, offset, length, header) -> {
assertEquals(MESSAGE_LENGTH, length);
assertEquals(reservedValue, header.reservedValue());
done.value = true;
}, FRAGMENT_COUNT_LIMIT);
if (0 == fragments) {
Tests.yield();
}
}
}
}
use of org.agrona.collections.MutableBoolean in project aeron by real-logic.
the class ArchiveTest method verifyDescriptorListOngoingArchive.
private void verifyDescriptorListOngoingArchive(final ArchiveProxy archiveProxy, final int publicationTermBufferLength) {
final long requestCorrelationId = client.nextCorrelationId();
archiveProxy.listRecording(recordingId, requestCorrelationId, controlSessionId);
final MutableBoolean isDone = new MutableBoolean();
final ControlResponseAdapter controlResponseAdapter = new ControlResponseAdapter(new FailControlResponseListener() {
public void onRecordingDescriptor(final long controlSessionId, final long correlationId, final long recordingId, final long startTimestamp, final long stopTimestamp, final long startPosition, final long stopPosition, final int initialTermId, final int segmentFileLength, final int termBufferLength, final int mtuLength, final int sessionId, final int streamId, final String strippedChannel, final String originalChannel, final String sourceIdentity) {
assertEquals(requestCorrelationId, correlationId);
assertEquals(ArchiveTest.this.recordingId, recordingId);
assertEquals(publicationTermBufferLength, termBufferLength);
assertEquals(PUBLISH_STREAM_ID, streamId);
assertEquals(publishUri, originalChannel);
isDone.set(true);
}
}, controlResponse, 1);
while (!isDone.get()) {
if (controlResponseAdapter.poll() == 0) {
if (!controlResponse.isConnected()) {
throw new IllegalStateException("control response not connected");
}
Tests.yield();
}
}
}
use of org.agrona.collections.MutableBoolean in project aeron by real-logic.
the class ArchiveTest method preSendChecks.
private void preSendChecks(final ArchiveProxy archiveProxy, final Subscription recordingEvents, final int sessionId, final int termBufferLength, final long startPosition) {
final MutableBoolean isRecordingStarted = new MutableBoolean();
final RecordingEventsAdapter recordingEventsAdapter = new RecordingEventsAdapter(new FailRecordingEventsListener() {
public void onStart(final long recordingId, final long startPosition0, final int sessionId0, final int streamId, final String channel, final String sourceIdentity) {
ArchiveTest.this.recordingId = recordingId;
assertEquals(PUBLISH_STREAM_ID, streamId);
assertEquals(sessionId, sessionId0);
assertEquals(startPosition, startPosition0);
isRecordingStarted.set(true);
}
}, recordingEvents, 1);
while (!isRecordingStarted.get()) {
if (recordingEventsAdapter.poll() == 0) {
if (!recordingEvents.isConnected()) {
throw new IllegalStateException("recording events not connected");
}
Tests.yield();
}
}
verifyDescriptorListOngoingArchive(archiveProxy, termBufferLength);
}
use of org.agrona.collections.MutableBoolean in project aeron by real-logic.
the class ClusterTest method shouldRejectAnInvalidAdminRequest.
@Test
@InterruptAfter(10)
void shouldRejectAnInvalidAdminRequest() {
final AdminRequestType invalidRequestType = AdminRequestType.NULL_VAL;
final AtomicBoolean authorisationServiceCalled = new AtomicBoolean();
cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> (protocolId, actionId, type, encodedPrincipal) -> {
authorisationServiceCalled.set(true);
assertEquals(MessageHeaderDecoder.SCHEMA_ID, protocolId);
assertEquals(AdminRequestEncoder.TEMPLATE_ID, actionId);
assertEquals(invalidRequestType, type);
return true;
}).start();
systemTestWatcher.cluster(cluster);
cluster.awaitLeader();
final long requestCorrelationId = System.nanoTime();
final MutableBoolean responseReceived = injectAdminResponseEgressListener(requestCorrelationId, invalidRequestType, AdminResponseCode.ERROR, "Unknown request type: " + invalidRequestType);
final AeronCluster client = cluster.connectClient();
final AdminRequestEncoder adminRequestEncoder = new AdminRequestEncoder().wrapAndApplyHeader(cluster.msgBuffer(), 0, new MessageHeaderEncoder()).leadershipTermId(client.leadershipTermId()).clusterSessionId(client.clusterSessionId()).correlationId(requestCorrelationId).requestType(invalidRequestType);
final Publication ingressPublication = client.ingressPublication();
while (ingressPublication.offer(adminRequestEncoder.buffer(), 0, MessageHeaderEncoder.ENCODED_LENGTH + adminRequestEncoder.encodedLength()) < 0) {
Tests.yield();
}
Tests.await(authorisationServiceCalled::get);
while (!responseReceived.get()) {
client.pollEgress();
Tests.yield();
}
}
use of org.agrona.collections.MutableBoolean in project aeron by real-logic.
the class ClusterTest method shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshotAndNotifyViaControlledPoll.
@Test
@InterruptAfter(20)
void shouldTakeASnapshotAfterReceivingAdminRequestOfTypeSnapshotAndNotifyViaControlledPoll() {
cluster = aCluster().withStaticNodes(3).withAuthorisationServiceSupplier(() -> (protocolId, actionId, type, encodedPrincipal) -> {
assertEquals(MessageHeaderDecoder.SCHEMA_ID, protocolId);
assertEquals(AdminRequestEncoder.TEMPLATE_ID, actionId);
assertEquals(AdminRequestType.SNAPSHOT, type);
return true;
}).start();
systemTestWatcher.cluster(cluster);
final TestNode leader = cluster.awaitLeader();
final long requestCorrelationId = System.nanoTime();
final MutableBoolean responseReceived = injectAdminRequestControlledEgressListener(requestCorrelationId, AdminRequestType.SNAPSHOT, AdminResponseCode.OK, "");
final AeronCluster client = cluster.connectClient();
while (!client.sendAdminRequestToTakeASnapshot(requestCorrelationId)) {
Tests.yield();
}
while (!responseReceived.get()) {
client.controlledPollEgress();
Tests.yield();
}
cluster.awaitSnapshotCount(1);
cluster.awaitNeutralControlToggle(leader);
}
Aggregations