@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]); }
@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)); }
/** * 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()))); }
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(); } }
@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()); }
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(); }
@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); }
public Destination getJMSDestination() throws JMSException { if (dest == null) { SimpleString sdest = message.getAddress(); dest = sdest == null ? null : HornetQDestination.fromAddress(sdest.toString()); } return dest; }
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; }
public String getJMSType() throws JMSException { if (jmsType == null) { SimpleString ss = message.getSimpleStringProperty(HornetQMessage.TYPE_HEADER_NAME); if (ss != null) { jmsType = ss.toString(); } } return jmsType; }
public String getStringProperty(final SimpleString key) throws HornetQPropertyConversionException { SimpleString str = getSimpleStringProperty(key); if (str == null) { return null; } else { return str.toString(); } }
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; }
@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()); } }
@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); } } } }
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(); } }
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); }
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); }
@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()); } }
@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); }
@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())); }
/** * Returns the ObjectName used by AddressControl. * * @see AddressControl */ public ObjectName getAddressObjectName(final SimpleString address) throws Exception { return createObjectName(ObjectNameBuilder.CORE_MODULE, "Address", address.toString()); }
public int compareTo(final SimpleString o) { return toString().compareTo(o.toString()); }
/** * 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)); } }
private PagingStore newStore(final SimpleString address) throws Exception { return pagingStoreFactory.newStore( address, addressSettingsRepository.getMatch(address.toString())); }
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); } }
@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()); }
public String getAddress() { return address.toString(); }