JMSConnectionHandlingActor extends AbstractActor { static Props props(final Connection connection, final ExceptionListener exceptionListener, final JmsConnectionFactory jmsConnectionFactory) { return Props.create(JMSConnectionHandlingActor.class, connection, exceptionListener, jmsConnectionFactory); } @SuppressWarnings("unused") private  JMSConnectionHandlingActor(final Connection connection, final ExceptionListener exceptionListener,
            final JmsConnectionFactory jmsConnectionFactory); @Override Receive createReceive();  }
@Test public void handleFailureOnJmsConnect() throws JMSException { new TestKit(actorSystem) {{ final IllegalStateException exception = new IllegalStateException("failureOnJmsConnect"); doThrow(exception).when(mockConnection).start(); final Props props = JMSConnectionHandlingActor.props(connection, e -> {}, jmsConnectionFactory); final ActorRef connectionHandlingActor = watch(actorSystem.actorOf(props)); final TestProbe origin = TestProbe.apply(actorSystem); connectionHandlingActor.tell(new AmqpClientActor.JmsConnect(origin.ref()), getRef()); final ConnectionFailure connectionFailure1 = expectMsgClass(ConnectionFailure.class); assertThat(connectionFailure1.getOrigin()).contains(origin.ref()); assertThat(connectionFailure1.getFailure().cause()).isSameAs(exception); }}; }
@Test public void handleFailureWhenCreatingConsumers() throws JMSException { new TestKit(actorSystem) {{ final IllegalStateException exception = new IllegalStateException("failureOnCreateConsumer"); doThrow(exception).when(mockSession).createConsumer(any()); final Props props = JMSConnectionHandlingActor.props(connection, e -> {}, jmsConnectionFactory); final ActorRef connectionHandlingActor = watch(actorSystem.actorOf(props)); final TestProbe origin = TestProbe.apply(actorSystem); connectionHandlingActor.tell(new AmqpClientActor.JmsConnect(origin.ref()), getRef()); final ConnectionFailure connectionFailure1 = expectMsgClass(ConnectionFailure.class); assertThat(connectionFailure1.getOrigin()).contains(origin.ref()); assertThat(connectionFailure1.getFailure().cause()).isSameAs(exception); }}; }
@Test public void handleJmsConnect() throws JMSException { new TestKit(actorSystem) {{ final Props props = JMSConnectionHandlingActor.props(connection, e -> {}, jmsConnectionFactory); final ActorRef connectionHandlingActor = watch(actorSystem.actorOf(props)); final TestProbe origin = TestProbe.apply(actorSystem); connectionHandlingActor.tell(new AmqpClientActor.JmsConnect(origin.ref()), getRef()); final ClientConnected connected = expectMsgClass(ClientConnected.class); assertThat(connected.getOrigin()).contains(origin.ref()); verify(mockConnection).start(); verify(mockSession, times(connection.getSources() .stream() .mapToInt(s -> s.getAddresses().size() * s.getConsumerCount()) .sum())).createConsumer(any()); }}; }
@Test public void handleJmsDisconnect() throws JMSException { new TestKit(actorSystem) {{ final Props props = JMSConnectionHandlingActor.props(connection, e -> {}, jmsConnectionFactory); final ActorRef connectionHandlingActor = watch(actorSystem.actorOf(props)); final TestProbe origin = TestProbe.apply(actorSystem); connectionHandlingActor.tell(new AmqpClientActor.JmsDisconnect(origin.ref(), mockConnection), getRef()); final ClientDisconnected disconnected = expectMsgClass(ClientDisconnected.class); assertThat(disconnected.getOrigin()).contains(origin.ref()); verify(mockConnection).close(); }}; }
@Test public void handleFailureDuringJmsDisconnect() throws JMSException { new TestKit(actorSystem) {{ final JMSException exception = new JMSException("failureOnJmsConnect"); doThrow(exception).when(mockConnection).stop(); final Props props = JMSConnectionHandlingActor.props(connection, e -> {}, jmsConnectionFactory); final ActorRef connectionHandlingActor = watch(actorSystem.actorOf(props)); final TestProbe origin = TestProbe.apply(actorSystem); connectionHandlingActor.tell(new AmqpClientActor.JmsDisconnect(origin.ref(), mockConnection), getRef()); final ClientDisconnected disconnected = expectMsgClass(ClientDisconnected.class); assertThat(disconnected.getOrigin()).contains(origin.ref()); verify(mockConnection).close(); }}; }