Exemplo n.º 1
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.º 2
0
 private void configurePaging() {
   AddressSettings addressSettings = new AddressSettings();
   addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
   addressSettings.setMaxSizeBytes(30 * 1024 * 1024);
   addressSettings.setPageSizeBytes(10 * 1024 * 1024);
   addressSettings.setPageCacheMaxSize(20);
   config.getAddressesSettings().put("jms.queue.*", addressSettings);
 }
Exemplo n.º 3
0
  /** @throws Exception */
  protected void initServer() throws Exception {
    configuration = createDefaultConfig();
    configuration.setSecurityEnabled(false);
    configuration.setJournalMinFiles(2);
    server = createServer(true, configuration);
    server.start();

    AddressSettings qs = server.getAddressSettingsRepository().getMatch("*");
    AddressSettings newSets = new AddressSettings();
    newSets.setRedeliveryDelay(DelayedMessageTest.DELAY);
    newSets.merge(qs);
    server.getAddressSettingsRepository().addMatch(qName, newSets);
    locator = createInVMNonHALocator();
  }
Exemplo n.º 4
0
  public void setDeadLetterAddress(final String deadLetterAddress) throws Exception {
    checkStarted();

    clearIO();
    try {
      AddressSettings addressSettings = addressSettingsRepository.getMatch(address);

      if (deadLetterAddress != null) {
        addressSettings.setDeadLetterAddress(new SimpleString(deadLetterAddress));
      }
    } finally {
      blockOnIO();
    }
  }
Exemplo n.º 5
0
  public String getDeadLetterAddress() {
    checkStarted();

    clearIO();
    try {
      AddressSettings addressSettings = addressSettingsRepository.getMatch(address);

      if (addressSettings != null && addressSettings.getDeadLetterAddress() != null) {
        return addressSettings.getDeadLetterAddress().toString();
      }
      return null;
    } finally {
      blockOnIO();
    }
  }
Exemplo n.º 6
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);
  }
Exemplo n.º 7
0
  public void setExpiryAddress(final String expiryAddress) throws Exception {
    checkStarted();

    clearIO();
    try {
      AddressSettings addressSettings = addressSettingsRepository.getMatch(address);

      SimpleString sExpiryAddress = new SimpleString(expiryAddress);

      if (expiryAddress != null) {
        addressSettings.setExpiryAddress(sExpiryAddress);
      }

      queue.setExpiryAddress(sExpiryAddress);
    } finally {
      blockOnIO();
    }
  }
Exemplo n.º 8
0
  private void restartServer() throws Exception {
    server.stop();
    server = null;
    server = createServer(true, configuration);
    server.getAddressSettingsRepository().addMatch(address.toString(), qs);
    // start the server
    server.start();

    AddressSettings qs1 = new AddressSettings();
    qs1.setLastValueQueue(true);
    server.getAddressSettingsRepository().addMatch(address.toString(), qs1);
    // then we create a client as normal
    locator.close();
    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);
  }
