use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class TestCluster method validateRecordingLogWithReplay.
public void validateRecordingLogWithReplay(final int nodeId) {
final TestNode node = node(nodeId);
final ConsensusModule.Context consensusModuleCtx = node.consensusModule().context();
final AeronArchive.Context clone = consensusModuleCtx.archiveContext().clone();
try (AeronArchive aeronArchive = AeronArchive.connect(clone);
RecordingLog recordingLog = new RecordingLog(consensusModuleCtx.clusterDir(), false)) {
final RecordingLog.Entry lastTerm = recordingLog.findLastTerm();
assertNotNull(lastTerm);
final long recordingId = lastTerm.recordingId;
final long recordingPosition = aeronArchive.getRecordingPosition(recordingId);
final Subscription replay = aeronArchive.replay(recordingId, 0, recordingPosition, "aeron:udp?endpoint=localhost:6666", 100001);
final MutableLong position = new MutableLong();
final MessageHeaderDecoder messageHeaderDecoder = new MessageHeaderDecoder();
final NewLeadershipTermEventDecoder newLeadershipTermEventDecoder = new NewLeadershipTermEventDecoder();
while (position.get() < recordingPosition) {
replay.poll((buffer, offset, length, header) -> {
messageHeaderDecoder.wrap(buffer, offset);
if (NewLeadershipTermEventDecoder.TEMPLATE_ID == messageHeaderDecoder.templateId()) {
newLeadershipTermEventDecoder.wrapAndApplyHeader(buffer, offset, messageHeaderDecoder);
final RecordingLog.Entry termEntry = recordingLog.findTermEntry(newLeadershipTermEventDecoder.leadershipTermId());
assertNotNull(termEntry);
assertEquals(newLeadershipTermEventDecoder.termBaseLogPosition(), termEntry.termBaseLogPosition);
if (0 < newLeadershipTermEventDecoder.leadershipTermId()) {
final RecordingLog.Entry previousTermEntry = recordingLog.findTermEntry(newLeadershipTermEventDecoder.leadershipTermId() - 1);
assertNotNull(previousTermEntry);
assertEquals(newLeadershipTermEventDecoder.termBaseLogPosition(), previousTermEntry.logPosition, previousTermEntry.toString());
}
}
position.set(header.position());
}, 10);
}
}
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class ListRecordingsSessionTest method shouldResendDescriptorWhenSendFails.
@Test
public void shouldResendDescriptorWhenSendFails() {
final long fromRecordingId = 1;
final ListRecordingsSession session = new ListRecordingsSession(correlationId, fromRecordingId, 1, catalog, controlResponseProxy, controlSession, descriptorBuffer);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).thenReturn(0);
session.doWork();
verify(controlSession, times(1)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
final MutableLong counter = new MutableLong(fromRecordingId);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
session.doWork();
verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class ListRecordingsSessionTest method shouldSend2Descriptors.
@Test
public void shouldSend2Descriptors() {
final int fromId = 1;
final ListRecordingsSession session = new ListRecordingsSession(correlationId, fromId, 2, catalog, controlResponseProxy, controlSession, descriptorBuffer);
final MutableLong counter = new MutableLong(fromId);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
session.doWork();
verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class ListRecordingsSessionTest method shouldSendAllDescriptors.
@Test
public void shouldSendAllDescriptors() {
final ListRecordingsSession session = new ListRecordingsSession(correlationId, 0, 3, catalog, controlResponseProxy, controlSession, descriptorBuffer);
final MutableLong counter = new MutableLong(0);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
session.doWork();
verify(controlSession, times(3)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
}
use of org.agrona.collections.MutableLong in project aeron by real-logic.
the class AuthenticationTest method shouldAuthenticateOnConnectRequestWithCredentials.
@Test
@InterruptAfter(10)
public void shouldAuthenticateOnConnectRequestWithCredentials() {
final AtomicLong serviceMsgCounter = new AtomicLong(0L);
final MutableLong serviceSessionId = new MutableLong(-1L);
final MutableLong authenticatorSessionId = new MutableLong(-1L);
final MutableReference<byte[]> encodedPrincipal = new MutableReference<>();
final CredentialsSupplier credentialsSupplier = spy(new CredentialsSupplier() {
public byte[] encodedCredentials() {
return encodedCredentials;
}
public byte[] onChallenge(final byte[] encodedChallenge) {
fail();
return null;
}
});
final Authenticator authenticator = spy(new Authenticator() {
public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
authenticatorSessionId.value = sessionId;
assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
}
public void onChallengeResponse(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
fail();
}
public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.authenticate(PRINCIPAL_STRING.getBytes());
}
public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
fail();
}
});
launchClusteredMediaDriver(() -> authenticator);
launchService(serviceSessionId, encodedPrincipal, serviceMsgCounter);
connectClient(credentialsSupplier);
sendCountedMessageIntoCluster(0);
Tests.awaitValue(serviceMsgCounter, 1);
assertEquals(aeronCluster.clusterSessionId(), authenticatorSessionId.value);
assertEquals(aeronCluster.clusterSessionId(), serviceSessionId.value);
assertEquals(PRINCIPAL_STRING, new String(encodedPrincipal.get()));
ClusterTests.failOnClusterError();
}
Aggregations