@Test(expected = PreparedCommandTransportException.class) public void testOnEventWhenPostIsNot2xx() { final OutboundCommandPrepared event = mock(OutboundCommandPrepared.class); final CommandMeta meta = mock(CommandMeta.class); final OutboundCommand command = mock(OutboundCommand.class); CommandTransporterStrategy strategy = mock(CommandTransporterStrategy.class); when(clientStrategy.get()).thenReturn(strategy); final ResponseEntity entity = mock(ResponseEntity.class); CommonSetup(event, meta, command); when(strategy.transportPrepareCommand(any())).thenReturn(false); when(mockRestTemplate.exchange(anyString(), any(), any(), same(TransporterCommand.class))).thenReturn(entity); when(entity.getStatusCode()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR); prepareRestCommandTransporter.onEvent(event); verifyTheCommonResults(command); verify(mockCommandOrchestrator, never()).receive(any(OutboundCommand.class)); }
@Override @Transactional @EventListener public void onEvent(final OutboundCommandPrepared event) { log.info("calling DefaultPrepareCommandTransporter by event {}", event.getClass().getName()); CommandTransporterStrategy commandTransporterStrategy = this.clientStrategy.get(); this.commandRepository.findOutboundCommandOpt(event.getMeta().getCommandId()).ifPresent(outboundCommand -> { if(outboundCommand.getStatus().equals(OutboundCommand.Status.PREPARED)) { final String source = environment.getProperty( "kermoss.serviceName", environment.getProperty("spring.application.name") ); outboundCommand.setSource(source); if(!commandTransporterStrategy.transportPrepareCommand(transform(outboundCommand))) { log.info("Failure Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); throw new PreparedCommandTransportException(outboundCommand.getId()); } log.info("Success Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); OutboundCommand command = OutboundCommand.builder() .subject(outboundCommand.getSubject()) .gTX(outboundCommand.getGTX()) .pGTX(outboundCommand.getPGTX()) .lTX(outboundCommand.getLTX()) .fLTX(outboundCommand.getFLTX()) .destination(outboundCommand.getDestination()) .trace(outboundCommand.getTraceId()) .build(); log.info("Changing OutboundCommand status from Prepared to Started: {}", txLogger.printJsonObject(outboundCommand)); commandOrchestrator.receive(command); txLogger.logTransactionState(txstatus -> log.info( "Transaction {} for Prepared OutboundCommand: {}", txstatus, txLogger.printJsonObject(outboundCommand))); } }); }
DefaultPrepareCommandTransporter extends AbstractCommandTransporter<OutboundCommandPrepared> { @Override @Transactional @EventListener public void onEvent(final OutboundCommandPrepared event) { log.info("calling DefaultPrepareCommandTransporter by event {}", event.getClass().getName()); CommandTransporterStrategy commandTransporterStrategy = this.clientStrategy.get(); this.commandRepository.findOutboundCommandOpt(event.getMeta().getCommandId()).ifPresent(outboundCommand -> { if(outboundCommand.getStatus().equals(OutboundCommand.Status.PREPARED)) { final String source = environment.getProperty( "kermoss.serviceName", environment.getProperty("spring.application.name") ); outboundCommand.setSource(source); if(!commandTransporterStrategy.transportPrepareCommand(transform(outboundCommand))) { log.info("Failure Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); throw new PreparedCommandTransportException(outboundCommand.getId()); } log.info("Success Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); OutboundCommand command = OutboundCommand.builder() .subject(outboundCommand.getSubject()) .gTX(outboundCommand.getGTX()) .pGTX(outboundCommand.getPGTX()) .lTX(outboundCommand.getLTX()) .fLTX(outboundCommand.getFLTX()) .destination(outboundCommand.getDestination()) .trace(outboundCommand.getTraceId()) .build(); log.info("Changing OutboundCommand status from Prepared to Started: {}", txLogger.printJsonObject(outboundCommand)); commandOrchestrator.receive(command); txLogger.logTransactionState(txstatus -> log.info( "Transaction {} for Prepared OutboundCommand: {}", txstatus, txLogger.printJsonObject(outboundCommand))); } }); } }
DefaultPrepareCommandTransporter extends AbstractCommandTransporter<OutboundCommandPrepared> { @Override @Transactional @EventListener public void onEvent(final OutboundCommandPrepared event) { log.info("calling DefaultPrepareCommandTransporter by event {}", event.getClass().getName()); CommandTransporterStrategy commandTransporterStrategy = this.clientStrategy.get(); this.commandRepository.findOutboundCommandOpt(event.getMeta().getCommandId()).ifPresent(outboundCommand -> { if(outboundCommand.getStatus().equals(OutboundCommand.Status.PREPARED)) { final String source = environment.getProperty( "kermoss.serviceName", environment.getProperty("spring.application.name") ); outboundCommand.setSource(source); if(!commandTransporterStrategy.transportPrepareCommand(transform(outboundCommand))) { log.info("Failure Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); throw new PreparedCommandTransportException(outboundCommand.getId()); } log.info("Success Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); OutboundCommand command = OutboundCommand.builder() .subject(outboundCommand.getSubject()) .gTX(outboundCommand.getGTX()) .pGTX(outboundCommand.getPGTX()) .lTX(outboundCommand.getLTX()) .fLTX(outboundCommand.getFLTX()) .destination(outboundCommand.getDestination()) .trace(outboundCommand.getTraceId()) .build(); log.info("Changing OutboundCommand status from Prepared to Started: {}", txLogger.printJsonObject(outboundCommand)); commandOrchestrator.receive(command); txLogger.logTransactionState(txstatus -> log.info( "Transaction {} for Prepared OutboundCommand: {}", txstatus, txLogger.printJsonObject(outboundCommand))); } }); } @Autowired  DefaultPrepareCommandTransporter(
    	final ApplicationEventPublisher publisher,
        final Environment environment,
        final CommandRepository commandRepository,
        final CommandOrchestrator commandOrchestrator,
        final KermossTxLogger txLogger,
        final HttpClientStrategy clientStrategy
    ); }
DefaultPrepareCommandTransporter extends AbstractCommandTransporter<OutboundCommandPrepared> { @Override @Transactional @EventListener public void onEvent(final OutboundCommandPrepared event) { log.info("calling DefaultPrepareCommandTransporter by event {}", event.getClass().getName()); CommandTransporterStrategy commandTransporterStrategy = this.clientStrategy.get(); this.commandRepository.findOutboundCommandOpt(event.getMeta().getCommandId()).ifPresent(outboundCommand -> { if(outboundCommand.getStatus().equals(OutboundCommand.Status.PREPARED)) { final String source = environment.getProperty( "kermoss.serviceName", environment.getProperty("spring.application.name") ); outboundCommand.setSource(source); if(!commandTransporterStrategy.transportPrepareCommand(transform(outboundCommand))) { log.info("Failure Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); throw new PreparedCommandTransportException(outboundCommand.getId()); } log.info("Success Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); OutboundCommand command = OutboundCommand.builder() .subject(outboundCommand.getSubject()) .gTX(outboundCommand.getGTX()) .pGTX(outboundCommand.getPGTX()) .lTX(outboundCommand.getLTX()) .fLTX(outboundCommand.getFLTX()) .destination(outboundCommand.getDestination()) .trace(outboundCommand.getTraceId()) .build(); log.info("Changing OutboundCommand status from Prepared to Started: {}", txLogger.printJsonObject(outboundCommand)); commandOrchestrator.receive(command); txLogger.logTransactionState(txstatus -> log.info( "Transaction {} for Prepared OutboundCommand: {}", txstatus, txLogger.printJsonObject(outboundCommand))); } }); } @Autowired  DefaultPrepareCommandTransporter(
    	final ApplicationEventPublisher publisher,
        final Environment environment,
        final CommandRepository commandRepository,
        final CommandOrchestrator commandOrchestrator,
        final KermossTxLogger txLogger,
        final HttpClientStrategy clientStrategy
    ); @Override @Transactional @EventListener void onEvent(final OutboundCommandPrepared event); }
DefaultPrepareCommandTransporter extends AbstractCommandTransporter<OutboundCommandPrepared> { @Override @Transactional @EventListener public void onEvent(final OutboundCommandPrepared event) { log.info("calling DefaultPrepareCommandTransporter by event {}", event.getClass().getName()); CommandTransporterStrategy commandTransporterStrategy = this.clientStrategy.get(); this.commandRepository.findOutboundCommandOpt(event.getMeta().getCommandId()).ifPresent(outboundCommand -> { if(outboundCommand.getStatus().equals(OutboundCommand.Status.PREPARED)) { final String source = environment.getProperty( "kermoss.serviceName", environment.getProperty("spring.application.name") ); outboundCommand.setSource(source); if(!commandTransporterStrategy.transportPrepareCommand(transform(outboundCommand))) { log.info("Failure Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); throw new PreparedCommandTransportException(outboundCommand.getId()); } log.info("Success Transport Prepared Command over HTTP: {}", txLogger.printJsonObject(outboundCommand)); OutboundCommand command = OutboundCommand.builder() .subject(outboundCommand.getSubject()) .gTX(outboundCommand.getGTX()) .pGTX(outboundCommand.getPGTX()) .lTX(outboundCommand.getLTX()) .fLTX(outboundCommand.getFLTX()) .destination(outboundCommand.getDestination()) .trace(outboundCommand.getTraceId()) .build(); log.info("Changing OutboundCommand status from Prepared to Started: {}", txLogger.printJsonObject(outboundCommand)); commandOrchestrator.receive(command); txLogger.logTransactionState(txstatus -> log.info( "Transaction {} for Prepared OutboundCommand: {}", txstatus, txLogger.printJsonObject(outboundCommand))); } }); } @Autowired  DefaultPrepareCommandTransporter(
    	final ApplicationEventPublisher publisher,
        final Environment environment,
        final CommandRepository commandRepository,
        final CommandOrchestrator commandOrchestrator,
        final KermossTxLogger txLogger,
        final HttpClientStrategy clientStrategy
    ); @Override @Transactional @EventListener void onEvent(final OutboundCommandPrepared event);  }