use of io.aeron.ExclusivePublication in project aeron by real-logic.
the class ClusterNodeRestartTest method launchReschedulingService.
private void launchReschedulingService(final AtomicLong triggeredTimersCounter) {
final ClusteredService service = new StubClusteredService() {
public void onSessionMessage(final ClientSession session, final long timestamp, final DirectBuffer buffer, final int offset, final int length, final Header header) {
scheduleNext(serviceCorrelationId(7), timestamp + 200);
}
public void onTimerEvent(final long correlationId, final long timestamp) {
triggeredTimersCounter.getAndIncrement();
scheduleNext(correlationId, timestamp + 200);
}
public void onStart(final Cluster cluster, final Image snapshotImage) {
super.onStart(cluster, snapshotImage);
if (null != snapshotImage) {
final FragmentHandler fragmentHandler = (buffer, offset, length, header) -> triggeredTimersCounter.set(buffer.getLong(offset));
while (true) {
final int fragments = snapshotImage.poll(fragmentHandler, 1);
if (fragments == 1 || snapshotImage.isEndOfStream()) {
break;
}
idleStrategy.idle();
}
}
}
public void onTakeSnapshot(final ExclusivePublication snapshotPublication) {
final ExpandableArrayBuffer buffer = new ExpandableArrayBuffer();
buffer.putLong(0, triggeredTimersCounter.get());
while (snapshotPublication.offer(buffer, 0, SIZE_OF_INT) < 0) {
idleStrategy.idle();
}
}
private void scheduleNext(final long correlationId, final long deadline) {
idleStrategy.reset();
while (!cluster.scheduleTimer(correlationId, deadline)) {
idleStrategy.idle();
}
}
};
container = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().clusteredService(service).terminationHook(ClusterTests.NOOP_TERMINATION_HOOK).errorHandler(ClusterTests.errorHandler(0)));
}
use of io.aeron.ExclusivePublication in project aeron by real-logic.
the class ArchiveDeleteAndRestartTest method recordAndReplayExclusivePublication.
@InterruptAfter(10)
@Test
public void recordAndReplayExclusivePublication() {
final UnsafeBuffer buffer = new UnsafeBuffer(new byte[1024]);
buffer.setMemory(0, buffer.capacity(), (byte) 'z');
AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
final String uri = "aeron:ipc?term-length=16m|init-term-id=502090867|term-offset=0|term-id=502090867";
final ExclusivePublication recordedPublication1 = client.addExclusivePublication(uri, STREAM_ID);
final long subscriptionId = aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
for (int i = 0; i < 10; i++) {
while (recordedPublication1.offer(buffer, 0, 1024) < 0) {
Tests.yieldingIdle("Failed to offer data");
}
}
final long position1 = recordedPublication1.position();
final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(10);
while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
Tests.yieldingIdle("Didn't find recording");
}
while (position1 != aeronArchive.getRecordingPosition(collector.descriptors().get(0).recordingId())) {
Tests.yieldingIdle("Failed to record data");
}
recordedPublication1.close();
aeronArchive.stopRecording(subscriptionId);
while (position1 != aeronArchive.getStopPosition(collector.descriptors().get(0).recordingId())) {
Tests.yieldingIdle("Failed to stop recording");
}
aeronArchive.close();
archive.close();
archive.context().deleteDirectory();
archive = Archive.launch(archiveContext.clone());
aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(client));
final ExclusivePublication recordedPublication2 = client.addExclusivePublication(uri, STREAM_ID);
aeronArchive.startRecording(uri, STREAM_ID, SourceLocation.LOCAL);
for (int i = 0; i < 10; i++) {
while (recordedPublication2.offer(buffer, 0, 1024) < 0) {
Tests.yieldingIdle("Failed to offer data");
}
}
while (aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()) < 1) {
Tests.yieldingIdle("Didn't find recording");
}
assertEquals(1, aeronArchive.listRecordings(0, Integer.MAX_VALUE, collector.reset()), collector.descriptors()::toString);
}
Aggregations