Exemplo n.º 1
0
  public void sendMessages(final int start, final int end) throws Exception {
    ClientSession session = null;
    try {

      session = factory.createSession(false, false);

      try {
        session.createQueue(QUEUE, QUEUE, true);
      } catch (Exception ignored) {
      }

      ClientProducer prod = session.createProducer(QUEUE);

      for (int i = start; i < end; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty(new SimpleString("key"), i);
        msg.getBodyBuffer().writeUTF("message " + i);
        prod.send(msg);
      }

      session.commit();
      session.close();
      // server.stop(); -- this test was not supposed to stop the server, it should crash
    } finally {
      session.close();
    }
  }
Exemplo n.º 2
0
  @Override
  @After
  public void tearDown() throws Exception {
    if (clientSession != null) {
      try {
        clientSession.close();
      } catch (HornetQException e1) {
        //
      }
    }
    if (clientSessionXa != null) {
      try {
        clientSessionXa.close();
      } catch (HornetQException e1) {
        //
      }
    }
    if (locator != null) {
      locator.close();
    }
    if (server != null && server.isStarted()) {
      try {
        server.stop();
      } catch (Exception e1) {
        //
      }
    }
    server = null;
    clientSession = null;

    super.tearDown();
  }
Exemplo n.º 3
0
  public void testRestartJournal() throws Throwable {
    runExternalProcess(0, JournalCrashTest.FIRST_RUN);
    runExternalProcess(JournalCrashTest.FIRST_RUN, JournalCrashTest.SECOND_RUN);
    runExternalProcess(JournalCrashTest.SECOND_RUN, JournalCrashTest.THIRD_RUN);
    runExternalProcess(JournalCrashTest.THIRD_RUN, JournalCrashTest.FOURTH_RUN);

    printJournal();

    ClientSession session = null;
    try {
      startServer();

      session = factory.createSession(true, true);
      ClientConsumer consumer = session.createConsumer(QUEUE);
      session.start();

      for (int i = 0; i < JournalCrashTest.FOURTH_RUN; i++) {
        ClientMessage msg = consumer.receive(5000);

        Assert.assertNotNull("Msg at " + i, msg);

        msg.acknowledge();

        Assert.assertEquals(i, msg.getObjectProperty(new SimpleString("key")));
      }
      session.close();
    } finally {
      try {
        session.close();
      } catch (Throwable ignored) {
      }
    }
  }
Exemplo n.º 4
0
  @Test
  public void testDelayedRedeliveryDefaultOnRollback() 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;

    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);
      Assert.assertNotNull(tm);
      Assert.assertEquals("message" + i, tm.getBodyBuffer().readString());
    }

    // Now rollback
    long now = System.currentTimeMillis();

    session2.rollback();

    // This should redeliver with a delayed redelivery

    for (int i = 0; i < NUM_MESSAGES; i++) {
      ClientMessage tm = consumer2.receive(DelayedMessageTest.DELAY + 1000);
      Assert.assertNotNull(tm);

      long time = System.currentTimeMillis();

      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);
    }

    session2.commit();
    session2.close();
  }
Exemplo n.º 5
0
  public void testAcksWithSmallSendWindow() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = sf.createSession(false, true, true);

    session.createQueue(QUEUE, QUEUE, null, false);

    ClientProducer producer = session.createProducer(QUEUE);

    final int numMessages = 10000;

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = createTextMessage(session, "m" + i);
      producer.send(message);
    }
    session.close();
    sf.close();
    final CountDownLatch latch = new CountDownLatch(numMessages);
    server
        .getRemotingService()
        .addInterceptor(
            new Interceptor() {
              public boolean intercept(final Packet packet, final RemotingConnection connection)
                  throws HornetQException {
                if (packet.getType() == PacketImpl.SESS_ACKNOWLEDGE) {
                  latch.countDown();
                }
                return true;
              }
            });
    ServerLocator locator = createInVMNonHALocator();
    locator.setConfirmationWindowSize(100);
    locator.setAckBatchSize(-1);
    ClientSessionFactory sfReceive = createSessionFactory(locator);
    ClientSession sessionRec = sfReceive.createSession(false, true, true);
    ClientConsumer consumer = sessionRec.createConsumer(QUEUE);
    consumer.setMessageHandler(
        new MessageHandler() {
          public void onMessage(final ClientMessage message) {
            try {
              message.acknowledge();
            } catch (HornetQException e) {
              e.printStackTrace();
            }
          }
        });
    sessionRec.start();
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    sessionRec.close();
    locator.close();
  }
