Example #1
0
  @Test
  public void testStartWithFailureThenSuccess() throws Exception {
    HornetQJMSConnectionFactory failingSourceCF =
        new HornetQJMSConnectionFactory(
            false, new TransportConfiguration(InVMConnectorFactory.class.getName())) {
          private static final long serialVersionUID = 4657153922210359725L;
          boolean firstTime = true;

          @Override
          public Connection createConnection() throws JMSException {
            if (firstTime) {
              firstTime = false;
              throw new JMSException("unable to create a conn");
            } else {
              return super.createConnection();
            }
          }
        };
    // Note! We disable automatic reconnection on the session factory. The bridge needs to do the
    // reconnection
    failingSourceCF.setReconnectAttempts(0);
    failingSourceCF.setBlockOnNonDurableSend(true);
    failingSourceCF.setBlockOnDurableSend(true);

    ConnectionFactoryFactory sourceCFF =
        JMSBridgeImplTest.newConnectionFactoryFactory(failingSourceCF);
    ConnectionFactoryFactory targetCFF =
        JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
    DestinationFactory sourceDF =
        JMSBridgeImplTest.newDestinationFactory(
            HornetQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
    DestinationFactory targetDF =
        JMSBridgeImplTest.newDestinationFactory(
            HornetQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
    TransactionManager tm = JMSBridgeImplTest.newTransactionManager();

    JMSBridgeImpl bridge = new JMSBridgeImpl();

    bridge.setSourceConnectionFactoryFactory(sourceCFF);
    bridge.setSourceDestinationFactory(sourceDF);
    bridge.setTargetConnectionFactoryFactory(targetCFF);
    bridge.setTargetDestinationFactory(targetDF);
    // retry after 10 ms
    bridge.setFailureRetryInterval(10);
    // retry only once
    bridge.setMaxRetries(1);
    bridge.setMaxBatchSize(1);
    bridge.setMaxBatchTime(-1);
    bridge.setTransactionManager(tm);
    bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);

    Assert.assertFalse(bridge.isStarted());
    bridge.start();

    Thread.sleep(500);
    Assert.assertTrue(bridge.isStarted());
    Assert.assertFalse(bridge.isFailed());

    bridge.stop();
  }
Example #2
0
  @Test
  public void testStartWithRepeatedFailure() throws Exception {
    HornetQJMSConnectionFactory failingSourceCF =
        new HornetQJMSConnectionFactory(
            false, new TransportConfiguration(InVMConnectorFactory.class.getName())) {
          private static final long serialVersionUID = 2834937512213001068L;

          @Override
          public Connection createConnection() throws JMSException {
            throw new JMSException("unable to create a conn");
          }
        };

    ConnectionFactoryFactory sourceCFF =
        JMSBridgeImplTest.newConnectionFactoryFactory(failingSourceCF);
    ConnectionFactoryFactory targetCFF =
        JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
    DestinationFactory sourceDF =
        JMSBridgeImplTest.newDestinationFactory(
            HornetQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
    DestinationFactory targetDF =
        JMSBridgeImplTest.newDestinationFactory(
            HornetQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
    TransactionManager tm = JMSBridgeImplTest.newTransactionManager();

    JMSBridgeImpl bridge = new JMSBridgeImpl();

    bridge.setSourceConnectionFactoryFactory(sourceCFF);
    bridge.setSourceDestinationFactory(sourceDF);
    bridge.setTargetConnectionFactoryFactory(targetCFF);
    bridge.setTargetDestinationFactory(targetDF);
    // retry after 10 ms
    bridge.setFailureRetryInterval(10);
    // retry only once
    bridge.setMaxRetries(1);
    bridge.setMaxBatchSize(1);
    bridge.setMaxBatchTime(-1);
    bridge.setTransactionManager(tm);
    bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);

    Assert.assertFalse(bridge.isStarted());
    bridge.start();

    Thread.sleep(50);
    Assert.assertFalse(bridge.isStarted());
    Assert.assertTrue(bridge.isFailed());

    bridge.stop();
  }