Search in sources :

Example 1 with Command

use of org.apache.qpid.disttest.message.Command in project qpid-broker-j by apache.

the class ControllerJmsDelegate method start.

public void start() {
    try {
        createControllerQueue();
        final MessageConsumer consumer = _controllerQueueListenerSession.createConsumer(_controllerQueue);
        consumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(final Message message) {
                try {
                    String jmsMessageID = message.getJMSMessageID();
                    LOGGER.debug("Received message ID {}", jmsMessageID);
                    final Command command = JmsMessageAdaptor.messageToCommand(message);
                    LOGGER.debug("Converted message ID {} into command {}", jmsMessageID, command);
                    processCommandWithFirstSupportingListener(command);
                    LOGGER.debug("Finished processing command for message ID", jmsMessageID);
                } catch (Exception t) {
                    LOGGER.error("Can't handle JMS message", t);
                }
            }
        });
    } catch (final JMSException e) {
        throw new DistributedTestException(e);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) Command(org.apache.qpid.disttest.message.Command) RegisterClientCommand(org.apache.qpid.disttest.message.RegisterClientCommand) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) DistributedTestException(org.apache.qpid.disttest.DistributedTestException)

Example 2 with Command

use of org.apache.qpid.disttest.message.Command in project qpid-broker-j by apache.

the class ClientConfig method createCommands.

public List<CommandForClient> createCommands() {
    List<CommandForClient> commandsForClient = new ArrayList<CommandForClient>();
    for (MessageProviderConfig messageProvider : _messageProviders) {
        Command command = messageProvider.createCommand();
        commandsForClient.add(new CommandForClient(_name, command));
    }
    for (ConnectionConfig connection : _connections) {
        List<Command> commands = connection.createCommands();
        for (Command command : commands) {
            commandsForClient.add(new CommandForClient(_name, command));
        }
    }
    return commandsForClient;
}
Also used : Command(org.apache.qpid.disttest.message.Command) ArrayList(java.util.ArrayList) CommandForClient(org.apache.qpid.disttest.controller.CommandForClient)

Example 3 with Command

use of org.apache.qpid.disttest.message.Command in project qpid-broker-j by apache.

the class ControllerTest method setUp.

@Before
public void setUp() throws Exception {
    _respondingJmsDelegate = mock(ControllerJmsDelegate.class);
    final Map<String, String> controllerOptions = new HashMap<>();
    controllerOptions.put(ControllerRunner.REGISTRATION_TIMEOUT, String.valueOf(REGISTRATION_TIMEOUT));
    controllerOptions.put(ControllerRunner.COMMAND_RESPONSE_TIMEOUT, String.valueOf(COMMAND_RESPONSE_TIMEOUT));
    _controller = new Controller(_respondingJmsDelegate, controllerOptions);
    _clientRegistry = mock(ClientRegistry.class);
    Config configWithOneClient = createMockConfig(1);
    _controller.setConfig(configWithOneClient);
    _controller.setClientRegistry(_clientRegistry);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            final String clientName = (String) invocation.getArguments()[0];
            final Command command = (Command) invocation.getArguments()[1];
            _controller.processStopClientResponse(new Response(clientName, command.getType()));
            return null;
        }
    }).when(_respondingJmsDelegate).sendCommandToClient(anyString(), isA(Command.class));
}
Also used : HashMap(java.util.HashMap) Config(org.apache.qpid.disttest.controller.config.Config) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Response(org.apache.qpid.disttest.message.Response) StopClientCommand(org.apache.qpid.disttest.message.StopClientCommand) RegisterClientCommand(org.apache.qpid.disttest.message.RegisterClientCommand) Command(org.apache.qpid.disttest.message.Command) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ControllerJmsDelegate(org.apache.qpid.disttest.jms.ControllerJmsDelegate) Before(org.junit.Before)

Example 4 with Command

use of org.apache.qpid.disttest.message.Command in project qpid-broker-j by apache.

the class ConnectionConfigTest method createConnectionConfigWithChildCommands.

private ConnectionConfig createConnectionConfigWithChildCommands() {
    SessionConfig sessionConfig = mock(SessionConfig.class);
    NoOpCommand cmd1 = mock(NoOpCommand.class);
    NoOpCommand cmd2 = mock(NoOpCommand.class);
    List<Command> commands = Arrays.asList((Command) cmd1, (Command) cmd2);
    when(sessionConfig.createCommands(CONNECTION_NAME)).thenReturn(commands);
    return new ConnectionConfig(CONNECTION_NAME, CONNECTION_FACTORY_NAME, sessionConfig);
}
Also used : ConfigTestUtils.getCommand(org.apache.qpid.disttest.controller.config.ConfigTestUtils.getCommand) Command(org.apache.qpid.disttest.message.Command) CreateConnectionCommand(org.apache.qpid.disttest.message.CreateConnectionCommand) NoOpCommand(org.apache.qpid.disttest.message.NoOpCommand) NoOpCommand(org.apache.qpid.disttest.message.NoOpCommand)

Example 5 with Command

use of org.apache.qpid.disttest.message.Command in project qpid-broker-j by apache.

the class ConnectionConfigTest method testCreateCommandsForConnectionAndChildren.

@Test
public void testCreateCommandsForConnectionAndChildren() {
    ConnectionConfig connectionConfig = createConnectionConfigWithChildCommands();
    List<Command> commands = connectionConfig.createCommands();
    assertEquals((long) 3, (long) commands.size());
    assertCommandEquals(commands, 0, CreateConnectionCommand.class);
    assertCommandEquals(commands, 1, NoOpCommand.class);
    assertCommandEquals(commands, 2, NoOpCommand.class);
    CreateConnectionCommand createConnectionCommand = getCommand(commands, 0);
    assertEquals(CONNECTION_NAME, createConnectionCommand.getConnectionName());
    assertEquals(CONNECTION_FACTORY_NAME, createConnectionCommand.getConnectionFactoryName());
}
Also used : ConfigTestUtils.getCommand(org.apache.qpid.disttest.controller.config.ConfigTestUtils.getCommand) Command(org.apache.qpid.disttest.message.Command) CreateConnectionCommand(org.apache.qpid.disttest.message.CreateConnectionCommand) NoOpCommand(org.apache.qpid.disttest.message.NoOpCommand) CreateConnectionCommand(org.apache.qpid.disttest.message.CreateConnectionCommand) Test(org.junit.Test)

Aggregations

Command (org.apache.qpid.disttest.message.Command)11 DistributedTestException (org.apache.qpid.disttest.DistributedTestException)3 CommandForClient (org.apache.qpid.disttest.controller.CommandForClient)3 ConfigTestUtils.getCommand (org.apache.qpid.disttest.controller.config.ConfigTestUtils.getCommand)3 CreateConnectionCommand (org.apache.qpid.disttest.message.CreateConnectionCommand)3 CreateProducerCommand (org.apache.qpid.disttest.message.CreateProducerCommand)3 RegisterClientCommand (org.apache.qpid.disttest.message.RegisterClientCommand)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 JMSException (javax.jms.JMSException)2 CreateConsumerCommand (org.apache.qpid.disttest.message.CreateConsumerCommand)2 CreateSessionCommand (org.apache.qpid.disttest.message.CreateSessionCommand)2 NoOpCommand (org.apache.qpid.disttest.message.NoOpCommand)2 Response (org.apache.qpid.disttest.message.Response)2 StopClientCommand (org.apache.qpid.disttest.message.StopClientCommand)2 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1