示例#1
0
  @Test
  public void testGetBindingNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    String divertName = RandomUtil.randomString();

    session.createQueue(address, queue, false);

    AddressControl addressControl = createManagementControl(address);
    String[] bindingNames = addressControl.getBindingNames();
    assertEquals(1, bindingNames.length);
    assertEquals(queue.toString(), bindingNames[0]);

    server
        .getHornetQServerControl()
        .createDivert(
            divertName,
            randomString(),
            address.toString(),
            RandomUtil.randomString(),
            false,
            null,
            null);

    bindingNames = addressControl.getBindingNames();
    Assert.assertEquals(2, bindingNames.length);

    session.deleteQueue(queue);

    bindingNames = addressControl.getBindingNames();
    assertEquals(1, bindingNames.length);
    assertEquals(divertName.toString(), bindingNames[0]);
  }
示例#2
0
  @Test
  public void testGetQueueNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString anotherQueue = RandomUtil.randomSimpleString();

    session.createQueue(address, queue, true);

    AddressControl addressControl = createManagementControl(address);
    String[] queueNames = addressControl.getQueueNames();
    Assert.assertEquals(1, queueNames.length);
    Assert.assertEquals(queue.toString(), queueNames[0]);

    session.createQueue(address, anotherQueue, false);
    queueNames = addressControl.getQueueNames();
    Assert.assertEquals(2, queueNames.length);

    session.deleteQueue(queue);

    queueNames = addressControl.getQueueNames();
    Assert.assertEquals(1, queueNames.length);
    Assert.assertEquals(anotherQueue.toString(), queueNames[0]);

    session.deleteQueue(anotherQueue);
  }
  public void testCreateAndDestroyQueueWithEmptyStringForFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    String filter = "";
    boolean durable = true;

    HornetQServerControl serverControl = createManagementControl();

    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));

    serverControl.createQueue(address.toString(), name.toString(), filter, durable);

    checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));
    QueueControl queueControl =
        ManagementControlHelper.createQueueControl(address, name, mbeanServer);
    Assert.assertEquals(address.toString(), queueControl.getAddress());
    Assert.assertEquals(name.toString(), queueControl.getName());
    Assert.assertNull(queueControl.getFilter());
    Assert.assertEquals(durable, queueControl.isDurable());
    Assert.assertEquals(false, queueControl.isTemporary());

    serverControl.destroyQueue(name.toString());

    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));
  }
示例#4
0
 /**
  * Returns the ObjectName used by QueueControl.
  *
  * @see QueueControl
  */
 public ObjectName getQueueObjectName(final SimpleString address, final SimpleString name)
     throws Exception {
   return ObjectName.getInstance(
       String.format(
           "%s:module=%s,type=%s,address=%s,name=%s",
           domain,
           ObjectNameBuilder.CORE_MODULE,
           "Queue",
           ObjectName.quote(address.toString()),
           ObjectName.quote(name.toString())));
 }
示例#5
0
  public Object[] getRoles() throws Exception {
    clearIO();
    try {
      Set<Role> roles = securityRepository.getMatch(address.toString());

      Object[] objRoles = new Object[roles.size()];

      int i = 0;
      for (Role role : roles) {
        objRoles[i++] =
            new Object[] {
              role.getName(),
              CheckType.SEND.hasRole(role),
              CheckType.CONSUME.hasRole(role),
              CheckType.CREATE_DURABLE_QUEUE.hasRole(role),
              CheckType.DELETE_DURABLE_QUEUE.hasRole(role),
              CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role),
              CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role),
              CheckType.MANAGE.hasRole(role)
            };
      }
      return objRoles;
    } finally {
      blockOnIO();
    }
  }
示例#6
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());
  }
示例#7
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();
  }
示例#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
  public Destination getJMSDestination() throws JMSException {
    if (dest == null) {
      SimpleString sdest = message.getAddress();

      dest = sdest == null ? null : HornetQDestination.fromAddress(sdest.toString());
    }

    return dest;
  }
示例#10
0
  public Map<String, Object> toMap() {
    Map<String, Object> map = new HashMap<String, Object>();

    map.put("messageID", messageID);
    if (userID != null) {
      map.put("userID", "ID:" + userID.toString());
    }
    map.put("address", address.toString());
    map.put("type", type);
    map.put("durable", durable);
    map.put("expiration", expiration);
    map.put("timestamp", timestamp);
    map.put("priority", priority);
    for (SimpleString propName : properties.getPropertyNames()) {
      map.put(propName.toString(), properties.getProperty(propName));
    }
    return map;
  }