Exemplo n.º 9
0
  /**
   * Create a setting.
   *
   * @param context the operation context
   * @param config the detyped config
   * @return the address settings
   * @throws OperationFailedException if the model is invalid
   */
  static AddressSettings createSettings(final OperationContext context, final ModelNode config)
      throws OperationFailedException {
    final AddressSettings settings = new AddressSettings();

    if (config.hasDefined(AddressSettingDefinition.ADDRESS_FULL_MESSAGE_POLICY.getName())) {
      final AddressFullMessagePolicy addressPolicy =
          AddressFullMessagePolicy.valueOf(
              AddressSettingDefinition.ADDRESS_FULL_MESSAGE_POLICY
                  .resolveModelAttribute(context, config)
                  .asString());
      settings.setAddressFullMessagePolicy(addressPolicy);
    }
    if (config.hasDefined(DEAD_LETTER_ADDRESS.getName())) {
      settings.setDeadLetterAddress(
          asSimpleString(DEAD_LETTER_ADDRESS.resolveModelAttribute(context, config), null));
    }
    if (config.hasDefined(AddressSettingDefinition.LAST_VALUE_QUEUE.getName())) {
      settings.setLastValueQueue(
          AddressSettingDefinition.LAST_VALUE_QUEUE
              .resolveModelAttribute(context, config)
              .asBoolean());
    }
    if (config.hasDefined(AddressSettingDefinition.MAX_DELIVERY_ATTEMPTS.getName())) {
      settings.setMaxDeliveryAttempts(
          AddressSettingDefinition.MAX_DELIVERY_ATTEMPTS
              .resolveModelAttribute(context, config)
              .asInt());
    }
    if (config.hasDefined(AddressSettingDefinition.MAX_SIZE_BYTES.getName())) {
      settings.setMaxSizeBytes(
          AddressSettingDefinition.MAX_SIZE_BYTES.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.MESSAGE_COUNTER_HISTORY_DAY_LIMIT.getName())) {
      settings.setMessageCounterHistoryDayLimit(
          AddressSettingDefinition.MESSAGE_COUNTER_HISTORY_DAY_LIMIT
              .resolveModelAttribute(context, config)
              .asInt());
    }
    if (config.hasDefined(CommonAttributes.EXPIRY_ADDRESS.getName())) {
      settings.setExpiryAddress(
          asSimpleString(EXPIRY_ADDRESS.resolveModelAttribute(context, config), null));
    }
    if (config.hasDefined(AddressSettingDefinition.EXPIRY_DELAY.getName())) {
      settings.setExpiryDelay(
          AddressSettingDefinition.EXPIRY_DELAY.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.REDELIVERY_DELAY.getName())) {
      settings.setRedeliveryDelay(
          AddressSettingDefinition.REDELIVERY_DELAY
              .resolveModelAttribute(context, config)
              .asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.REDELIVERY_MULTIPLIER.getName())) {
      settings.setRedeliveryMultiplier(
          AddressSettingDefinition.REDELIVERY_MULTIPLIER
              .resolveModelAttribute(context, config)
              .asDouble());
    }
    if (config.hasDefined(AddressSettingDefinition.MAX_REDELIVERY_DELAY.getName())) {
      settings.setMaxRedeliveryDelay(
          AddressSettingDefinition.MAX_REDELIVERY_DELAY
              .resolveModelAttribute(context, config)
              .asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.REDISTRIBUTION_DELAY.getName())) {
      settings.setRedistributionDelay(
          AddressSettingDefinition.REDISTRIBUTION_DELAY
              .resolveModelAttribute(context, config)
              .asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.PAGE_SIZE_BYTES.getName())) {
      settings.setPageSizeBytes(
          AddressSettingDefinition.PAGE_SIZE_BYTES.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.PAGE_MAX_CACHE_SIZE.getName())) {
      settings.setPageCacheMaxSize(
          AddressSettingDefinition.PAGE_MAX_CACHE_SIZE
              .resolveModelAttribute(context, config)
              .asInt());
    }
    if (config.hasDefined(AddressSettingDefinition.SEND_TO_DLA_ON_NO_ROUTE.getName())) {
      settings.setSendToDLAOnNoRoute(
          AddressSettingDefinition.SEND_TO_DLA_ON_NO_ROUTE
              .resolveModelAttribute(context, config)
              .asBoolean());
    }
    return settings;
  }
Exemplo n.º 10
0
  @Test
  public void testGetNumberOfPages() throws Exception {
    session.close();
    server.stop();
    server.getConfiguration().setPersistenceEnabled(true);

    SimpleString address = RandomUtil.randomSimpleString();

    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setPageSizeBytes(1024);
    addressSettings.setMaxSizeBytes(10 * 1024);
    final int NUMBER_MESSAGES_BEFORE_PAGING = 5;

    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.start();
    session.createQueue(address, address, true);

    QueueImpl serverQueue = (QueueImpl) server.locateQueue(address);

    ClientProducer producer = session.createProducer(address);

    for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++) {
      ClientMessage msg = session.createMessage(true);
      msg.getBodyBuffer().writeBytes(new byte[512]);
      producer.send(msg);
    }
    session.commit();

    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(0, addressControl.getNumberOfPages());

    ClientMessage msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[512]);
    producer.send(msg);

    session.commit();
    Assert.assertEquals(1, addressControl.getNumberOfPages());

    msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[512]);
    producer.send(msg);

    session.commit();
    Assert.assertEquals(1, addressControl.getNumberOfPages());

    msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[512]);
    producer.send(msg);

    session.commit();

    Assert.assertEquals("# of pages is 2", 2, addressControl.getNumberOfPages());

    System.out.println("Address size=" + addressControl.getAddressSize());

    Assert.assertEquals(
        serverQueue.getPageSubscription().getPagingStore().getAddressSize(),
        addressControl.getAddressSize());
  }
