Пример #1
0
  /**
   * This would force a journal duplication on bindings even with the scenario that generated fixed,
   * the server shouldn't hold of from starting
   *
   * @throws Exception
   */
  @Test
  public void testForceDuplicationOnBindings() throws Exception {
    queue = server.createQueue(QUEUE, QUEUE, null, true, false);

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

    ClientProducer producer = session.createProducer(QUEUE);

    producer.send(session.createMessage(true));
    session.commit();

    long queueID = server.getStorageManager().generateUniqueID();
    long txID = server.getStorageManager().generateUniqueID();

    // Forcing a situation where the server would unexpectedly create a duplicated queue. The server
    // should still start normally
    LocalQueueBinding newBinding =
        new LocalQueueBinding(
            QUEUE,
            new QueueImpl(queueID, QUEUE, QUEUE, null, true, false, null, null, null, null, null),
            server.getNodeID());
    server.getStorageManager().addQueueBinding(txID, newBinding);
    server.getStorageManager().commitBindings(txID);

    server.stop();

    // a duplicate binding would impede the server from starting
    server.start();
    waitForServer(server);

    server.stop();
  }
Пример #2
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();
 }
  public void testSSL() throws Exception {
    String text = RandomUtil.randomString();

    tc.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
    tc.getParams()
        .put(TransportConstants.KEYSTORE_PATH_PROP_NAME, TransportConstants.DEFAULT_KEYSTORE_PATH);
    tc.getParams()
        .put(
            TransportConstants.KEYSTORE_PASSWORD_PROP_NAME,
            TransportConstants.DEFAULT_KEYSTORE_PASSWORD);

    ServerLocator locator = addServerLocator(HornetQClient.createServerLocatorWithoutHA(tc));
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(CoreClientOverSSLTest.QUEUE, CoreClientOverSSLTest.QUEUE, false);
    ClientProducer producer = session.createProducer(CoreClientOverSSLTest.QUEUE);

    ClientMessage message = createTextMessage(session, text);
    producer.send(message);

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

    Message m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(text, m.getBodyBuffer().readString());
  }
Пример #4
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();
      }
    }
Пример #5
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();
  }
  /**
   * 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);
    }
  }
Пример #7
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();
  }
Пример #8
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    configuration = createDefaultConfig();
    configuration.setSecurityEnabled(false);
    server = createServer(true, configuration);
    // start the server
    server.start();

    qs = new AddressSettings();
    qs.setLastValueQueue(true);
    server.getAddressSettingsRepository().addMatch(address.toString(), qs);
    // then we create a client as normal
    locator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));

    locator.setBlockOnAcknowledge(true);
    locator.setAckBatchSize(0);
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    clientSession = sessionFactory.createSession(false, true, true);
    clientSessionXa = sessionFactory.createSession(true, false, false);
    clientSession.createQueue(address, qName1, null, true);
  }
Пример #9
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();
  }
Пример #10
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());
  }
Пример #11
0
 /**
  * Set up the {@link ClientSessionFactory} to throw an exception when {@link
  * ClientSessionFactory#createSession()} is called. Make sure, we throw up our hands saying "I am
  * not dealing with this".
  *
  * @throws Exception
  */
 @Test(expected = RuntimeException.class)
 public void eventSinkShouldThrowExceptionWhenSessionCreationFailsInConstructor()
     throws Exception {
   final ClientSessionFactory csFactory = mock(ClientSessionFactory.class);
   doThrow(new HornetQException()).when(csFactory.createSession());
   createEventSink(csFactory);
   fail("Runtime exception should have been thrown.");
 }
Пример #12
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();
  }
Пример #13
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();
  }
Пример #14
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();
  }
Пример #15
0
 public void testConnectIntoNonBackup() throws Exception {
   setupServer(false);
   try {
     ClientSessionFactory sf = createSessionFactory(locator);
     manager = new ReplicationManager(sf.getConnection(), factory);
     addHornetQComponent(manager);
     manager.start();
     Assert.fail("Exception was expected");
   } catch (NotConnectedException nce) {
     // ok
   } catch (HornetQException expected) {
     fail("Invalid Exception type:" + expected.getType());
   }
 }
