InteropTestCase5PubSubMessageSize.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  *
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  *
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.interop.testcases;
022 
023 import org.apache.log4j.Logger;
024 
025 import org.apache.qpid.test.framework.FrameworkBaseCase;
026 
027 import java.util.Properties;
028 
029 /**
030  * Implements test case 5, from the interop test specification. This test sets up the TC2_PubSubMessageSize test for 10
031  * messages, sent to 5 consumers, and a variety of message sizes. It checks that the sender and receivers reports both
032  * indicate that all the test messages were transmitted successfully.
033  *
034  <p><table id="crc"><caption>CRC Card</caption>
035  <tr><th> Responsibilities <th> Collaborations
036  <tr><td> Setup pub/sub test parameters and compare with test output. <td> {@link FrameworkBaseCase}
037  </table>
038  */
039 public class InteropTestCase5PubSubMessageSize extends FrameworkBaseCase
040 {
041     /** Used for debugging. */
042     private static final Logger log = Logger.getLogger(InteropTestCase5PubSubMessageSize.class);
043 
044     /**
045      * Creates a new coordinating test case with the specified name.
046      *
047      @param name The test case name.
048      */
049     public InteropTestCase5PubSubMessageSize(String name)
050     {
051         super(name);
052     }
053 
054     /**
055      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 0K in size.
056      *
057      @throws Exception Any exceptions are allowed to fall through and fail the test.
058      */
059     public void testPubSubMessageSize0K() throws Exception
060     {
061         runTestForMessagesOfSize(0);
062     }
063 
064     /**
065      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 63K in size.
066      *
067      @throws Exception Any exceptions are allowed to fall through and fail the test.
068      */
069     public void testPubSubMessageSize63K() throws Exception
070     {
071         runTestForMessagesOfSize(63 1024);
072     }
073 
074     /**
075      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 64K in size.
076      *
077      @throws Exception Any exceptions are allowed to fall through and fail the test.
078      */
079     public void testPubSubMessageSize64K() throws Exception
080     {
081         runTestForMessagesOfSize(64 1024);
082     }
083 
084     /**
085      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 65K in size.
086      *
087      @throws Exception Any exceptions are allowed to fall through and fail the test.
088      */
089     public void testPubSubMessageSize65K() throws Exception
090     {
091         runTestForMessagesOfSize(65 1024);
092     }
093 
094     /**
095      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 127K in size.
096      *
097      @throws Exception Any exceptions are allowed to fall through and fail the test.
098      */
099     public void testPubSubMessageSize127K() throws Exception
100     {
101         runTestForMessagesOfSize(127 1024);
102     }
103 
104     /**
105      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 128K in size.
106      *
107      @throws Exception Any exceptions are allowed to fall through and fail the test.
108      */
109     public void testPubSubMessageSize128K() throws Exception
110     {
111         runTestForMessagesOfSize(128 1024);
112     }
113 
114     /**
115      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 129K in size.
116      *
117      @throws Exception Any exceptions are allowed to fall through and fail the test.
118      */
119     public void testPubSubMessageSize129K() throws Exception
120     {
121         runTestForMessagesOfSize(129 1024);
122     }
123 
124     /**
125      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 255K in size.
126      *
127      @throws Exception Any exceptions are allowed to fall through and fail the test.
128      */
129     public void testPubSubMessageSize255K() throws Exception
130     {
131         runTestForMessagesOfSize(255 1024);
132     }
133 
134     /**
135      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 256K in size.
136      *
137      @throws Exception Any exceptions are allowed to fall through and fail the test.
138      */
139     public void testPubSubMessageSize256K() throws Exception
140     {
141         runTestForMessagesOfSize(256 1024);
142     }
143 
144     /**
145      * Performs the P2P message test case, "Test Case 4" in the specification, for messages 257K in size.
146      *
147      @throws Exception Any exceptions are allowed to fall through and fail the test.
148      */
149     public void testPubSubMessageSize257K() throws Exception
150     {
151         runTestForMessagesOfSize(257 1024);
152     }
153 
154     /**
155      * Sends 50 test messages of the specified size, and asserts that all were received.
156      *
157      @param size The size of the messages to send in bytes.
158      */
159     private void runTestForMessagesOfSize(int size)
160     {
161         Properties testConfig = new Properties();
162         testConfig.put("TEST_NAME""TC5_PubSubMessageSize");
163         testConfig.put("PUBSUB_KEY""tc3route");
164         testConfig.put("PUBSUB_NUM_MESSAGES"10);
165         testConfig.put("PUBSUB_NUM_RECEIVERS"5);
166         testConfig.put("messageSize", size);
167 
168         /*Message[] reports =*/
169         getCircuitFactory().sequenceTest(null, null, testConfig);
170 
171         // Compare sender and receivers reports.
172         /*
173         int messagesSent = reports[0].getIntProperty("MESSAGE_COUNT");
174         int messagesReceived = reports[1].getIntProperty("MESSAGE_COUNT");
175 
176         Assert.assertEquals("The requested number of messages were not sent.", 50, messagesSent);
177         Assert.assertEquals("Sender and receivers messages sent did not match up.", messagesSent, messagesReceived);
178          */
179     }
180 
181     /**
182      * Should provide a translation from the junit method name of a test to its test case name as defined in the
183      * interop testing specification. For example the method "testP2P" might map onto the interop test case name
184      * "TC2_BasicP2P".
185      *
186      @param methodName The name of the JUnit test method.
187      @return The name of the corresponding interop test case.
188      */
189     public String getTestCaseNameForTestMethod(String methodName)
190     {
191         return "TC5_PubSubMessageSize";
192     }
193 }