@Test public void testCreateDurableQueueUsingJMXAndRestartServer() throws Exception { String queueName = RandomUtil.randomString(); String binding = RandomUtil.randomString(); ActiveMQTestBase.checkNoBinding(context, binding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); JMSServerControl control = ManagementControlHelper.createJMSServerControl(mbeanServer); control.createQueue(queueName, binding); Object o = ActiveMQTestBase.checkBinding(context, binding); Assert.assertTrue(o instanceof Queue); Queue queue = (Queue) o; Assert.assertEquals(queueName, queue.getQueueName()); checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); serverManager.stop(); ActiveMQTestBase.checkNoBinding(context, binding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); serverManager = createJMSServer(); serverManager.start(); o = ActiveMQTestBase.checkBinding(context, binding); Assert.assertTrue(o instanceof Queue); queue = (Queue) o; Assert.assertEquals(queueName, queue.getQueueName()); checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); }
@Test public void testGetBindingNames() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); String divertName = RandomUtil.randomString(); session.createQueue(address, queue, false); CoreMessagingProxy proxy = createProxy(address); Object[] bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames"); assertEquals(1, bindingNames.length); assertEquals(queue.toString(), bindingNames[0]); server .getActiveMQServerControl() .createDivert( divertName, randomString(), address.toString(), RandomUtil.randomString(), false, null, null); bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames"); assertEquals(2, bindingNames.length); session.deleteQueue(queue); bindingNames = (Object[]) proxy.retrieveAttributeValue("bindingNames"); assertEquals(1, bindingNames.length); assertEquals(divertName.toString(), bindingNames[0]); }
@Test public void testMapWithArrayValues() throws Exception { String resource = RandomUtil.randomString(); String operationName = RandomUtil.randomString(); Map<String, Object> map = new HashMap<>(); String key1 = RandomUtil.randomString(); String[] val1 = new String[] {"a", "b", "c"}; ManagementHelperTest.log.info("val1 type is " + Arrays.toString(val1)); String key2 = RandomUtil.randomString(); Long[] val2 = new Long[] {1L, 2L, 3L, 4L, 5L}; ManagementHelperTest.log.info("val2 type is " + Arrays.toString(val2)); map.put(key1, val1); map.put(key2, val2); Object[] params = new Object[] {"hello", map}; Message msg = new ClientMessageImpl((byte) 0, false, 0, 0, (byte) 4, 1000); ManagementHelper.putOperationInvocation(msg, resource, operationName, params); Object[] parameters = ManagementHelper.retrieveOperationParameters(msg); Assert.assertEquals(params.length, parameters.length); Assert.assertEquals("hello", parameters[0]); Map map2 = (Map) parameters[1]; Assert.assertEquals(2, map2.size()); Object[] arr1 = (Object[]) map2.get(key1); Assert.assertEquals(val1.length, arr1.length); Assert.assertEquals(arr1[0], val1[0]); Assert.assertEquals(arr1[1], val1[1]); Assert.assertEquals(arr1[2], val1[2]); Object[] arr2 = (Object[]) map2.get(key2); Assert.assertEquals(val2.length, arr2.length); Assert.assertEquals(arr2[0], val2[0]); Assert.assertEquals(arr2[1], val2[1]); Assert.assertEquals(arr2[2], val2[2]); }
@Test public void testCreateDurableQueueUsingJMSAndRestartServer() throws Exception { String queueName = RandomUtil.randomString(); String binding = RandomUtil.randomString(); ActiveMQTestBase.checkNoBinding(context, binding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); TransportConfiguration config = new TransportConfiguration(InVMConnectorFactory.class.getName()); Connection connection = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, config) .createConnection(); connection.start(); Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management"); QueueSession session = (QueueSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE); QueueRequestor requestor = new QueueRequestor(session, managementQueue); Message message = session.createMessage(); JMSManagementHelper.putOperationInvocation( message, "jms.server", "createQueue", queueName, binding); Message reply = requestor.request(message); Assert.assertTrue(JMSManagementHelper.hasOperationSucceeded(reply)); connection.close(); Object o = ActiveMQTestBase.checkBinding(context, binding); Assert.assertTrue(o instanceof Queue); Queue queue = (Queue) o; Assert.assertEquals(queueName, queue.getQueueName()); checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); serverManager.stop(); ActiveMQTestBase.checkNoBinding(context, binding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); serverManager = createJMSServer(); serverManager.start(); o = ActiveMQTestBase.checkBinding(context, binding); Assert.assertTrue(o instanceof Queue); queue = (Queue) o; Assert.assertEquals(queueName, queue.getQueueName()); checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); }
@Test public void testSECURITY_AUTHENTICATION_VIOLATION() throws Exception { String unknownUser = RandomUtil.randomString(); SecurityNotificationTest.flush(notifConsumer); ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory sf = createSessionFactory(locator); try { sf.createSession(unknownUser, RandomUtil.randomString(), false, true, true, false, 1); Assert.fail("authentication must fail and a notification of security violation must be sent"); } catch (Exception e) { } ClientMessage[] notifications = SecurityNotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals( SECURITY_AUTHENTICATION_VIOLATION.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); }
@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); CoreMessagingProxy proxy = createProxy(address); Object[] roles = (Object[]) proxy.retrieveAttributeValue("roles"); for (Object role2 : roles) { System.out.println(((Object[]) role2)[0]); } Assert.assertEquals(0, roles.length); Set<Role> newRoles = new HashSet<>(); newRoles.add(role); server.getSecurityRepository().addMatch(address.toString(), newRoles); roles = (Object[]) proxy.retrieveAttributeValue("roles"); 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); }
@Test public void testArrayOfStringParameter() throws Exception { String resource = RandomUtil.randomString(); String operationName = RandomUtil.randomString(); String param = RandomUtil.randomString(); String[] params = new String[] { RandomUtil.randomString(), RandomUtil.randomString(), RandomUtil.randomString() }; Message msg = new ClientMessageImpl((byte) 0, false, 0, 0, (byte) 4, 1000); ManagementHelper.putOperationInvocation(msg, resource, operationName, param, params); Object[] parameters = ManagementHelper.retrieveOperationParameters(msg); Assert.assertEquals(2, parameters.length); Assert.assertEquals(param, parameters[0]); Object parameter_2 = parameters[1]; ManagementHelperTest.log.info("type " + parameter_2); Assert.assertTrue(parameter_2 instanceof Object[]); Object[] retrievedParams = (Object[]) parameter_2; Assert.assertEquals(params.length, retrievedParams.length); for (int i = 0; i < retrievedParams.length; i++) { Assert.assertEquals(params[i], retrievedParams[i]); } }
private void testSettersThrowException(final ActiveMQConnectionFactory cf) { String discoveryAddress = RandomUtil.randomString(); int discoveryPort = RandomUtil.randomPositiveInt(); long discoveryRefreshTimeout = RandomUtil.randomPositiveLong(); String clientID = RandomUtil.randomString(); long clientFailureCheckPeriod = RandomUtil.randomPositiveLong(); long connectionTTL = RandomUtil.randomPositiveLong(); long callTimeout = RandomUtil.randomPositiveLong(); int minLargeMessageSize = RandomUtil.randomPositiveInt(); int consumerWindowSize = RandomUtil.randomPositiveInt(); int consumerMaxRate = RandomUtil.randomPositiveInt(); int confirmationWindowSize = RandomUtil.randomPositiveInt(); int producerMaxRate = RandomUtil.randomPositiveInt(); boolean blockOnAcknowledge = RandomUtil.randomBoolean(); boolean blockOnDurableSend = RandomUtil.randomBoolean(); boolean blockOnNonDurableSend = RandomUtil.randomBoolean(); boolean autoGroup = RandomUtil.randomBoolean(); boolean preAcknowledge = RandomUtil.randomBoolean(); String loadBalancingPolicyClassName = RandomUtil.randomString(); int dupsOKBatchSize = RandomUtil.randomPositiveInt(); int transactionBatchSize = RandomUtil.randomPositiveInt(); long initialWaitTimeout = RandomUtil.randomPositiveLong(); boolean useGlobalPools = RandomUtil.randomBoolean(); int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt(); int threadPoolMaxSize = RandomUtil.randomPositiveInt(); long retryInterval = RandomUtil.randomPositiveLong(); double retryIntervalMultiplier = RandomUtil.randomDouble(); int reconnectAttempts = RandomUtil.randomPositiveInt(); boolean failoverOnServerShutdown = RandomUtil.randomBoolean(); try { cf.setClientID(clientID); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setClientFailureCheckPeriod(clientFailureCheckPeriod); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setConnectionTTL(connectionTTL); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setCallTimeout(callTimeout); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setMinLargeMessageSize(minLargeMessageSize); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setConsumerWindowSize(consumerWindowSize); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setConsumerMaxRate(consumerMaxRate); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setConfirmationWindowSize(confirmationWindowSize); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setProducerMaxRate(producerMaxRate); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setBlockOnAcknowledge(blockOnAcknowledge); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setBlockOnDurableSend(blockOnDurableSend); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setBlockOnNonDurableSend(blockOnNonDurableSend); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setAutoGroup(autoGroup); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setPreAcknowledge(preAcknowledge); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setDupsOKBatchSize(dupsOKBatchSize); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setTransactionBatchSize(transactionBatchSize); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setUseGlobalPools(useGlobalPools); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setThreadPoolMaxSize(threadPoolMaxSize); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setRetryInterval(retryInterval); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setRetryIntervalMultiplier(retryIntervalMultiplier); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } try { cf.setReconnectAttempts(reconnectAttempts); Assert.fail("Should throw exception"); } catch (IllegalStateException e) { // OK } cf.getStaticConnectors(); cf.getClientID(); cf.getClientFailureCheckPeriod(); cf.getConnectionTTL(); cf.getCallTimeout(); cf.getMinLargeMessageSize(); cf.getConsumerWindowSize(); cf.getConsumerMaxRate(); cf.getConfirmationWindowSize(); cf.getProducerMaxRate(); cf.isBlockOnAcknowledge(); cf.isBlockOnDurableSend(); cf.isBlockOnNonDurableSend(); cf.isAutoGroup(); cf.isPreAcknowledge(); cf.getConnectionLoadBalancingPolicyClassName(); cf.getDupsOKBatchSize(); cf.getTransactionBatchSize(); cf.isUseGlobalPools(); cf.getScheduledThreadPoolMaxSize(); cf.getThreadPoolMaxSize(); cf.getRetryInterval(); cf.getRetryIntervalMultiplier(); cf.getReconnectAttempts(); cf.close(); }
@Test public void testGettersAndSetters() { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC); long clientFailureCheckPeriod = RandomUtil.randomPositiveLong(); long connectionTTL = RandomUtil.randomPositiveLong(); long callTimeout = RandomUtil.randomPositiveLong(); int minLargeMessageSize = RandomUtil.randomPositiveInt(); int consumerWindowSize = RandomUtil.randomPositiveInt(); int consumerMaxRate = RandomUtil.randomPositiveInt(); int confirmationWindowSize = RandomUtil.randomPositiveInt(); int producerMaxRate = RandomUtil.randomPositiveInt(); boolean blockOnAcknowledge = RandomUtil.randomBoolean(); boolean blockOnDurableSend = RandomUtil.randomBoolean(); boolean blockOnNonDurableSend = RandomUtil.randomBoolean(); boolean autoGroup = RandomUtil.randomBoolean(); boolean preAcknowledge = RandomUtil.randomBoolean(); String loadBalancingPolicyClassName = RandomUtil.randomString(); boolean useGlobalPools = RandomUtil.randomBoolean(); int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt(); int threadPoolMaxSize = RandomUtil.randomPositiveInt(); long retryInterval = RandomUtil.randomPositiveLong(); double retryIntervalMultiplier = RandomUtil.randomDouble(); int reconnectAttempts = RandomUtil.randomPositiveInt(); cf.setClientFailureCheckPeriod(clientFailureCheckPeriod); cf.setConnectionTTL(connectionTTL); cf.setCallTimeout(callTimeout); cf.setMinLargeMessageSize(minLargeMessageSize); cf.setConsumerWindowSize(consumerWindowSize); cf.setConsumerMaxRate(consumerMaxRate); cf.setConfirmationWindowSize(confirmationWindowSize); cf.setProducerMaxRate(producerMaxRate); cf.setBlockOnAcknowledge(blockOnAcknowledge); cf.setBlockOnDurableSend(blockOnDurableSend); cf.setBlockOnNonDurableSend(blockOnNonDurableSend); cf.setAutoGroup(autoGroup); cf.setPreAcknowledge(preAcknowledge); cf.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName); cf.setUseGlobalPools(useGlobalPools); cf.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize); cf.setThreadPoolMaxSize(threadPoolMaxSize); cf.setRetryInterval(retryInterval); cf.setRetryIntervalMultiplier(retryIntervalMultiplier); cf.setReconnectAttempts(reconnectAttempts); Assert.assertEquals(clientFailureCheckPeriod, cf.getClientFailureCheckPeriod()); Assert.assertEquals(connectionTTL, cf.getConnectionTTL()); Assert.assertEquals(callTimeout, cf.getCallTimeout()); Assert.assertEquals(minLargeMessageSize, cf.getMinLargeMessageSize()); Assert.assertEquals(consumerWindowSize, cf.getConsumerWindowSize()); Assert.assertEquals(consumerMaxRate, cf.getConsumerMaxRate()); Assert.assertEquals(confirmationWindowSize, cf.getConfirmationWindowSize()); Assert.assertEquals(producerMaxRate, cf.getProducerMaxRate()); Assert.assertEquals(blockOnAcknowledge, cf.isBlockOnAcknowledge()); Assert.assertEquals(blockOnDurableSend, cf.isBlockOnDurableSend()); Assert.assertEquals(blockOnNonDurableSend, cf.isBlockOnNonDurableSend()); Assert.assertEquals(autoGroup, cf.isAutoGroup()); Assert.assertEquals(preAcknowledge, cf.isPreAcknowledge()); Assert.assertEquals( loadBalancingPolicyClassName, cf.getConnectionLoadBalancingPolicyClassName()); Assert.assertEquals(useGlobalPools, cf.isUseGlobalPools()); Assert.assertEquals(scheduledThreadPoolMaxSize, cf.getScheduledThreadPoolMaxSize()); Assert.assertEquals(threadPoolMaxSize, cf.getThreadPoolMaxSize()); Assert.assertEquals(retryInterval, cf.getRetryInterval()); Assert.assertEquals(retryIntervalMultiplier, cf.getRetryIntervalMultiplier(), 0.0001); Assert.assertEquals(reconnectAttempts, cf.getReconnectAttempts()); cf.close(); }
@Test public void testParams() throws Exception { String resource = RandomUtil.randomString(); String operationName = RandomUtil.randomString(); long i = RandomUtil.randomInt(); String s = RandomUtil.randomString(); double d = RandomUtil.randomDouble(); boolean b = RandomUtil.randomBoolean(); long l = RandomUtil.randomLong(); Map<String, Object> map = new HashMap<>(); String key1 = RandomUtil.randomString(); int value1 = RandomUtil.randomInt(); String key2 = RandomUtil.randomString(); double value2 = RandomUtil.randomDouble(); String key3 = RandomUtil.randomString(); String value3 = RandomUtil.randomString(); String key4 = RandomUtil.randomString(); boolean value4 = RandomUtil.randomBoolean(); String key5 = RandomUtil.randomString(); long value5 = RandomUtil.randomLong(); map.put(key1, value1); map.put(key2, value2); map.put(key3, value3); map.put(key4, value4); map.put(key5, value5); Map<String, Object> map2 = new HashMap<>(); String key2_1 = RandomUtil.randomString(); int value2_1 = RandomUtil.randomInt(); String key2_2 = RandomUtil.randomString(); double value2_2 = RandomUtil.randomDouble(); String key2_3 = RandomUtil.randomString(); String value2_3 = RandomUtil.randomString(); String key2_4 = RandomUtil.randomString(); boolean value2_4 = RandomUtil.randomBoolean(); String key2_5 = RandomUtil.randomString(); long value2_5 = RandomUtil.randomLong(); map2.put(key2_1, value2_1); map2.put(key2_2, value2_2); map2.put(key2_3, value2_3); map2.put(key2_4, value2_4); map2.put(key2_5, value2_5); Map<String, Object> map3 = new HashMap<>(); String key3_1 = RandomUtil.randomString(); int value3_1 = RandomUtil.randomInt(); String key3_2 = RandomUtil.randomString(); double value3_2 = RandomUtil.randomDouble(); String key3_3 = RandomUtil.randomString(); String value3_3 = RandomUtil.randomString(); String key3_4 = RandomUtil.randomString(); boolean value3_4 = RandomUtil.randomBoolean(); String key3_5 = RandomUtil.randomString(); long value3_5 = RandomUtil.randomLong(); map3.put(key3_1, value3_1); map3.put(key3_2, value3_2); map3.put(key3_3, value3_3); map3.put(key3_4, value3_4); map3.put(key3_5, value3_5); Map[] maps = new Map[] {map2, map3}; String strElem0 = RandomUtil.randomString(); String strElem1 = RandomUtil.randomString(); String strElem2 = RandomUtil.randomString(); String[] strArray = new String[] {strElem0, strElem1, strElem2}; Object[] params = new Object[] {i, s, d, b, l, map, strArray, maps}; Message msg = new ClientMessageImpl((byte) 0, false, 0, 0, (byte) 4, 1000); ManagementHelper.putOperationInvocation(msg, resource, operationName, params); Object[] parameters = ManagementHelper.retrieveOperationParameters(msg); Assert.assertEquals(params.length, parameters.length); Assert.assertEquals(i, parameters[0]); Assert.assertEquals(s, parameters[1]); Assert.assertEquals(d, parameters[2]); Assert.assertEquals(b, parameters[3]); Assert.assertEquals(l, parameters[4]); Map mapRes = (Map) parameters[5]; Assert.assertEquals(map.size(), mapRes.size()); Assert.assertEquals((long) value1, mapRes.get(key1)); Assert.assertEquals(value2, mapRes.get(key2)); Assert.assertEquals(value3, mapRes.get(key3)); Assert.assertEquals(value4, mapRes.get(key4)); Assert.assertEquals(value5, mapRes.get(key5)); Object[] strArr2 = (Object[]) parameters[6]; Assert.assertEquals(strArray.length, strArr2.length); Assert.assertEquals(strElem0, strArr2[0]); Assert.assertEquals(strElem1, strArr2[1]); Assert.assertEquals(strElem2, strArr2[2]); Object[] mapArray = (Object[]) parameters[7]; Assert.assertEquals(2, mapArray.length); Map mapRes2 = (Map) mapArray[0]; Assert.assertEquals(map2.size(), mapRes2.size()); Assert.assertEquals((long) value2_1, mapRes2.get(key2_1)); Assert.assertEquals(value2_2, mapRes2.get(key2_2)); Assert.assertEquals(value2_3, mapRes2.get(key2_3)); Assert.assertEquals(value2_4, mapRes2.get(key2_4)); Assert.assertEquals(value2_5, mapRes2.get(key2_5)); Map mapRes3 = (Map) mapArray[1]; Assert.assertEquals(map3.size(), mapRes3.size()); Assert.assertEquals((long) value3_1, mapRes3.get(key3_1)); Assert.assertEquals(value3_2, mapRes3.get(key3_2)); Assert.assertEquals(value3_3, mapRes3.get(key3_3)); Assert.assertEquals(value3_4, mapRes3.get(key3_4)); Assert.assertEquals(value3_5, mapRes3.get(key3_5)); }