Exemplo n.º 6
0
      @Override
      public void run() {
        ClientSession session = null;
        latchReady.countDown();
        try {
          UnitTestCase.waitForLatch(latchStart);
          session = sf.createSession(true, true);
          session.start();
          ClientConsumer cons = session.createConsumer(CompactingStressTest.Q2);
          for (int i = 0; i < NUMBER_OF_FAST_MESSAGES; i++) {
            ClientMessage msg = cons.receive(60 * 1000);
            msg.acknowledge();
          }

          Assert.assertNull(cons.receiveImmediate());
        } catch (Throwable e) {
          this.e = e;
        } finally {
          try {
            session.close();
          } catch (Throwable e) {
            this.e = e;
          }
        }
      }
  /**
   * Remove any old message queues that have a 0 message count in them. This lets us not worry about
   * changing around the registered listeners.
   */
  private void cleanupOldQueues() {
    log.debug("Cleaning old message queues");
    try {
      String[] queues = hornetqServer.getHornetQServer().getHornetQServerControl().getQueueNames();

      ServerLocator locator =
          HornetQClient.createServerLocatorWithoutHA(
              new TransportConfiguration(InVMConnectorFactory.class.getName()));

      ClientSessionFactory factory = locator.createSessionFactory();
      ClientSession session = factory.createSession(true, true);
      session.start();

      for (int i = 0; i < queues.length; i++) {
        long msgCount = session.queueQuery(new SimpleString(queues[i])).getMessageCount();
        if (msgCount == 0) {
          log.debug(String.format("found queue '%s' with 0 messages. deleting", queues[i]));
          session.deleteQueue(queues[i]);
        } else {
          log.debug(String.format("found queue '%s' with %d messages. kept", queues[i], msgCount));
        }
      }

      session.stop();
      session.close();
    } catch (HornetQException e) {
      log.error("Problem cleaning old message queues:", e);
      throw new RuntimeException(e);
    } catch (Exception e) {
      log.error("Problem cleaning old message queues:", e);
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 8
0
  public void testConsumerAckImmediateAutoCommitFalse() throws Exception {

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = sf.createSession(false, true, false, true);

    session.createQueue(QUEUE, QUEUE, null, false);

    ClientProducer producer = session.createProducer(QUEUE);

    final int numMessages = 100;

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = createTextMessage(session, "m" + i);
      producer.send(message);
    }

    ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();
    for (int i = 0; i < numMessages; i++) {
      ClientMessage message2 = consumer.receive(1000);

      Assert.assertEquals("m" + i, message2.getBodyBuffer().readString());
    }
    // assert that all the messages are there and none have been acked
    Assert.assertEquals(
        0, ((Queue) server.getPostOffice().getBinding(QUEUE).getBindable()).getDeliveringCount());
    Assert.assertEquals(
        0, ((Queue) server.getPostOffice().getBinding(QUEUE).getBindable()).getMessageCount());

    session.close();
  }
Exemplo n.º 9
0
  public void testNoReceiveWithListener() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = sf.createSession(false, true, true);

    session.createQueue(QUEUE, QUEUE, null, false);

    ClientConsumer consumer = session.createConsumer(QUEUE);

    consumer.setMessageHandler(
        new MessageHandler() {
          public void onMessage(final ClientMessage msg) {}
        });

    try {
      consumer.receiveImmediate();
      Assert.fail("Should throw exception");
    } catch (HornetQIllegalStateException ise) {
      // ok
    } catch (HornetQException me) {
      Assert.fail("Wrong exception code");
    }

    session.close();
  }
