@Test public void communicationExceptionThrownInSendMethodsShouldBeRethrownInTheEventLoop() throws CommunicationException { when(client.readMessage()).thenReturn(exampleMessage); doThrow(new LoopThroughCommunicationException(new ExemplaryFatalCommunicationException())) .when(exampleLocalExpertAdvisor).handleMessage(exampleMessage); boolean exceptionCatched = false; try { cut.start(); } catch (final ExemplaryFatalCommunicationException e) { exceptionCatched = true; } assertThat(exceptionCatched) .as("The 'SimulateWriteFailed' exception was expected to be re-thrown out of the start() method but it wasn't") .isTrue(); }
public void start() throws CommunicationException { final TradingEnvironmentInformationMessage environment = clientConnection .readMessage(TradingEnvironmentInformationMessage.class); final ReleasableMoneyManagement moneyManagement = factory.newSharedMoneyManagementInstance(); expertAdvisor = factory .newLocalExpertAdvisorByNumber(expertAdvisorNumber, clientConnection, moneyManagement, environment.getInformation()) .orElseThrow(() -> new ProtocolException("Recieved an request for the expert advisor with the number " + expertAdvisorNumber + " which is unknown.")); while (true) { try { expertAdvisor.handleMessage(clientConnection.readMessage()); clientConnection.sendMessage(new EventHandlingFinishedMessage()); } catch (LoopThroughCommunicationException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final LoopThroughIllegalStateException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final Exception e) { moneyManagement.realeaseAllAquieredVolume(); throw e; } } }
ExpertAdvisorProtocol { public void start() throws CommunicationException { final TradingEnvironmentInformationMessage environment = clientConnection .readMessage(TradingEnvironmentInformationMessage.class); final ReleasableMoneyManagement moneyManagement = factory.newSharedMoneyManagementInstance(); expertAdvisor = factory .newLocalExpertAdvisorByNumber(expertAdvisorNumber, clientConnection, moneyManagement, environment.getInformation()) .orElseThrow(() -> new ProtocolException("Recieved an request for the expert advisor with the number " + expertAdvisorNumber + " which is unknown.")); while (true) { try { expertAdvisor.handleMessage(clientConnection.readMessage()); clientConnection.sendMessage(new EventHandlingFinishedMessage()); } catch (LoopThroughCommunicationException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final LoopThroughIllegalStateException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final Exception e) { moneyManagement.realeaseAllAquieredVolume(); throw e; } } } }
ExpertAdvisorProtocol { public void start() throws CommunicationException { final TradingEnvironmentInformationMessage environment = clientConnection .readMessage(TradingEnvironmentInformationMessage.class); final ReleasableMoneyManagement moneyManagement = factory.newSharedMoneyManagementInstance(); expertAdvisor = factory .newLocalExpertAdvisorByNumber(expertAdvisorNumber, clientConnection, moneyManagement, environment.getInformation()) .orElseThrow(() -> new ProtocolException("Recieved an request for the expert advisor with the number " + expertAdvisorNumber + " which is unknown.")); while (true) { try { expertAdvisor.handleMessage(clientConnection.readMessage()); clientConnection.sendMessage(new EventHandlingFinishedMessage()); } catch (LoopThroughCommunicationException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final LoopThroughIllegalStateException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final Exception e) { moneyManagement.realeaseAllAquieredVolume(); throw e; } } } ExpertAdvisorProtocol(final MessageBasedClientConnection clientConnection,
            final ProtocolFactory protocolFactory, final int expertAdvisorNumber); }
ExpertAdvisorProtocol { public void start() throws CommunicationException { final TradingEnvironmentInformationMessage environment = clientConnection .readMessage(TradingEnvironmentInformationMessage.class); final ReleasableMoneyManagement moneyManagement = factory.newSharedMoneyManagementInstance(); expertAdvisor = factory .newLocalExpertAdvisorByNumber(expertAdvisorNumber, clientConnection, moneyManagement, environment.getInformation()) .orElseThrow(() -> new ProtocolException("Recieved an request for the expert advisor with the number " + expertAdvisorNumber + " which is unknown.")); while (true) { try { expertAdvisor.handleMessage(clientConnection.readMessage()); clientConnection.sendMessage(new EventHandlingFinishedMessage()); } catch (LoopThroughCommunicationException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final LoopThroughIllegalStateException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final Exception e) { moneyManagement.realeaseAllAquieredVolume(); throw e; } } } ExpertAdvisorProtocol(final MessageBasedClientConnection clientConnection,
            final ProtocolFactory protocolFactory, final int expertAdvisorNumber); void start(); }
ExpertAdvisorProtocol { public void start() throws CommunicationException { final TradingEnvironmentInformationMessage environment = clientConnection .readMessage(TradingEnvironmentInformationMessage.class); final ReleasableMoneyManagement moneyManagement = factory.newSharedMoneyManagementInstance(); expertAdvisor = factory .newLocalExpertAdvisorByNumber(expertAdvisorNumber, clientConnection, moneyManagement, environment.getInformation()) .orElseThrow(() -> new ProtocolException("Recieved an request for the expert advisor with the number " + expertAdvisorNumber + " which is unknown.")); while (true) { try { expertAdvisor.handleMessage(clientConnection.readMessage()); clientConnection.sendMessage(new EventHandlingFinishedMessage()); } catch (LoopThroughCommunicationException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final LoopThroughIllegalStateException e) { moneyManagement.realeaseAllAquieredVolume(); throw e.getWrappedException(); } catch (final Exception e) { moneyManagement.realeaseAllAquieredVolume(); throw e; } } } ExpertAdvisorProtocol(final MessageBasedClientConnection clientConnection,
            final ProtocolFactory protocolFactory, final int expertAdvisorNumber); void start();  }