Пример #16
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();
      }
    }
  }
Пример #17
0
 @Before
 public void init() throws Exception {
   this.factory = new EventFactory(mockPrincipalProvider);
   this.principal = TestUtil.createOwnerPrincipal();
   eventFilter = new EventFilter(new CandlepinCommonTestConfig());
   when(mockPrincipalProvider.get()).thenReturn(this.principal);
   when(mockSessionFactory.createTransactedSession()).thenReturn(mockClientSession);
   when(mockClientSession.createProducer(anyString())).thenReturn(mockClientProducer);
   when(mockClientSession.createMessage(anyBoolean())).thenReturn(mockClientMessage);
   when(mockClientMessage.getBodyBuffer()).thenReturn(HornetQBuffers.fixedBuffer(2000));
   when(mockSessionFactory.getServerLocator()).thenReturn(mockLocator);
   this.mapper = spy(new ObjectMapper());
   this.eventSinkImpl = createEventSink(mockSessionFactory);
   o = new Owner("test owner");
 }
Пример #18
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();
  }
Пример #19
0
  /**
   * Connects to the yamcs server. This method blocks until a connection is established or some
   * error has occurred, thus this should be called in a separate thread. Hornetq will try
   * indefinitely to establish the connection and also provides automatic re-connection afterwards.
   *
   * @throws Exception if the hornetq session could not be established due to some error
   */
  public void connect() throws Exception {
    for (ConnectionListener cl : connectionListeners) {
      cl.connecting(connParams.getUrl());
    }

    Map<String, Object> tcpConfig = new HashMap<String, Object>();
    tcpConfig.put(TransportConstants.HOST_PROP_NAME, connParams.host);
    tcpConfig.put(TransportConstants.PORT_PROP_NAME, connParams.port);

    locator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(NettyConnectorFactory.class.getName(), tcpConfig));

    locator.setInitialConnectAttempts(initialConnectAttempts);
    locator.setReconnectAttempts(reconnectAttempts);
    locator.setRetryInterval(retryInterval);
    locator.setRetryIntervalMultiplier(retryIntervalMultiplier);
    locator.setMaxRetryInterval(maxRetryInterval);
    locator.setAckBatchSize(ackBatchSize);

    sessionFactory = locator.createSessionFactory();

    // TODO Use hornetq auth (like YamcsConnector), or keep anonymous connection?
    session = sessionFactory.createSession(false, true, true, preAcknowledge);
    session.addFailureListener(YamcsAckConnector.this);
    session.start();

    for (ConnectionListener cl : connectionListeners) {
      cl.connected(connParams.getUrl());
    }
  }
    @Override
    public void run() {
      try {
        if (shareConnectionFactory) {
          session = sharedSf.createSession(false, false);
        } else {
          locator = createInVMNonHALocator();
          sf = createSessionFactory(locator);
          session = sf.createSession(false, false);
        }

        ClientProducer prod = session.createProducer(MultipleConsumersPageStressTest.ADDRESS);

        int count = 0;

        while (enabled()) {
          int numberOfMessages = getNumberOfMessages();

          for (int i = 0; i < numberOfMessages; i++) {
            ClientMessage msg = session.createMessage(true);
            msg.putStringProperty("Test", "This is a simple test");
            msg.putIntProperty("count", count++);
            prod.send(msg);
          }

          messagesAvailable.addAndGet(numberOfMessages);
          session.commit();
        }
      } catch (Throwable e) {
        exceptionHappened(e);
      }
    }
Пример #21
0
  private void receiveMessages() throws Exception {
    ClientSession session = sf.createSession(true, true);
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = consumer.receive(100);
      assertNotNull("Expecting a message " + i, message);
      assertMessageBody(i, message);
      assertEquals(i, message.getIntProperty("int").intValue());
      assertEquals((short) i, message.getShortProperty("short").shortValue());
      assertEquals((byte) i, message.getByteProperty("byte").byteValue());
      assertEquals(floatValue(i), message.getFloatProperty("float").floatValue(), 0.001);
      assertEquals(
          new SimpleString(Integer.toString(i)),
          message.getSimpleStringProperty(SIMPLE_STRING_KEY.toString()));
      assertEqualsByteArrays(byteArray(i), message.getBytesProperty("byte[]"));

      assertTrue(message.containsProperty("null-value"));
      assertEquals(message.getObjectProperty("null-value"), null);

      message.acknowledge();
    }
    assertNull("no more messages", consumer.receive(50));
    consumer.close();
    session.commit();
  }