Exemplo n.º 10
0
  // https://jira.jboss.org/browse/HORNETQ-410
  public void testConsumeWithNoConsumerFlowControl() throws Exception {

    ServerLocator locator = createInVMNonHALocator();

    locator.setConsumerWindowSize(-1);

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = sf.createSession(false, true, true);

    session.createQueue(QUEUE, QUEUE, null, false);

    session.start();

    ClientProducer producer = session.createProducer(QUEUE);

    final int numMessages = 100;

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = createTextMessage(session, "m" + i);
      producer.send(message);
    }

    ClientConsumer consumer = session.createConsumer(QUEUE);

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = consumer.receive(10000);
      assertNotNull(message);
      message.acknowledge();
    }

    session.close();
    sf.close();
    locator.close();
  }
Exemplo n.º 11
0
  private void drainQueue() throws Exception {
    PerfBase.log.info("Draining queue");

    ClientSession session = null;

    try {
      session = factory.createSession();

      ClientConsumer consumer = session.createConsumer(perfParams.getQueueName());

      session.start();

      ClientMessage message = null;

      int count = 0;
      do {
        message = consumer.receive(3000);

        if (message != null) {
          message.acknowledge();

          count++;
        }
      } while (message != null);

      PerfBase.log.info("Drained " + count + " messages");
    } finally {
      if (session != null) {
        session.close();
      }
    }
  }
Exemplo n.º 12
0
  @Test
  public void testGetNumberOfBytesPerPage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createQueue(address, address, true);

    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(
        HornetQDefaultConfiguration.getDefaultJournalFileSize(),
        addressControl.getNumberOfBytesPerPage());

    session.close();
    server.stop();

    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setPageSizeBytes(1024);

    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    server.start();
    ServerLocator locator2 =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
    addServerLocator(locator2);
    ClientSessionFactory sf2 = createSessionFactory(locator2);

    session = sf2.createSession(false, true, false);
    session.createQueue(address, address, true);
    Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage());
  }
Exemplo n.º 13
0
    @Override
    public void run() {
      locator.setReconnectAttempts(0);

      final ClientSessionFactory sessionFactory;
      ClientSession session;
      try {
        sessionFactory = locator.createSessionFactory(tc);
        if (sessionFactory != null) {
          session = sessionFactory.createSession();
          if (session != null) {
            if (nodeIsDown(total, count.incrementAndGet())) {
              while (latch.getCount() > 0) latch.countDown();
            }
            session.close();
            sessionFactory.close();
          }
        }
      } catch (Exception e) {
        // no-op
      } finally {
        latch.countDown();
        locator.close();
      }
    }
  @Test
  public void testSimpleMessageReceivedOnQueueManyMessages() throws Exception {
    HornetQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    HornetQActivationSpec spec = new HornetQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(15);
    MultipleEndpoints endpoint = new MultipleEndpoints(latch, false);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    for (int i = 0; i < 15; i++) {
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("teststring" + i);
      clientProducer.send(message);
    }
    session.close();
    latch.await(5, TimeUnit.SECONDS);

    qResourceAdapter.endpointDeactivation(endpointFactory, spec);

    qResourceAdapter.stop();
  }
Exemplo n.º 15
0
 public void testProducerWithSmallWindowSizeAndLargeMessage() throws Exception {
   final CountDownLatch latch = new CountDownLatch(1);
   server
       .getRemotingService()
       .addInterceptor(
           new Interceptor() {
             public boolean intercept(final Packet packet, final RemotingConnection connection)
                 throws HornetQException {
               if (packet.getType() == PacketImpl.SESS_SEND) {
                 latch.countDown();
               }
               return true;
             }
           });
   ServerLocator locator = createInVMNonHALocator();
   locator.setConfirmationWindowSize(100);
   ClientSessionFactory cf = locator.createSessionFactory();
   ClientSession session = cf.createSession(false, true, true);
   ClientProducer producer = session.createProducer(QUEUE);
   ClientMessage message = session.createMessage(true);
   byte[] body = new byte[1000];
   message.getBodyBuffer().writeBytes(body);
   producer.send(message);
   Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
   session.close();
   locator.close();
 }
