Ejemplo n.º 1
0
  @Test
  public void testCreateDurableQueueUsingJMXAndRestartServer() throws Exception {
    String queueName = RandomUtil.randomString();
    String binding = RandomUtil.randomString();

    UnitTestCase.checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    JMSServerControl control = ManagementControlHelper.createJMSServerControl(mbeanServer);
    control.createQueue(queueName, binding);

    Object o = UnitTestCase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    Queue queue = (Queue) o;
    assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager.stop();

    checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager = createJMSServer();
    serverManager.start();

    o = UnitTestCase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    queue = (Queue) o;
    assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));
  }
Ejemplo n.º 2
0
  @Override
  @After
  public void tearDown() throws Exception {
    backupJMSService.stop();

    liveJMSService.stop();

    Assert.assertEquals(0, InVMRegistry.instance.size());

    liveService = null;

    liveJMSService = null;

    backupJMSService = null;

    ctx1 = null;

    ctx2 = null;

    backupService = null;

    backupParams = null;

    super.tearDown();
  }
Ejemplo n.º 3
0
 protected void createQueue(final String queueName, final int index) throws Exception {
   JMSServerManager server = jmsServer0;
   if (index == 1) {
     server = jmsServer1;
   }
   assertTrue(
       "queue '/queue/" + queueName + "' created",
       server.createQueue(false, queueName, null, true, "/queue/" + queueName));
 }
Ejemplo n.º 4
0
 public synchronized void stop(StopContext context) {
   final JMSServerManager jmsServer = this.jmsServer;
   this.jmsServer = null;
   try {
     jmsServer.stop();
   } catch (Exception e) {
     MESSAGING_LOGGER.errorStoppingJmsServer(e);
   }
 }
Ejemplo n.º 5
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    // Start the servers
    Configuration conf0 = createBasicConfig();
    conf0.setJournalDirectory(getJournalDir(0, false));
    conf0.setBindingsDirectory(getBindingsDir(0, false));
    conf0.setSecurityEnabled(false);
    conf0.getAcceptorConfigurations().add(new TransportConfiguration(INVM_ACCEPTOR_FACTORY));
    server0 = addServer(HornetQServers.newHornetQServer(conf0, false));

    context0 = new InVMNamingContext();
    jmsServer0 = new JMSServerManagerImpl(server0);
    jmsServer0.setContext(context0);
    jmsServer0.start();

    Configuration conf1 = createBasicConfig();
    conf1.setSecurityEnabled(false);
    conf1.setJournalDirectory(getJournalDir(1, false));
    conf1.setBindingsDirectory(getBindingsDir(1, false));
    params1 = new HashMap<String, Object>();
    params1.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    conf1
        .getAcceptorConfigurations()
        .add(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, params1));

    server1 = addServer(HornetQServers.newHornetQServer(conf1, false));

    context1 = new InVMNamingContext();

    jmsServer1 = new JMSServerManagerImpl(server1);
    jmsServer1.setContext(context1);
    jmsServer1.start();

    createQueue("sourceQueue", 0);

    jmsServer0.createTopic(false, "sourceTopic", "/topic/sourceTopic");

    createQueue("localTargetQueue", 0);

    createQueue("targetQueue", 1);

    setUpAdministeredObjects();
    TxControl.enable();
    // We need a local transaction and recovery manager
    // We must start this after the remote servers have been created or it won't
    // have deleted the database and the recovery manager may attempt to recover transactions

  }
