Ejemplo n.º 1
0
  public void testSubscribeToTopic() throws Exception {

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = receiveFrame(100000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame =
        "SUBSCRIBE\n"
            + "destination:"
            + getTopicPrefix()
            + getTopicName()
            + "\n"
            + "receipt: 12\n"
            + "\n\n"
            + Stomp.NULL;
    sendFrame(frame);
    // wait for SUBSCRIBE's receipt
    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("RECEIPT"));

    sendMessage(getName(), topic);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));
    Assert.assertTrue(frame.indexOf("destination:") > 0);
    Assert.assertTrue(frame.indexOf(getName()) > 0);

    frame =
        "UNSUBSCRIBE\n"
            + "destination:"
            + getTopicPrefix()
            + getTopicName()
            + "\n"
            + "receipt: 1234\n"
            + "\n\n"
            + Stomp.NULL;
    sendFrame(frame);
    // wait for UNSUBSCRIBE's receipt
    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("RECEIPT"));

    sendMessage(getName(), topic);

    try {
      frame = receiveFrame(1000);
      log.info("Received frame: " + frame);
      Assert.fail("No message should have been received since subscription was removed");
    } catch (SocketTimeoutException e) {

    }

    frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);
  }
Ejemplo n.º 2
0
  @Test
  public void testAutoFailbackThenFailover() throws Exception {
    createSessionFactory();
    ClientSession session = sendAndConsume(sf, true);

    CountDownSessionFailureListener listener = new CountDownSessionFailureListener();

    session.addFailureListener(listener);

    liveServer.crash(session);

    ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);

    ClientMessage message = session.createMessage(true);

    setBody(0, message);

    producer.send(message);

    session.removeFailureListener(listener);

    listener = new CountDownSessionFailureListener();

    session.addFailureListener(listener);

    log.info("restarting live node now");
    liveServer.start();

    assertTrue("expected a session failure", listener.getLatch().await(5, TimeUnit.SECONDS));

    message = session.createMessage(true);

    setBody(1, message);

    producer.send(message);

    session.removeFailureListener(listener);

    listener = new CountDownSessionFailureListener();

    session.addFailureListener(listener);

    waitForBackup(sf, 10);

    liveServer.crash();

    assertTrue("expected a session failure", listener.getLatch().await(5, TimeUnit.SECONDS));

    session.close();

    wrapUpSessionFactory();
  }
Ejemplo n.º 3
0
  public void testSubscribeToTopicWithNoLocal() throws Exception {

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = receiveFrame(100000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame =
        "SUBSCRIBE\n"
            + "destination:"
            + getTopicPrefix()
            + getTopicName()
            + "\n"
            + "receipt: 12\n"
            + "no-local: true\n"
            + "\n\n"
            + Stomp.NULL;
    sendFrame(frame);
    // wait for SUBSCRIBE's receipt
    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("RECEIPT"));

    // send a message on the same connection => it should not be received
    frame =
        "SEND\n"
            + "destination:"
            + getTopicPrefix()
            + getTopicName()
            + "\n\n"
            + "Hello World"
            + Stomp.NULL;
    sendFrame(frame);

    try {
      frame = receiveFrame(2000);
      log.info("Received frame: " + frame);
      Assert.fail("No message should have been received since subscription is noLocal");
    } catch (SocketTimeoutException e) {
    }

    // send message on another JMS connection => it should be received
    sendMessage(getName(), topic);
    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));
    Assert.assertTrue(frame.indexOf("destination:") > 0);
    Assert.assertTrue(frame.indexOf(getName()) > 0);

    frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);
  }
Ejemplo n.º 4
0
  public void testUnsubscribe() throws Exception {

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);
    frame = receiveFrame(100000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame =
        "SUBSCRIBE\n"
            + "destination:"
            + getQueuePrefix()
            + getQueueName()
            + "\n"
            + "ack:auto\n\n"
            + Stomp.NULL;
    sendFrame(frame);

    // send a message to our queue
    sendMessage("first message");

    // receive message from socket
    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));

    // remove suscription
    frame =
        "UNSUBSCRIBE\n"
            + "destination:"
            + getQueuePrefix()
            + getQueueName()
            + "\n"
            + "receipt:567\n"
            + "\n\n"
            + Stomp.NULL;
    sendFrame(frame);
    waitForReceipt();

    // send a message to our queue
    sendMessage("second message");

    try {
      frame = receiveFrame(1000);
      log.info("Received frame: " + frame);
      Assert.fail("No message should have been received since subscription was removed");
    } catch (SocketTimeoutException e) {

    }
  }