Exemplo n.º 11
0
  public synchronized void deployBridge(final BridgeConfiguration config) throws Exception {
    if (config.getName() == null) {
      HornetQServerLogger.LOGGER.bridgeNotUnique();

      return;
    }

    if (config.getQueueName() == null) {
      HornetQServerLogger.LOGGER.bridgeNoQueue(config.getName());

      return;
    }

    if (config.getForwardingAddress() == null) {
      HornetQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName());
    }

    if (bridges.containsKey(config.getName())) {
      HornetQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName());

      return;
    }

    Transformer transformer = instantiateTransformer(config.getTransformerClassName());

    Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName()));

    if (binding == null) {
      HornetQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName());

      return;
    }

    Queue queue = (Queue) binding.getBindable();

    ServerLocatorInternal serverLocator;

    if (config.getDiscoveryGroupName() != null) {
      DiscoveryGroupConfiguration discoveryGroupConfiguration =
          configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
      if (discoveryGroupConfiguration == null) {
        HornetQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName());

        return;
      }

      if (config.isHA()) {
        serverLocator =
            (ServerLocatorInternal)
                HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
      } else {
        serverLocator =
            (ServerLocatorInternal)
                HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
      }

    } else {
      TransportConfiguration[] tcConfigs = connectorNameListToArray(config.getStaticConnectors());

      if (tcConfigs == null) {
        HornetQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName());
        return;
      }

      if (config.isHA()) {
        serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(tcConfigs);
      } else {
        serverLocator =
            (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(tcConfigs);
      }
    }

    if (config.getForwardingAddress() != null) {
      AddressSettings addressConfig =
          configuration.getAddressesSettings().get(config.getForwardingAddress());

      // The address config could be null on certain test cases or some Embedded environment
      if (addressConfig == null) {
        // We will certainly have this warning on testcases which is ok
        HornetQServerLogger.LOGGER.bridgeCantFindAddressConfig(
            config.getName(), config.getForwardingAddress());
      } else {
        final int windowSize = config.getConfirmationWindowSize();
        final long maxBytes = addressConfig.getMaxSizeBytes();

        if (maxBytes != -1 && maxBytes < windowSize) {
          HornetQServerLogger.LOGGER.bridgeConfirmationWindowTooSmall(
              config.getName(), config.getForwardingAddress(), windowSize, maxBytes);
        }
      }
    }

    serverLocator.setIdentity("Bridge " + config.getName());
    serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());

    // We are going to manually retry on the bridge in case of failure
    serverLocator.setReconnectAttempts(0);
    serverLocator.setInitialConnectAttempts(0);
    serverLocator.setRetryInterval(config.getRetryInterval());
    serverLocator.setMaxRetryInterval(config.getMaxRetryInterval());
    serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
    serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
    serverLocator.setConnectionTTL(config.getConnectionTTL());
    serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize());
    // disable flow control
    serverLocator.setProducerWindowSize(-1);

    // This will be set to 30s unless it's changed from embedded / testing
    // there is no reason to exception the config for this timeout
    // since the Bridge is supposed to be non-blocking and fast
    // We may expose this if we find a good use case
    serverLocator.setCallTimeout(config.getCallTimeout());
    if (!config.isUseDuplicateDetection()) {
      HornetQServerLogger.LOGGER.debug(
          "Bridge "
              + config.getName()
              + " is configured to not use duplicate detecion, it will send messages synchronously");
    }

    clusterLocators.add(serverLocator);

    Bridge bridge =
        new BridgeImpl(
            serverLocator,
            config.getReconnectAttempts(),
            config.getReconnectAttemptsOnSameNode(),
            config.getRetryInterval(),
            config.getRetryIntervalMultiplier(),
            config.getMaxRetryInterval(),
            nodeManager.getUUID(),
            new SimpleString(config.getName()),
            queue,
            executorFactory.getExecutor(),
            FilterImpl.createFilter(config.getFilterString()),
            SimpleString.toSimpleString(config.getForwardingAddress()),
            scheduledExecutor,
            transformer,
            config.isUseDuplicateDetection(),
            config.getUser(),
            config.getPassword(),
            !backup,
            server.getStorageManager());

    bridges.put(config.getName(), bridge);

    managementService.registerBridge(bridge, config);

    bridge.start();
  }
