use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class ArchiveAuthenticationTest method shouldBeAbleToRecordWithAuthenticateOnChallengeResponse.
@Test
@InterruptAfter(10)
public void shouldBeAbleToRecordWithAuthenticateOnChallengeResponse() {
final MutableLong authenticatorSessionId = new MutableLong(-1L);
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() {
boolean challengeSuccessful = false;
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) {
assertEquals(sessionId, authenticatorSessionId.value);
assertEquals(CREDENTIALS_STRING, new String(encodedCredentials));
challengeSuccessful = true;
}
public void onConnectedSession(final SessionProxy sessionProxy, final long nowMs) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.challenge(encodedChallenge);
}
public void onChallengedSession(final SessionProxy sessionProxy, final long nowMs) {
if (challengeSuccessful) {
assertEquals(sessionProxy.sessionId(), authenticatorSessionId.value);
sessionProxy.authenticate(PRINCIPAL_STRING.getBytes());
}
}
});
launchArchivingMediaDriver(() -> authenticator);
connectClient(credentialsSupplier);
assertEquals(aeronArchive.controlSessionId(), authenticatorSessionId.value);
createRecording();
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class ReplicateRecordingTest method shouldReplicateStoppedRecording.
@Test
@InterruptAfter(10)
public void shouldReplicateStoppedRecording() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long srcRecordingId;
final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
final CountersReader counters = srcAeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
srcRecordingId = RecordingPos.getRecordingId(counters, counterId);
offer(publication, messageCount, messagePrefix);
awaitPosition(counters, counterId, publication.position());
}
srcAeronArchive.stopRecording(subscriptionId);
final MutableLong dstRecordingId = new MutableLong();
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
final ObjectHashSet<RecordingSignal> transitionEventsSet = new ObjectHashSet<>();
transitionEventsSet.add(awaitSignal(signalRef, adapter));
transitionEventsSet.add(awaitSignal(signalRef, adapter));
assertTrue(transitionEventsSet.contains(RecordingSignal.STOP));
assertTrue(transitionEventsSet.contains(RecordingSignal.SYNC));
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class ReplicateRecordingTest method shouldThrowExceptionWhenSrcRecordingIdUnknown.
@Test
@InterruptAfter(10)
public void shouldThrowExceptionWhenSrcRecordingIdUnknown() {
final long unknownId = 7L;
final ControlEventListener listener = mock(ControlEventListener.class);
final MutableLong dstRecordingId = new MutableLong();
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter = newRecordingSignalAdapter(listener, signalRef, dstRecordingId);
final long replicationId = dstAeronArchive.replicate(unknownId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
awaitSignalOrResponse(signalRef, adapter);
verify(listener).onResponse(eq(dstAeronArchive.controlSessionId()), eq(replicationId), eq((long) ArchiveException.UNKNOWN_RECORDING), eq(ControlResponseCode.ERROR), anyString());
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class TimestampingSystemTest method shouldSupportReceiveTimestampsOnMds.
@Test
@InterruptAfter(10)
void shouldSupportReceiveTimestampsOnMds() {
final MutableDirectBuffer buffer = new UnsafeBuffer(new byte[64]);
try (TestMediaDriver driver = driver();
Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(driver.aeronDirectoryName()))) {
final Subscription mdsSub = aeron.addSubscription("aeron:udp?control-mode=manual|channel-rcv-ts-offset=0", 1000);
final Publication pub1 = aeron.addPublication("aeron:udp?endpoint=localhost:23424", 1000);
final Publication pub2 = aeron.addPublication("aeron:udp?endpoint=localhost:23425", 1000);
mdsSub.addDestination("aeron:udp?endpoint=localhost:23424");
mdsSub.addDestination("aeron:udp?endpoint=localhost:23425");
while (!pub1.isConnected() || !pub2.isConnected()) {
Tests.yieldingIdle("Failed to connect");
}
buffer.putLong(0, SENTINEL_VALUE);
while (0 > pub1.offer(buffer, 0, buffer.capacity())) {
Tests.yieldingIdle("Failed to offer message");
}
while (0 > pub2.offer(buffer, 0, buffer.capacity())) {
Tests.yieldingIdle("Failed to offer message");
}
final MutableLong sendTimestamp = new MutableLong(SENTINEL_VALUE);
final FragmentHandler fragmentHandler = (buffer1, offset, length, header) -> sendTimestamp.set(buffer1.getLong(offset));
while (1 > mdsSub.poll(fragmentHandler, 1)) {
Tests.yieldingIdle("Failed to receive message");
}
assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
while (1 > mdsSub.poll(fragmentHandler, 1)) {
Tests.yieldingIdle("Failed to receive message");
}
assertNotEquals(SENTINEL_VALUE, sendTimestamp.longValue());
}
}
use of org.agrona.collections.MutableLong in project Aeron by real-logic.
the class ConsensusModuleAgentTest method shouldSuspendThenResume.
@Test
public void shouldSuspendThenResume() {
final TestClusterClock clock = new TestClusterClock(TimeUnit.MILLISECONDS);
final MutableLong stateValue = new MutableLong();
final Counter mockState = mock(Counter.class);
when(mockState.get()).thenAnswer((invocation) -> stateValue.value);
doAnswer((invocation) -> {
stateValue.value = invocation.getArgument(0);
return null;
}).when(mockState).set(anyLong());
final MutableLong controlValue = new MutableLong(NEUTRAL.code());
final Counter mockControlToggle = mock(Counter.class);
when(mockControlToggle.get()).thenAnswer((invocation) -> controlValue.value);
doAnswer((invocation) -> {
controlValue.value = invocation.getArgument(0);
return null;
}).when(mockControlToggle).set(anyLong());
doAnswer((invocation) -> {
final long expected = invocation.getArgument(0);
if (expected == controlValue.value) {
controlValue.value = invocation.getArgument(1);
return true;
}
return false;
}).when(mockControlToggle).compareAndSet(anyLong(), anyLong());
ctx.moduleStateCounter(mockState);
ctx.controlToggleCounter(mockControlToggle);
ctx.epochClock(clock).clusterClock(clock);
final ConsensusModuleAgent agent = new ConsensusModuleAgent(ctx);
Tests.setField(agent, "appendPosition", mock(ReadableCounter.class));
assertEquals(ConsensusModule.State.INIT.code(), stateValue.get());
agent.state(ConsensusModule.State.ACTIVE);
agent.role(Cluster.Role.LEADER);
assertEquals(ConsensusModule.State.ACTIVE.code(), stateValue.get());
SUSPEND.toggle(mockControlToggle);
clock.update(SLOW_TICK_INTERVAL_MS, TimeUnit.MILLISECONDS);
agent.doWork();
assertEquals(ConsensusModule.State.SUSPENDED.code(), stateValue.get());
assertEquals(SUSPEND.code(), controlValue.get());
RESUME.toggle(mockControlToggle);
clock.update(SLOW_TICK_INTERVAL_MS * 2, TimeUnit.MILLISECONDS);
agent.doWork();
assertEquals(ConsensusModule.State.ACTIVE.code(), stateValue.get());
assertEquals(NEUTRAL.code(), controlValue.get());
final InOrder inOrder = Mockito.inOrder(mockLogPublisher);
inOrder.verify(mockLogPublisher).appendClusterAction(anyLong(), anyLong(), eq(ClusterAction.SUSPEND));
inOrder.verify(mockLogPublisher).appendClusterAction(anyLong(), anyLong(), eq(ClusterAction.RESUME));
}
Aggregations