Ejemplo n.º 5
0
  protected void assertSubscribeWithClientAckThenConsumeWithAutoAck(boolean sendDisconnect)
      throws Exception {

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame =
        "SUBSCRIBE\n"
            + "destination:"
            + getQueuePrefix()
            + getQueueName()
            + "\n"
            + "ack:client\n\n"
            + Stomp.NULL;

    sendFrame(frame);
    sendMessage(getName());

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));

    log.info("Reconnecting!");

    if (sendDisconnect) {
      frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
      sendFrame(frame);
      waitForFrameToTakeEffect();
      reconnect();
    } else {
      reconnect(100);
      waitForFrameToTakeEffect();
    }

    // message should be received since message was not acknowledged
    frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame =
        "SUBSCRIBE\n" + "destination:" + getQueuePrefix() + getQueueName() + "\n\n" + Stomp.NULL;

    sendFrame(frame);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));

    frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);
    waitForFrameToTakeEffect();

    // now lets make sure we don't see the message again
    reconnect();

    frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame =
        "SUBSCRIBE\n"
            + "destination:"
            + getQueuePrefix()
            + getQueueName()
            + "\n"
            + "receipt: 1234\n\n"
            + Stomp.NULL;

    sendFrame(frame);
    // wait for SUBSCRIBE's receipt
    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("RECEIPT"));

    sendMessage("shouldBeNextMessage");

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));
    System.out.println(frame);
    Assert.assertTrue(frame.contains("shouldBeNextMessage"));
  }
Ejemplo n.º 6
0
  // HORNETQ-1007
  public void testMultiProtocolConsumers() throws Exception {
    final int TIME_OUT = 100;

    int count = 1000;

    // Create 2 core consumers
    MessageConsumer consumer1 = session.createConsumer(topic);
    MessageConsumer consumer2 = session.createConsumer(topic);

    // connect and subscribe STOMP consumer
    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);
    frame = receiveFrame(TIME_OUT);
    Assert.assertTrue(frame.startsWith("CONNECTED"));
    frame =
        "SUBSCRIBE\n"
            + "destination:"
            + getTopicPrefix()
            + getTopicName()
            + "\n"
            + "receipt: 12\n"
            + "\n\n"
            + Stomp.NULL;
    sendFrame(frame);
    // wait for SUBSCRIBE's receipt
    frame = receiveFrame(TIME_OUT);
    Assert.assertTrue(frame.startsWith("RECEIPT"));

    MessageProducer producer = session.createProducer(topic);
    TextMessage message = session.createTextMessage(getName());

    for (int i = 1; i <= count; i++) {
      producer.send(message);
      Assert.assertNotNull(consumer1.receive(TIME_OUT));
      Assert.assertNotNull(consumer2.receive(TIME_OUT));
      frame = receiveFrame(TIME_OUT);
      Assert.assertTrue(frame.startsWith("MESSAGE"));
      Assert.assertTrue(frame.indexOf("destination:") > 0);
      Assert.assertTrue(frame.indexOf(getName()) > 0);
    }

    consumer1.close();
    consumer2.close();
    frame =
        "UNSUBSCRIBE\n"
            + "destination:"
            + getTopicPrefix()
            + getTopicName()
            + "\n"
            + "receipt: 1234\n"
            + "\n\n"
            + Stomp.NULL;
    sendFrame(frame);
    // wait for UNSUBSCRIBE's receipt
    frame = receiveFrame(TIME_OUT);
    Assert.assertTrue(frame.startsWith("RECEIPT"));

    sendMessage(getName(), topic);

    try {
      frame = receiveFrame(TIME_OUT);
      log.info("Received frame: " + frame);
      Assert.fail("No message should have been received since subscription was removed");
    } catch (SocketTimeoutException e) {

    }

    frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);
  }
