You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2008/03/04 22:01:57 UTC
svn commit: r633639 [7/7] - in /activemq/sandbox/activemq-router: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/activemq/ src/main/java/org/apache/activemq/broker/
src/main/java/org/apache/active...
Added: activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/journal/JournalStoreTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/journal/JournalStoreTest.java?rev=633639&view=auto
==============================================================================
--- activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/journal/JournalStoreTest.java (added)
+++ activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/journal/JournalStoreTest.java Tue Mar 4 13:01:41 2008
@@ -0,0 +1,34 @@
+/**
+ * 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.router.store.journal;
+
+import java.io.File;
+
+import org.apache.activemq.broker.router.store.StoreTestSupport;
+import org.apache.activemq.broker.router.store.api.DataStoreManager;
+
+public class JournalStoreTest extends StoreTestSupport {
+
+ @Override
+ protected DataStoreManager createDataStoreManager() throws Exception {
+ JournalDataStoreManagerFactory factory = new JournalDataStoreManagerFactory();
+ factory.setDataDirectory(new File("target/data/" + getName()));
+// factory.getEntityManagerProperties().put("openjpa.Log", "DefaultLevel=WARN,SQL=TRACE");
+ return factory.createJournalDataStoreManager();
+ }
+
+}
Added: activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/journal/data/JournalTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/journal/data/JournalTest.java?rev=633639&view=auto
==============================================================================
--- activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/journal/data/JournalTest.java (added)
+++ activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/journal/data/JournalTest.java Tue Mar 4 13:01:41 2008
@@ -0,0 +1,69 @@
+/**
+ * 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.router.store.journal.data;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.command.ActiveMQTextMessage;
+import org.apache.activemq.kaha.impl.async.AsyncDataManager;
+import org.apache.activemq.openwire.OpenWireFormat;
+import org.apache.activemq.util.ByteSequence;
+
+public class JournalTest extends TestCase {
+
+ private Journal journal;
+
+ @Override
+ protected void setUp() throws Exception {
+ AsyncDataManager asyncDataManager = new AsyncDataManager();
+ OpenWireFormat openWireFormat = new OpenWireFormat();
+ openWireFormat.setCacheEnabled(false);
+ openWireFormat.setTightEncodingEnabled(false);
+ openWireFormat.setSizePrefixDisabled(true);
+ journal = new Journal(asyncDataManager, openWireFormat);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testAddMessageMarshalling() throws Exception {
+ AddMessageJournalEntry expected = new AddMessageJournalEntry();
+ expected.setDatatStore("test-store");
+ ActiveMQTextMessage message = new ActiveMQTextMessage();
+ message.setText("This is the text");
+ expected.setMessage(message);
+
+ ByteSequence encode = journal.encode(expected);
+ AddMessageJournalEntry actual = (AddMessageJournalEntry) journal.decode(encode);
+
+ assertEquals(expected.getTransactionId(), actual.getTransactionId());
+ assertEquals(expected.getDatatStore(), actual.getDatatStore());
+ ActiveMQTextMessage message2 = (ActiveMQTextMessage) actual.getMessage();
+ assertEquals(message.getText(), message2.getText());
+ }
+
+ public void testTraceMarshalling() throws Exception {
+ TraceJournalEntry expected = new TraceJournalEntry("This is a test");
+
+ ByteSequence encode = journal.encode(expected);
+ TraceJournalEntry actual = (TraceJournalEntry) journal.decode(encode);
+
+ assertEquals(expected.getMessage(), actual.getMessage());
+ }
+}
Added: activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/memory/MemoryStoreTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/memory/MemoryStoreTest.java?rev=633639&view=auto
==============================================================================
--- activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/memory/MemoryStoreTest.java (added)
+++ activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/store/memory/MemoryStoreTest.java Tue Mar 4 13:01:41 2008
@@ -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.
+ */
+package org.apache.activemq.broker.router.store.memory;
+
+import org.apache.activemq.broker.router.store.StoreTestSupport;
+import org.apache.activemq.broker.router.store.api.DataStoreManager;
+
+/**
+ * @author chirino
+ */
+public class MemoryStoreTest extends StoreTestSupport {
+
+ @Override
+ protected DataStoreManager createDataStoreManager() throws Exception {
+ MemoryDataStoreManager rc = new MemoryDataStoreManager();
+ return rc;
+ }
+
+ @Override
+ protected void restartDataStoreManager() throws Exception {
+ // Sorry we don't really support restarts..
+ }
+
+}
Added: activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/DuplicateAndMissedCheckerTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/DuplicateAndMissedCheckerTest.java?rev=633639&view=auto
==============================================================================
--- activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/DuplicateAndMissedCheckerTest.java (added)
+++ activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/DuplicateAndMissedCheckerTest.java Tue Mar 4 13:01:41 2008
@@ -0,0 +1,94 @@
+/**
+ * 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.router.util;
+
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * @author chirino
+ */
+public class DuplicateAndMissedCheckerTest extends TestCase {
+
+ public void testOrderDoesNotMatter() {
+ String producerId = "p1";
+
+ DuplicateAndMissedChecker checker = new DuplicateAndMissedChecker();
+
+ // add 2 sequences that are out of order.
+ checker.onMessage(producerId, 4);
+ checker.onMessage(producerId, 2);
+ checker.onMessage(producerId, 1);
+ checker.onMessage(producerId, 5);
+
+ Map<String, List<Sequence>> receivedMessages = checker.getReceivedMessages();
+ List<Sequence> list = receivedMessages.get(producerId);
+ assertEquals(2, list.size());
+
+ System.out.println("Messaages recived: " + list);
+
+ // Add the guy that joins the sequence..
+ checker.onMessage(producerId, 3);
+
+ receivedMessages = checker.getReceivedMessages();
+ list = receivedMessages.get(producerId);
+ assertEquals(1, list.size());
+
+ System.out.println("Messaages recived: " + list);
+ }
+
+ public void testMissingMessagesDetected() {
+ String producerId = "p1";
+
+ DuplicateAndMissedChecker checker = new DuplicateAndMissedChecker();
+
+ // add 2 sequences that are out of order.
+ checker.onMessage(producerId, 4);
+ checker.onMessage(producerId, 2);
+ checker.onMessage(producerId, 1);
+ checker.onMessage(producerId, 5);
+
+ Map<String, List<Sequence>> missing = checker.getMissingMessages(1, 5);
+ List<Sequence> list = missing.get(producerId);
+ assertEquals(1, list.size());
+
+ System.out.println("Missing: " + list);
+ }
+
+ public void testDuplicateMessagesDetected() {
+ String producerId = "p1";
+
+ DuplicateAndMissedChecker checker = new DuplicateAndMissedChecker();
+
+ // add 2 sequences that are out of order.
+ checker.onMessage(producerId, 4);
+ checker.onMessage(producerId, 2);
+ checker.onMessage(producerId, 1);
+ checker.onMessage(producerId, 5);
+
+ try {
+ // Try to add a dup message.
+ checker.onMessage(producerId, 2);
+ fail("Expected an IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ // This is expected.
+ }
+ }
+
+}
Added: activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/LinkedNodeTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/LinkedNodeTest.java?rev=633639&view=auto
==============================================================================
--- activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/LinkedNodeTest.java (added)
+++ activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/LinkedNodeTest.java Tue Mar 4 13:01:41 2008
@@ -0,0 +1,184 @@
+/**
+ * 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.router.util;
+
+import org.apache.activemq.broker.router.util.LinkedNode;
+import org.apache.activemq.broker.router.util.LinkedNodeList;
+
+import junit.framework.TestCase;
+
+/**
+ * @author chirino
+ */
+public class LinkedNodeTest extends TestCase {
+
+ static class IntLinkedNode extends LinkedNode<IntLinkedNode> {
+ public final int v;
+
+ public IntLinkedNode(int v) {
+ this.v = v;
+ };
+
+ @Override
+ public String toString() {
+ return "" + v;
+ }
+ }
+
+ LinkedNodeList<IntLinkedNode> list = new LinkedNodeList<IntLinkedNode>();
+
+ IntLinkedNode i1 = new IntLinkedNode(1);
+ IntLinkedNode i2 = new IntLinkedNode(2);
+ IntLinkedNode i3 = new IntLinkedNode(3);
+ IntLinkedNode i4 = new IntLinkedNode(4);
+ IntLinkedNode i5 = new IntLinkedNode(5);
+ IntLinkedNode i6 = new IntLinkedNode(6);
+
+ public void testLinkAfter() {
+ list.addLast(i1);
+ i1.linkAfter(i2);
+ i2.linkAfter(i3);
+ // Order should be 1,2,3
+
+ assertTrue(i1.getNext() == i2);
+ assertTrue(i1.getNext().getNext() == i3);
+ assertNull(i1.getNext().getNext().getNext());
+
+ assertTrue(i3.getPrevious() == i2);
+ assertTrue(i3.getPrevious().getPrevious() == i1);
+ assertNull(i3.getPrevious().getPrevious().getPrevious());
+
+ assertTrue(i1.isHeadNode());
+ assertFalse(i1.isTailNode());
+ assertFalse(i2.isHeadNode());
+ assertFalse(i2.isTailNode());
+ assertTrue(i3.isTailNode());
+ assertFalse(i3.isHeadNode());
+
+ i1.linkAfter(i4);
+ i4.linkAfter(i5);
+ // Order should be 1,4,5,2,3
+
+ assertTrue(i1.getNext() == i4);
+ assertTrue(i1.getNext().getNext() == i5);
+ assertTrue(i1.getNext().getNext().getNext() == i2);
+ assertTrue(i1.getNext().getNext().getNext().getNext() == i3);
+ assertNull(i1.getNext().getNext().getNext().getNext().getNext());
+
+ assertTrue(i3.getPrevious() == i2);
+ assertTrue(i3.getPrevious().getPrevious() == i5);
+ assertTrue(i3.getPrevious().getPrevious().getPrevious() == i4);
+ assertTrue(i3.getPrevious().getPrevious().getPrevious().getPrevious() == i1);
+ assertNull(i3.getPrevious().getPrevious().getPrevious().getPrevious().getPrevious());
+
+ assertTrue(i1.isHeadNode());
+ assertFalse(i1.isTailNode());
+ assertFalse(i4.isHeadNode());
+ assertFalse(i4.isTailNode());
+ assertFalse(i5.isHeadNode());
+ assertFalse(i5.isTailNode());
+ assertFalse(i2.isHeadNode());
+ assertFalse(i2.isTailNode());
+ assertTrue(i3.isTailNode());
+ assertFalse(i3.isHeadNode());
+
+ }
+
+ public void testLinkBefore() {
+
+ list.addLast(i3);
+ i3.linkBefore(i2);
+ i2.linkBefore(i1);
+
+ assertTrue(i1.getNext() == i2);
+ assertTrue(i1.getNext().getNext() == i3);
+ assertNull(i1.getNext().getNext().getNext());
+
+ assertTrue(i3.getPrevious() == i2);
+ assertTrue(i3.getPrevious().getPrevious() == i1);
+ assertNull(i3.getPrevious().getPrevious().getPrevious());
+
+ assertTrue(i1.isHeadNode());
+ assertFalse(i1.isTailNode());
+ assertFalse(i2.isHeadNode());
+ assertFalse(i2.isTailNode());
+ assertTrue(i3.isTailNode());
+ assertFalse(i3.isHeadNode());
+
+ i2.linkBefore(i5);
+ i5.linkBefore(i4);
+
+ // Order should be 1,4,5,2,3
+
+ assertTrue(i1.getNext() == i4);
+ assertTrue(i1.getNext().getNext() == i5);
+ assertTrue(i1.getNext().getNext().getNext() == i2);
+ assertTrue(i1.getNext().getNext().getNext().getNext() == i3);
+ assertNull(i1.getNext().getNext().getNext().getNext().getNext());
+
+ assertTrue(i3.getPrevious() == i2);
+ assertTrue(i3.getPrevious().getPrevious() == i5);
+ assertTrue(i3.getPrevious().getPrevious().getPrevious() == i4);
+ assertTrue(i3.getPrevious().getPrevious().getPrevious().getPrevious() == i1);
+ assertNull(i3.getPrevious().getPrevious().getPrevious().getPrevious().getPrevious());
+
+ assertTrue(i1.isHeadNode());
+ assertFalse(i1.isTailNode());
+ assertFalse(i4.isHeadNode());
+ assertFalse(i4.isTailNode());
+ assertFalse(i5.isHeadNode());
+ assertFalse(i5.isTailNode());
+ assertFalse(i2.isHeadNode());
+ assertFalse(i2.isTailNode());
+ assertTrue(i3.isTailNode());
+ assertFalse(i3.isHeadNode());
+
+ }
+
+ public void testUnlink() {
+
+ list.addLast(i1);
+ i1.linkAfter(i2);
+ i2.linkAfter(i3);
+ i3.linkAfter(i4);
+ i1.linkBefore(i5);
+ i1.linkAfter(i6);
+
+ // Order should be 5,1,6,2,3,4
+ i4.unlink();
+ i5.unlink();
+ i6.unlink();
+
+ // Order should be 1,2,3
+
+ assertTrue(i1.getNext() == i2);
+ assertTrue(i1.getNext().getNext() == i3);
+ assertNull(i1.getNext().getNext().getNext());
+
+ assertTrue(i3.getPrevious() == i2);
+ assertTrue(i3.getPrevious().getPrevious() == i1);
+ assertNull(i3.getPrevious().getPrevious().getPrevious());
+
+ assertTrue(i1.isHeadNode());
+ assertFalse(i1.isTailNode());
+ assertFalse(i2.isHeadNode());
+ assertFalse(i2.isTailNode());
+ assertTrue(i3.isTailNode());
+ assertFalse(i3.isHeadNode());
+ }
+
+}
Added: activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/OrderCheckerTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/OrderCheckerTest.java?rev=633639&view=auto
==============================================================================
--- activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/OrderCheckerTest.java (added)
+++ activemq/sandbox/activemq-router/src/test/java/org/apache/activemq/broker/router/util/OrderCheckerTest.java Tue Mar 4 13:01:41 2008
@@ -0,0 +1,44 @@
+/**
+ * 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.router.util;
+
+import junit.framework.TestCase;
+
+/**
+ * @author chirino
+ */
+public class OrderCheckerTest extends TestCase {
+
+ public void testBadOrderError() {
+ String producerId = "p1";
+
+ DuplicateAndMissedChecker duplicateAndMissedChecker = new DuplicateAndMissedChecker();
+ OrderChecker checker = new OrderChecker(duplicateAndMissedChecker);
+
+ checker.onMessage(producerId, 1);
+ checker.onMessage(producerId, 3);
+ checker.onMessage(producerId, 4);
+
+ try {
+ checker.onMessage(producerId, 2);
+ fail("Expected an IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected.
+ }
+
+ }
+}
Added: activemq/sandbox/activemq-router/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-router/src/test/resources/log4j.properties?rev=633639&view=auto
==============================================================================
--- activemq/sandbox/activemq-router/src/test/resources/log4j.properties (added)
+++ activemq/sandbox/activemq-router/src/test/resources/log4j.properties Tue Mar 4 13:01:41 2008
@@ -0,0 +1,39 @@
+## ------------------------------------------------------------------------
+## 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 for eclipse testing, We want to see debug output on the console.
+#
+log4j.rootLogger=INFO, out
+
+log4j.logger.org.apache.activemq.broker.router=INFO
+log4j.logger.org.apache.activemq.broker.router.store.journal.JournalDataStore=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+log4j.appender.out.threshold=INFO
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.fout=org.apache.log4j.FileAppender
+log4j.appender.fout.layout=org.apache.log4j.PatternLayout
+log4j.appender.fout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.fout.file=test.log
+log4j.appender.fout.append=true
+