@Test public void whenExpertAdvisorIsUnknownTheProtocolShouldFailWithAProtocolException() throws CommunicationException { boolean exceptionCatched = false; try { new ExpertAdvisorProtocol(client, factory, UNKNOWN_EXPERT_ADVISOR).start(); } catch (final ProtocolException e) { exceptionCatched = true; assertThat(e.getMessage()).contains("expert").contains("advisor").contains("number"); } assertThat(exceptionCatched).as("Expected to catch a protocol exception but didn't.").isTrue(); verify(client, times(0)).readMessage(); }
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();  }