コード例 #1
0
 @After
 public void tearDown() throws Exception {
   if (s2 != null) {
     s2.stop();
   }
   if (s1 != null) {
     s1.stop();
   }
 }
コード例 #2
0
ファイル: JmsHelper.java プロジェクト: gytis/narayana
  public EmbeddedJMS startServer() throws Exception {
    EmbeddedJMS jmsServer = new EmbeddedJMS();
    jmsServer.setConfiguration(getCoreConfiguration());
    jmsServer.setJmsConfiguration(getJmsConfiguration());
    jmsServer.start();

    LOGGER.info("Started embedded JMS server");

    return jmsServer;
  }
コード例 #3
0
  @Before
  public void setUp() throws Exception {

    Configuration config1 = createConfig(1);
    Configuration config2 = createConfig(2);

    deployClusterConfiguration(config1, 2);
    deployClusterConfiguration(config2, 1);

    server1 =
        new EmbeddedJMS().setConfiguration(config1).setJmsConfiguration(new JMSConfigurationImpl());
    server2 =
        new EmbeddedJMS().setConfiguration(config2).setJmsConfiguration(new JMSConfigurationImpl());

    server1.start();
    server2.start();
    Assert.assertTrue(server1.waitClusterForming(100, TimeUnit.MILLISECONDS, 20, 2));
    Assert.assertTrue(server2.waitClusterForming(100, TimeUnit.MILLISECONDS, 20, 2));
  }
コード例 #4
0
  @Before
  public void setUp() throws Exception {

    Configuration config0 = createConfig("127.0.0.1", 0);
    Configuration config1 = createConfig("127.0.0.1", 1);

    deployClusterConfiguration(config0, 1);
    deployClusterConfiguration(config1, 0);

    s1 =
        new EmbeddedJMS().setConfiguration(config0).setJmsConfiguration(new JMSConfigurationImpl());
    s2 =
        new EmbeddedJMS().setConfiguration(config1).setJmsConfiguration(new JMSConfigurationImpl());
    s1.start();
    s2.start();

    Assert.assertTrue(s1.waitClusterForming(100, TimeUnit.MILLISECONDS, 20, 2));
    Assert.assertTrue(s2.waitClusterForming(100, TimeUnit.MILLISECONDS, 20, 2));
  }
コード例 #5
0
 private int getConnectionCount(EmbeddedJMS server) throws Exception {
   ManagementService managementService = server.getActiveMQServer().getManagementService();
   ActiveMQServerControl jmsControl =
       (ActiveMQServerControl) managementService.getResource(ResourceNames.BROKER);
   String[] ids = jmsControl.listConnectionIDs();
   if (ids != null) {
     return ids.length;
   }
   return 0;
 }
コード例 #6
0
  @Test
  public void testNoSuspendedCallbackOnNoReconnect() throws Exception {

    String uriString =
        "failover://(" + newURI(1) + "," + newURI(2) + ")?randomize=false&maxReconnectAttempts=0";

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(uriString);
    final AtomicInteger calls = new AtomicInteger(0);
    connectionFactory.setTransportListener(
        new TransportListener() {
          @Override
          public void onCommand(Object command) {}

          @Override
          public void onException(IOException error) {
            LOG.info("on exception: " + error);
            calls.set(0x01 | calls.intValue());
          }

          @Override
          public void transportInterupted() {
            LOG.info("on transportInterupted");
            calls.set(0x02 | calls.intValue());
          }

          @Override
          public void transportResumed() {
            LOG.info("on transportResumed");
            calls.set(0x04 | calls.intValue());
          }
        });
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue("foo");
    MessageProducer producer = session.createProducer(destination);

    final Message message = session.createTextMessage("TEST");
    producer.send(message);

    // clear listener state
    calls.set(0);

    LOG.info("Stopping the Broker1...");
    server1.stop();

    LOG.info("Attempting to send... failover should throw on disconnect");
    try {
      producer.send(destination, message);
      fail("Expect IOException to bubble up on send");
    } catch (javax.jms.IllegalStateException producerClosed) {
    }

    assertEquals("Only an exception is reported to the listener", 0x1, calls.get());
  }
コード例 #7
0
  @Test
  public void testInitialReconnectDelay() throws Exception {

    String uriString =
        "failover://("
            + newURI(1)
            + ","
            + newURI(2)
            + ")?randomize=false&initialReconnectDelay=15000";

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(uriString);
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue("foo");
    MessageProducer producer = session.createProducer(destination);

    long start = (new Date()).getTime();
    producer.send(session.createTextMessage("TEST"));
    long end = (new Date()).getTime();

    // Verify we can send quickly
    assertTrue((end - start) < 2000);

    // Halt the broker1...
    LOG.info("Stopping the Broker1...");
    start = (new Date()).getTime();
    server1.stop();

    LOG.info("Attempting to send... failover should kick in...");
    producer.send(session.createTextMessage("TEST"));
    end = (new Date()).getTime();

    // Inital reconnection should kick in and be darned close to what we expected
    LOG.info("Failover took " + (end - start) + " ms.");
    assertTrue(
        "Failover took " + (end - start) + " ms and should be > 14000.", (end - start) > 14000);
    connection.close();
  }
コード例 #8
0
 @After
 public void tearDown() throws Exception {
   server1.stop();
   server2.stop();
 }
コード例 #9
0
ファイル: JmsHelper.java プロジェクト: gytis/narayana
  public void stopServer(EmbeddedJMS jmsServer) throws Exception {
    jmsServer.stop();

    LOGGER.info("Stopped embedded JMS server");
  }