示例#11
0
  public String getJMSType() throws JMSException {
    if (jmsType == null) {
      SimpleString ss = message.getSimpleStringProperty(HornetQMessage.TYPE_HEADER_NAME);

      if (ss != null) {
        jmsType = ss.toString();
      }
    }
    return jmsType;
  }
示例#12
0
  public String getStringProperty(final SimpleString key)
      throws HornetQPropertyConversionException {
    SimpleString str = getSimpleStringProperty(key);

    if (str == null) {
      return null;
    } else {
      return str.toString();
    }
  }
示例#13
0
  public Destination getJMSReplyTo() throws JMSException {
    if (replyTo == null) {
      SimpleString repl = message.getSimpleStringProperty(HornetQMessage.REPLYTO_HEADER_NAME);

      if (repl != null) {
        replyTo = HornetQDestination.fromAddress(repl.toString());
      }
    }
    return replyTo;
  }
示例#14
0
 @Override
 public String getStringProperty(String name) {
   try {
     SimpleString prop = properties.getSimpleStringProperty(new SimpleString(name));
     if (prop == null) return null;
     return prop.toString();
   } catch (HornetQPropertyConversionException ce) {
     throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
     throw new JMSRuntimeException(e.getMessage());
   }
 }
示例#15
0
  @Test
  public void testGetAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();

    session.createQueue(address, queue, false);

    AddressControl addressControl = createManagementControl(address);

    Assert.assertEquals(address.toString(), addressControl.getAddress());

    session.deleteQueue(queue);
  }
 /** {@inheritDoc} */
 @Override
 public void mapFrom(ClientMessage source, Context context) throws Exception {
   for (SimpleString key : source.getPropertyNames()) {
     String name = key.toString();
     if (matches(name)) {
       Object value = source.getObjectProperty(key);
       if (value != null) {
         // HornetQ ClientMessage properties -> Context EXCHANGE properties
         context.setProperty(name, value, EXCHANGE).addLabels(HORNETQ_MESSAGE_PROPERTY);
       }
     }
   }
 }
示例#17
0
  public String getRolesAsJSON() throws Exception {
    clearIO();
    try {
      JSONArray json = new JSONArray();
      Set<Role> roles = securityRepository.getMatch(address.toString());

      for (Role role : roles) {
        json.put(new JSONObject(role));
      }
      return json.toString();
    } finally {
      blockOnIO();
    }
  }
示例#18
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);
  }
示例#19
0
  public Enumeration getPropertyNames() throws JMSException {
    HashSet<String> set = new HashSet<String>();

    for (SimpleString propName : message.getPropertyNames()) {
      if (!propName.startsWith(HornetQMessage.JMS)
          || propName.startsWith(HornetQMessage.JMSX)
          || propName.startsWith(HornetQMessage.JMS_)) {
        set.add(propName.toString());
      }
    }

    set.add(HornetQMessage.JMSXDELIVERYCOUNT);

    return Collections.enumeration(set);
  }
示例#20
0
  @Override
  public Set<String> getPropertyNames() {
    try {
      Set<String> propNames = new HashSet<String>();

      for (SimpleString str : properties.getPropertyNames()) {
        propNames.add(str.toString());
      }
      return propNames;
    } catch (HornetQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
    } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
    }
  }
示例#21
0
  @Test
  public void testGetRolesAsJSON() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    Role role =
        new Role(
            RandomUtil.randomString(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean());

    session.createQueue(address, queue, true);

    AddressControl addressControl = createManagementControl(address);
    String jsonString = addressControl.getRolesAsJSON();
    Assert.assertNotNull(jsonString);
    RoleInfo[] roles = RoleInfo.from(jsonString);
    Assert.assertEquals(0, roles.length);

    Set<Role> newRoles = new HashSet<Role>();
    newRoles.add(role);
    server.getSecurityRepository().addMatch(address.toString(), newRoles);

    jsonString = addressControl.getRolesAsJSON();
    Assert.assertNotNull(jsonString);
    roles = RoleInfo.from(jsonString);
    Assert.assertEquals(1, roles.length);
    RoleInfo r = roles[0];
    Assert.assertEquals(role.getName(), roles[0].getName());
    Assert.assertEquals(role.isSend(), r.isSend());
    Assert.assertEquals(role.isConsume(), r.isConsume());
    Assert.assertEquals(role.isCreateDurableQueue(), r.isCreateDurableQueue());
    Assert.assertEquals(role.isDeleteDurableQueue(), r.isDeleteDurableQueue());
    Assert.assertEquals(role.isCreateNonDurableQueue(), r.isCreateNonDurableQueue());
    Assert.assertEquals(role.isDeleteNonDurableQueue(), r.isDeleteNonDurableQueue());
    Assert.assertEquals(role.isManage(), r.isManage());

    session.deleteQueue(queue);
  }
