http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/NonSerializableFactory.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/NonSerializableFactory.java b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/NonSerializableFactory.java new file mode 100644 index 0000000..0c39f13 --- /dev/null +++ b/tests/activemq5-unit-tests/src/main/java/org/apache/activemq/broker/artemiswrapper/NonSerializableFactory.java @@ -0,0 +1,111 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.broker.artemiswrapper; + +import javax.naming.Context; +import javax.naming.Name; +import javax.naming.NamingException; +import javax.naming.RefAddr; +import javax.naming.Reference; +import javax.naming.StringRefAddr; +import javax.naming.spi.ObjectFactory; + +//import org.jboss.util.naming.Util; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; + +/** + * used by the default context when running in embedded local configuration + * + * @author <a href="[email protected]">Andy Taylor</a> + */ +public class NonSerializableFactory implements ObjectFactory +{ + + public NonSerializableFactory() + { + } +/* + public static void unbind(final Context ctx, final String strName) throws NamingException + { + Name name = ctx.getNameParser("").parse(strName); + int size = name.size(); + String atom = name.get(size - 1); + Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1)); + String key = new StringBuilder().append(parentCtx.getNameInNamespace()).append("/").append(atom).toString(); + NonSerializableFactory.getWrapperMap().remove(key); + Util.unbind(ctx, strName); + } + + public static void rebind(final Context ctx, final String strName, final Object value) throws NamingException + { + Name name = ctx.getNameParser("").parse(strName); + int size = name.size(); + String atom = name.get(size - 1); + Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1)); + String key = new StringBuilder().append(parentCtx.getNameInNamespace()).append("/").append(atom).toString(); + NonSerializableFactory.getWrapperMap().put(key, value); + String className = value.getClass().getName(); + String factory = NonSerializableFactory.class.getName(); + StringRefAddr addr = new StringRefAddr("nns", key); + Reference memoryRef = new Reference(className, addr, factory, null); + parentCtx.rebind(atom, memoryRef); + } + + public static void bind(final Context ctx, final String strName, final Object value) throws NamingException + { + Name name = ctx.getNameParser("").parse(strName); + int size = name.size(); + String atom = name.get(size - 1); + Context parentCtx = Util.createSubcontext(ctx, name.getPrefix(size - 1)); + String key = new StringBuilder().append(parentCtx.getNameInNamespace()).append("/").append(atom).toString(); + NonSerializableFactory.getWrapperMap().put(key, value); + String className = value.getClass().getName(); + String factory = NonSerializableFactory.class.getName(); + StringRefAddr addr = new StringRefAddr("nns", key); + Reference memoryRef = new Reference(className, addr, factory, null); + + parentCtx.bind(atom, memoryRef); + } +*/ + public static Object lookup(final String name) throws NamingException + { + if (NonSerializableFactory.getWrapperMap().get(name) == null) + { + throw new NamingException(name + " not found"); + } + return NonSerializableFactory.getWrapperMap().get(name); + } + + public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?, ?> env) throws Exception + { + Reference ref = (Reference) obj; + RefAddr addr = ref.get("nns"); + String key = (String) addr.getContent(); + return NonSerializableFactory.getWrapperMap().get(key); + } + + public static Map<String, Object> getWrapperMap() + { + return NonSerializableFactory.wrapperMap; + } + + private static Map<String, Object> wrapperMap = Collections.synchronizedMap(new HashMap<String, Object>()); +}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/main/resources/META-INF/services/org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/main/resources/META-INF/services/org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory b/tests/activemq5-unit-tests/src/main/resources/META-INF/services/org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory new file mode 100644 index 0000000..c76e40e --- /dev/null +++ b/tests/activemq5-unit-tests/src/main/resources/META-INF/services/org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory @@ -0,0 +1,2 @@ +org.apache.activemq.artemis.core.protocol.openwire.OpenWireProtocolManagerFactory + http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/activemq-browse.properties ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/activemq-browse.properties b/tests/activemq5-unit-tests/src/test/java/activemq-browse.properties new file mode 100644 index 0000000..36559c7 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/activemq-browse.properties @@ -0,0 +1,61 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +# Remote addresses for the other brokers in mesh + + +# 1a +1a.name=1a-nc +1a.uri=failover:(tcp://localhost:6106)?randomize=false +1a.transport=tcp://localhost:6106 +1a.jmx=1090 +1a.data=target/data/1a_store + +# 1b +1b.name=1b-nc +1b.uri=failover:(tcp://localhost:6107)?randomize=false +1b.transport=tcp://localhost:6107 +1b.jmx=1091 +1b.data=target/data/1b_store + +# 2a +2a.name=2a-nc +2a.uri=failover:(tcp://localhost:6108)?randomize=false +2a.transport=tcp://localhost:6108 +2a.jmx=1092 +2a.data=target/data/2a_store + +# 2b +2b.name=2b-nc +2b.uri=failover:(tcp://localhost:6109)?randomize=false +2b.transport=tcp://localhost:6109 +2b.jmx=1093 +2b.data=target/data/2b_store + +# 3a +3a.name=3a-nc +3a.uri=failover:(tcp://localhost:6110)?randomize=false +3a.transport=tcp://localhost:6110 +3a.jmx=1094 +3a.data=target/data/3a_store + +# 3b +3b.name=3b-nc +3b.uri=failover:(tcp://localhost:6111)?randomize=false +3b.transport=tcp://localhost:6111 +3b.jmx=1095 +3b.data=target/data/3b_store http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/activemq-partition.xml ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/activemq-partition.xml b/tests/activemq5-unit-tests/src/test/java/activemq-partition.xml new file mode 100644 index 0000000..4bb96f2 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/activemq-partition.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<!-- START SNIPPET: xbean --> +<beans + xmlns="http://www.springframework.org/schema/beans" + xmlns:amq="http://activemq.apache.org/schema/core" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> + + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> + + <bean id="config" class="java.lang.String"> + <constructor-arg><value> + <![CDATA[ + { + "by_client_id":{ + "client1":{"ids":["broker1"]}, + "client2":{"ids":["broker1","broker2"]} + }, + "brokers":{ + "broker1":"tcp://localhost:61616", + "broker2":"tcp://localhost:61616" + } + } + ]]> + </value></constructor-arg> + </bean> + + <broker useJmx="false" xmlns="http://activemq.apache.org/schema/core" persistent="false"> + + <plugins> + <partitionBrokerPlugin minTransferCount="5" configAsJson="#config"/> + </plugins> + + <transportConnectors> + <transportConnector uri="tcp://localhost:61616"/> + </transportConnectors> + + </broker> + +</beans> +<!-- END SNIPPET: xbean --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/activemq.xml ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/activemq.xml b/tests/activemq5-unit-tests/src/test/java/activemq.xml new file mode 100644 index 0000000..eb49ca0 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/activemq.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<!-- START SNIPPET: xbean --> +<beans + xmlns="http://www.springframework.org/schema/beans" + xmlns:amq="http://activemq.apache.org/schema/core" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd + http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> + + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> + + <broker useJmx="false" xmlns="http://activemq.apache.org/schema/core" persistent="false"> + + <transportConnectors> + <transportConnector uri="nio://localhost:61616?wireFormat.maxFrameSize=1048576" /> + </transportConnectors> + + </broker> + +</beans> +<!-- END SNIPPET: xbean --> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/client.keystore ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/client.keystore b/tests/activemq5-unit-tests/src/test/java/client.keystore new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/credentials.properties ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/credentials.properties b/tests/activemq5-unit-tests/src/test/java/credentials.properties new file mode 100644 index 0000000..86f7199 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/credentials.properties @@ -0,0 +1,24 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +# Defines credentials that will be used by components (like web console) to access the broker + +activemq.username=system +#activemq.password=manager +activemq.password=ENC(mYRkg+4Q4hua1kvpCCI2hg==) +#guest.password=password +guest.password=ENC(Cf3Jf3tM+UrSOoaKU50od5CuBa8rxjoL) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/dummy.keystore ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/dummy.keystore b/tests/activemq5-unit-tests/src/test/java/dummy.keystore new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/jmx.access ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/jmx.access b/tests/activemq5-unit-tests/src/test/java/jmx.access new file mode 100644 index 0000000..4625b7d --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/jmx.access @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +admin readwrite \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/jmx.password ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/jmx.password b/tests/activemq5-unit-tests/src/test/java/jmx.password new file mode 100644 index 0000000..053aa65 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/jmx.password @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +admin activemq \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/jndi.properties ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/jndi.properties b/tests/activemq5-unit-tests/src/test/java/jndi.properties new file mode 100644 index 0000000..d627de9 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/jndi.properties @@ -0,0 +1,38 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +# START SNIPPET: jndi + +java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory + +# use the following property to configure the default connector +java.naming.provider.url = vm://localhost + +# use the following property to specify the JNDI name the connection factory +# should appear as. +#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry + +# register some queues in JNDI using the form +# queue.[jndiName] = [physicalName] +queue.MyQueue = example.MyQueue + + +# register some topics in JNDI using the form +# topic.[jndiName] = [physicalName] +topic.MyTopic = example.MyTopic + +# END SNIPPET: jndi http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/log4j.properties ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/log4j.properties b/tests/activemq5-unit-tests/src/test/java/log4j.properties new file mode 100644 index 0000000..4704dbc --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/log4j.properties @@ -0,0 +1,46 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +# +# The logging properties used during tests.. +# +log4j.rootLogger=INFO, out, stdout + +#log4j.logger.org.apache.activemq.broker.scheduler=DEBUG +#log4j.logger.org.apache.activemq.store.kahadb.scheduler=DEBUG +#log4j.logger.org.apache.activemq.network.DemandForwardingBridgeSupport=DEBUG +#log4j.logger.org.apache.activemq.transport.failover=TRACE +#log4j.logger.org.apache.activemq.store.jdbc=TRACE +#log4j.logger.org.apache.activemq.store.kahadb=TRACE +#log4j.logger.org.apache.activemq.broker.region.cursors.AbstractStoreCursor=DEBUG +#log4j.logger.org.apache.activemq.store.jdbc.JDBCMessageStore=DEBUG +#log4j.logger.org.apache.activemq.store.kahadb.disk.journal=DEBUG +#log4j.logger.org.apache.activemq.store.kahadb.AbstractKahaDBStore=DEBUG + +# CONSOLE appender not used by default +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n +#log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n + +# File appender +log4j.appender.out=org.apache.log4j.FileAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n +log4j.appender.out.file=target/activemq-test.log +log4j.appender.out.append=true http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/login.config ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/login.config b/tests/activemq5-unit-tests/src/test/java/login.config new file mode 100644 index 0000000..1f5f77c --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/login.config @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +activemq-domain { + org.apache.activemq.jaas.PropertiesLoginModule required + debug=true + org.apache.activemq.jaas.properties.user="org/apache/activemq/security/users.properties" + org.apache.activemq.jaas.properties.group="org/apache/activemq/security/groups.properties"; +}; + +activemq-guest-domain { + org.apache.activemq.jaas.PropertiesLoginModule sufficient + debug=true + org.apache.activemq.jaas.properties.user="org/apache/activemq/security/users.properties" + org.apache.activemq.jaas.properties.group="org/apache/activemq/security/groups.properties"; + org.apache.activemq.jaas.GuestLoginModule sufficient + debug=true + org.apache.activemq.jaas.guest.user="guest" + org.apache.activemq.jaas.guest.group="guests"; +}; + +activemq-guest-when-no-creds-only-domain { + org.apache.activemq.jaas.GuestLoginModule sufficient + debug=true + credentialsInvalidate=true + org.apache.activemq.jaas.guest.user="guest" + org.apache.activemq.jaas.guest.group="guests"; + + org.apache.activemq.jaas.PropertiesLoginModule requisite + debug=true + org.apache.activemq.jaas.properties.user="org/apache/activemq/security/users.properties" + org.apache.activemq.jaas.properties.group="org/apache/activemq/security/groups.properties"; +}; + +cert-login { + org.apache.activemq.jaas.TextFileCertificateLoginModule required + debug=true + org.apache.activemq.jaas.textfiledn.user="org/apache/activemq/security/users.properties" + org.apache.activemq.jaas.textfiledn.group="org/apache/activemq/security/groups.properties"; + +}; + +broker1 { + org.apache.activemq.jaas.TextFileCertificateLoginModule required + debug=true + org.apache.activemq.jaas.textfiledn.user="org/apache/activemq/security/users1.properties" + org.apache.activemq.jaas.textfiledn.group="org/apache/activemq/security/groups.properties"; +}; + +broker2 { + org.apache.activemq.jaas.TextFileCertificateLoginModule required + debug=true + org.apache.activemq.jaas.textfiledn.user="org/apache/activemq/security/users2.properties" + org.apache.activemq.jaas.textfiledn.group="org/apache/activemq/security/groups.properties"; +}; + +LDAPLogin { + org.apache.activemq.jaas.LDAPLoginModule required + debug=true + initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory + connectionURL="ldap://localhost:1024" + connectionUsername="uid=admin,ou=system" + connectionPassword=secret + connectionProtocol=s + authentication=simple + userBase="ou=User,ou=ActiveMQ,ou=system" + userSearchMatching="(uid={0})" + userSearchSubtree=false + roleBase="ou=Group,ou=ActiveMQ,ou=system" + roleName=cn + roleSearchMatching="(uid={1})" + roleSearchSubtree=true + ; +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/openwire-control/org.apache.activemq.openwire.BrokerInfoData.bin ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/openwire-control/org.apache.activemq.openwire.BrokerInfoData.bin b/tests/activemq5-unit-tests/src/test/java/openwire-control/org.apache.activemq.openwire.BrokerInfoData.bin new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/openwire-control/org.apache.activemq.openwire.WireFormatInfoData.bin ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/openwire-control/org.apache.activemq.openwire.WireFormatInfoData.bin b/tests/activemq5-unit-tests/src/test/java/openwire-control/org.apache.activemq.openwire.WireFormatInfoData.bin new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java new file mode 100644 index 0000000..353f1d3 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java @@ -0,0 +1,261 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.URI; +import java.net.URISyntaxException; + +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.Session; + +import org.apache.activemq.broker.BrokerRegistry; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ActiveMQConnectionFactoryTest extends CombinationTestSupport { + private static final Logger LOG = LoggerFactory.getLogger(ActiveMQConnectionFactoryTest.class); + + private ActiveMQConnection connection; + private BrokerService broker; + + public void testUseURIToSetUseClientIDPrefixOnConnectionFactory() throws URISyntaxException, JMSException { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory( + "vm://localhost?jms.clientIDPrefix=Cheese"); + assertEquals("Cheese", cf.getClientIDPrefix()); + + connection = (ActiveMQConnection)cf.createConnection(); + connection.start(); + + String clientID = connection.getClientID(); + LOG.info("Got client ID: " + clientID); + + assertTrue("should start with Cheese! but was: " + clientID, clientID.startsWith("Cheese")); + } + + @Override + public void tearDown() throws Exception { + // Try our best to close any previously opend connection. + try { + connection.close(); + } catch (Throwable ignore) { + } + // Try our best to stop any previously started broker. + try { + broker.stop(); + } catch (Throwable ignore) { + } + } + + public void testUseURIToSetOptionsOnConnectionFactory() throws URISyntaxException, JMSException { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?jms.useAsyncSend=true"); + assertTrue(cf.isUseAsyncSend()); + // the broker url have been adjusted. + assertEquals("vm://localhost", cf.getBrokerURL()); + + cf = new ActiveMQConnectionFactory("vm://localhost?jms.useAsyncSend=false"); + assertFalse(cf.isUseAsyncSend()); + // the broker url have been adjusted. + assertEquals("vm://localhost", cf.getBrokerURL()); + + cf = new ActiveMQConnectionFactory("vm:(broker:()/localhost)?jms.useAsyncSend=true"); + assertTrue(cf.isUseAsyncSend()); + // the broker url have been adjusted. + assertEquals("vm:(broker:()/localhost)", cf.getBrokerURL()); + + cf = new ActiveMQConnectionFactory("vm://localhost?jms.auditDepth=5000"); + assertEquals(5000, cf.getAuditDepth()); + } + + public void testUseURIToConfigureRedeliveryPolicy() throws URISyntaxException, JMSException { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory( + "vm://localhost?jms.redeliveryPolicy.maximumRedeliveries=2"); + assertEquals("connection redeliveries", 2, cf.getRedeliveryPolicy().getMaximumRedeliveries()); + + ActiveMQConnection connection = (ActiveMQConnection)cf.createConnection(); + assertEquals("connection redeliveries", 2, connection.getRedeliveryPolicy().getMaximumRedeliveries()); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer)session.createConsumer(session + .createQueue("FOO.BAR")); + assertEquals("consumer redeliveries", 2, consumer.getRedeliveryPolicy().getMaximumRedeliveries()); + connection.close(); + } + + public void testCreateVMConnectionWithEmbdeddBroker() throws URISyntaxException, JMSException { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://myBroker2?broker.persistent=false"); + // Make sure the broker is not created until the connection is + // instantiated. + assertNull(BrokerRegistry.getInstance().lookup("myBroker2")); + connection = (ActiveMQConnection)cf.createConnection(); + // This should create the connection. + assertNotNull(connection); + // Verify the broker was created. + assertNotNull(BrokerRegistry.getInstance().lookup("myBroker2")); + + connection.close(); + + // Verify the broker was destroyed. + assertNull(BrokerRegistry.getInstance().lookup("myBroker2")); + } + + public void testGetBrokerName() throws URISyntaxException, JMSException { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); + connection = (ActiveMQConnection)cf.createConnection(); + connection.start(); + + String brokerName = connection.getBrokerName(); + LOG.info("Got broker name: " + brokerName); + + assertNotNull("No broker name available!", brokerName); + } + + public void testCreateTcpConnectionUsingAllocatedPort() throws Exception { + assertCreateConnection("tcp://localhost:0?wireFormat.tcpNoDelayEnabled=true"); + } + + public void testCreateTcpConnectionUsingKnownPort() throws Exception { + assertCreateConnection("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true"); + } + + public void testCreateTcpConnectionUsingKnownLocalPort() throws Exception { + broker = new BrokerService(); + broker.setPersistent(false); + broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true"); + broker.start(); + + // This should create the connection. + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61610/localhost:51610"); + connection = (ActiveMQConnection)cf.createConnection(); + assertNotNull(connection); + + connection.close(); + + broker.stop(); + } + + public void testConnectionFailsToConnectToVMBrokerThatIsNotRunning() throws Exception { + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?create=false"); + try { + factory.createConnection(); + fail("Expected connection failure."); + } catch (JMSException e) { + } + } + + public void testFactorySerializable() throws Exception { + String clientID = "TestClientID"; + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); + cf.setClientID(clientID); + ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); + ObjectOutputStream objectsOut = new ObjectOutputStream(bytesOut); + objectsOut.writeObject(cf); + objectsOut.flush(); + byte[] data = bytesOut.toByteArray(); + ByteArrayInputStream bytesIn = new ByteArrayInputStream(data); + ObjectInputStream objectsIn = new ObjectInputStream(bytesIn); + cf = (ActiveMQConnectionFactory)objectsIn.readObject(); + assertEquals(cf.getClientID(), clientID); + } + + public void testSetExceptionListener() throws Exception { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); + connection = (ActiveMQConnection)cf.createConnection(); + assertNull(connection.getExceptionListener()); + + ExceptionListener exListener = new ExceptionListener() { + @Override + public void onException(JMSException arg0) { + } + }; + cf.setExceptionListener(exListener); + connection.close(); + + connection = (ActiveMQConnection)cf.createConnection(); + assertNotNull(connection.getExceptionListener()); + assertEquals(exListener, connection.getExceptionListener()); + connection.close(); + + connection = (ActiveMQConnection)cf.createConnection(); + assertEquals(exListener, connection.getExceptionListener()); + + assertEquals(exListener, cf.getExceptionListener()); + connection.close(); + + } + + + public void testSetClientInternalExceptionListener() throws Exception { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); + connection = (ActiveMQConnection)cf.createConnection(); + assertNull(connection.getClientInternalExceptionListener()); + + ClientInternalExceptionListener listener = new ClientInternalExceptionListener() { + @Override + public void onException(Throwable exception) { + } + }; + connection.setClientInternalExceptionListener(listener); + cf.setClientInternalExceptionListener(listener); + connection.close(); + + connection = (ActiveMQConnection)cf.createConnection(); + assertNotNull(connection.getClientInternalExceptionListener()); + assertEquals(listener, connection.getClientInternalExceptionListener()); + connection.close(); + + connection = (ActiveMQConnection)cf.createConnection(); + assertEquals(listener, connection.getClientInternalExceptionListener()); + assertEquals(listener, cf.getClientInternalExceptionListener()); + connection.close(); + + } + + protected void assertCreateConnection(String uri) throws Exception { + // Start up a broker with a tcp connector. + broker = new BrokerService(); + broker.setPersistent(false); + broker.setUseJmx(false); + TransportConnector connector = broker.addConnector(uri); + broker.start(); + + URI temp = new URI(uri); + // URI connectURI = connector.getServer().getConnectURI(); + // TODO this sometimes fails when using the actual local host name + URI currentURI = new URI(connector.getPublishableConnectString()); + + // sometimes the actual host name doesn't work in this test case + // e.g. on OS X so lets use the original details but just use the actual + // port + URI connectURI = new URI(temp.getScheme(), temp.getUserInfo(), temp.getHost(), currentURI.getPort(), + temp.getPath(), temp.getQuery(), temp.getFragment()); + + LOG.info("connection URI is: " + connectURI); + + // This should create the connection. + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectURI); + connection = (ActiveMQConnection)cf.createConnection(); + assertNotNull(connection); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQInputStreamTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQInputStreamTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQInputStreamTest.java new file mode 100644 index 0000000..77f422e --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQInputStreamTest.java @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq; + +import java.io.InputStream; +import java.io.OutputStream; + +import javax.jms.Queue; +import javax.jms.Session; + +import junit.framework.TestCase; + +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.command.ActiveMQDestination; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Deprecated +public class ActiveMQInputStreamTest extends TestCase { + + private static final Logger LOG = LoggerFactory.getLogger(ActiveMQInputStreamTest.class); + + private static final String BROKER_URL = "tcp://localhost:0"; + private static final String DESTINATION = "destination"; + private static final int STREAM_LENGTH = 64 * 1024 + 0; // change 0 to 1 to make it not crash + + private BrokerService broker; + private String connectionUri; + + @Override + public void setUp() throws Exception { + broker = new BrokerService(); + broker.setUseJmx(false); + broker.setPersistent(false); + broker.setDestinations(new ActiveMQDestination[] { + ActiveMQDestination.createDestination(DESTINATION, ActiveMQDestination.QUEUE_TYPE), + }); + broker.addConnector(BROKER_URL); + broker.start(); + broker.waitUntilStarted(); + + connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString(); + } + + @Override + public void tearDown() throws Exception { + broker.stop(); + broker.waitUntilStopped(); + } + + public void testInputStreamSetSyncSendOption() throws Exception { + + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionUri); + ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Queue destination = session.createQueue(DESTINATION + "?producer.alwaysSyncSend=true"); + + OutputStream out = null; + try { + out = connection.createOutputStream(destination); + + assertTrue(((ActiveMQOutputStream)out).isAlwaysSyncSend()); + + LOG.debug("writing..."); + for (int i = 0; i < STREAM_LENGTH; ++i) { + out.write(0); + } + LOG.debug("wrote " + STREAM_LENGTH + " bytes"); + } finally { + if (out != null) { + out.close(); + } + } + + InputStream in = null; + try { + in = connection.createInputStream(destination); + LOG.debug("reading..."); + int count = 0; + while (-1 != in.read()) { + ++count; + } + LOG.debug("read " + count + " bytes"); + } finally { + if (in != null) { + in.close(); + } + } + + connection.close(); + } + + public void testInputStreamMatchesDefaultChuckSize() throws Exception { + + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionUri); + ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Queue destination = session.createQueue(DESTINATION); + + OutputStream out = null; + try { + out = connection.createOutputStream(destination); + LOG.debug("writing..."); + for (int i = 0; i < STREAM_LENGTH; ++i) { + out.write(0); + } + LOG.debug("wrote " + STREAM_LENGTH + " bytes"); + } finally { + if (out != null) { + out.close(); + } + } + + InputStream in = null; + try { + in = connection.createInputStream(destination); + LOG.debug("reading..."); + int count = 0; + while (-1 != in.read()) { + ++count; + } + LOG.debug("read " + count + " bytes"); + } finally { + if (in != null) { + in.close(); + } + } + + connection.close(); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java new file mode 100644 index 0000000..af18084 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQMessageAuditTest.java @@ -0,0 +1,186 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.List; +import junit.framework.TestCase; +import org.apache.activemq.broker.region.MessageReference; +import org.apache.activemq.command.ActiveMQMessage; +import org.apache.activemq.command.MessageId; +import org.apache.activemq.command.ProducerId; +import org.apache.activemq.util.IdGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ActiveMQMessageAuditTest + * + * + */ +public class ActiveMQMessageAuditTest extends TestCase { + + static final Logger LOG = LoggerFactory.getLogger(ActiveMQMessageAuditTest.class); + + /** + * Constructor for ActiveMQMessageAuditTest. + * + * @param name + */ + public ActiveMQMessageAuditTest(String name) { + super(name); + } + + public static void main(String[] args) { + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * test case for isDuplicate + */ + public void testIsDuplicateString() { + int count = 10000; + ActiveMQMessageAudit audit = new ActiveMQMessageAudit(); + IdGenerator idGen = new IdGenerator(); + // add to a list + List<String> list = new ArrayList<String>(); + for (int i = 0; i < count; i++) { + String id = idGen.generateId(); + list.add(id); + assertFalse(audit.isDuplicate(id)); + } + List<String> windowList = list.subList(list.size() -1 -audit.getAuditDepth(), list.size() -1); + for (String id : windowList) { + assertTrue("duplicate, id:" + id, audit.isDuplicate(id)); + } + } + + public void testIsDuplicateMessageReference() { + int count = 10000; + ActiveMQMessageAudit audit = new ActiveMQMessageAudit(); + // add to a list + List<MessageReference> list = new ArrayList<MessageReference>(); + for (int i = 0; i < count; i++) { + ProducerId pid = new ProducerId(); + pid.setConnectionId("test"); + pid.setSessionId(0); + pid.setValue(1); + MessageId id = new MessageId(); + id.setProducerId(pid); + id.setProducerSequenceId(i); + ActiveMQMessage msg = new ActiveMQMessage(); + msg.setMessageId(id); + list.add(msg); + assertFalse(audit.isDuplicate(msg.getMessageId())); + } + List<MessageReference> windowList = list.subList(list.size() -1 -audit.getAuditDepth(), list.size() -1); + for (MessageReference msg : windowList) { + assertTrue("duplicate msg:" + msg, audit.isDuplicate(msg)); + } + } + + public void testIsInOrderString() { + int count = 10000; + ActiveMQMessageAudit audit = new ActiveMQMessageAudit(); + IdGenerator idGen = new IdGenerator(); + // add to a list + List<String> list = new ArrayList<String>(); + for (int i = 0; i < count; i++) { + String id = idGen.generateId(); + if (i==0) { + assertFalse(audit.isDuplicate(id)); + assertTrue(audit.isInOrder(id)); + } + if (i > 1 && i%2 != 0) { + list.add(id); + } + + } + for (String id : list) { + assertFalse(audit.isInOrder(id)); + assertFalse(audit.isDuplicate(id)); + } + } + + public void testSerialization() throws Exception { + ActiveMQMessageAuditNoSync audit = new ActiveMQMessageAuditNoSync(); + + byte[] bytes = serialize(audit); + LOG.debug("Length: " + bytes.length); + audit = recover(bytes); + + List<MessageReference> list = new ArrayList<MessageReference>(); + + for (int j = 0; j < 1000; j++) { + ProducerId pid = new ProducerId(); + pid.setConnectionId("test"); + pid.setSessionId(0); + pid.setValue(j); + LOG.debug("producer " + j); + + for (int i = 0; i < 1000; i++) { + MessageId id = new MessageId(); + id.setProducerId(pid); + id.setProducerSequenceId(i); + ActiveMQMessage msg = new ActiveMQMessage(); + msg.setMessageId(id); + list.add(msg); + assertFalse(audit.isDuplicate(msg.getMessageId().toString())); + + if (i % 100 == 0) { + bytes = serialize(audit); + LOG.debug("Length: " + bytes.length); + audit = recover(bytes); + } + + if (i % 250 == 0) { + for (MessageReference message : list) { + audit.rollback(message.getMessageId().toString()); + } + list.clear(); + bytes = serialize(audit); + LOG.debug("Length: " + bytes.length); + audit = recover(bytes); + } + } + } + } + + protected byte[] serialize(ActiveMQMessageAuditNoSync audit) throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oout = new ObjectOutputStream(baos); + oout.writeObject(audit); + oout.flush(); + return baos.toByteArray(); + } + + protected ActiveMQMessageAuditNoSync recover(byte[] bytes) throws Exception { + ObjectInputStream objectIn = new ObjectInputStream(new ByteArrayInputStream(bytes)); + return (ActiveMQMessageAuditNoSync)objectIn.readObject(); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java ---------------------------------------------------------------------- diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java new file mode 100644 index 0000000..5d1ec80 --- /dev/null +++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java @@ -0,0 +1,262 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.KeyStore; +import java.security.SecureRandom; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.SslBrokerService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport { + private static final Log LOG = LogFactory.getLog(ActiveMQSslConnectionFactoryTest.class); + + public static final String KEYSTORE_TYPE = "jks"; + public static final String PASSWORD = "password"; + public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore"; + public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore"; + + private ActiveMQConnection connection; + private BrokerService broker; + + @Override + protected void tearDown() throws Exception { + // Try our best to close any previously opend connection. + try { + connection.close(); + } catch (Throwable ignore) { + } + // Try our best to stop any previously started broker. + try { + broker.stop(); + } catch (Throwable ignore) { + } + } + + public void testCreateTcpConnectionUsingKnownPort() throws Exception { + // Control case: check that the factory can create an ordinary (non-ssl) connection. + broker = createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true"); + + // This should create the connection. + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true"); + connection = (ActiveMQConnection)cf.createConnection(); + assertNotNull(connection); + connection.start(); + connection.stop(); + brokerStop(); + } + + public void testCreateFailoverTcpConnectionUsingKnownPort() throws Exception { + // Control case: check that the factory can create an ordinary (non-ssl) connection. + broker = createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true"); + + // This should create the connection. + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true)"); + connection = (ActiveMQConnection)cf.createConnection(); + assertNotNull(connection); + connection.start(); + connection.stop(); + brokerStop(); + } + + public void testCreateSslConnection() throws Exception { + // Create SSL/TLS connection with trusted cert from truststore. + String sslUri = "ssl://localhost:61611"; + broker = createSslBroker(sslUri); + assertNotNull(broker); + + // This should create the connection. + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri); + cf.setTrustStore("server.keystore"); + cf.setTrustStorePassword("password"); + connection = (ActiveMQConnection)cf.createConnection(); + LOG.info("Created client connection"); + assertNotNull(connection); + connection.start(); + connection.stop(); + brokerStop(); + } + + public void testFailoverSslConnection() throws Exception { + // Create SSL/TLS connection with trusted cert from truststore. + String sslUri = "ssl://localhost:61611"; + broker = createSslBroker(sslUri); + assertNotNull(broker); + + // This should create the connection. + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4"); + cf.setTrustStore("server.keystore"); + cf.setTrustStorePassword("password"); + connection = (ActiveMQConnection)cf.createConnection(); + LOG.info("Created client connection"); + assertNotNull(connection); + connection.start(); + connection.stop(); + + brokerStop(); + } + + public void testFailoverSslConnectionWithKeyAndTrustManagers() throws Exception { + String sslUri = "ssl://localhost:61611"; + broker = createSslBroker(sslUri); + assertNotNull(broker); + + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory("failover:(" + sslUri + ")?maxReconnectAttempts=4"); + cf.setKeyAndTrustManagers(getKeyManager(), getTrustManager(), new SecureRandom()); + connection = (ActiveMQConnection)cf.createConnection(); + LOG.info("Created client connection"); + assertNotNull(connection); + connection.start(); + connection.stop(); + + brokerStop(); + } + + public void testNegativeCreateSslConnectionWithWrongPassword() throws Exception { + // Create SSL/TLS connection with trusted cert from truststore. + String sslUri = "ssl://localhost:61611"; + broker = createSslBroker(sslUri); + assertNotNull(broker); + + // This should FAIL to connect, due to wrong password. + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri); + cf.setTrustStore("server.keystore"); + cf.setTrustStorePassword("wrongPassword"); + try { + connection = (ActiveMQConnection)cf.createConnection(); + } + catch (javax.jms.JMSException ignore) { + // Expected exception + LOG.info("Expected java.io.Exception [" + ignore + "]"); + } + assertNull(connection); + + brokerStop(); + } + + public void testNegativeCreateSslConnectionWithWrongCert() throws Exception { + // Create SSL/TLS connection with trusted cert from truststore. + String sslUri = "ssl://localhost:61611"; + broker = createSslBroker(sslUri); + assertNotNull(broker); + + // This should FAIL to connect, due to wrong password. + ActiveMQSslConnectionFactory cf = new ActiveMQSslConnectionFactory(sslUri); + cf.setTrustStore("dummy.keystore"); + cf.setTrustStorePassword("password"); + try { + connection = (ActiveMQConnection)cf.createConnection(); + } + catch (javax.jms.JMSException ignore) { + // Expected exception + LOG.info("Expected SSLHandshakeException [" + ignore + "]"); + } + assertNull(connection); + + brokerStop(); + } + + protected BrokerService createBroker(String uri) throws Exception { + // Start up a broker with a tcp connector. + BrokerService service = new BrokerService(); + service.setPersistent(false); + service.setUseJmx(false); + service.addConnector(uri); + service.start(); + + return service; + } + + protected BrokerService createSslBroker(String uri) throws Exception { + + // http://java.sun.com/javase/javaseforbusiness/docs/TLSReadme.html + // work around: javax.net.ssl.SSLHandshakeException: renegotiation is not allowed + //System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true"); + + SslBrokerService service = new SslBrokerService(); + service.setPersistent(false); + + service.setupSsl(KEYSTORE_TYPE, PASSWORD, SERVER_KEYSTORE); + + service.start(); + + return service; + } + + protected void brokerStop() throws Exception { + broker.stop(); + } + + public static TrustManager[] getTrustManager() throws Exception { + TrustManager[] trustStoreManagers = null; + KeyStore trustedCertStore = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE); + + trustedCertStore.load(new FileInputStream(ActiveMQSslConnectionFactoryTest.TRUST_KEYSTORE), null); + TrustManagerFactory tmf = + TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + + tmf.init(trustedCertStore); + trustStoreManagers = tmf.getTrustManagers(); + return trustStoreManagers; + } + + public static KeyManager[] getKeyManager() throws Exception { + KeyManagerFactory kmf = + KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + KeyStore ks = KeyStore.getInstance(ActiveMQSslConnectionFactoryTest.KEYSTORE_TYPE); + KeyManager[] keystoreManagers = null; + + byte[] sslCert = loadClientCredential(ActiveMQSslConnectionFactoryTest.SERVER_KEYSTORE); + + + if (sslCert != null && sslCert.length > 0) { + ByteArrayInputStream bin = new ByteArrayInputStream(sslCert); + ks.load(bin, ActiveMQSslConnectionFactoryTest.PASSWORD.toCharArray()); + kmf.init(ks, ActiveMQSslConnectionFactoryTest.PASSWORD.toCharArray()); + keystoreManagers = kmf.getKeyManagers(); + } + return keystoreManagers; + } + + private static byte[] loadClientCredential(String fileName) throws IOException { + if (fileName == null) { + return null; + } + FileInputStream in = new FileInputStream(fileName); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buf = new byte[512]; + int i = in.read(buf); + while (i > 0) { + out.write(buf, 0, i); + i = in.read(buf); + } + in.close(); + return out.toByteArray(); + } + +}
