public static FixLibrary blockingConnect(final LibraryConfiguration configuration) { final FixLibrary library = FixLibrary.connect(configuration); while (!library.isConnected()) { library.poll(1); Thread.yield(); } return library; }
while (library.isConnected()) System.out.println("Disconnected: " + (!library.isConnected())); while (!library.isConnected())
public static void main(final String[] args) { final LibraryConfiguration libraryConfiguration = new LibraryConfiguration() .libraryAeronChannels(singletonList(SoleEngine.AERON_CHANNEL)) .libraryIdleStrategy(new YieldingIdleStrategy()); libraryConfiguration.replyTimeoutInMs(1000); try (FixLibrary library = SampleUtil.blockingConnect(libraryConfiguration)) { System.out.println("Connected"); while (library.isConnected()) { library.poll(1); Thread.yield(); } } } }
private void awaitIsConnected(final boolean isConnected, final FixLibrary library) { assertEventuallyTrue( "isConnected never became: " + isConnected, () -> { testSystem.poll(); return library.isConnected() == isConnected; }); }
static void awaitLibraryConnect(final FixLibrary library) { assertEventuallyTrue( () -> "Library hasn't seen Engine", () -> { library.poll(5); return library.isConnected(); }, AWAIT_TIMEOUT, () -> {} ); }
public static FixLibrary connect(final LibraryConfiguration configuration) { final FixLibrary library = FixLibrary.connect(configuration); assertEventuallyTrue( () -> "Unable to connect to engine", () -> { library.poll(LIBRARY_LIMIT); return library.isConnected(); }, DEFAULT_TIMEOUT_IN_MS, library::close); return library; }
@Test public void libraryShouldRefuseConnectionWhenThereIsNoAcceptor() { launchEngine(); launchLibrary(); assertTrue("Library not connected", initiatingLibrary.isConnected()); initiateResultsInError(); }
public FixLibrary connect(final LibraryConfiguration configuration) { final FixLibrary library = FixLibrary.connect(configuration); add(library); assertEventuallyTrue( () -> "Unable to connect to engine", () -> { poll(); return library.isConnected(); }, DEFAULT_TIMEOUT_IN_MS, () -> close(library)); return library; }
@Test public void libraryDetectsEngineDisconnect() { library = connectLibrary(); awaitLibraryConnect(library); CloseHelper.close(engine); assertEventuallyTrue( () -> "Engine still hasn't disconnected", () -> { library.poll(5); return !library.isConnected(); }, AWAIT_TIMEOUT, () -> { } ); }
@Test public void enginesShouldBeRestartable() { messagesCanBeExchanged(); acceptingEngine.close(); assertAllMessagesHaveSequenceIndex(0); clearMessages(); assertEventuallyTrue( "Library failed to disconnect", () -> { testSystem.poll(); return !acceptingLibrary.isConnected(); }); testSystem.close(acceptingLibrary); launchAcceptingEngine(); acceptingLibrary = testSystem.add(newAcceptingLibrary(acceptingHandler)); assertTrue("acceptingLibrary has failed to connect", acceptingLibrary.isConnected()); assertTrue("initiatingLibrary is no longer connected", initiatingLibrary.isConnected()); wireSessions(); messagesCanBeExchanged(); assertSequenceIndicesAre(1); }
@Test public void shouldEnableLibraryConnectionsOneAfterAnother() { for (int i = 0; i < 20; i++) { DebugLogger.log(LogTag.FIX_TEST, "Iteration: " + i); acceptingLibrary = testSystem.add(newAcceptingLibrary(acceptingHandler)); while (!acceptingLibrary.isConnected()) { testSystem.poll(); Thread.yield(); } acquireAcceptingSession(); final Reply<SessionReplyStatus> reply = testSystem.awaitReply(acceptingLibrary.releaseToGateway( acceptingSession, DEFAULT_REPLY_TIMEOUT_IN_MS)); assertEquals(SessionReplyStatus.OK, reply.resultIfPresent()); acceptingLibrary.close(); } }