示例#22
0
  @Test
  public void testGetRoles() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    Role role =
        new Role(
            RandomUtil.randomString(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean());

    session.createQueue(address, queue, true);

    AddressControl addressControl = createManagementControl(address);
    Object[] roles = addressControl.getRoles();
    Assert.assertEquals(0, roles.length);

    Set<Role> newRoles = new HashSet<Role>();
    newRoles.add(role);
    server.getSecurityRepository().addMatch(address.toString(), newRoles);

    roles = addressControl.getRoles();
    Assert.assertEquals(1, roles.length);
    Object[] r = (Object[]) roles[0];
    Assert.assertEquals(role.getName(), r[0]);
    Assert.assertEquals(CheckType.SEND.hasRole(role), r[1]);
    Assert.assertEquals(CheckType.CONSUME.hasRole(role), r[2]);
    Assert.assertEquals(CheckType.CREATE_DURABLE_QUEUE.hasRole(role), r[3]);
    Assert.assertEquals(CheckType.DELETE_DURABLE_QUEUE.hasRole(role), r[4]);
    Assert.assertEquals(CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role), r[5]);
    Assert.assertEquals(CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role), r[6]);
    Assert.assertEquals(CheckType.MANAGE.hasRole(role), r[7]);

    session.deleteQueue(queue);
  }
  public void testGetAddressNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();

    HornetQServerControl serverControl = createManagementControl();

    // due to replication, there can be another queue created for replicating
    // management operations

    Assert.assertFalse(
        HornetQServerControlTest.contains(address.toString(), serverControl.getAddressNames()));

    serverControl.createQueue(address.toString(), name.toString());
    Assert.assertTrue(
        HornetQServerControlTest.contains(address.toString(), serverControl.getAddressNames()));

    serverControl.destroyQueue(name.toString());
    Assert.assertFalse(
        HornetQServerControlTest.contains(address.toString(), serverControl.getAddressNames()));
  }
示例#24
0
 /**
  * Returns the ObjectName used by AddressControl.
  *
  * @see AddressControl
  */
 public ObjectName getAddressObjectName(final SimpleString address) throws Exception {
   return createObjectName(ObjectNameBuilder.CORE_MODULE, "Address", address.toString());
 }
示例#25
0
 public int compareTo(final SimpleString o) {
   return toString().compareTo(o.toString());
 }
示例#26
0
 /**
  * Sets all properties we carry onto the message.
  *
  * @param message
  * @throws JMSException
  */
 private void setProperties(Message message) throws JMSException {
   for (SimpleString name : properties.getPropertyNames()) {
     message.setObjectProperty(name.toString(), properties.getProperty(name));
   }
 }
示例#27
0
 private PagingStore newStore(final SimpleString address) throws Exception {
   return pagingStoreFactory.newStore(
       address, addressSettingsRepository.getMatch(address.toString()));
 }
示例#28
0
    public synchronized void onMessage(final ClientMessage message) {
      if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
        HornetQServerLogger.LOGGER.debug(
            "ClusterCommunication::Flow record on "
                + clusterConnector
                + " Receiving message "
                + message);
      }
      try {
        // Reset the bindings
        if (message.containsProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA)) {
          clearBindings();

          firstReset = true;

          return;
        }

        if (!firstReset) {
          return;
        }

        // TODO - optimised this by just passing int in header - but filter needs to be extended to
        // support IN with
        // a list of integers
        SimpleString type = message.getSimpleStringProperty(ManagementHelper.HDR_NOTIFICATION_TYPE);

        NotificationType ntype = NotificationType.valueOf(type.toString());

        switch (ntype) {
          case BINDING_ADDED:
            {
              doBindingAdded(message);

              break;
            }
          case BINDING_REMOVED:
            {
              doBindingRemoved(message);

              break;
            }
          case CONSUMER_CREATED:
            {
              doConsumerCreated(message);

              break;
            }
          case CONSUMER_CLOSED:
            {
              doConsumerClosed(message);

              break;
            }
          case PROPOSAL:
            {
              doProposalReceived(message);

              break;
            }
          case PROPOSAL_RESPONSE:
            {
              doProposalResponseReceived(message);

              break;
            }
          default:
            {
              throw HornetQMessageBundle.BUNDLE.invalidType(ntype);
            }
        }
      } catch (Exception e) {
        HornetQServerLogger.LOGGER.errorHandlingMessage(e);
      }
    }
示例#29
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());
  }
示例#30
0
 public String getAddress() {
   return address.toString();
 }