Exemplo n.º 16
0
  /**
   * Setup the activation
   *
   * @throws Exception Thrown if an error occurs
   */
  protected synchronized void setup() throws Exception {
    HornetQRALogger.LOGGER.debug("Setting up " + spec);

    setupCF();

    setupDestination();
    for (int i = 0; i < spec.getMaxSession(); i++) {
      ClientSession session = null;

      try {
        ClientSessionFactory cf = factory.getServerLocator().createSessionFactory();
        session = setupSession(cf);
        HornetQMessageHandler handler =
            new HornetQMessageHandler(this, ra.getTM(), (ClientSessionInternal) session, cf, i);
        handler.setup();
        session.start();
        handlers.add(handler);
      } catch (Exception e) {
        if (session != null) {
          session.close();
        }

        throw e;
      }
    }

    resourceRecovery =
        ra.getRecoveryManager().register(factory, spec.getUser(), spec.getPassword());

    HornetQRALogger.LOGGER.debug("Setup complete " + this);
  }
  @Test
  public void testXACommit() throws Exception {
    HornetQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    HornetQActivationSpec spec = new HornetQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    XADummyEndpoint endpoint = new XADummyEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);

    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    endpoint.prepare();
    endpoint.commit();
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
  }
Exemplo n.º 18
0
  /** Cleans up all resources that are still in use. */
  public synchronized void close() {
    for (ClientConsumer consumer : dataConsumers) {
      try {
        consumer.close();
      } catch (HornetQException e) {
        // ignore exception
      }
    }

    dataConsumers.clear();

    try {
      if (session != null) {
        session.close();
      }
    } catch (Exception e) {
      // ignore exception
    } finally {
      if (sessionFactory != null) {
        sessionFactory.close();
      }
      if (locator != null) {
        locator.close();
      }
    }

    for (ConnectionListener cl : connectionListeners) {
      cl.disconnected();
    }
  }
 @Override
 public void close() {
   try {
     session.rollback();
     session.close();
   } catch (Exception ignored) {
   }
 }
Exemplo n.º 20
0
  @Test
  public void testLargeMessageCompression2() throws Exception {
    final int messageSize = (int) (3.5 * HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);

    HornetQServer server = createServer(true, isNetty());

    server.start();

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = addClientSession(sf.createSession(false, false, false));

    session.createTemporaryQueue(ADDRESS, ADDRESS);

    ClientProducer producer = session.createProducer(ADDRESS);

    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);

    producer.send(clientFile);

    session.commit();

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);

    String testDir = getTestDir();
    File testFile = new File(testDir, "async_large_message");
    FileOutputStream output = new FileOutputStream(testFile);

    msg1.setOutputStream(output);

    msg1.waitOutputStreamCompletion(0);

    msg1.acknowledge();

    output.close();

    session.commit();

    consumer.close();

    session.close();

    // verify
    FileInputStream input = new FileInputStream(testFile);
    for (int i = 0; i < messageSize; i++) {
      byte b = (byte) input.read();
      assertEquals("position = " + i, getSamplebyte(i), b);
    }
    input.close();
    testFile.delete();
    validateNoFilesOnLargeDir();
  }
Exemplo n.º 21
0
  public void close() throws HornetQException {
    try {
      if (session != null) session.close();
    } finally {
      if (sessionFactory != null) sessionFactory.close();
      if (locator != null) locator.close();
    }
    /*sessionList.remove(this);*/

  }
Exemplo n.º 22
0
  public void disconnect() {
    try {
      if (session != null) {
        session.close();
      }
    } catch (Exception ignored) {
      ignored.printStackTrace();
    }

    session = null;
  }
