return new AmqpAuthenticationException(ex);
@Test public void testRetry() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); final AtomicInteger count = new AtomicInteger(); willAnswer(invocation -> { count.incrementAndGet(); throw new AuthenticationFailureException("foo"); }).given(mockConnectionFactory).newConnection(any(ExecutorService.class), anyString()); SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); connectionFactory.setExecutor(mock(ExecutorService.class)); RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setRetryTemplate(new RetryTemplate()); try { template.convertAndSend("foo", "bar", "baz"); } catch (AmqpAuthenticationException e) { assertThat(e.getMessage(), containsString("foo")); } assertEquals(3, count.get()); }
this.startupException = new FatalListenerStartupException("Authentication failure", new AmqpAuthenticationException(ex));
this.startupException = new FatalListenerStartupException("Authentication failure", new AmqpAuthenticationException(ex));
@Test public void testPossibleAuthenticationFailureNotFatal() { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); given(connectionFactory.createConnection()) .willThrow(new AmqpAuthenticationException(new PossibleAuthenticationFailureException("intentional"))); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setQueueNames("foo"); container.setPossibleAuthenticationFailureFatal(false); container.start(); assertTrue(container.isActive()); assertTrue(container.isRunning()); container.destroy(); }