http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/main/java/org/apache/rocketmq/jms/support/PrimitiveTypeCast.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/rocketmq/jms/support/PrimitiveTypeCast.java b/core/src/main/java/org/apache/rocketmq/jms/support/PrimitiveTypeCast.java deleted file mode 100644 index 6e24ab0..0000000 --- a/core/src/main/java/org/apache/rocketmq/jms/support/PrimitiveTypeCast.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * 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.rocketmq.jms.support; - -import javax.jms.JMSException; -import javax.jms.MapMessage; - -/** - * Primitive type converter, according to the conversion table in {@link MapMessage}. - */ -public class PrimitiveTypeCast { - - /** - * Indicate if the parameter obj is primitive type. - * - * @param obj that to be check - * @return true if the obj is primitive type, otherwise return false - */ - public static boolean isPrimitiveType(Object obj) { - if (obj == null) { - return false; - } - if (Boolean.class.isInstance(obj) - || Byte.class.isInstance(obj) - || Short.class.isInstance(obj) - || Character.class.isInstance(obj) - || Integer.class.isInstance(obj) - || Long.class.isInstance(obj) - || Float.class.isInstance(obj) - || Double.class.isInstance(obj) - || String.class.isInstance(obj) - || byte[].class.isInstance(obj)) { - return true; - } - - return false; - } - - public static boolean cast2Boolean(Object obj) throws JMSException { - if (obj == null) { - return Boolean.valueOf(null); - } - - if (Boolean.class.isInstance(obj)) { - return (Boolean) obj; - } - if (String.class.isInstance(obj)) { - return Boolean.valueOf((String) obj); - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static byte cast2Byte(Object obj) throws JMSException { - if (obj == null) { - return Byte.valueOf(null); - } - - if (Byte.class.isInstance(obj)) { - return (Byte) obj; - } - if (String.class.isInstance(obj)) { - return Byte.valueOf((String) obj); - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static short cast2Short(Object obj) throws JMSException { - if (obj == null) { - return Short.valueOf(null); - } - - if (Byte.class.isInstance(obj)) { - return ((Byte) obj).shortValue(); - } - if (Short.class.isInstance(obj)) { - return (Short) obj; - } - if (String.class.isInstance(obj)) { - return Short.valueOf((String) obj); - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static char cast2Char(Object obj) throws JMSException { - if (obj == null) { - throw new NullPointerException("Obj is required"); - } - - if (Character.class.isInstance(obj)) { - return (Character) obj; - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static int cast2Int(Object obj) throws JMSException { - if (obj == null) { - return Integer.valueOf(null); - } - - if (Byte.class.isInstance(obj)) { - return ((Byte) obj).intValue(); - } - if (Short.class.isInstance(obj)) { - return ((Short) obj).intValue(); - } - if (Integer.class.isInstance(obj)) { - return (Integer) obj; - } - if (String.class.isInstance(obj)) { - return Integer.parseInt((String) obj); - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static long cast2Long(Object obj) throws JMSException { - if (obj == null) { - return Long.valueOf(null); - } - - if (Byte.class.isInstance(obj)) { - return ((Byte) obj).longValue(); - } - if (Short.class.isInstance(obj)) { - return ((Short) obj).longValue(); - } - if (Integer.class.isInstance(obj)) { - return ((Integer) obj).longValue(); - } - if (Long.class.isInstance(obj)) { - return (Long) obj; - } - if (String.class.isInstance(obj)) { - return Long.parseLong((String) obj); - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static float cast2Float(Object obj) throws JMSException { - if (obj == null) { - return Float.valueOf(null); - } - - if (Float.class.isInstance(obj)) { - return (Float) obj; - } - if (String.class.isInstance(obj)) { - return Float.parseFloat((String) obj); - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static double cast2Double(Object obj) throws JMSException { - if (obj == null) { - return Double.valueOf(null); - } - - if (Float.class.isInstance(obj)) { - return ((Float) obj).doubleValue(); - } - if (Double.class.isInstance(obj)) { - return (Double) obj; - } - if (String.class.isInstance(obj)) { - return Double.parseDouble((String) obj); - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static String cast2String(Object obj) throws JMSException { - if (obj == null) { - return String.valueOf(null); - } - - if (Boolean.class.isInstance(obj) - || Byte.class.isInstance(obj) - || Short.class.isInstance(obj) - || Character.class.isInstance(obj) - || Integer.class.isInstance(obj) - || Long.class.isInstance(obj) - || Float.class.isInstance(obj) - || Double.class.isInstance(obj) - || String.class.isInstance(obj) - ) { - return obj.toString(); - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } - - public static byte[] cast2ByteArray(Object obj) throws JMSException { - if (obj instanceof byte[]) { - return (byte[]) obj; - } - - throw new JMSException("Incorrect type[" + obj.getClass() + "] to cast"); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/main/java/org/apache/rocketmq/jms/support/ProviderVersion.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/rocketmq/jms/support/ProviderVersion.java b/core/src/main/java/org/apache/rocketmq/jms/support/ProviderVersion.java deleted file mode 100644 index c67e71c..0000000 --- a/core/src/main/java/org/apache/rocketmq/jms/support/ProviderVersion.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.rocketmq.jms.support; - -public class ProviderVersion { - - public static final Version CURRENT_VERSION = Version.V1_1_0; - - public enum Version { - - V1_1_0(1); - private int value; - - Version(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/main/resources/logback.xml ---------------------------------------------------------------------- diff --git a/core/src/main/resources/logback.xml b/core/src/main/resources/logback.xml deleted file mode 100644 index 39da112..0000000 --- a/core/src/main/resources/logback.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?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. - --> - -<configuration> - <appender name="DefaultAppender" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <file>${user.home}/logs/rocketmq/jms.log</file> - <append>true</append> - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${user.home}/logs/rocketmq/otherdays/jms.%i.log - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>10</maxIndex> - </rollingPolicy> - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>100MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>%d{yyy-MM-dd HH:mm:ss,GMT+8} %p %t - %m%n</pattern> - <charset class="java.nio.charset.Charset">UTF-8</charset> - </encoder> - </appender> - - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <append>true</append> - <encoder> - <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> - <charset class="java.nio.charset.Charset">UTF-8</charset> - </encoder> - </appender> - - <logger name="org.apache.rocketmq.jms"> - <level value="DEBUG"/> - </logger> - - <root> - <level value="ERROR"/> - <appender-ref ref="STDOUT"/> - </root> -</configuration> http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/RocketMQConnectionFactoryTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/RocketMQConnectionFactoryTest.java b/core/src/test/java/org/apache/rocketmq/jms/RocketMQConnectionFactoryTest.java deleted file mode 100644 index 61f1e54..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/RocketMQConnectionFactoryTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.rocketmq.jms; - -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNull.notNullValue; - -public class RocketMQConnectionFactoryTest { - - @Test - public void testClientId() throws Exception { - final String nameServerAddress = "localhost:6789"; - RocketMQConnectionFactory connectionFactory = new RocketMQConnectionFactory(nameServerAddress); - - assertThat(connectionFactory.getNameServerAddress(), is(nameServerAddress)); - assertThat(connectionFactory.getClientId(), notNullValue()); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/destination/RocketMQQueueTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/destination/RocketMQQueueTest.java b/core/src/test/java/org/apache/rocketmq/jms/destination/RocketMQQueueTest.java deleted file mode 100644 index 0a3b36b..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/destination/RocketMQQueueTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.rocketmq.jms.destination; - -import org.junit.Test; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -public class RocketMQQueueTest { - - @Test - public void test() throws Exception { - RocketMQQueue queue = new RocketMQQueue("MyQueue"); - - assertThat(queue.getQueueName(), is("MyQueue")); - assertThat(queue.toString(), is("MyQueue")); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/destination/RocketMQTopicTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/destination/RocketMQTopicTest.java b/core/src/test/java/org/apache/rocketmq/jms/destination/RocketMQTopicTest.java deleted file mode 100644 index c482e1c..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/destination/RocketMQTopicTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.rocketmq.jms.destination; - -import org.junit.Test; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -public class RocketMQTopicTest { - - @Test - public void test() throws Exception { - RocketMQTopic topic = new RocketMQTopic("MyTopic"); - - assertThat(topic.getTopicName(), is("MyTopic")); - assertThat(topic.toString(), is("MyTopic")); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/hook/ReceiveMessageHookTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/hook/ReceiveMessageHookTest.java b/core/src/test/java/org/apache/rocketmq/jms/hook/ReceiveMessageHookTest.java deleted file mode 100644 index 62b5056..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/hook/ReceiveMessageHookTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.rocketmq.jms.hook; - -import java.text.SimpleDateFormat; -import java.util.Date; -import javax.jms.Message; -import org.apache.rocketmq.jms.exception.MessageExpiredException; -import org.apache.rocketmq.jms.msg.JMSTextMessage; -import org.apache.rocketmq.jms.msg.enums.JMSPropertiesEnum; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThan; - -public class ReceiveMessageHookTest { - - @Test(expected = MessageExpiredException.class) - public void testValidateFail() throws Exception { - ReceiveMessageHook hook = new ReceiveMessageHook(); - - Message message = new JMSTextMessage("text"); - message.setJMSExpiration(new Date().getTime()); - Thread.sleep(100); - hook.before(message); - } - - @Test - public void testValidateSuccess() throws Exception { - ReceiveMessageHook hook = new ReceiveMessageHook(); - - Message message = new JMSTextMessage("text"); - // never expired - message.setJMSExpiration(0); - hook.before(message); - - // expired in the future - message.setJMSExpiration(new SimpleDateFormat("yyyy-MM-dd").parse("2999-01-01").getTime()); - hook.before(message); - } - - @Test - public void setProviderProperties() throws Exception { - ReceiveMessageHook hook = new ReceiveMessageHook(); - - Message message = new JMSTextMessage("text"); - hook.before(message); - - assertThat(message.getLongProperty(JMSPropertiesEnum.JMSXRcvTimestamp.name()), greaterThan(0L)); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/hook/SendMessageHookTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/hook/SendMessageHookTest.java b/core/src/test/java/org/apache/rocketmq/jms/hook/SendMessageHookTest.java deleted file mode 100644 index 29e91ec..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/hook/SendMessageHookTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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.rocketmq.jms.hook; - -import javax.jms.DeliveryMode; -import javax.jms.Destination; -import org.apache.rocketmq.jms.RocketMQProducer; -import org.apache.rocketmq.jms.destination.RocketMQTopic; -import org.apache.rocketmq.jms.exception.UnsupportDeliveryModelException; -import org.apache.rocketmq.jms.msg.JMSTextMessage; -import org.apache.rocketmq.jms.msg.enums.JMSHeaderEnum; -import org.apache.rocketmq.jms.msg.enums.JMSPropertiesEnum; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.core.IsNull.notNullValue; -import static org.hamcrest.core.IsNull.nullValue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class SendMessageHookTest { - - @Test(expected = UnsupportDeliveryModelException.class) - public void testValidate() throws Exception { - final JMSTextMessage message = new JMSTextMessage("text"); - final RocketMQTopic destination = new RocketMQTopic("destination"); - final int deliveryMode = DeliveryMode.NON_PERSISTENT; - final int priority = 4; - final long timeToLive = 1000 * 100L; - - SendMessageHook hook = new SendMessageHook(); - hook.before(message, destination, deliveryMode, priority, timeToLive); - } - - @Test - public void testSetHeader() throws Exception { - RocketMQProducer producer = mock(RocketMQProducer.class); - when(producer.getDeliveryDelay()).thenReturn(0L); - - final JMSTextMessage message = new JMSTextMessage("text"); - final Destination destination = new RocketMQTopic("destination"); - final int deliveryMode = DeliveryMode.PERSISTENT; - final int priority = 5; - long timeToLive = JMSHeaderEnum.JMS_TIME_TO_LIVE_DEFAULT_VALUE; - SendMessageHook hook = new SendMessageHook(producer); - hook.before(message, destination, deliveryMode, priority, timeToLive); - - assertThat(message.getJMSDestination(), is(destination)); - assertThat(message.getJMSDeliveryMode(), is(JMSHeaderEnum.JMS_DELIVERY_MODE_DEFAULT_VALUE)); - assertThat(message.getJMSExpiration(), is(0L)); - assertThat(message.getJMSDeliveryTime(), notNullValue()); - assertThat(message.getJMSPriority(), is(5)); - assertThat(message.getJMSMessageID(), notNullValue()); - assertThat(message.getJMSTimestamp(), notNullValue()); - } - - /** - * Disable ID,timestamp, and set expired time - * - * @throws Exception - */ - @Test - public void testSetHeader2() throws Exception { - RocketMQProducer producer = mock(RocketMQProducer.class); - when(producer.getUserName()).thenReturn("user"); - when(producer.getDisableMessageID()).thenReturn(true); - when(producer.getDisableMessageTimestamp()).thenReturn(true); - - final JMSTextMessage message = new JMSTextMessage("text"); - final Destination destination = new RocketMQTopic("destination"); - final int deliveryMode = DeliveryMode.PERSISTENT; - final int priority = 5; - final long timeToLive = 1000 * 100L; - SendMessageHook hook = new SendMessageHook(producer); - hook.before(message, destination, deliveryMode, priority, timeToLive); - - // assert header - assertThat(message.getJMSMessageID(), nullValue()); - assertThat(message.getJMSTimestamp(), is(0L)); - assertThat(message.getJMSExpiration(), not(is(0L))); - - // assert properties - assertThat(message.getStringProperty(JMSPropertiesEnum.JMSXUserID.name()), is("user")); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/JMSBytesMessageTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSBytesMessageTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSBytesMessageTest.java deleted file mode 100644 index 20520f6..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSBytesMessageTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.rocketmq.jms.msg; - -import javax.jms.MessageNotReadableException; -import javax.jms.MessageNotWriteableException; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class JMSBytesMessageTest { - - private byte[] receiveData = "receive data test".getBytes(); - private byte[] sendData = "send data test".getBytes(); - - @Test - public void testGetData() throws Exception { - JMSBytesMessage readMessage = new JMSBytesMessage(receiveData); - assertThat(new String(receiveData), is(new String(readMessage.getBody()))); - - JMSBytesMessage sendMessage = new JMSBytesMessage(); - sendMessage.writeBytes(sendData, 0, sendData.length); - assertThat(new String(sendData), is(new String(sendMessage.getBody()))); - } - - @Test - public void testGetBodyLength() throws Exception { - JMSBytesMessage msg = new JMSBytesMessage(receiveData); - assertThat(msg.getBodyLength(), is(new Long(receiveData.length))); - } - - @Test - public void testReadBytes1() throws Exception { - JMSBytesMessage msg = new JMSBytesMessage(receiveData); - byte[] receiveValue = new byte[receiveData.length]; - msg.readBytes(receiveValue); - assertThat(new String(receiveValue), is(new String(receiveData))); - } - - @Test - public void testReadBytes2() throws Exception { - JMSBytesMessage msg = new JMSBytesMessage(receiveData); - - byte[] receiveValue1 = new byte[2]; - msg.readBytes(receiveValue1); - assertThat(new String(receiveData).substring(0, 2), is(new String(receiveValue1))); - - byte[] receiveValue2 = new byte[2]; - msg.readBytes(receiveValue2); - assertThat(new String(receiveData).substring(2, 4), is(new String(receiveValue2))); - - } - - @Test - public void testWriteBytes() throws Exception { - JMSBytesMessage msg = new JMSBytesMessage(); - msg.writeBytes(sendData); - assertThat(new String(msg.getBody()), is(new String(sendData))); - } - - @Test(expected = MessageNotReadableException.class) - public void testNotReadableException() throws Exception { - JMSBytesMessage msg = new JMSBytesMessage(); - msg.writeBoolean(true); - msg.readBoolean(); - } - - @Test(expected = MessageNotWriteableException.class) - public void testNotWritableException() throws Exception { - JMSBytesMessage msg = new JMSBytesMessage(receiveData); - msg.writeBoolean(true); - } - - @Test - public void testClearBody() throws Exception { - JMSBytesMessage msg = new JMSBytesMessage(receiveData); - msg.clearBody(); - msg.writeBoolean(true); - } - - @Test - public void testReset() throws Exception { - JMSBytesMessage msg = new JMSBytesMessage(receiveData); - byte[] b = new byte[2]; - msg.readBytes(b); - msg.reset(); - msg.readBytes(b); - assertThat(new String(receiveData).substring(0, 2), is(new String(b))); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/JMSMapMessageTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSMapMessageTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSMapMessageTest.java deleted file mode 100644 index cb34653..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSMapMessageTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.rocketmq.jms.msg; - -import javax.jms.JMSException; -import javax.jms.MessageNotWriteableException; -import org.junit.Test; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class JMSMapMessageTest { - - @Test - public void testGetBoolean() throws Exception { - JMSMapMessage msg = new JMSMapMessage(); - - // get an empty value will return false - assertThat(msg.getBoolean("man"), is(false)); - - // get an not empty value - msg.setBoolean("man", true); - assertThat(msg.getBoolean("man"), is(true)); - - // key is null - try { - msg.getBoolean(null); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - - // in read-only model - msg.setReadOnly(true); - try { - msg.setBoolean("man", true); - assertTrue(false); - } - catch (MessageNotWriteableException e) { - assertTrue(true); - } - - // both read and write are allowed after clearBody() - msg.clearBody(); - msg.setBoolean("man", false); - msg.getBoolean("man"); - - // map is empty after clearBody() - msg.clearBody(); - assertThat(msg.getBoolean("man"), is(false)); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/JMSObjectMessageTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSObjectMessageTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSObjectMessageTest.java deleted file mode 100644 index 63c03ae..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSObjectMessageTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.rocketmq.jms.msg; - -import java.io.Serializable; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class JMSObjectMessageTest { - - @Test - public void testGetObject() throws Exception { - final User user = new User("jack", 20); - JMSObjectMessage msg = new JMSObjectMessage(user); - assertThat((User)msg.getObject(), is(user)); - } - - @Test - public void testGetBody() throws Exception { - final User user = new User("jack", 20); - JMSObjectMessage msg = new JMSObjectMessage(user); - assertThat((User)msg.getBody(Object.class), is((User)msg.getObject())); - } - - private class User implements Serializable { - private String name; - private int age; - - private User(String name, int age) { - this.name = name; - this.age = age; - } - - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/JMSTextMessageTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSTextMessageTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/JMSTextMessageTest.java deleted file mode 100644 index d9c0cac..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/JMSTextMessageTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.rocketmq.jms.msg; - -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class JMSTextMessageTest { - private String text = "jmsRocketMQTextMessage test"; - - @Test - public void testGetBody() throws Exception { - JMSTextMessage msg = new JMSTextMessage(text); - assertThat(msg.getBody(String.class), is(text)); - } - - @Test - public void testSetText() throws Exception { - JMSTextMessage msg = new JMSTextMessage(); - msg.setText(text); - assertThat(msg.getText(), is(text)); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvertTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvertTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvertTest.java deleted file mode 100644 index 13a048c..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/convert/JMS2RMQMessageConvertTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.rocketmq.jms.msg.convert; - -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.jms.destination.RocketMQTopic; -import org.apache.rocketmq.jms.msg.AbstractJMSMessage; -import org.apache.rocketmq.jms.msg.JMSTextMessage; -import org.apache.rocketmq.jms.msg.enums.JMSHeaderEnum; -import org.apache.rocketmq.jms.msg.enums.JMSMessageModelEnum; -import org.junit.Test; - -import static org.apache.rocketmq.jms.msg.enums.JMSMessageModelEnum.MSG_MODEL_NAME; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class JMS2RMQMessageConvertTest { - - @Test - public void testConvert() throws Exception { - AbstractJMSMessage jmsMessage = new JMSTextMessage("text"); - - // given - jmsMessage.setJMSDestination(new RocketMQTopic("topic")); - jmsMessage.setJMSMessageID("ID:XXX"); - jmsMessage.setJMSTimestamp(1488273583542L); - jmsMessage.setJMSExpiration(0L); - - jmsMessage.setStringProperty("MyProperty", "MyValue"); - - // when - MessageExt rmqMessage = JMS2RMQMessageConvert.convert(jmsMessage); - - // then - assertThat(rmqMessage.getTopic(), is("topic")); - assertThat(rmqMessage.getUserProperty(JMSHeaderEnum.JMSMessageID.name()), is("ID:XXX")); - assertThat(rmqMessage.getBornTimestamp(), is(1488273583542L)); - assertThat(rmqMessage.getUserProperty(JMSHeaderEnum.JMSExpiration.name()), is("0")); - assertThat(rmqMessage.getKeys(), is("ID:XXX")); - - assertThat(rmqMessage.getUserProperty(JMS2RMQMessageConvert.USER_PROPERTY_PREFIX + "MyProperty"), is("MyValue")); - assertThat(rmqMessage.getUserProperty(MSG_MODEL_NAME), is(JMSMessageModelEnum.STRING.name())); - assertThat(new String(rmqMessage.getBody()), is("text")); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/convert/RMQ2JMSMessageConvertTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/convert/RMQ2JMSMessageConvertTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/convert/RMQ2JMSMessageConvertTest.java deleted file mode 100644 index 1d5bb11..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/convert/RMQ2JMSMessageConvertTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.rocketmq.jms.msg.convert; - -import javax.jms.Message; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.jms.msg.JMSBytesMessage; -import org.apache.rocketmq.jms.msg.enums.JMSHeaderEnum; -import org.apache.rocketmq.jms.msg.enums.JMSMessageModelEnum; -import org.apache.rocketmq.jms.msg.enums.JMSPropertiesEnum; -import org.apache.rocketmq.jms.support.JMSUtils; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class RMQ2JMSMessageConvertTest { - - @Test - public void testConvert() throws Exception { - MessageExt rmqMessage = new MessageExt(); - - // given - rmqMessage.setBody("body".getBytes()); - rmqMessage.putUserProperty(JMSMessageModelEnum.MSG_MODEL_NAME, JMSMessageModelEnum.BYTE.name()); - rmqMessage.putUserProperty(JMSHeaderEnum.JMSMessageID.name(), "ID:YYY"); - rmqMessage.setBornTimestamp(1488273585542L); - rmqMessage.putUserProperty(JMSHeaderEnum.JMSExpiration.name(), "0"); - rmqMessage.setReconsumeTimes(2); - rmqMessage.setTopic("topic"); - - rmqMessage.putUserProperty(JMSPropertiesEnum.JMSXDeliveryCount.name(), "2"); - rmqMessage.putUserProperty(JMS2RMQMessageConvert.USER_PROPERTY_PREFIX + "MyProperty", "MyValue"); - - // when - Message jmsMessage = RMQ2JMSMessageConvert.convert(rmqMessage); - - // then - assertThat(JMSBytesMessage.class.isInstance(jmsMessage), is(true)); - assertThat(jmsMessage.getJMSMessageID(), is("ID:YYY")); - assertThat(jmsMessage.getJMSTimestamp(), is(1488273585542L)); - assertThat(jmsMessage.getJMSExpiration(), is(0L)); - assertThat(jmsMessage.getJMSRedelivered(), is(true)); - assertThat(JMSUtils.getDestinationName(jmsMessage.getJMSDestination()), is("topic")); - - assertThat(jmsMessage.getStringProperty("MyProperty"), is("MyValue")); - assertThat(jmsMessage.getIntProperty(JMSPropertiesEnum.JMSXDeliveryCount.name()), is(3)); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/enums/JMSMessageModelEnumTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/enums/JMSMessageModelEnumTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/enums/JMSMessageModelEnumTest.java deleted file mode 100644 index 28255dd..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/enums/JMSMessageModelEnumTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.rocketmq.jms.msg.enums; - -import org.apache.rocketmq.jms.msg.JMSTextMessage; -import org.junit.Test; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -public class JMSMessageModelEnumTest { - @Test - public void testToMsgModelEnum() throws Exception { - assertThat(JMSMessageModelEnum.toMsgModelEnum(new JMSTextMessage("text")), is(JMSMessageModelEnum.STRING)); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/MapSerializeTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/MapSerializeTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/MapSerializeTest.java deleted file mode 100644 index 5204fb3..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/MapSerializeTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.rocketmq.jms.msg.serialize; - -import java.util.HashMap; -import java.util.Map; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class MapSerializeTest { - - @Test - public void serializeAndDeserialize() throws Exception { - Map map = new HashMap(); - map.put("name", "John"); - map.put("age", 20); - - byte[] bytes = MapSerialize.instance().serialize(map); - Map newMap = MapSerialize.instance().deserialize(bytes); - - assertThat(map.size(), is(newMap.size())); - assertThat(newMap.get("name").toString(), is("John")); - assertThat(newMap.get("age").toString(), is("20")); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerializeTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerializeTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerializeTest.java deleted file mode 100644 index 1661b08..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/ObjectSerializeTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.rocketmq.jms.msg.serialize; - -import java.io.Serializable; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class ObjectSerializeTest { - - @Test - public void serializeAndDeserialize() throws Exception { - Person person = new Person(); - person.setName("John"); - person.setAge(30); - - byte[] bytes = ObjectSerialize.instance().serialize(person); - Person newPerson = (Person)ObjectSerialize.instance().deserialize(bytes); - - assertThat(newPerson.getName(), is(person.getName())); - assertThat(newPerson.getAge(), is(person.getAge())); - } - - private static class Person implements Serializable { - private static final long serialVersionUID = -4981805070659153282L; - - private String name; - private int age; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/StringSerializeTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/StringSerializeTest.java b/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/StringSerializeTest.java deleted file mode 100644 index 4e6a54a..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/msg/serialize/StringSerializeTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.rocketmq.jms.msg.serialize; - -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class StringSerializeTest { - - @Test - public void serializeAndDeserialize() throws Exception { - String text = "MyText"; - - byte[] bytes = StringSerialize.instance().serialize(text); - String newText = StringSerialize.instance().deserialize(bytes); - - assertThat(text, is(newText)); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/support/JMSUtilsTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/support/JMSUtilsTest.java b/core/src/test/java/org/apache/rocketmq/jms/support/JMSUtilsTest.java deleted file mode 100644 index db15fee..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/support/JMSUtilsTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.rocketmq.jms.support; - -import org.apache.rocketmq.jms.destination.RocketMQQueue; -import org.apache.rocketmq.jms.destination.RocketMQTopic; -import org.junit.Test; - -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNull.notNullValue; -import static org.junit.Assert.assertThat; - -public class JMSUtilsTest { - - @Test - public void getTopicName() throws Exception { - RocketMQTopic topic = new RocketMQTopic("topic"); - assertThat(JMSUtils.getDestinationName(topic), is("topic")); - - RocketMQQueue queue = new RocketMQQueue("queue"); - assertThat(JMSUtils.getDestinationName(queue), is("queue")); - } - - @Test - public void getConsumerGroup() throws Exception { - final String subscriptionName = "subscriptionName"; - final String clientID = "clientID"; - String consumerGroupA = JMSUtils.getConsumerGroup(subscriptionName, clientID, true); - assertThat(consumerGroupA.contains(subscriptionName), is(true)); - assertThat(consumerGroupA.contains(clientID), is(true)); - assertThat(consumerGroupA.substring(subscriptionName.length() + clientID.length() + 2).length(), is(36)); - - String consumerGroupB = JMSUtils.getConsumerGroup(subscriptionName, clientID, false); - assertThat(consumerGroupB.contains(subscriptionName), is(true)); - assertThat(consumerGroupB.contains(clientID), is(true)); - assertThat(consumerGroupB.length(), is(subscriptionName.length() + clientID.length() + 1)); - - String consumerGroupC = JMSUtils.getConsumerGroup(null, null, true); - assertThat(consumerGroupC.length(), is(36)); - } - - @Test - public void uuid() throws Exception { - assertThat(JMSUtils.uuid(), notNullValue()); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/support/ObjectTypeCastTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/support/ObjectTypeCastTest.java b/core/src/test/java/org/apache/rocketmq/jms/support/ObjectTypeCastTest.java deleted file mode 100644 index 21fc50b..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/support/ObjectTypeCastTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.rocketmq.jms.support; - -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -public class ObjectTypeCastTest { - - @Test - public void testConvert2String() throws Exception { - assertThat(ObjectTypeCast.cast2String("name"), is("name")); - } - - @Test - public void testConvert2Long() throws Exception { - assertThat(ObjectTypeCast.cast2Long(100l), is(100l)); - } - - @Test - public void testConvert2Integer() throws Exception { - assertThat(ObjectTypeCast.cast2Integer(100), is(100)); - } - - @Test - public void testConvert2Boolean() throws Exception { - assertThat(ObjectTypeCast.cast2Boolean(true), is(true)); - } - - @Test - public void testConvert2Object() throws Exception { - final ObjectTypeCast obj = new ObjectTypeCast(); - assertThat(ObjectTypeCast.cast2Object(obj, ObjectTypeCast.class), is(obj)); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/core/src/test/java/org/apache/rocketmq/jms/support/PrimitiveTypeCastTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/rocketmq/jms/support/PrimitiveTypeCastTest.java b/core/src/test/java/org/apache/rocketmq/jms/support/PrimitiveTypeCastTest.java deleted file mode 100644 index 53ae0da..0000000 --- a/core/src/test/java/org/apache/rocketmq/jms/support/PrimitiveTypeCastTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * 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.rocketmq.jms.support; - -import java.util.Date; -import javax.jms.JMSException; -import org.junit.Test; - -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2Boolean; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2Byte; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2ByteArray; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2Char; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2Double; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2Float; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2Int; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2Long; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2Short; -import static org.apache.rocketmq.jms.support.PrimitiveTypeCast.cast2String; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class PrimitiveTypeCastTest { - - @Test - public void testConvert2Boolean() throws Exception { - assertThat(cast2Boolean(new Boolean(true)), is(true)); - assertThat(cast2Boolean(null), is(false)); - - assertThat(cast2Boolean("true"), is(true)); - assertThat(cast2Boolean("hello"), is(false)); - - try { - cast2Boolean(new Date()); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2Byte() throws Exception { - final byte b = Byte.parseByte("101", 2); - assertThat(cast2Byte(b), is(b)); - - assertThat(cast2Byte(new String("5")), is(b)); - try { - assertThat(cast2Byte(null), is(b)); - assertTrue(false); - } - catch (RuntimeException e) { - assertTrue(true); - } - - try { - cast2Byte("abc"); - assertTrue(false); - } - catch (RuntimeException e) { - assertTrue(true); - } - - try { - cast2Byte(new Date()); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2Short() throws Exception { - final Short s = new Short("12"); - assertThat(cast2Short(s), is(s)); - - assertThat(cast2Short("3"), is(new Short("3"))); - - try { - cast2Short(new Date()); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2Char() throws Exception { - final char c = 'a'; - assertThat(cast2Char(c), is(c)); - - try { - cast2Char("a"); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2Int() throws Exception { - assertThat(cast2Int(12), is(12)); - - assertThat(cast2Int("12"), is(12)); - assertThat(cast2Int(Byte.parseByte("11", 2)), is(3)); - - try { - cast2Int(new Date()); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2Long() throws Exception { - assertThat(cast2Long(12), is(12l)); - - assertThat(cast2Long("12"), is(12l)); - - try { - cast2Int(new Date()); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2Float() throws Exception { - assertThat(cast2Float(12.00f), is(12f)); - - assertThat(cast2Float("12.00"), is(12f)); - - try { - cast2Float(12); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2Double() throws Exception { - assertThat(cast2Double(12.00d), is(12d)); - - assertThat(cast2Double("12.00"), is(12d)); - assertThat(cast2Double(12.00f), is(12d)); - - try { - cast2Double(12); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2String() throws Exception { - assertThat(cast2String(12.00d), is("12.0")); - - assertThat(cast2String("12.00"), is("12.00")); - assertThat(cast2String(true), is("true")); - - try { - cast2String(new Date()); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } - - @Test - public void testConvert2ByteArray() throws Exception { - byte[] arr = new byte[] {Byte.parseByte("11", 2), Byte.parseByte("101", 2)}; - - assertThat(cast2ByteArray(arr), is(arr)); - - try { - cast2ByteArray("10"); - assertTrue(false); - } - catch (JMSException e) { - assertTrue(true); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0949474..5211c1c 100644 --- a/pom.xml +++ b/pom.xml @@ -22,13 +22,9 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.rocketmq</groupId> - <artifactId>rocketmq-jms-all</artifactId> - <packaging>pom</packaging> - <version>1.0-SNAPSHOT</version> - <modules> - <module>core</module> - <module>test</module> - </modules> + <artifactId>rocketmq-jms</artifactId> + <packaging>jar</packaging> + <version>1.0.0</version> <properties> @@ -41,62 +37,76 @@ <maven.compiler.target>1.7</maven.compiler.target> <surefire.version>2.19.1</surefire.version> <rocketmq.version>4.0.0-incubating</rocketmq.version> + <spring.version>4.3.6.RELEASE</spring.version> </properties> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>rocketmq-jms-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.rocketmq</groupId> - <artifactId>rocketmq-client</artifactId> - <version>${rocketmq.version}</version> - </dependency> - <dependency> - <groupId>org.apache.rocketmq</groupId> - <artifactId>rocketmq-tools</artifactId> - <version>${rocketmq.version}</version> - </dependency> - <dependency> - <groupId>javax.jms</groupId> - <artifactId>javax.jms-api</artifactId> - <version>2.0.1</version> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>18.0</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.6</version> - </dependency> + <dependencies> + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-client</artifactId> + <version>${rocketmq.version}</version> + </dependency> + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-tools</artifactId> + <version>${rocketmq.version}</version> + </dependency> + <dependency> + <groupId>javax.jms</groupId> + <artifactId>javax.jms-api</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>18.0</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + </dependency> - <!--test--> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - <version>4.12</version> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-all</artifactId> - <version>1.3</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>2.7.12</version> - <scope>test</scope> - </dependency> - </dependencies> - </dependencyManagement> + <!--test--> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + <version>4.12</version> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-all</artifactId> + <version>1.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>2.7.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jms</artifactId> + <version>${spring.version}</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>${spring.version}</version> + </dependency> + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-namesrv</artifactId> + <version>${rocketmq.version}</version> + </dependency> + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-broker</artifactId> + <version>${rocketmq.version}</version> + </dependency> + </dependencies> <build> <plugins> http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/src/main/java/org/apache/rocketmq/jms/Constant.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/rocketmq/jms/Constant.java b/src/main/java/org/apache/rocketmq/jms/Constant.java new file mode 100644 index 0000000..9519bea --- /dev/null +++ b/src/main/java/org/apache/rocketmq/jms/Constant.java @@ -0,0 +1,82 @@ +/* + * 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.rocketmq.jms; + +public interface Constant { + + String NO_MESSAGE_SELECTOR = "*"; + + boolean DEFAULT_NO_LOCAL = true; + + boolean DEFAULT_DURABLE = false; + + //-------------------------JMS defined properties constant---------------------------- + /** + * The identity of the user sending the Send message + */ + String JMS_XUSER_ID = "jmsXUserID"; + /** + * The identity of the application Send sending the message + */ + String JMS_XAPP_ID = "jmsXAppID"; + /** + * The number of message delivery Receive attempts + */ + String JMS_XDELIVERY_COUNT = "jmsXDeliveryCount"; + /** + * The identity of the message group this message is part of + */ + String JMS_XGROUP_ID = "jmsXGroupID"; + /** + * The sequence number of this message within the group; the first message is 1, the second 2,... + */ + String JMS_XGROUP_SEQ = "jmsXGroupSeq"; + /** + * The transaction identifier of the Send transaction within which this message was produced + */ + String JMS_XPRODUCER_TXID = "jmsXProducerTXID"; + /** + * The transaction identifier of the Receive transaction within which this message was consumed + */ + String JMS_XCONSUMER_TXID = "jmsXConsumerTXID"; + + /** + * The time JMS delivered the Receive message to the consumer + */ + String JMS_XRCV_TIMESTAMP = "jmsXRcvTimestamp"; + /** + * Assume there exists a message warehouse that contains a separate copy of each message sent to each consumer and + * that these copies exist from the time the original message was sent. Each copyâs state is one of: 1(waiting), + * 2(ready), 3(expired) or 4(retained) Since state is of no interest to producers and consumers it is not provided + * to either. It is only of relevance to messages looked up in a warehouse and JMS provides no API for this. + */ + String JMS_XSTATE = "jmsXState"; + + //---------------------------JMS Headers' value constant--------------------------- + /** + * Default time to live + */ + long DEFAULT_TIME_TO_LIVE = 3 * 24 * 60 * 60 * 1000; + + /** + * Default Jms Type + */ + String DEFAULT_JMS_TYPE = "rocketmq"; + + String MESSAGE_ID_PREFIX = "ID:"; +} http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/src/main/java/org/apache/rocketmq/jms/ConsumeMessageService.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/rocketmq/jms/ConsumeMessageService.java b/src/main/java/org/apache/rocketmq/jms/ConsumeMessageService.java new file mode 100644 index 0000000..6187ac2 --- /dev/null +++ b/src/main/java/org/apache/rocketmq/jms/ConsumeMessageService.java @@ -0,0 +1,71 @@ +/* + * 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.rocketmq.jms; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.atomic.AtomicLong; +import javax.jms.JMSRuntimeException; +import org.apache.rocketmq.common.ServiceThread; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConsumeMessageService extends ServiceThread { + + private static final Logger log = LoggerFactory.getLogger(DeliverMessageService.class); + private static final AtomicLong COUNTER = new AtomicLong(0L); + + private BlockingQueue<MessageWrapper> queue = new ArrayBlockingQueue(1000); + private RocketMQSession session; + private final long index = COUNTER.incrementAndGet(); + + public ConsumeMessageService(RocketMQSession session) { + this.session = session; + } + + @Override public String getServiceName() { + return ConsumeMessageService.class.getSimpleName() + "-" + this.index; + } + + @Override public void run() { + while (!this.isStopped()) { + try { + MessageWrapper wrapper = queue.take(); + RocketMQConsumer consumer = wrapper.getConsumer(); + consumer.getMessageListener().onMessage(wrapper.getMessage()); + consumer.getDeliverMessageService().ack(wrapper.getMq(), wrapper.getOffset()); + } + catch (Exception e) { + log.error(e.getMessage(), e); + } + } + } + + public void put(MessageWrapper wrapper) { + try { + this.queue.put(wrapper); + } + catch (InterruptedException e) { + throw new JMSRuntimeException(e.getMessage()); + } + } + + public RocketMQSession getSession() { + return session; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rocketmq-externals/blob/db8e0dd1/src/main/java/org/apache/rocketmq/jms/ConsumeModel.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/rocketmq/jms/ConsumeModel.java b/src/main/java/org/apache/rocketmq/jms/ConsumeModel.java new file mode 100644 index 0000000..356cbd7 --- /dev/null +++ b/src/main/java/org/apache/rocketmq/jms/ConsumeModel.java @@ -0,0 +1,23 @@ +/* + * 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.rocketmq.jms; + +public enum ConsumeModel { + SYNC, + ASYNC +}