You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2009/02/13 12:19:38 UTC

svn commit: r744074 - in /qpid/trunk/qpid/java/broker/src: main/java/org/apache/qpid/server/queue/ test/java/org/apache/qpid/server/queue/

Author: ritchiem
Date: Fri Feb 13 11:19:38 2009
New Revision: 744074

URL: http://svn.apache.org/viewvc?rev=744074&view=rev
Log:
QPID-1629 : Fully test MessageHandles before move

Added:
    qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/InMemoryMessageHandleTest.java
    qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/WeakMessageHandleTest.java
Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/InMemoryMessageHandle.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/WeakReferenceMessageHandle.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/InMemoryMessageHandle.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/InMemoryMessageHandle.java?rev=744074&r1=744073&r2=744074&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/InMemoryMessageHandle.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/InMemoryMessageHandle.java Fri Feb 13 11:19:38 2009
@@ -75,7 +75,12 @@
 
     public ContentChunk getContentChunk(StoreContext context, int index) throws AMQException, IllegalArgumentException
     {
-        if (index > _contentBodies.size() - 1)
+        if(_contentBodies == null)
+        {
+            throw new RuntimeException("No ContentBody has been set");
+        }
+
+        if (index > _contentBodies.size() - 1 || index < 0)
         {
             throw new IllegalArgumentException("Index " + index + " out of valid range 0 to " +
                                                (_contentBodies.size() - 1));

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/WeakReferenceMessageHandle.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/WeakReferenceMessageHandle.java?rev=744074&r1=744073&r2=744074&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/WeakReferenceMessageHandle.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/WeakReferenceMessageHandle.java Fri Feb 13 11:19:38 2009
@@ -109,7 +109,12 @@
 
     public ContentChunk getContentChunk(StoreContext context, int index) throws AMQException, IllegalArgumentException
     {
-        if (index > _contentBodies.size() - 1)
+        if(_contentBodies == null)
+        {
+            throw new RuntimeException("No ContentBody has been set");
+        }        
+
+        if (index > _contentBodies.size() - 1 || index < 0)
         {
             throw new IllegalArgumentException("Index " + index + " out of valid range 0 to " +
                                                (_contentBodies.size() - 1));
@@ -197,8 +202,7 @@
 
         final long arrivalTime = System.currentTimeMillis();
 
-
-        MessageMetaData mmd = new MessageMetaData(publishBody, contentHeaderBody, _contentBodies.size(), arrivalTime);
+        MessageMetaData mmd = new MessageMetaData(publishBody, contentHeaderBody, _contentBodies == null ? 0 : _contentBodies.size(), arrivalTime);
 
         _messageStore.storeMessageMetaData(storeContext, _messageId, mmd);
 

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/InMemoryMessageHandleTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/InMemoryMessageHandleTest.java?rev=744074&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/InMemoryMessageHandleTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/InMemoryMessageHandleTest.java Fri Feb 13 11:19:38 2009
@@ -0,0 +1,311 @@
+/*
+ *
+ * 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.qpid.server.queue;
+
+import junit.framework.TestCase;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.framing.BasicContentHeaderProperties;
+import org.apache.qpid.framing.ContentHeaderBody;
+import org.apache.qpid.framing.ContentHeaderProperties;
+import org.apache.qpid.framing.abstraction.ContentChunk;
+import org.apache.qpid.framing.abstraction.MessagePublishInfo;
+import org.apache.qpid.framing.abstraction.MessagePublishInfoImpl;
+
+public class InMemoryMessageHandleTest extends TestCase
+{
+    AMQMessageHandle _handle;
+
+    protected AMQMessageHandle newHandle(Long id)
+    {
+        return new InMemoryMessageHandle(id);
+    }
+
+    public void testMessageID()
+    {
+        Long id = 1L;
+        _handle = newHandle(id);
+
+        assertEquals("Message not set value", id, _handle.getMessageId());
+    }
+
+    public void testInvalidContentChunk()
+    {
+        _handle = newHandle(1L);
+
+        try
+        {
+            _handle.getContentChunk(null, 0);
+            fail("getContentChunk should not succeed");
+        }
+        catch (RuntimeException e)
+        {
+            assertTrue(e.getMessage().equals("No ContentBody has been set"));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        ContentChunk cc = new MockContentChunk(null, 100);
+
+        try
+        {
+            _handle.addContentBodyFrame(null, cc, false);
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        try
+        {
+            _handle.getContentChunk(null, -1);
+            fail("getContentChunk should not succeed");
+        }
+        catch (IllegalArgumentException e)
+        {
+            assertTrue(e.getMessage().contains("out of valid range"));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        try
+        {
+            _handle.getContentChunk(null, 1);
+            fail("getContentChunk should not succeed");
+        }
+        catch (IllegalArgumentException e)
+        {
+            assertTrue(e.getMessage().contains("out of valid range"));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+    }
+
+    public void testAddSingleContentChunk()
+    {
+
+        _handle = newHandle(1L);
+
+        ContentChunk cc = new MockContentChunk(null, 100);
+
+        try
+        {
+            _handle.addContentBodyFrame(null, cc, true);
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        try
+        {
+            assertEquals("Incorrect body count", 1, _handle.getBodyCount(null));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        try
+        {
+            assertEquals("Incorrect ContentChunk returned.", cc, _handle.getContentChunk(null, 0));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        cc = new MockContentChunk(null, 100);
+
+        try
+        {
+            _handle.addContentBodyFrame(null, cc, true);
+            fail("Exception should prevent adding two final chunks");
+        }
+        catch (UnsupportedOperationException e)
+        {
+            //normal path
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+    }
+
+    public void testAddMultipleContentChunk()
+    {
+
+        _handle = newHandle(1L);
+
+        ContentChunk cc = new MockContentChunk(null, 100);
+
+        try
+        {
+            _handle.addContentBodyFrame(null, cc, false);
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        try
+        {
+            assertEquals("Incorrect body count", 1, _handle.getBodyCount(null));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        try
+        {
+            assertEquals("Incorrect ContentChunk returned.", cc, _handle.getContentChunk(null, 0));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        cc = new MockContentChunk(null, 100);
+
+        try
+        {
+            _handle.addContentBodyFrame(null, cc, true);
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        try
+        {
+            assertEquals("Incorrect body count", 2, _handle.getBodyCount(null));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+        try
+        {
+            assertEquals("Incorrect ContentChunk returned.", cc, _handle.getContentChunk(null, 1));
+        }
+        catch (AMQException e)
+        {
+            fail("AMQException thrown:" + e.getMessage());
+        }
+
+    }
+
+    // todo Move test to QueueEntry
+//    public void testRedelivered()
+//    {
+//        _handle = newHandle(1L);
+//
+//        assertFalse("New message should not be redelivered", _handle.isRedelivered());
+//
+//        _handle.setRedelivered(true);
+//
+//        assertTrue("New message should not be redelivered", _handle.isRedelivered());
+//    }
+
+    public void testInitialArrivalTime()
+    {
+        _handle = newHandle(1L);
+
+        assertEquals("Initial Arrival time should be 0L", 0L, _handle.getArrivalTime());
+    }
+
+    public void testSetPublishAndContentHeaderBody_WithBody()
+    {
+        _handle = newHandle(1L);
+
+        MessagePublishInfo mpi = new MessagePublishInfoImpl();
+        int bodySize = 100;
+
+        ContentHeaderBody chb = new ContentHeaderBody(0, 0, new BasicContentHeaderProperties(), bodySize);
+
+        try
+        {
+            _handle.setPublishAndContentHeaderBody(null, mpi, chb);
+
+            assertEquals("BodySize not returned correctly. ", bodySize, _handle.getBodySize(null));
+        }
+        catch (AMQException e)
+        {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+    }
+
+    public void testSetPublishAndContentHeaderBody_Empty()
+    {
+        _handle = newHandle(1L);
+
+        MessagePublishInfo mpi = new MessagePublishInfoImpl();
+        int bodySize = 0;                                                         
+
+        BasicContentHeaderProperties props = new BasicContentHeaderProperties();
+
+        props.setAppId("HandleTest");
+
+        ContentHeaderBody chb = new ContentHeaderBody(0, 0, props, bodySize);
+
+        try
+        {
+            _handle.setPublishAndContentHeaderBody(null, mpi, chb);
+
+            assertEquals("BodySize not returned correctly. ", bodySize, _handle.getBodySize(null));
+
+            ContentHeaderBody retreived_chb = _handle.getContentHeaderBody(null);
+
+            ContentHeaderProperties chp = retreived_chb.properties;
+
+            assertEquals("ContentHeaderBody not correct", chb, retreived_chb);
+
+            assertEquals("AppID not correctly retreived", "HandleTest",
+                         ((BasicContentHeaderProperties) chp).getAppIdAsString());
+
+            MessagePublishInfo retreived_mpi = _handle.getMessagePublishInfo(null);
+
+            assertEquals("MessagePublishInfo not correct", mpi, retreived_mpi);
+
+
+        }
+        catch (AMQException e)
+        {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+    }
+
+    public void testIsPersistent()
+    {
+        _handle = newHandle(1L);
+        
+        assertFalse(_handle.isPersistent());
+    }
+
+}

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/WeakMessageHandleTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/WeakMessageHandleTest.java?rev=744074&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/WeakMessageHandleTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/WeakMessageHandleTest.java Fri Feb 13 11:19:38 2009
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.qpid.server.queue;
+
+import org.apache.qpid.server.store.MemoryMessageStore;
+
+public class WeakMessageHandleTest extends InMemoryMessageHandleTest
+{
+    private MemoryMessageStore _messageStore;
+
+    public void setUp()
+    {
+        _messageStore = new MemoryMessageStore();
+        _messageStore.configure();
+    }
+
+    protected AMQMessageHandle newHandle(Long id)
+    {
+        return new WeakReferenceMessageHandle(id, _messageStore);
+    }
+
+    @Override
+    public void testIsPersistent()
+    {
+        _handle = newHandle(1L);        
+        assertTrue(_handle.isPersistent());
+    }
+
+
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org