Example usage for org.springframework.amqp.utils.test TestUtils getPropertyValue

List of usage examples for org.springframework.amqp.utils.test TestUtils getPropertyValue

Introduction

In this page you can find the example usage for org.springframework.amqp.utils.test TestUtils getPropertyValue.

Prototype

public static Object getPropertyValue(Object root, String propertyPath) 

Source Link

Document

Uses nested DirectFieldAccessor s to obtain a property using dotted notation to traverse fields; e.g.

Usage

From source file:org.springframework.amqp.rabbit.connection.CachingConnectionFactoryTests.java

@Test
public void testPublisherConnection() throws Exception {
    com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock(
            com.rabbitmq.client.ConnectionFactory.class);
    com.rabbitmq.client.Connection mockConnection = mock(com.rabbitmq.client.Connection.class);
    Channel mockChannel = mock(Channel.class);

    when(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString()))
            .thenReturn(mockConnection);
    when(mockConnection.createChannel()).thenReturn(mockChannel);
    when(mockChannel.isOpen()).thenReturn(true);
    when(mockConnection.isOpen()).thenReturn(true);

    CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory);
    ccf.setExecutor(mock(ExecutorService.class));
    Connection con = ccf.getPublisherConnectionFactory().createConnection();

    Channel channel = con.createChannel(false);
    channel.close(); // should be ignored, and placed into channel cache.
    con.close(); // should be ignored

    Connection con2 = ccf.getPublisherConnectionFactory().createConnection();
    /*/*  w w  w  . j  a  v a2s. c  om*/
     * will retrieve same channel object that was just put into channel cache
     */
    Channel channel2 = con2.createChannel(false);
    channel2.close(); // should be ignored
    con2.close(); // should be ignored

    assertSame(con, con2);
    assertSame(channel, channel2);
    verify(mockConnection, never()).close();
    verify(mockChannel, never()).close();

    assertNull(TestUtils.getPropertyValue(ccf, "connection.target"));
    assertNotNull(TestUtils.getPropertyValue(ccf, "publisherConnectionFactory.connection.target"));
    assertSame(con, TestUtils.getPropertyValue(ccf, "publisherConnectionFactory.connection"));
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerLongTests.java

private void waitForNConsumers(SimpleMessageListenerContainer container, int n, int howLong)
        throws InterruptedException {
    int i = 0;//from ww w.jav  a  2s.  co  m
    while (true) {
        Map<?, ?> consumers = (Map<?, ?>) TestUtils.getPropertyValue(container, "consumers");
        if (n == 0 && consumers == null) {
            break;
        }
        if (consumers != null && consumers.size() == n) {
            break;
        }
        Thread.sleep(100);
        if (i++ > howLong / 100) {
            fail("Never reached " + n + " consumers");
        }
    }
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerTests.java

private void waitForConsumersToStop(Set<?> consumers) throws Exception {
    int n = 0;//from   w  w w  .j  ava 2  s.  c om
    boolean stillUp = true;
    while (stillUp && n++ < 1000) {
        stillUp = false;
        for (Object consumer : consumers) {
            stillUp |= TestUtils.getPropertyValue(consumer, "consumer") != null;
        }
        Thread.sleep(10);
    }
    assertFalse(stillUp);
}