protected void restartServer() throws Exception {
   namingContext = new InVMNamingContext();
   jmsServer.setRegistry(new JndiBindingRegistry(namingContext));
   jmsServer.start();
   jmsServer.activated();
   registerConnectionFactory();
 }
  /** @throws Exception */
  protected Queue createQueue(final String name) throws Exception {
    jmsServer2.createQueue(false, name, null, true, "/queue/" + name);
    jmsServer1.createQueue(false, name, null, true, "/queue/" + name);

    assertTrue(waitForBindings(server1, "jms.queue." + name, false, 1, 0, 10000));
    assertTrue(waitForBindings(server2, "jms.queue." + name, false, 1, 0, 10000));

    return (Queue) context1.lookup("/queue/" + name);
  }
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    setupServer2();
    setupServer1();

    jmsServer1.start();
    jmsServer1.activated();
    waitForServerToStart(jmsServer1.getActiveMQServer());

    jmsServer2.start();
    jmsServer2.activated();
    waitForServerToStart(jmsServer2.getActiveMQServer());

    waitForTopology(jmsServer1.getActiveMQServer(), 2);

    waitForTopology(jmsServer2.getActiveMQServer(), 2);

    cf1 =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(
            JMSFactoryType.CF,
            new TransportConfiguration(
                InVMConnectorFactory.class.getName(), generateInVMParams(1)));
    cf2 =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(
            JMSFactoryType.CF,
            new TransportConfiguration(
                InVMConnectorFactory.class.getName(), generateInVMParams(2)));
  }
  @Override
  @After
  public void tearDown() throws Exception {
    try {
      for (JMSContext jmsContext : contextSet) {
        jmsContext.close();
      }
    } catch (RuntimeException ignored) {
      // no-op
    } finally {
      contextSet.clear();
    }
    try {
      if (conn != null) conn.close();
    } catch (Exception e) {
      // no-op
    }

    namingContext.close();
    jmsServer.stop();
    server = null;
    cf = null;
    jmsServer = null;

    namingContext = null;

    MBeanServerFactory.releaseMBeanServer(mbeanServer);

    mbeanServer = null;

    ServiceUtils.setTransactionManager(null);

    super.tearDown();
  }
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    mbeanServer = MBeanServerFactory.createMBeanServer();

    Configuration config =
        createDefaultConfig(true)
            .setSecurityEnabled(useSecurity())
            .addConnectorConfiguration("invm", new TransportConfiguration(INVM_CONNECTOR_FACTORY))
            .setTransactionTimeoutScanPeriod(100);

    server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, usePersistence()));
    jmsServer = new JMSServerManagerImpl(server);
    namingContext = new InVMNamingContext();
    jmsServer.setRegistry(new JndiBindingRegistry(namingContext));
    jmsServer.start();

    registerConnectionFactory();
  }
  /** @throws Exception */
  private void setupServer1() throws Exception {
    Configuration configuration = createConfigServer(1, 2);

    JMSConfigurationImpl jmsconfig = new JMSConfigurationImpl();

    mBeanServer1 = MBeanServerFactory.createMBeanServer();
    server1 =
        addServer(
            ActiveMQServers.newActiveMQServer(configuration, mBeanServer1, enablePersistence()));
    jmsServer1 = new JMSServerManagerImpl(server1, jmsconfig);
    context1 = new InVMNamingContext();
    jmsServer1.setRegistry(new JndiBindingRegistry(context1));
  }
  /**
   * @param connectorConfigs
   * @param jndiBindings
   * @throws Exception
   */
  protected void createCF(
      final List<TransportConfiguration> connectorConfigs, final String... jndiBindings)
      throws Exception {
    List<String> connectorNames = registerConnectors(server, connectorConfigs);

    ConnectionFactoryConfiguration configuration =
        new ConnectionFactoryConfigurationImpl()
            .setName(name.getMethodName())
            .setConnectorNames(connectorNames)
            .setRetryInterval(1000)
            .setReconnectAttempts(-1);
    testCaseCfExtraConfig(configuration);
    jmsServer.createConnectionFactory(false, configuration, jndiBindings);
  }
  protected Topic createTopic(final String name, boolean durable) throws Exception {
    jmsServer2.createTopic(durable, name, "/topic/" + name);
    jmsServer1.createTopic(durable, name, "/topic/" + name);

    return (Topic) context1.lookup("/topic/" + name);
  }
 protected void killServer() throws Exception {
   jmsServer.stop();
 }
  protected Topic createTopic(final boolean storeConfig, final String topicName) throws Exception {
    jmsServer.createTopic(storeConfig, topicName, "/jms/" + topicName);

    return (Topic) namingContext.lookup("/jms/" + topicName);
  }
  /** @throws Exception */
  protected Queue createQueue(final boolean storeConfig, final String queueName) throws Exception {
    jmsServer.createQueue(storeConfig, queueName, null, true, "/jms/" + queueName);

    return (Queue) namingContext.lookup("/jms/" + queueName);
  }