Пример #22
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();
    }
  }
Пример #23
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();
      }
    }
  }
Пример #24
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) {
      }
    }
  }
Пример #25
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();
    }
  }
Пример #26
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();
 }
  public void testListPreparedTransactionDetails() throws Exception {
    SimpleString atestq = new SimpleString("BasicXaTestq");
    Xid xid = newXID();

    ServerLocator locator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
    ClientSessionFactory csf = locator.createSessionFactory();
    ClientSession clientSession = csf.createSession(true, false, false);
    clientSession.createQueue(atestq, atestq, null, true);

    ClientMessage m1 = createTextMessage(clientSession, "");
    ClientMessage m2 = createTextMessage(clientSession, "");
    ClientMessage m3 = createTextMessage(clientSession, "");
    ClientMessage m4 = createTextMessage(clientSession, "");
    m1.putStringProperty("m1", "m1");
    m2.putStringProperty("m2", "m2");
    m3.putStringProperty("m3", "m3");
    m4.putStringProperty("m4", "m4");
    ClientProducer clientProducer = clientSession.createProducer(atestq);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m1);
    clientProducer.send(m2);
    clientProducer.send(m3);
    clientProducer.send(m4);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);

    HornetQServerControl serverControl = createManagementControl();

    JSONArray jsonArray = new JSONArray(serverControl.listProducersInfoAsJSON());

    assertEquals(1, jsonArray.length());
    assertEquals(4, ((JSONObject) jsonArray.get(0)).getInt("msgSent"));

    clientSession.close();
    locator.close();

    String txDetails = serverControl.listPreparedTransactionDetailsAsJSON();

    Assert.assertTrue(txDetails.matches(".*m1.*"));
    Assert.assertTrue(txDetails.matches(".*m2.*"));
    Assert.assertTrue(txDetails.matches(".*m3.*"));
    Assert.assertTrue(txDetails.matches(".*m4.*"));
  }
 public void testCreateConsumerWithFilter() throws Exception {
   HornetQServer service = createServer(false);
   try {
     service.start();
     ClientSessionFactory cf = createInVMFactory();
     cf.setProducerMaxRate(99);
     cf.setBlockOnNonDurableSend(true);
     cf.setBlockOnNonDurableSend(true);
     ClientSessionInternal clientSession =
         (ClientSessionInternal) cf.createSession(false, true, true);
     clientSession.createQueue(queueName, queueName, false);
     ClientConsumer consumer = clientSession.createConsumer(queueName, "foo=bar");
     Assert.assertNotNull(consumer);
     clientSession.close();
   } finally {
     service.stop();
   }
 }
Пример #29
0
  // An exception during delivery shouldn't make the message disappear
  @Test
  public void testExceptionWhileDelivering() throws Exception {
    queue = server.createQueue(QUEUE, QUEUE, null, true, false);

    HangInterceptor hangInt = new HangInterceptor();
    try {
      locator.addInterceptor(hangInt);

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

      ClientProducer producer = session.createProducer(QUEUE);

      ClientConsumer consumer = session.createConsumer(QUEUE);

      producer.send(session.createMessage(true));
      session.commit();

      hangInt.close();

      session.start();

      Assert.assertTrue(hangInt.reusableLatch.await(10, TimeUnit.SECONDS));

      hangInt.pendingException = new HornetQException();

      hangInt.open();

      session.close();

      session = factory.createSession(false, false);
      session.start();

      consumer = session.createConsumer(QUEUE);

      ClientMessage msg = consumer.receive(5000);
      Assert.assertNotNull(msg);
      msg.acknowledge();

      session.commit();
    } finally {
      hangInt.open();
    }
  }
Пример #30
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);*/

  }