Package org.springframework.amqp.rabbit.connection

Examples of org.springframework.amqp.rabbit.connection.CachingConnectionFactory


  @Test
  public void testBadCredentials() throws Exception {
    RabbitTemplate template = createTemplate(1);
    com.rabbitmq.client.ConnectionFactory cf = new com.rabbitmq.client.ConnectionFactory();
    cf.setUsername("foo");
    final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(cf);
    try {
      this.doTest(MessageCount.LOW, Concurrency.LOW, TransactionMode.OFF, template, connectionFactory);
      fail("expected exception");
    }
    catch (AmqpIllegalStateException e) {
View Full Code Here


    container.stop();
  }

  @Test
  public void testSimpleMessageListenerContainerStoppedWithoutWarn() throws Exception {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");
    connectionFactory.setPort(BrokerTestUtils.getPort());

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    Log log = spy(TestUtils.getPropertyValue(container, "logger", Log.class));
    final CountDownLatch latch = new CountDownLatch(1);
    when(log.isDebugEnabled()).thenReturn(true);
    doAnswer(new Answer<Void>() {

      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        latch.countDown();
        invocation.callRealMethod();
        return null;
      }
    }).when(log).debug(
        Mockito.contains("Consumer received Shutdown Signal, processing stopped"));
    DirectFieldAccessor dfa = new DirectFieldAccessor(container);
    dfa.setPropertyValue("logger", log);
    container.setQueues(queue);
    container.setMessageListener(new MessageListenerAdapter());
    container.afterPropertiesSet();
    container.start();

    try {
      connectionFactory.destroy();

      assertTrue(latch.await(10, TimeUnit.SECONDS));
      Mockito.verify(log).debug(
          Mockito.contains("Consumer received Shutdown Signal, processing stopped"));
      Mockito.verify(log, Mockito.never()).warn(Mockito.anyString(), Mockito.any(Throwable.class));
View Full Code Here

    ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
    Connection mockConnection = mock(Connection.class);
    final Channel onlyChannel = mock(Channel.class);
    when(onlyChannel.isOpen()).thenReturn(true);

    final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);

    final AtomicReference<Exception> tooManyChannels = new AtomicReference<Exception>();
View Full Code Here

    final Channel listenerChannel = mock(Channel.class);
    Channel templateChannel = mock(Channel.class);
    when(listenerChannel.isOpen()).thenReturn(true);
    when(templateChannel.isOpen()).thenReturn(true);

    final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(listenerConnectionFactory);
    final CachingConnectionFactory cachingTemplateConnectionFactory = new CachingConnectionFactory(templateConnectionFactory);

    when(listenerConnectionFactory.newConnection((ExecutorService) null)).thenReturn(listenerConnection);
    when(listenerConnection.isOpen()).thenReturn(true);
    when(templateConnectionFactory.newConnection((ExecutorService) null)).thenReturn(templateConnection);
    when(templateConnection.isOpen()).thenReturn(true);
View Full Code Here

    ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
    Connection mockConnection = mock(Connection.class);
    final Channel onlyChannel = mock(Channel.class);
    when(onlyChannel.isOpen()).thenReturn(true);

    final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(mockConnectionFactory);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);

    final AtomicReference<Exception> tooManyChannels = new AtomicReference<Exception>();
View Full Code Here

  @Configuration
  public static class FixedReplyQueueDeadLetterConfig {

    @Bean
    public ConnectionFactory rabbitConnectionFactory() {
      CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
      connectionFactory.setHost("localhost");
      return connectionFactory;
    }
View Full Code Here

        mockConnections.add(connection);
        return connection;
      }
    }).when(mockConnectionFactory).newConnection((ExecutorService) null);

    CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory);
    ccf.setCacheMode(CacheMode.CONNECTION);
    ccf.afterPropertiesSet();

    RabbitAdmin admin = new RabbitAdmin(ccf);
    GenericApplicationContext context = new GenericApplicationContext();
    Queue queue = new Queue("foo");
    context.getBeanFactory().registerSingleton("foo", queue);
    context.refresh();
    admin.setApplicationContext(context);
    admin.afterPropertiesSet();
    ccf.createConnection().close();
    ccf.destroy();

    assertEquals("Admin should not have created a channel", 0,  mockChannels.size());
  }
View Full Code Here

  }

  @Test(expected = AmqpIOException.class)
  public void testDoubleDeclarationOfExclusiveQueue() throws Exception {
    // Expect exception because the queue is locked when it is declared a second time.
    CachingConnectionFactory connectionFactory1 = new CachingConnectionFactory();
    connectionFactory1.setHost("localhost");
    connectionFactory1.setPort(BrokerTestUtils.getPort());
    CachingConnectionFactory connectionFactory2 = new CachingConnectionFactory();
    connectionFactory2.setHost("localhost");
    connectionFactory2.setPort(BrokerTestUtils.getPort());
    Queue queue = new Queue("test.queue", false, true, true);
    rabbitAdmin.deleteQueue(queue.getName());
    new RabbitAdmin(connectionFactory1).declareQueue(queue);
    try {
      new RabbitAdmin(connectionFactory2).declareQueue(queue);
    } finally {
      // Need to release the connection so the exclusive queue is deleted
      connectionFactory1.destroy();
      connectionFactory2.destroy();
    }
  }
View Full Code Here

  @Test
  public void testDoubleDeclarationOfAutodeleteQueue() throws Exception {
    // No error expected here: the queue is autodeleted when the last consumer is cancelled, but this one never has
    // any consumers.
    CachingConnectionFactory connectionFactory1 = new CachingConnectionFactory();
    connectionFactory1.setHost("localhost");
    connectionFactory1.setPort(BrokerTestUtils.getPort());
    CachingConnectionFactory connectionFactory2 = new CachingConnectionFactory();
    connectionFactory2.setHost("localhost");
    connectionFactory2.setPort(BrokerTestUtils.getPort());
    Queue queue = new Queue("test.queue", false, false, true);
    new RabbitAdmin(connectionFactory1).declareQueue(queue);
    new RabbitAdmin(connectionFactory2).declareQueue(queue);
    connectionFactory1.destroy();
    connectionFactory2.destroy();
  }
View Full Code Here

  public void declareQueue() {
    if (repeat.isInitialized()) {
      // Important to prevent concurrent re-initialization
      return;
    }
    connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("localhost");
    connectionFactory.setChannelCacheSize(repeat.getConcurrency());
    connectionFactory.setPort(BrokerTestUtils.getPort());
    template.setConnectionFactory(connectionFactory);
  }
View Full Code Here

TOP

Related Classes of org.springframework.amqp.rabbit.connection.CachingConnectionFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.