Exemplo n.º 23
0
  @Test
  public void testSendPacketsWithFailure() throws Exception {
    final int nMsg = 100;
    final int stop = 37;
    setupServer(true, TestInterceptor.class.getName());

    manager = liveServer.getReplicationManager();
    waitForComponent(manager);
    ClientSessionFactory sf = createSessionFactory(locator);
    final ClientSession session = sf.createSession();
    final ClientSession session2 = sf.createSession();
    session.createQueue(ADDRESS, ADDRESS, null, true);

    final ClientProducer producer = session.createProducer(ADDRESS);

    session.start();
    session2.start();
    try {
      final ClientConsumer consumer = session2.createConsumer(ADDRESS);
      for (int i = 0; i < nMsg; i++) {

        ClientMessage message = session.createMessage(true);
        setBody(i, message);
        message.putIntProperty("counter", i);
        producer.send(message);
        if (i == stop) {
          // Now we start intercepting the communication with the backup
          TestInterceptor.value.set(false);
        }
        ClientMessage msgRcvd = consumer.receive(1000);
        Assert.assertNotNull("Message should exist!", msgRcvd);
        assertMessageBody(i, msgRcvd);
        Assert.assertEquals(i, msgRcvd.getIntProperty("counter").intValue());
        msgRcvd.acknowledge();
      }
    } finally {
      TestInterceptor.value.set(false);
      if (!session.isClosed()) session.close();
      if (!session2.isClosed()) session2.close();
    }
  }
  @Test
  public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
    ClientSession session = addClientSession(sf.createSession());

    session.createQueue("fooaddress", "fooqueue");

    ClientProducer prod = session.createProducer("fooaddress");

    ClientConsumer cons = session.createConsumer("fooqueue");

    session.start();

    prod.send(session.createMessage(false));

    Assert.assertNotNull(cons.receive());

    // Now fail the underlying connection

    RemotingConnection connection = ((ClientSessionInternal) session).getConnection();

    connection.fail(new HornetQNotConnectedException());

    Assert.assertTrue(session.isClosed());

    Assert.assertTrue(prod.isClosed());

    Assert.assertTrue(cons.isClosed());

    // Now try and use the producer

    try {
      prod.send(session.createMessage(false));

      Assert.fail("Should throw exception");
    } catch (HornetQObjectClosedException oce) {
      // ok
    } catch (HornetQException e) {
      fail("Invalid Exception type:" + e.getType());
    }

    try {
      cons.receive();

      Assert.fail("Should throw exception");
    } catch (HornetQObjectClosedException oce) {
      // ok
    } catch (HornetQException e) {
      fail("Invalid Exception type:" + e.getType());
    }

    session.close();
  }
Exemplo n.º 25
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();
  }
Exemplo n.º 26
0
  @Test
  public void testMultipleMessagesAfterRecovery() throws Exception {
    Xid xid = new XidImpl("bq1".getBytes(), 4, "gtid1".getBytes());
    ClientProducer producer = clientSessionXa.createProducer(address);
    SimpleString messageId1 = new SimpleString("SMID1");
    SimpleString messageId2 = new SimpleString("SMID2");
    clientSessionXa.start(xid, XAResource.TMNOFLAGS);
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId2);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId2);
    producer.send(m1);
    producer.send(m2);
    producer.send(m3);
    producer.send(m4);
    clientSessionXa.end(xid, XAResource.TMSUCCESS);
    clientSessionXa.prepare(xid);

    clientSession.close();
    clientSessionXa.close();
    restartServer();

    clientSessionXa.commit(xid, false);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    clientSession.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
  }
Exemplo n.º 27
0
      @Override
      public void run() {
        ClientSession session = null;
        ClientSession sessionSlow = null;
        latchReady.countDown();
        try {
          UnitTestCase.waitForLatch(latchStart);
          session = sf.createSession(true, true);
          sessionSlow = sf.createSession(false, false);
          ClientProducer prod = session.createProducer(CompactingStressTest.AD2);
          ClientProducer slowProd = sessionSlow.createProducer(CompactingStressTest.AD1);
          for (int i = 0; i < NUMBER_OF_FAST_MESSAGES; i++) {
            if (i % SLOW_INTERVAL == 0) {
              if (numberOfMessages.incrementAndGet() % 5 == 0) {
                sessionSlow.commit();
              }
              slowProd.send(session.createMessage(true));
            }
            ClientMessage msg = session.createMessage(true);

            prod.send(msg);
          }
          sessionSlow.commit();
        } catch (Throwable e) {
          this.e = e;
        } finally {
          try {
            session.close();
          } catch (Throwable e) {
            this.e = e;
          }
          try {
            sessionSlow.close();
          } catch (Throwable e) {
            this.e = e;
          }
        }
      }
