use of io.aeron.ChannelUriStringBuilder in project aeron by real-logic.
the class UdpChannelTest method shouldParseWithNameResolver.
@ParameterizedTest
@CsvSource({ "NAME_ENDPOINT,192.168.1.1,,,UDP-127.0.0.1:0-NAME_ENDPOINT", "localhost:41024,127.0.0.1,,,UDP-127.0.0.1:0-localhost:41024", "[fe80::5246:5dff:fe73:df06]:40456,[fe80::5246:5dff:fe73:df06],,," + "UDP-127.0.0.1:0-[fe80::5246:5dff:fe73:df06]:40456", "NAME_ENDPOINT,224.0.1.1,,,UDP-127.0.0.1:0-224.0.1.1:40124", "NAME_ENDPOINT,192.168.1.1,NAME_CONTROL,192.168.1.2,UDP-NAME_CONTROL-NAME_ENDPOINT", "NAME_ENDPOINT,224.0.1.1,NAME_CONTROL,127.0.0.1,UDP-127.0.0.1:0-224.0.1.1:40124", "192.168.1.1:40124,192.168.1.1,NAME_CONTROL,192.168.1.2,UDP-NAME_CONTROL-192.168.1.1:40124", "192.168.1.1:40124,192.168.1.1,192.168.1.2:40192,192.168.1.2,UDP-192.168.1.2:40192-192.168.1.1:40124" })
void shouldParseWithNameResolver(final String endpointName, final String endpointAddress, final String controlName, final String controlAddress, final String canonicalForm) {
final int port = 40124;
final NameResolver resolver = new NameResolver() {
public InetAddress resolve(final String name, final String uriParamName, final boolean isReResolution) {
return DefaultNameResolver.INSTANCE.resolve(name, uriParamName, isReResolution);
}
public String lookup(final String name, final String uriParamName, final boolean isReLookup) {
if (endpointName.equals(name)) {
return endpointAddress + ":" + port;
} else if (controlName.equals(name)) {
return controlAddress + ":" + port;
}
return name;
}
};
final ChannelUriStringBuilder uriBuilder = new ChannelUriStringBuilder().media("udp").networkInterface("localhost");
if (!Strings.isEmpty(endpointName)) {
uriBuilder.endpoint(endpointName);
}
if (!Strings.isEmpty(controlName)) {
uriBuilder.controlEndpoint(controlName);
}
final UdpChannel udpChannel = UdpChannel.parse(uriBuilder.build(), resolver);
assertThat(udpChannel.canonicalForm(), is(canonicalForm));
}
use of io.aeron.ChannelUriStringBuilder in project aeron by real-logic.
the class ArchiveTest method shouldRecoverRecordingWithNonZeroStartPosition.
@Test
public void shouldRecoverRecordingWithNonZeroStartPosition() {
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final Archive.Context archiveCtx = new Archive.Context().threadingMode(SHARED);
long resultingPosition;
final int initialPosition = DataHeaderFlyweight.HEADER_LENGTH * 9;
final long recordingId;
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx.clone(), archiveCtx.clone());
AeronArchive archive = AeronArchive.connect()) {
final int termLength = 128 * 1024;
final int initialTermId = 29;
final String channel = new ChannelUriStringBuilder().media(CommonContext.IPC_MEDIA).initialPosition(initialPosition, initialTermId, termLength).build();
final Publication publication = archive.addRecordedExclusivePublication(channel, 1);
final DirectBuffer buffer = new UnsafeBuffer("Hello World".getBytes(StandardCharsets.US_ASCII));
while ((resultingPosition = publication.offer(buffer)) <= 0) {
Tests.yield();
}
final Aeron aeron = archive.context().aeron();
int counterId;
final int sessionId = publication.sessionId();
final CountersReader countersReader = aeron.countersReader();
while (Aeron.NULL_VALUE == (counterId = RecordingPos.findCounterIdBySession(countersReader, sessionId))) {
Tests.yield();
}
recordingId = RecordingPos.getRecordingId(countersReader, counterId);
while (countersReader.getCounterValue(counterId) < resultingPosition) {
Tests.yield();
}
}
try (Catalog catalog = openCatalog(archiveCtx)) {
final Catalog.CatalogEntryProcessor catalogEntryProcessor = (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> descriptorEncoder.stopPosition(Aeron.NULL_VALUE);
assertTrue(catalog.forEntry(recordingId, catalogEntryProcessor));
}
final Archive.Context archiveCtxClone = archiveCtx.clone();
final MediaDriver.Context driverCtxClone = driverCtx.clone();
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtxClone, archiveCtxClone);
AeronArchive archive = AeronArchive.connect()) {
assertEquals(initialPosition, archive.getStartPosition(recordingId));
assertEquals(resultingPosition, archive.getStopPosition(recordingId));
} finally {
archiveCtxClone.deleteDirectory();
driverCtxClone.deleteDirectory();
}
}
Aggregations