Ejemplo n.º 6
0
  public synchronized void start(StartContext context) throws StartException {
    try {
      final JMSServerManager jmsServer =
          new JMSServerManagerImpl(
              hornetQServer.getValue(),
              new AS7BindingRegistry(context.getController().getServiceContainer()));

      try {
        // FIXME - we also need the TCCL here in case the JMSServerManager starts the HornetQServer
        final ClassLoader loader = getClass().getClassLoader();
        SecurityActions.setContextClassLoader(loader);
        jmsServer.start();

        // FIXME - this check is a work-around for AS7-3658
        if (!hornetQServer.getValue().getConfiguration().isBackup()) {
          hornetQServer
              .getValue()
              .getRemotingService()
              .allowInvmSecurityOverride(
                  new HornetQPrincipal(
                      HornetQDefaultCredentials.getUsername(),
                      HornetQDefaultCredentials.getPassword()));
        } else {
          hornetQServer
              .getValue()
              .registerActivateCallback(
                  new ActivateCallback() {
                    public void preActivate() {}

                    public void activated() {
                      hornetQServer
                          .getValue()
                          .getRemotingService()
                          .allowInvmSecurityOverride(
                              new HornetQPrincipal(
                                  HornetQDefaultCredentials.getUsername(),
                                  HornetQDefaultCredentials.getPassword()));
                    }

                    public void deActivate() {}
                  });
        }
      } finally {
        SecurityActions.setContextClassLoader(null);
      }
      this.jmsServer = jmsServer;
    } catch (Exception e) {
      throw new StartException(e);
    }
  }
Ejemplo n.º 7
0
  @Override
  @After
  public void tearDown() throws Exception {
    jmsServer.stop();

    super.tearDown();
  }
Ejemplo n.º 8
0
 @Override
 @After
 public void tearDown() throws Exception {
   serverManager.stop();
   serverManager = null;
   super.tearDown();
 }
Ejemplo n.º 9
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    serverManager = createJMSServer();
    serverManager.start();
  }
Ejemplo n.º 10
0
  @Test
  public void testCreateDurableQueueUsingJMSAndRestartServer() throws Exception {
    String queueName = RandomUtil.randomString();
    String binding = RandomUtil.randomString();

    UnitTestCase.checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    TransportConfiguration config =
        new TransportConfiguration(InVMConnectorFactory.class.getName());
    Connection connection =
        HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, config)
            .createConnection();
    connection.start();
    Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");
    QueueSession session = (QueueSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueRequestor requestor = new QueueRequestor(session, managementQueue);
    Message message = session.createMessage();
    JMSManagementHelper.putOperationInvocation(
        message, "jms.server", "createQueue", queueName, binding);
    Message reply = requestor.request(message);
    assertTrue(JMSManagementHelper.hasOperationSucceeded(reply));
    connection.close();

    Object o = UnitTestCase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    Queue queue = (Queue) o;
    assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager.stop();

    checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager = createJMSServer();
    serverManager.start();

    o = UnitTestCase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    queue = (Queue) o;
    assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));
  }
Ejemplo n.º 11
0
  @Override
  protected void tearDown() throws Exception {
    jmsServer.stop();
    jmsServer = null;
    context = null;
    deploymentManager = null;
    config = null;

    super.tearDown();
  }
Ejemplo n.º 12
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    config = createBasicConfig();
    config
        .getConnectorConfigurations()
        .put("netty", new TransportConfiguration(NettyConnectorFactory.class.getName()));

    DiscoveryGroupConfiguration dcg =
        new DiscoveryGroupConfiguration("mygroup", "172.16.8.10", "243.7.7.7", 12345, 5432, 5432);
    config.getDiscoveryGroupConfigurations().put("mygroup", dcg);
    HornetQServer server = createServer(false, config);

    deploymentManager = new FileDeploymentManager(config.getFileDeployerScanPeriod());

    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMContext();
    jmsServer.setContext(context);
    jmsServer.start();
  }
Ejemplo n.º 13
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    Configuration config = createBasicConfig();
    config.setFileDeploymentEnabled(false);
    config.setSecurityEnabled(false);
    config
        .getAcceptorConfigurations()
        .add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
    InVMContext context = new InVMContext();
    jmsServer = new JMSServerManagerImpl(HornetQServers.newHornetQServer(config, false));
    jmsServer.setContext(context);
    jmsServer.start();

    jmsServer.createQueue(
        false, JMSBridgeImplTest.SOURCE, null, true, "/queue/" + JMSBridgeImplTest.SOURCE);
    jmsServer.createQueue(
        false, JMSBridgeImplTest.TARGET, null, true, "/queue/" + JMSBridgeImplTest.TARGET);
  }
