Ejemplo n.º 1
0
  private void sendKillTwoAndReceive(ClusterNode node1, ClusterNode node2, ClusterNode node3) {

    log.info("Sending messages on node 1");
    HazelcastMQProducer mqProducer = node1.getMqContext().createProducer();
    mqProducer.send(destination, "Hello " + msgCounter++);
    mqProducer.send(destination, "Hello " + msgCounter++);

    // Kill the first two nodes. Again, this may not prove too much because we
    // don't know where the original data landed in the cluster. There's a
    // chance the "master" data isn't sitting on node1 or node2 anyway.
    log.info("Killing node 1");
    node1.kill();

    log.info("Killing node 2");
    node2.kill();

    log.info("Attempting receive from node 3");
    HazelcastMQConsumer mqConsumer = node3.getMqContext().createConsumer(destination);
    String msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 3: " + msg);
    mqConsumer.close();

    mqConsumer = node3.getMqContext().createConsumer(destination);
    msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 3: " + msg);
    mqConsumer.close();
  }
Ejemplo n.º 2
0
  private void sendAndReceiveOnMultipleNodes(
      ClusterNode node1, ClusterNode node2, ClusterNode node3) {

    HazelcastMQProducer mqProducer = node1.getMqContext().createProducer();
    mqProducer.send(destination, "Hello " + msgCounter++);
    mqProducer.send(destination, "Hello " + msgCounter++);
    mqProducer.send(destination, "Hello " + msgCounter++);
    mqProducer.send(destination, "Hello " + msgCounter++);

    HazelcastMQConsumer mqConsumer = node2.getMqContext().createConsumer(destination);
    String msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 2: " + msg);
    mqConsumer.close();

    mqConsumer = node1.getMqContext().createConsumer(destination);
    msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 1: " + msg);
    mqConsumer.close();

    mqConsumer = node3.getMqContext().createConsumer(destination);
    msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 3: " + msg);
    mqConsumer.close();

    mqConsumer = node2.getMqContext().createConsumer(destination);
    msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 2: " + msg);
    mqConsumer.close();
  }
Ejemplo n.º 3
0
  private void sendKillTwoRestartOneKillOneAndReceive(
      ClusterNode node1, ClusterNode node2, ClusterNode node3) throws InterruptedException {

    HazelcastMQProducer mqProducer = node1.getMqContext().createProducer();
    mqProducer.send(destination, "Hello " + msgCounter++);
    mqProducer.send(destination, "Hello " + msgCounter++);

    // Kill the first two nodes. Again, this may not prove too much because we
    // don't know where the original data landed in the cluster. There's a
    // chance the "master" data isn't sitting on node1 or node2 anyway.
    node1.kill();
    node2.kill();

    HazelcastMQConsumer mqConsumer = node3.getMqContext().createConsumer(destination);
    String msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 3: " + msg);
    mqConsumer.close();

    // Now restart node 2 and give it some time to join the cluster and migrate
    // data.
    node2.restart();
    Thread.sleep(10000);

    // Now kill node 3. In theory the remaining queued message should have
    // migrated to node 2.
    node3.kill();

    mqConsumer = node2.getMqContext().createConsumer(destination);
    msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 2: " + msg);
    mqConsumer.close();
  }
Ejemplo n.º 4
0
  private void sendKillAndReceiveOnMultipleNodes(
      ClusterNode node1, ClusterNode node2, ClusterNode node3) {

    HazelcastMQProducer mqProducer = node1.getMqContext().createProducer();
    mqProducer.send(destination, "Hello " + msgCounter++);
    mqProducer.send(destination, "Hello " + msgCounter++);

    // Kill the node. This doesn't prove too much because we don't know where
    // the original data landed in the cluster. There's a good chance the
    // "master" data isn't sitting on node1 anyway.
    node1.kill();

    HazelcastMQConsumer mqConsumer = node2.getMqContext().createConsumer(destination);
    String msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 2: " + msg);
    mqConsumer.close();

    mqConsumer = node3.getMqContext().createConsumer(destination);
    msg = new String(mqConsumer.receiveBody(1, TimeUnit.SECONDS));
    log.info("Got message on node 3: " + msg);
    mqConsumer.close();
  }