Author: gatfora
Date: Mon Feb  5 05:10:21 2007
New Revision: 503667

URL: http://svn.apache.org/viewvc?view=rev&rev=503667
Log:
RangeString doesn't perform for long running sequences, Add a test for 
MessageRolloverFaults and add method to RMSampleService.java to stop 
MethodNotFound exceptions

Added:
    
webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java
Modified:
    
webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/RMSampleService.java
    
webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RangeString.java

Modified: 
webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/RMSampleService.java
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/RMSampleService.java?view=diff&rev=503667&r1=503666&r2=503667
==============================================================================
--- 
webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/RMSampleService.java
 (original)
+++ 
webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/RMSampleService.java
 Mon Feb  5 05:10:21 2007
@@ -43,7 +43,11 @@
        private final String EchoStringReturn = "EchoStringReturn";
        private final String Attachment = "Attachment";
        private final String DESTINATION_IMAGE_FILE = "mtom-image1.jpg";
-       
+
+  public void init(org.apache.axis2.context.ServiceContext serviceContext) {
+
+  }
+
        public OMElement echoString(OMElement in) throws Exception {
                
                OMElement textElem = in.getFirstChildWithName(new QName 
(applicationNamespaceName,Text));
@@ -112,4 +116,4 @@
                        throw new AxisFault(e);
                }
        }
-}
\ No newline at end of file
+}