Ejemplo n.º 7
0
  public void testClientAckNotPartOfTransaction() throws Exception {

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = receiveFrame(100000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame =
        "SUBSCRIBE\n"
            + "destination:"
            + getQueuePrefix()
            + getQueueName()
            + "\n"
            + "ack:client\n"
            + "\n\n"
            + Stomp.NULL;
    sendFrame(frame);

    sendMessage(getName());

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));
    Assert.assertTrue(frame.indexOf("destination:") > 0);
    Assert.assertTrue(frame.indexOf(getName()) > 0);
    Assert.assertTrue(frame.indexOf("message-id:") > 0);
    Pattern cl = Pattern.compile("message-id:\\s*(\\S+)", Pattern.CASE_INSENSITIVE);
    Matcher cl_matcher = cl.matcher(frame);
    Assert.assertTrue(cl_matcher.find());
    String messageID = cl_matcher.group(1);

    frame = "BEGIN\n" + "transaction: tx1\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame =
        "ACK\n"
            + "message-id:"
            + messageID
            + "\n"
            + "transaction: tx1\n"
            + "\n"
            + "second message"
            + Stomp.NULL;
    sendFrame(frame);

    frame = "ABORT\n" + "transaction: tx1\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);

    try {
      frame = receiveFrame(1000);
      log.info("Received frame: " + frame);
      Assert.fail(
          "No message should have been received as the message was acked even though the transaction has been aborted");
    } catch (SocketTimeoutException e) {
    }

    frame =
        "UNSUBSCRIBE\n" + "destination:" + getQueuePrefix() + getQueueName() + "\n\n" + Stomp.NULL;
    sendFrame(frame);

    frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);
  }
  @Test
  public void testFailLiveNodes() throws Throwable {
    setupCluster();

    startServers(3, 4, 5, 0, 1, 2);
    // startServers(0, 1, 2, 3, 4, 5);

    for (int i = 0; i < 3; i++) {
      waitForTopology(servers[i], 3, 3);
    }

    waitForFailoverTopology(3, 0, 1, 2);
    waitForFailoverTopology(4, 0, 1, 2);
    waitForFailoverTopology(5, 0, 1, 2);

    setupSessionFactory(0, 3, isNetty(), false);
    setupSessionFactory(1, 4, isNetty(), false);
    setupSessionFactory(2, 5, isNetty(), false);

    createQueue(0, QUEUES_TESTADDRESS, QUEUE_NAME, null, true);
    createQueue(1, QUEUES_TESTADDRESS, QUEUE_NAME, null, true);
    createQueue(2, QUEUES_TESTADDRESS, QUEUE_NAME, null, true);

    addConsumer(0, 0, QUEUE_NAME, null);
    waitForBindings(0, QUEUES_TESTADDRESS, 1, 1, true);
    addConsumer(1, 1, QUEUE_NAME, null);
    waitForBindings(1, QUEUES_TESTADDRESS, 1, 1, true);
    addConsumer(2, 2, QUEUE_NAME, null);
    waitForBindings(2, QUEUES_TESTADDRESS, 1, 1, true);

    waitForBindings();

    send(0, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    send(1, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    send(2, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);
    Thread.sleep(1000);
    log.info(
        "######### Topology on client = "
            + locators[0].getTopology().describe()
            + " locator = "
            + locators[0]);
    log.info("######### Crashing it........., sfs[0] = " + sfs[0]);
    failNode(0);

    waitForFailoverTopology(4, 3, 1, 2);
    waitForFailoverTopology(5, 3, 1, 2);

    // live nodes
    waitForBindings(1, QUEUES_TESTADDRESS, 1, 1, true);
    waitForBindings(2, QUEUES_TESTADDRESS, 1, 1, true);
    // activated backup nodes
    waitForBindings(3, QUEUES_TESTADDRESS, 1, 1, true);

    // live nodes
    waitForBindings(1, QUEUES_TESTADDRESS, 2, 2, false);
    waitForBindings(2, QUEUES_TESTADDRESS, 2, 2, false);
    // activated backup nodes
    waitForBindings(3, QUEUES_TESTADDRESS, 2, 2, false);

    ClusterWithBackupFailoverTestBase.log.info("** now sending");

    send(0, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    send(1, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    send(2, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    failNode(1);

    waitForFailoverTopology(5, 3, 4, 2);

    Thread.sleep(1000);
    // live nodes
    waitForBindings(2, QUEUES_TESTADDRESS, 1, 1, true);
    // activated backup nodes
    waitForBindings(3, QUEUES_TESTADDRESS, 1, 1, true);
    waitForBindings(4, QUEUES_TESTADDRESS, 1, 1, true);

    // live nodes
    waitForBindings(2, QUEUES_TESTADDRESS, 2, 2, false);
    // activated backup nodes
    waitForBindings(3, QUEUES_TESTADDRESS, 2, 2, false);
    waitForBindings(4, QUEUES_TESTADDRESS, 2, 2, false);

    send(0, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    send(1, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    send(2, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    failNode(2);

    Thread.sleep(1000);
    // activated backup nodes
    waitForBindings(3, QUEUES_TESTADDRESS, 1, 1, true);
    waitForBindings(4, QUEUES_TESTADDRESS, 1, 1, true);
    waitForBindings(5, QUEUES_TESTADDRESS, 1, 1, true);

    // activated backup nodes
    waitForBindings(3, QUEUES_TESTADDRESS, 2, 2, false);
    waitForBindings(4, QUEUES_TESTADDRESS, 2, 2, false);
    waitForBindings(5, QUEUES_TESTADDRESS, 2, 2, false);

    send(0, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    send(1, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    send(2, QUEUES_TESTADDRESS, 10, false, null);
    verifyReceiveRoundRobinInSomeOrder(true, 10, 0, 1, 2);

    removeConsumer(0);
    removeConsumer(1);
    removeConsumer(2);
  }
Ejemplo n.º 9
0
  @Test
  public void testDelayedRedeliveryDefaultOnClose() throws Exception {
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(false, false, false);

    session.createQueue(qName, qName, null, true);
    session.close();

    ClientSession session1 = sessionFactory.createSession(false, true, true);
    ClientProducer producer = session1.createProducer(qName);

    final int NUM_MESSAGES = 5;

    UnitTestCase.forceGC();

    for (int i = 0; i < NUM_MESSAGES; i++) {
      ClientMessage tm = createDurableMessage(session1, "message" + i);
      producer.send(tm);
    }

    session1.close();

    ClientSession session2 = sessionFactory.createSession(false, false, false);

    ClientConsumer consumer2 = session2.createConsumer(qName);
    session2.start();

    for (int i = 0; i < NUM_MESSAGES; i++) {
      ClientMessage tm = consumer2.receive(500);

      tm.acknowledge();

      Assert.assertNotNull(tm);

      Assert.assertEquals("message" + i, tm.getBodyBuffer().readString());
    }

    // Now close the session
    // This should cancel back to the queue with a delayed redelivery

    long now = System.currentTimeMillis();

    session2.close();

    ClientSession session3 = sessionFactory.createSession(false, false, false);

    ClientConsumer consumer3 = session3.createConsumer(qName);
    session3.start();
    for (int i = 0; i < NUM_MESSAGES; i++) {
      ClientMessage tm = consumer3.receive(DelayedMessageTest.DELAY + 1000);

      Assert.assertNotNull(tm);

      long time = System.currentTimeMillis();

      log.info("delay " + (time - now));

      Assert.assertTrue(time - now >= DelayedMessageTest.DELAY);

      // Hudson can introduce a large degree of indeterminism
      Assert.assertTrue(
          time - now + ">" + (DelayedMessageTest.DELAY + 1000),
          time - now < DelayedMessageTest.DELAY + 1000);
    }

    session3.commit();
    session3.close();
  }
Ejemplo n.º 10
0
  public void testRestartWithQueuesCreateInDiffOrder() throws Exception {
    setupServer(0, isFileStorage(), isNetty());
    setupServer(1, isFileStorage(), isNetty());

    setupClusterConnection("cluster0", "queues", false, 1, isNetty(), 0, 1);

    setupClusterConnection("cluster1", "queues", false, 1, isNetty(), 1, 0);

    startServers(0, 1);

    System.out.println("server 0 = " + getServer(0).getNodeID());
    System.out.println("server 1 = " + getServer(1).getNodeID());

    setupSessionFactory(0, isNetty(), -1);
    setupSessionFactory(1, isNetty());

    // create some dummy queues to ensure that the test queue has a high numbered binding
    createQueue(0, "queues.testaddress2", "queue0", null, false);
    createQueue(0, "queues.testaddress2", "queue1", null, false);
    createQueue(0, "queues.testaddress2", "queue2", null, false);
    createQueue(0, "queues.testaddress2", "queue3", null, false);
    createQueue(0, "queues.testaddress2", "queue4", null, false);
    createQueue(0, "queues.testaddress2", "queue5", null, false);
    createQueue(0, "queues.testaddress2", "queue6", null, false);
    createQueue(0, "queues.testaddress2", "queue7", null, false);
    createQueue(0, "queues.testaddress2", "queue8", null, false);
    createQueue(0, "queues.testaddress2", "queue9", null, false);
    // now create the 2 queues and make sure they are durable
    createQueue(0, "queues.testaddress", "queue10", null, true);
    createQueue(1, "queues.testaddress", "queue10", null, true);

    addConsumer(0, 0, "queue10", null);

    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);

    waitForBindings(0, "queues.testaddress", 1, 0, false);
    waitForBindings(1, "queues.testaddress", 1, 1, false);

    printBindings(2);

    sendInRange(1, "queues.testaddress", 0, 10, true, null);

    log.info("stopping******************************************************");
    stopServers(0);
    // Waiting some time after stopped
    Thread.sleep(2000);
    startServers(0);

    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 0, true);

    waitForBindings(0, "queues.testaddress", 1, 0, false);
    waitForBindings(1, "queues.testaddress", 1, 1, false);

    printBindings(2);

    sendInRange(1, "queues.testaddress", 10, 20, false, null);

    verifyReceiveAllInRange(0, 20, 0);
    System.out.println(
        "*****************************************************************************");
  }
Ejemplo n.º 11
0
  @Test
  public void testAutoFailback() throws Exception {
    createSessionFactory();
    final CountDownLatch latch = new CountDownLatch(1);

    ClientSession session = sendAndConsume(sf, true);

    CountDownSessionFailureListener listener = new CountDownSessionFailureListener(latch);

    session.addFailureListener(listener);

    liveServer.crash();

    assertTrue(latch.await(5, TimeUnit.SECONDS));

    log.info(
        "backup (nowLive) topology = "
            + backupServer
                .getServer()
                .getClusterManager()
                .getDefaultConnection(null)
                .getTopology()
                .describe());

    log.info("Server Crash!!!");

    ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);

    ClientMessage message = session.createMessage(true);

    setBody(0, message);

    producer.send(message);

    verifyMessageOnServer(1, 1);

    session.removeFailureListener(listener);

    final CountDownLatch latch2 = new CountDownLatch(1);

    listener = new CountDownSessionFailureListener(latch2);

    session.addFailureListener(listener);

    log.info("******* starting live server back");
    liveServer.start();

    Thread.sleep(1000);

    System.out.println("After failback: " + locator.getTopology().describe());

    assertTrue(latch2.await(5, TimeUnit.SECONDS));

    message = session.createMessage(true);

    setBody(1, message);

    producer.send(message);

    session.close();

    verifyMessageOnServer(0, 1);

    wrapUpSessionFactory();
  }
Ejemplo n.º 12
0
  public void testSimpleBroadcastSpecificNIC() throws Exception {
    final InetAddress groupAddress = InetAddress.getByName(address1);
    final int groupPort = getUDPDiscoveryPort();
    final int timeout = 500;

    final String nodeID = RandomUtil.randomString();

    // We need to choose a real NIC on the local machine - note this will silently pass if the
    // machine
    // has no usable NIC!

    Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();

    InetAddress localAddress = null;

    outer:
    while (networkInterfaces.hasMoreElements()) {
      NetworkInterface networkInterface = networkInterfaces.nextElement();
      if (networkInterface.isLoopback()
          || networkInterface.isVirtual()
          || !networkInterface.isUp()
          || !networkInterface.supportsMulticast()) {
        continue;
      }

      Enumeration<InetAddress> en = networkInterface.getInetAddresses();

      while (en.hasMoreElements()) {
        InetAddress ia = en.nextElement();

        if (ia.getAddress().length == 4) {
          localAddress = ia;

          break outer;
        }
      }
    }

    if (localAddress == null) {
      log.warn("Can't find address to use");

      return;
    }

    log.info("Local address is " + localAddress);

    bg =
        newBroadcast(
            nodeID, RandomUtil.randomString(), localAddress, 6552, groupAddress, groupPort);

    bg.start();

    TransportConfiguration live1 = generateTC();

    bg.addConnector(live1);

    dg =
        newDiscoveryGroup(
            RandomUtil.randomString(),
            RandomUtil.randomString(),
            localAddress,
            groupAddress,
            groupPort,
            timeout);

    dg.start();

    verifyBroadcast(bg, dg);

    List<DiscoveryEntry> entries = dg.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);
  }
Ejemplo n.º 13
0
 public void failoverEvent(FailoverEventType eventType) {
   eventTypeList.add(eventType);
   log.info("Failover event just happened : " + eventType.toString());
 }
Ejemplo n.º 14
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);
  }