Exemplo n.º 28
0
  public void testConnection(
      final String acceptorHost, final String connectorHost, final boolean mustConnect)
      throws Exception {
    System.out.println(
        "acceptor="
            + acceptorHost
            + ", connector="
            + connectorHost
            + ", mustConnect="
            + mustConnect);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(getHostPropertyKey(), acceptorHost);
    TransportConfiguration acceptorConfig =
        new TransportConfiguration(getAcceptorFactoryClassName(), params);
    Set<TransportConfiguration> transportConfigs = new HashSet<TransportConfiguration>();
    transportConfigs.add(acceptorConfig);

    Configuration config = createDefaultConfig(true);
    config.setAcceptorConfigurations(transportConfigs);
    HornetQServer messagingService = createServer(false, config);
    messagingService.start();

    params = new HashMap<String, Object>();
    params.put(getHostPropertyKey(), connectorHost);
    TransportConfiguration connectorConfig =
        new TransportConfiguration(getConnectorFactoryClassName(), params);

    try {
      ClientSessionFactory sf = HornetQClient.createClientSessionFactory(connectorConfig);

      if (mustConnect) {
        ClientSession session = sf.createSession(false, true, true);
        session.close();
        System.out.println("connection OK");
      } else {
        try {
          sf.createSession(false, true, true);
          Assert.fail(
              "session creation must fail because connector must not be able to connect to the server bound to another network interface");
        } catch (Exception e) {
        }
      }
    } finally {
      if (messagingService != null) {
        messagingService.stop();
      }
    }
  }
Exemplo n.º 29
0
  // https://jira.jboss.org/jira/browse/HORNETQ-111
  // Test that, on rollback credits are released for messages cleared in the buffer
  public void testConsumerCreditsOnRollbackLargeMessages() throws Exception {

    locator.setConsumerWindowSize(10000);
    locator.setMinLargeMessageSize(1000);

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = sf.createTransactedSession();

    session.createQueue(QUEUE, QUEUE, null, false);

    ClientProducer producer = session.createProducer(QUEUE);

    final int numMessages = 100;

    final byte[] bytes = new byte[10000];

    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = session.createMessage(false);

      message.getBodyBuffer().writeBytes(bytes);

      message.putIntProperty("count", i);

      producer.send(message);
    }

    session.commit();

    ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();

    for (int i = 0; i < 110; i++) {
      ClientMessage message = consumer.receive();

      int count = message.getIntProperty("count");

      boolean redelivered = message.getDeliveryCount() > 1;

      if (count % 2 == 0 && !redelivered) {
        session.rollback();
      } else {
        session.commit();
      }
    }

    session.close();
  }
Exemplo n.º 30
0
 /**
  * @throws Exception
  * @throws HornetQException
  */
 private void verifyMessageOnServer(final int server, final int numberOfMessages)
     throws Exception, HornetQException {
   ServerLocator backupLocator = createInVMLocator(server);
   ClientSessionFactory factorybkp = addSessionFactory(createSessionFactory(backupLocator));
   ClientSession sessionbkp = factorybkp.createSession(false, false);
   sessionbkp.start();
   ClientConsumer consumerbkp = sessionbkp.createConsumer(ADDRESS);
   for (int i = 0; i < numberOfMessages; i++) {
     ClientMessage msg = consumerbkp.receive(1000);
     assertNotNull(msg);
     msg.acknowledge();
     sessionbkp.commit();
   }
   sessionbkp.close();
   factorybkp.close();
   backupLocator.close();
 }