Modified: 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RangeString.java
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RangeString.java?view=diff&rev=503667&r1=503666&r2=503667
==============================================================================
--- 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RangeString.java 
(original)
+++ 
webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RangeString.java 
Mon Feb  5 05:10:21 2007
@@ -20,6 +20,7 @@
 import java.io.Serializable;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -77,14 +78,23 @@
        private Range getNextRangeBelow(long msgNumber){
                //start at the specified index and work down the list of ranges
                //util we find one
+               Iterator iterator = rangeMap.keySet().iterator();
                
-               for(long i = msgNumber; i>=0; i--){
-                       Range r = (Range)rangeMap.get(new Long(i));
-                       if(r!=null){
-                               //this is the next range below
-                               return r;
+               long cachedKey = -1;
+               while (iterator.hasNext()) {
+                       long key = ((Long)iterator.next()).longValue();
+                       
+                       if (key > cachedKey && key <= msgNumber) {
+                               cachedKey = key;
                        }
                }
+               
+               if (cachedKey != -1) {
+                       //this is the next range below
+                       Range r = (Range)rangeMap.get(new Long(cachedKey));
+                       return r;
+               }
+               
                //no range below this one
                return null; 
        }
@@ -101,12 +111,21 @@
                //its end 
                long startOfRangeLookup = envelopeRange.lowerValue + 1;
                long endOfRangeLookup = envelopeRange.upperValue;
-               for(long i=startOfRangeLookup; i<=endOfRangeLookup; i++){
-                       Range removedRange = (Range)rangeMap.remove(new 
Long(i)); //remove if there is anything present
-                       if(removedRange!=null && 
removedRange.upperValue>envelopeRange.upperValue){
-                               //this range started in our envelope but 
stretched out beyond it so we
-                               //can absorb its upper value
-                               envelopeRange.upperValue = 
removedRange.upperValue;
+               // Iterator over the available ranges.
+               Iterator ranges = rangeMap.keySet().iterator();
+               while (ranges.hasNext()) {
+                       // Get the key
+                       long key = ((Long)ranges.next()).longValue();
+                       if (key >= startOfRangeLookup && key <= 
endOfRangeLookup) {
+                               Range removedRange = (Range)rangeMap.get(new 
Long(key));
+                               
+                               if(removedRange!=null && 
removedRange.upperValue>envelopeRange.upperValue){
+                                       //this range started in our envelope 
but stretched out beyond it so we
+                                       //can absorb its upper value
+                                       envelopeRange.upperValue = 
removedRange.upperValue;
+                               }
+                               // Remove the current range from the HashMap.
+                               ranges.remove();
                        }
                }
        }
@@ -126,9 +145,8 @@
                if(getRangeForMessageNumber(messageNumber)!=null){
                        return true;
                }
-               else{
-                       return false;
-               }
+               
+               return false;
        }
        
        public Range getRangeForMessageNumber(long messageNumber){

Added: 
webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java
URL: 
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java?view=auto&rev=503667
==============================================================================
--- 
webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java
 (added)
+++ 
webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/MessageNumberRolloverFaultTest.java
 Mon Feb  5 05:10:21 2007
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed 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.sandesha2.faulttests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaTestCase;
+import org.apache.sandesha2.msgreceivers.RMMessageReceiver;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.Transaction;
+import org.apache.sandesha2.storage.beanmanagers.RMDBeanMgr;
+import org.apache.sandesha2.storage.beans.RMDBean;
+import org.apache.sandesha2.util.Range;
+import org.apache.sandesha2.util.RangeString;
+import org.apache.sandesha2.util.SandeshaUtil;
+import org.apache.sandesha2.util.SpecSpecificConstants;
+import org.apache.sandesha2.wsrm.Identifier;
+import org.apache.sandesha2.wsrm.MessageNumber;
+import org.apache.sandesha2.wsrm.Sequence;
+
+
+public class MessageNumberRolloverFaultTest extends SandeshaTestCase {
+
+       private static final String server_repoPath = "target" + File.separator
+           + "repos" + File.separator + "server";
+
+       private static final String server_axis2_xml = "target" + File.separator
+           + "repos" + File.separator + "server" + File.separator
+           + "server_axis2.xml";
+       
+       private ConfigurationContext serverConfigContext;
+       
+       public MessageNumberRolloverFaultTest() {
+               super("MessageNumberRolloverFaultTest");
+       }
+
+       public void setUp() throws Exception {
+               super.setUp();
+               serverConfigContext = startServer(server_repoPath, 
server_axis2_xml);
+       }
+
+       /**
+        * Sends an application message to the RMD.
+        * The RMD should reject the message with a MessageRolloverFault
+        * 
+        * @throws Exception
+        */
+       public void testMessageNumberRolloverFault() throws Exception {
+    // Open a connection to the endpoint
+               HttpURLConnection connection = 
+                       FaultTestUtils.getHttpURLConnection("http://127.0.0.1:"; 
+ serverPort + "/axis2/services/RMSampleService",
+                                       pingAction);
+
+               StorageManager storageManager = 
+                       
SandeshaUtil.getSandeshaStorageManager(serverConfigContext, 
serverConfigContext.getAxisConfiguration());
+               
+               RMDBeanMgr rmdBeanMgr = storageManager.getRMDBeanMgr();
+               
+               String seqID = SandeshaUtil.getUUID();
+               
+               // Mockup an RMSBean
+               RMDBean rmdBean = new RMDBean();
+               rmdBean.setSequenceID(seqID);
+               rmdBean.setToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+               
rmdBean.setAcksToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+               
rmdBean.setReplyToEPR(AddressingConstants.Final.WSA_ANONYMOUS_URL);
+               rmdBean.setRMVersion(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+               rmdBean.setServerCompletedMessages(new RangeString());
+               rmdBean.getServerCompletedMessages().addRange(new Range(1, 
Long.MAX_VALUE -1));
+               rmdBean.getServerCompletedMessages().addRange(new 
Range(Long.MAX_VALUE, Long.MAX_VALUE));
+               
+               // Create a transaction and insert the RMSBean
+               Transaction tran = storageManager.getTransaction();
+               
+               rmdBeanMgr.insert(rmdBean);
+               
+               tran.commit();
+
+               
+               OutputStream tmpOut2 = connection.getOutputStream();
+
+               byte ar[] = getAppMessageAsBytes(seqID);
+               
+               // Send the message to the socket.
+               tmpOut2.write(ar);
+               tmpOut2.flush();
+
+               // Get the response message from the connection
+               String message = 
FaultTestUtils.retrieveResponseMessage(connection);
+    
+    // Check that the fault message isn't null
+    assertNotNull(message);
+    
+    // Check that the response contains the MessageNumberRollover tag    
+    assertTrue(message.indexOf("wsrm:MessageNumberRollover") > -1);
+    
+    // Disconnect at the end of the test
+    connection.disconnect();
+       }
+       
+       /**
+        * Get an application message as bytes
+        * 
+        * This sets the message number to "Long.maxValue"
+        * 
+        * @return
+        */
+       private byte[] getAppMessageAsBytes(String uuid) throws Exception
+       {
+               SOAPFactory factory = new SOAP11Factory();
+               SOAPEnvelope dummyEnvelope = factory.getDefaultEnvelope();
+               
+               // Create a "new" application message
+               MessageContext messageContext = new MessageContext();
+               messageContext.setConfigurationContext(serverConfigContext);
+               
messageContext.setAxisService(serverConfigContext.getAxisConfiguration().getService("RMSampleService"));
                
+               messageContext.setEnvelope(dummyEnvelope);
+               
+               RMMsgContext applicationRMMsg = new 
RMMsgContext(messageContext);
+               
+               // Generate the Sequence field.
+               // -------------------------------
+               String rmNamespaceValue = 
SpecSpecificConstants.getRMNamespaceValue(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+
+               Sequence sequence = new Sequence(rmNamespaceValue);
+               MessageNumber msgNumber = new MessageNumber(rmNamespaceValue);
+               msgNumber.setMessageNumber(Long.MAX_VALUE);
+               sequence.setMessageNumber(msgNumber);
+               Identifier id1 = new Identifier(rmNamespaceValue);
+               id1.setIndentifer(uuid);
+               sequence.setIdentifier(id1);
+               
applicationRMMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQUENCE, 
sequence);
+               applicationRMMsg.addSOAPEnvelope();
+
+               // --------------------------------------------
+               // Finished generating Sequence part
+               
+               // Create an RMSBean so the create sequence message can be 
created
+               messageContext.setWSAAction(pingAction);
+
+               // Set the AxisOperation to be InOut
+               AxisOperation operation = 
messageContext.getAxisService().getOperation(new QName("RMInOutOperation"));
+               operation.setMessageReceiver(new RMMessageReceiver());
+               messageContext.setAxisOperation(operation);
+
+               ByteArrayOutputStream outputStream = new 
ByteArrayOutputStream();
+               
+               // Serialize the application message
+               
applicationRMMsg.getMessageContext().getEnvelope().serialize(outputStream);
+               
+               return outputStream.toByteArray();
+       }
+}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to