Exemplo n.º 12
0
  public void contextInitialized(Injector injector) {
    org.candlepin.common.config.Configuration candlepinConfig =
        injector.getInstance(org.candlepin.common.config.Configuration.class);

    if (hornetqServer == null) {
      Configuration config = new ConfigurationImpl();

      HashSet<TransportConfiguration> transports = new HashSet<TransportConfiguration>();
      transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
      config.setAcceptorConfigurations(transports);

      // alter the default pass to silence log output
      config.setClusterUser(null);
      config.setClusterPassword(null);

      // in vm, who needs security?
      config.setSecurityEnabled(false);

      config.setJournalType(JournalType.NIO);

      config.setCreateBindingsDir(true);
      config.setCreateJournalDir(true);

      String baseDir = candlepinConfig.getString(ConfigProperties.HORNETQ_BASE_DIR);

      config.setBindingsDirectory(new File(baseDir, "bindings").toString());
      config.setJournalDirectory(new File(baseDir, "journal").toString());
      config.setLargeMessagesDirectory(new File(baseDir, "largemsgs").toString());
      config.setPagingDirectory(new File(baseDir, "paging").toString());

      Map<String, AddressSettings> settings = new HashMap<String, AddressSettings>();
      AddressSettings pagingConfig = new AddressSettings();

      String addressPolicyString =
          candlepinConfig.getString(ConfigProperties.HORNETQ_ADDRESS_FULL_POLICY);
      long maxQueueSizeInMb = candlepinConfig.getInt(ConfigProperties.HORNETQ_MAX_QUEUE_SIZE);
      long maxPageSizeInMb = candlepinConfig.getInt(ConfigProperties.HORNETQ_MAX_PAGE_SIZE);

      AddressFullMessagePolicy addressPolicy = null;
      if (addressPolicyString.equals("PAGE")) {
        addressPolicy = AddressFullMessagePolicy.PAGE;
      } else if (addressPolicyString.equals("BLOCK")) {
        addressPolicy = AddressFullMessagePolicy.BLOCK;
      } else {
        throw new IllegalArgumentException(
            "Unknown HORNETQ_ADDRESS_FULL_POLICY: "
                + addressPolicyString
                + " . Please use one of: PAGE, BLOCK");
      }

      // Paging sizes need to be converted to bytes
      pagingConfig.setMaxSizeBytes(maxQueueSizeInMb * FileUtils.ONE_MB);
      if (addressPolicy == AddressFullMessagePolicy.PAGE) {
        pagingConfig.setPageSizeBytes(maxPageSizeInMb * FileUtils.ONE_MB);
      }
      pagingConfig.setAddressFullMessagePolicy(addressPolicy);
      // Enable for all the queues
      settings.put("#", pagingConfig);
      config.setAddressesSettings(settings);

      int maxScheduledThreads =
          candlepinConfig.getInt(ConfigProperties.HORNETQ_MAX_SCHEDULED_THREADS);
      int maxThreads = candlepinConfig.getInt(ConfigProperties.HORNETQ_MAX_THREADS);
      if (maxThreads != -1) {
        config.setThreadPoolMaxSize(maxThreads);
      }

      if (maxScheduledThreads != -1) {
        config.setScheduledThreadPoolMaxSize(maxScheduledThreads);
      }

      /**
       * Anything up to size of LARGE_MSG_SIZE may be needed to be written to the Journal, so we
       * must set buffer size accordingly.
       *
       * <p>If buffer size would be < LARGE_MSG_SIZE we may get exceptions such as this: Can't write
       * records bigger than the bufferSize(XXXYYY) on the journal
       */
      int largeMsgSize = candlepinConfig.getInt(ConfigProperties.HORNETQ_LARGE_MSG_SIZE);
      config.setJournalBufferSize_AIO(largeMsgSize);
      config.setJournalBufferSize_NIO(largeMsgSize);

      hornetqServer = new EmbeddedHornetQ();
      hornetqServer.setConfiguration(config);
    }
    try {
      hornetqServer.start();
      log.info("Hornetq server started");
    } catch (Exception e) {
      log.error("Failed to start hornetq message server:", e);
      throw new RuntimeException(e);
    }

    setupAmqp(injector, candlepinConfig);
    cleanupOldQueues();

    List<String> listeners = getHornetqListeners(candlepinConfig);

    eventSource = injector.getInstance(EventSource.class);
    for (int i = 0; i < listeners.size(); i++) {
      try {
        Class<?> clazz = this.getClass().getClassLoader().loadClass(listeners.get(i));
        eventSource.registerListener((EventListener) injector.getInstance(clazz));
      } catch (Exception e) {
        log.warn("Unable to register listener " + listeners.get(i), e);
      }
    }

    // Initialize the Event sink AFTER the internal server has been
    // created and started.
    EventSink sink = injector.getInstance(EventSink.class);
    try {
      sink.initialize();
    } catch (Exception e) {
      log.error("Failed to initialize EventSink:", e);
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 13
0
  @Test
  public void testPagingOverCreatedDestinationQueues() throws Exception {

    Configuration config = createDefaultConfig();

    config.setJournalSyncNonTransactional(false);

    HornetQServer server =
        createServer(
            true,
            config,
            -1,
            -1,
            AddressFullMessagePolicy.BLOCK,
            new HashMap<String, AddressSettings>());

    JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    InVMNamingContext context = new InVMNamingContext();
    jmsServer.setContext(context);
    jmsServer.start();

    server
        .getHornetQServerControl()
        .addAddressSettings(
            "jms.queue.Q1",
            "DLQ",
            "DLQ",
            -1,
            false,
            5,
            100 * 1024,
            10 * 1024,
            5,
            5,
            1,
            1000,
            0,
            false,
            "PAGE",
            -1,
            10,
            "KILL");

    jmsServer.createQueue(true, "Q1", null, true, "/queue/Q1");

    HornetQJMSConnectionFactory cf =
        (HornetQJMSConnectionFactory)
            HornetQJMSClient.createConnectionFactoryWithoutHA(
                JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

    conn = cf.createConnection();
    conn.setClientID("tst");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Queue queue = (javax.jms.Queue) context.lookup("/queue/Q1");

    MessageProducer prod = sess.createProducer(queue);
    prod.setDeliveryMode(DeliveryMode.PERSISTENT);
    BytesMessage bmt = sess.createBytesMessage();

    bmt.writeBytes(new byte[1024]);

    for (int i = 0; i < 500; i++) {
      prod.send(bmt);
    }

    PagingStore store = server.getPagingManager().getPageStore(new SimpleString("jms.queue.Q1"));

    assertEquals(100 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());

    jmsServer.stop();

    server =
        createServer(
            true,
            config,
            -1,
            -1,
            AddressFullMessagePolicy.BLOCK,
            new HashMap<String, AddressSettings>());

    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMNamingContext();
    jmsServer.setContext(context);
    jmsServer.start();

    AddressSettings settings = server.getAddressSettingsRepository().getMatch("jms.queue.Q1");

    assertEquals(100 * 1024, settings.getMaxSizeBytes());
    assertEquals(10 * 1024, settings.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());

    store = server.getPagingManager().getPageStore(new SimpleString("jms.queue.Q1"));
    assertEquals(100 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());
  }
Exemplo n.º 14
0
  @Test
  public void testPagingOverCreatedDestinationTopics() throws Exception {

    Configuration config = createDefaultConfig();

    config.setJournalSyncNonTransactional(false);

    HornetQServer server =
        createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());

    JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
    InVMNamingContext context = new InVMNamingContext();
    jmsServer.setContext(context);
    jmsServer.start();

    jmsServer.createTopic(true, "tt", "/topic/TT");

    server
        .getHornetQServerControl()
        .addAddressSettings(
            "jms.topic.TT",
            "DLQ",
            "DLQ",
            -1,
            false,
            5,
            1024 * 1024,
            1024 * 10,
            5,
            5,
            1,
            1000,
            0,
            false,
            "PAGE",
            -1,
            10,
            "KILL");

    HornetQJMSConnectionFactory cf =
        (HornetQJMSConnectionFactory)
            HornetQJMSClient.createConnectionFactoryWithoutHA(
                JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

    Connection conn = cf.createConnection();
    conn.setClientID("tst");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = (Topic) context.lookup("/topic/TT");
    sess.createDurableSubscriber(topic, "t1");

    MessageProducer prod = sess.createProducer(topic);
    prod.setDeliveryMode(DeliveryMode.PERSISTENT);
    TextMessage txt = sess.createTextMessage("TST");
    prod.send(txt);

    PagingStore store = server.getPagingManager().getPageStore(new SimpleString("jms.topic.TT"));

    assertEquals(1024 * 1024, store.getMaxSize());
    assertEquals(10 * 1024, store.getPageSizeBytes());

    jmsServer.stop();

    server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());

    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMNamingContext();
    jmsServer.setContext(context);
    jmsServer.start();

    AddressSettings settings = server.getAddressSettingsRepository().getMatch("jms.topic.TT");

    assertEquals(1024 * 1024, settings.getMaxSizeBytes());
    assertEquals(10 * 1024, settings.getPageSizeBytes());
    assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());

    store = server.getPagingManager().getPageStore(new SimpleString("TT"));

    conn.close();

    server.stop();
  }