axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whitl...@apache.org
Subject cvs commit: xml-axis-wsif/java/test/jms JmsTest.java Jms.wsdl
Date Wed, 25 Sep 2002 12:38:43 GMT
whitlock    2002/09/25 05:38:43

  Modified:    java/src/org/apache/wsif/util/jms WSIFJMSDestination.java
               java/test/jms JmsTest.java Jms.wsdl
  Log:
  Fix and test JMS synchronous timeouts
  
  Revision  Changes    Path
  1.8       +37 -15    xml-axis-wsif/java/src/org/apache/wsif/util/jms/WSIFJMSDestination.java
  
  Index: WSIFJMSDestination.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/jms/WSIFJMSDestination.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WSIFJMSDestination.java	18 Sep 2002 15:38:19 -0000	1.7
  +++ WSIFJMSDestination.java	25 Sep 2002 12:38:43 -0000	1.8
  @@ -141,7 +141,8 @@
   
           try {
               connection = finder.getFactory().createQueueConnection();
  -            session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
  +            session =
  +                connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   
               Destination initDest = finder.getInitialDestination();
               if (initDest != null && altDestName != null)
  @@ -158,7 +159,7 @@
               connection.start();
   
           } catch (JMSException je) {
  -        	Trc.exception(je);
  +            Trc.exception(je);
               throw WSIFJMSConstants.ToWsifException(je);
           }
           if (Trc.ON)
  @@ -186,7 +187,7 @@
               if (cnnctn != null)
                   cnnctn.close();
           } catch (JMSException je) {
  -        	Trc.exception(je);
  +            Trc.exception(je);
               throw WSIFJMSConstants.ToWsifException(je);
           }
           Trc.exit();
  @@ -229,7 +230,7 @@
               Trc.exit(s);
               return s;
           } catch (JMSException je) {
  -        	Trc.exception(je);
  +            Trc.exception(je);
               throw WSIFJMSConstants.ToWsifException(je);
           }
       }
  @@ -263,7 +264,7 @@
               Trc.exit(s);
               return s;
           } catch (JMSException je) {
  -        	Trc.exception(je);
  +            Trc.exception(je);
               throw WSIFJMSConstants.ToWsifException(je);
           }
       }
  @@ -299,7 +300,7 @@
               msgId = msg.getJMSMessageID();
   
           } catch (JMSException je) {
  -        	Trc.exception(je);
  +            Trc.exception(je);
               throw WSIFJMSConstants.ToWsifException(je);
           } finally { // If properties were set, trash the sender so we get the default props
next time.
               if (propsSet)
  @@ -338,7 +339,7 @@
                       "Reply message was not a TextMessage:msg="
                           + (msg == null ? "null" : msg.toString()));
           } catch (JMSException e) {
  -        	Trc.exception(e);
  +            Trc.exception(e);
               throw WSIFJMSConstants.ToWsifException(e);
           }
           Trc.exit(s);
  @@ -367,15 +368,21 @@
   
               msg = rec.receive(timeout);
   
  +            if (msg == null)
  +                throw new WSIFException(
  +                    "Receive timed out on JMS queue "
  +                        + readQ.getQueueName()
  +                        + ", timeout "
  +                        + timeout);
           } catch (JMSException e) {
  -        	Trc.exception(e);
  +            Trc.exception(e);
               throw WSIFJMSConstants.ToWsifException(e);
           } finally {
               try {
                   if (rec != null)
                       rec.close();
               } catch (Exception ignored) {
  -	        	Trc.ignoredException(ignored);
  +                Trc.ignoredException(ignored);
               }
           }
   
  @@ -395,11 +402,12 @@
               if (syncTempQueue == null)
                   syncTempQueue = session.createTemporaryQueue();
           } catch (JMSException je) {
  -        	Trc.exception(je);
  +            Trc.exception(je);
               throw WSIFJMSConstants.ToWsifException(je);
           }
   
  -        readQ = syncTempQueue; // So we don't overwrite readQ if there was an error.
  +        readQ = syncTempQueue;
  +        // So we don't overwrite readQ if there was an error.
           replyToName = null;
           Trc.exit();
       }
  @@ -442,7 +450,7 @@
           Trc.entry(this, b);
           areWeClosed();
           if (asyncMode != b) {
  -           asyncMode = b;
  +            asyncMode = b;
           }
           Trc.exit();
       }
  @@ -522,16 +530,30 @@
   
           try {
               if (msgType
  -                == org.apache.wsif.wsdl.extensions.jms.JMSConstants.MESSAGE_TYPE_OBJECTMESSAGE)
  +                == org
  +                    .apache
  +                    .wsif
  +                    .wsdl
  +                    .extensions
  +                    .jms
  +                    .JMSConstants
  +                    .MESSAGE_TYPE_OBJECTMESSAGE)
                   jmsMsg = session.createObjectMessage();
               else if (
                   msgType
  -                    == org.apache.wsif.wsdl.extensions.jms.JMSConstants.MESSAGE_TYPE_TEXTMESSAGE)
  +                    == org
  +                        .apache
  +                        .wsif
  +                        .wsdl
  +                        .extensions
  +                        .jms
  +                        .JMSConstants
  +                        .MESSAGE_TYPE_TEXTMESSAGE)
                   jmsMsg = session.createTextMessage();
               else
                   throw new WSIFException("Unable to support message type");
           } catch (JMSException je) {
  -        	Trc.exception(je);
  +            Trc.exception(je);
               throw WSIFJMSConstants.ToWsifException(je);
           }
           Trc.exit(jmsMsg);
  
  
  
  1.10      +78 -14    xml-axis-wsif/java/test/jms/JmsTest.java
  
  Index: JmsTest.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/jms/JmsTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JmsTest.java	16 Sep 2002 08:18:56 -0000	1.9
  +++ JmsTest.java	25 Sep 2002 12:38:43 -0000	1.10
  @@ -58,6 +58,8 @@
   package jms;
   
   import java.rmi.RemoteException;
  +import java.text.DateFormat;
  +import java.util.Date;
   
   import javax.jms.DeliveryMode;
   import javax.xml.namespace.QName;
  @@ -68,7 +70,6 @@
   import org.apache.wsif.WSIFException;
   import org.apache.wsif.WSIFService;
   import org.apache.wsif.WSIFServiceFactory;
  -import org.apache.wsif.util.WSIFPluggableProviders;
   import util.AddressUtility;
   import util.TestUtilities;
   
  @@ -106,6 +107,7 @@
       private final static String  ABPV     = "address and binding property values";
       private final static String  UPV      = "user properties values";
       private final static String  OPV      = "overiding property values";
  +    private final static String  TO       = "timeout";
   
       private interface AddressBookWithAttrs extends AddressBook {
           public void addEntry(String name, Address address) throws RemoteException;
  @@ -158,6 +160,8 @@
           TestUtilities.setUpExtensionsAndProviders();
       }
   
  +    /* *************** Start of SOAP tests ****************** */
  +    
       public void testSoapDefault() {
           doit("default", SOAP, REPLYTOQ, 3, NPERS, 0, null);
       }
  @@ -307,6 +311,12 @@
   //        doit("bad-pvnoname", SOAP, REPLYTOQ, 3, NPERS, 0, APV);
   //    }
   
  +    public void testSoapTimeout() {
  +        doit("timeout", SOAP, REPLYTOQ, 3, NPERS, 0, TO);
  +    }
  +
  +    /* ********** Start of AXIS tests ************ */
  +    
       public void testAxisDefault() {
           doit("default", AXIS, REPLYTOQ, 3, NPERS, 0, null);
       }
  @@ -443,6 +453,11 @@
           doit("bindpv", AXIS, REPLYTOQ, 3, PERS, 0, BPV);
       }
   
  +    public void testAxisTimeout() {
  +        doit("timeout", AXIS, REPLYTOQ, 3, NPERS, 0, TO);
  +    }
  +
  +    /* ********** Start of Native JMS tests ************ */
   
   	public void testNativeJMSDefault() {
   		doit("NJdefault", NJMS, REPLYTOQ, 3, NPERS, 0, null);
  @@ -544,6 +559,10 @@
   		doit("NJbindpv", NJMS, REPLYTOQ, 3, PERS, 0, BPV);
   	}
   
  +    public void testNativeJMSTimeout() {
  +        doit("NJtimeout", NJMS, REPLYTOQ, 3, NPERS, 0, TO);
  +    }
  +
       public void testJavaNoAttrs() {
           doit("java-noattrs", JAVA, null, 3, NPERS, 0, null);
       }
  @@ -556,6 +575,7 @@
           int deliveryMode,
           long timeToLive,
           String cmd) {
  +        	
           if (!TestUtilities.areWeTesting("jms"))
               return;
   
  @@ -580,19 +600,23 @@
               AddressBookWithAttrs stub =
                   (AddressBookWithAttrs) service.getStub(portName, AddressBookWithAttrs.class);
   
  -            if (cmd == null)
  -                stub.addEntry(
  -                    name,
  -                    addr,
  -                    priority,
  -                    replyTo,
  -                    deliveryMode,
  -                    timeToLive);
  -            else
  -                doProperties(stub, cmd, deliveryMode);
  -
  -            Address resp = stub.getAddressFromName(name, deliveryMode);
  -            assertTrue(new AddressUtility(resp).equals(addr));
  +            if ("timeout".equals(cmd))
  +                doTimeout(stub, deliveryMode);
  +            else {
  +                if (cmd == null)
  +                    stub.addEntry(
  +                        name,
  +                        addr,
  +                        priority,
  +                        replyTo,
  +                        deliveryMode,
  +                        timeToLive);
  +                else
  +                    doProperties(stub, cmd, deliveryMode);
  +
  +                Address resp = stub.getAddressFromName(name, deliveryMode);
  +                assertTrue(new AddressUtility(resp).equals(addr));
  +            }
               assertTrue(!ExceptionExpected);
           } catch (Exception e) {
               System.err.println("JmsTest(" + portName + ") caught exception " + e);
  @@ -639,4 +663,44 @@
           } else
               assertTrue(false);
       }
  +
  +    /**
  +     * This test only tests out synchronous timeouts. Asynchronous timeouts
  +     * are the responsibility of the application since it is the application
  +     * that does the listen or receive for the response message. The asynchronous
  +     * timeout in wsif.properties is also used by the correlation service,
  +     * but this is tested in a separate unit test.
  +     */
  +    private void doTimeout(
  +        AddressBookWithAttrs stub,
  +        int deliveryMode)
  +        throws Exception {
  +
  +        boolean caught = false;
  +        Date first = new Date();
  +        try {
  +            stub.addEntry(name, addr, deliveryMode);
  +        } catch (WSIFException we) {
  +            System.out.println("Caught expected " + we);
  +            caught = true;
  +        }
  +        assertTrue(caught);
  +        Date second = new Date();
  +
  +        DateFormat df = DateFormat.getDateTimeInstance();
  +        System.out.println("first date was " + df.format(first));
  +        System.out.println("second date was " + df.format(second));
  +
  +        // getTime() returns milliseconds.
  +        long firstTime = first.getTime();
  +        long secondTime = second.getTime();
  +        System.out.println("first time was " + firstTime);
  +        System.out.println("second time was " + secondTime);
  +
  +        // Default synchronous timeout is 10 seconds
  +        assertTrue(firstTime<secondTime);
  +        assertTrue((secondTime-firstTime)>10000);
  +        assertTrue((secondTime-firstTime)<20000);
  +    }
  +
   }
  
  
  
  1.6       +14 -0     xml-axis-wsif/java/test/jms/Jms.wsdl
  
  Index: Jms.wsdl
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/jms/Jms.wsdl,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Jms.wsdl	25 Jun 2002 08:35:07 -0000	1.5
  +++ Jms.wsdl	25 Sep 2002 12:38:43 -0000	1.6
  @@ -645,6 +645,13 @@
           <jms:propertyValue name="JMSReplyTo" type="xsd:string" value="trash"/>
         </jms:address>
       </port>
  +    <port name="timeout" binding="tns:SOAPJmsBinding">
  +      <jms:address jmsProviderDestinationName="SYSTEM.DEAD.LETTER.QUEUE"
  +                   destinationStyle="queue"
  +                   jndiConnectionFactoryName="WSIFSampleQCF"
  +                   initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory"
  +                   jndiProviderURL="file:///JNDI-Directory"/>
  +    </port>
       <port name="NJdefault" binding="tns:NativeJmsBinding">
         <jms:address jmsVendorURI="http://ibm.com/ns/mqseries"
                      jndiDestinationName="NativeJmsRequestQueue"
  @@ -848,6 +855,13 @@
                      jndiProviderURL="file://C:/JNDI-Directory">
           <jms:propertyValue name="JMSReplyTo" type="xsd:string" value="trash"/>
         </jms:address>
  +    </port>
  +    <port name="NJtimeout" binding="tns:NativeJmsBinding">
  +      <jms:address jmsProviderDestinationName="SYSTEM.DEAD.LETTER.QUEUE"
  +                   destinationStyle="queue"
  +                   jndiConnectionFactoryName="WSIFSampleQCF"
  +                   initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory"
  +                   jndiProviderURL="file:///JNDI-Directory"/>
       </port>
     </service>
   
  
  
  

Mime
View raw message