Ejemplo n.º 14
0
  private JMSServerManager createJMSServer() throws Exception {
    Configuration conf = createDefaultConfig();
    conf.setSecurityEnabled(false);
    conf.setJMXManagementEnabled(true);
    conf.setPersistenceEnabled(true);
    conf.setJournalType(JournalType.NIO);
    conf.getAcceptorConfigurations()
        .add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
    HornetQServer server = HornetQServers.newHornetQServer(conf, mbeanServer);

    context = new InVMContext();

    serverManager = new JMSServerManagerImpl(server);
    serverManager.setContext(context);
    return serverManager;
  }
Ejemplo n.º 15
0
  /** @throws Exception */
  protected void startServers() throws Exception {
    NodeManager nodeManager = new InVMNodeManager(false);
    backuptc = new TransportConfiguration(INVM_CONNECTOR_FACTORY, backupParams);
    livetc = new TransportConfiguration(INVM_CONNECTOR_FACTORY);

    liveAcceptortc = new TransportConfiguration(INVM_ACCEPTOR_FACTORY);

    backupAcceptortc = new TransportConfiguration(INVM_ACCEPTOR_FACTORY, backupParams);

    backupConf = createBasicConfig(0);

    backupConf.getAcceptorConfigurations().add(backupAcceptortc);
    backupConf.getConnectorConfigurations().put(livetc.getName(), livetc);
    backupConf.getConnectorConfigurations().put(backuptc.getName(), backuptc);
    basicClusterConnectionConfig(backupConf, backuptc.getName(), livetc.getName());

    backupConf.setSecurityEnabled(false);
    backupConf.setJournalType(getDefaultJournalType());
    backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    backupConf
        .getAcceptorConfigurations()
        .add(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, backupParams));
    backupConf.setBackup(true);
    backupConf.setSharedStore(true);
    backupConf.setBindingsDirectory(getBindingsDir());
    backupConf.setJournalMinFiles(2);
    backupConf.setJournalDirectory(getJournalDir());
    backupConf.setPagingDirectory(getPageDir());
    backupConf.setLargeMessagesDirectory(getLargeMessagesDir());
    backupConf.setPersistenceEnabled(true);
    backupService = new InVMNodeManagerServer(backupConf, nodeManager);

    backupJMSService = new JMSServerManagerImpl(backupService);

    backupJMSService.setContext(ctx2);

    backupJMSService.getHornetQServer().setIdentity("JMSBackup");
    log.info("Starting backup");
    backupJMSService.start();

    liveConf = createBasicConfig(0);

    liveConf.setJournalDirectory(getJournalDir());
    liveConf.setBindingsDirectory(getBindingsDir());

    liveConf.setSecurityEnabled(false);
    liveConf.getAcceptorConfigurations().add(liveAcceptortc);
    basicClusterConnectionConfig(liveConf, livetc.getName());
    liveConf.setSharedStore(true);
    liveConf.setJournalType(getDefaultJournalType());
    liveConf.setBindingsDirectory(getBindingsDir());
    liveConf.setJournalMinFiles(2);
    liveConf.setJournalDirectory(getJournalDir());
    liveConf.setPagingDirectory(getPageDir());
    liveConf.setLargeMessagesDirectory(getLargeMessagesDir());
    liveConf.getConnectorConfigurations().put(livetc.getName(), livetc);
    liveConf.setPersistenceEnabled(true);
    liveService = new InVMNodeManagerServer(liveConf, nodeManager);

    liveJMSService = new JMSServerManagerImpl(liveService);

    liveJMSService.setContext(ctx1);

    liveJMSService.getHornetQServer().setIdentity("JMSLive");
    log.info("Starting life");

    liveJMSService.start();

    JMSUtil.waitForServer(backupService);
  }