use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class ListRecordingsSessionTest method shouldSendTwoDescriptorsThenRecordingUnknown.
@Test
public void shouldSendTwoDescriptorsThenRecordingUnknown() {
final ListRecordingsSession session = new ListRecordingsSession(correlationId, 1, 3, catalog, controlResponseProxy, controlSession, descriptorBuffer);
final MutableLong counter = new MutableLong(1);
when(controlSession.sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy))).then(verifySendDescriptor(counter));
session.doWork();
verify(controlSession, times(2)).sendDescriptor(eq(correlationId), any(), eq(controlResponseProxy));
verify(controlSession).sendRecordingUnknown(eq(correlationId), eq(3L), eq(controlResponseProxy));
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class ClusterTool method queryClusterMembers.
/**
* Query the membership of a cluster.
*
* @param controlProperties from a {@link ClusterMarkFile}.
* @param timeoutMs to wait for the query.
* @param clusterMembership to populate.
* @return true if the query was successful.
*/
public static boolean queryClusterMembers(final ClusterNodeControlProperties controlProperties, final long timeoutMs, final ClusterMembership clusterMembership) {
final MutableLong id = new MutableLong(NULL_VALUE);
final ClusterControlAdapter.Listener listener = new ClusterControlAdapter.Listener() {
public void onClusterMembersResponse(final long correlationId, final int leaderMemberId, final String activeMembers, final String passiveMembers) {
if (correlationId == id.get()) {
clusterMembership.leaderMemberId = leaderMemberId;
clusterMembership.activeMembersStr = activeMembers;
clusterMembership.passiveMembersStr = passiveMembers;
id.set(NULL_VALUE);
}
}
public void onClusterMembersExtendedResponse(final long correlationId, final long currentTimeNs, final int leaderMemberId, final int memberId, final List<ClusterMember> activeMembers, final List<ClusterMember> passiveMembers) {
if (correlationId == id.get()) {
clusterMembership.currentTimeNs = currentTimeNs;
clusterMembership.leaderMemberId = leaderMemberId;
clusterMembership.memberId = memberId;
clusterMembership.activeMembers = activeMembers;
clusterMembership.passiveMembers = passiveMembers;
clusterMembership.activeMembersStr = ClusterMember.encodeAsString(activeMembers);
clusterMembership.passiveMembersStr = ClusterMember.encodeAsString(passiveMembers);
id.set(NULL_VALUE);
}
}
};
try (Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(controlProperties.aeronDirectoryName));
ConsensusModuleProxy consensusModuleProxy = new ConsensusModuleProxy(aeron.addPublication(controlProperties.controlChannel, controlProperties.consensusModuleStreamId));
ClusterControlAdapter clusterControlAdapter = new ClusterControlAdapter(aeron.addSubscription(controlProperties.controlChannel, controlProperties.serviceStreamId), listener)) {
id.set(aeron.nextCorrelationId());
if (consensusModuleProxy.clusterMembersQuery(id.get())) {
final long startTime = System.currentTimeMillis();
do {
if (clusterControlAdapter.poll() == 0) {
if ((System.currentTimeMillis() - startTime) > timeoutMs) {
break;
}
Thread.yield();
}
} while (NULL_VALUE != id.get());
}
}
return id.get() == NULL_VALUE;
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class AuthenticationTest method shouldRejectOnConnectRequest.
@Test
@InterruptAfter(10)
public void shouldRejectOnConnectRequest() {
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 NULL_CREDENTIAL;
}
public byte[] onChallenge(final byte[] encodedChallenge) {
assertEquals(CHALLENGE_STRING, new String(encodedChallenge));
return encodedCredentials;
}
});
final Authenticator authenticator = spy(new Authenticator() {
public void onConnectRequest(final long sessionId, final byte[] encodedCredentials, final long nowMs) {
authenticatorSessionId.value = sessionId;
assertEquals(0, encodedCredentials.length);
}
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.reject();
}
public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
fail();
}
});
launchClusteredMediaDriver(() -> authenticator);
launchService(serviceSessionId, encodedPrincipal, serviceMsgCounter);
try {
connectClient(credentialsSupplier);
} catch (final AuthenticationException ex) {
assertEquals(-1L, serviceSessionId.value);
ClusterTests.failOnClusterError();
return;
}
fail("should have seen exception");
}
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();
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class AuthenticationTest method shouldAuthenticateOnConnectRequestWithEmptyCredentials.
@Test
@InterruptAfter(10)
public void shouldAuthenticateOnConnectRequestWithEmptyCredentials() {
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 NULL_CREDENTIAL;
}
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(0, encodedCredentials.length);
}
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(null);
}
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(0, encodedPrincipal.get().length);
ClusterTests.failOnClusterError();
}
Aggregations