qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From philharveyonl...@apache.org
Subject svn commit: r1501793 - in /qpid/jms/trunk: ./ src/main/java/org/apache/qpid/jms/ src/main/java/org/apache/qpid/jms/engine/ src/main/java/org/apache/qpid/jms/impl/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/qpid/ src/test/java...
Date Wed, 10 Jul 2013 15:21:19 GMT
Author: philharveyonline
Date: Wed Jul 10 15:21:19 2013
New Revision: 1501793

URL: http://svn.apache.org/r1501793
Log:
NO-JIRA: made Main a JUnit test that also stops the driver, laying the groundwork for getting
some proper tests up and running
Also general source clean-up:
- Implemented toString() in several classes
- Created SimplePredicate class that can produce diagnostic information if waitFor(..) times
out
- Removed whitespace, added missing annotations etc.

Added:
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SimplePredicate.java
    qpid/jms/trunk/src/test/java/org/
    qpid/jms/trunk/src/test/java/org/apache/
    qpid/jms/trunk/src/test/java/org/apache/qpid/
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/JmsTest.java
    qpid/jms/trunk/src/test/resources/
    qpid/jms/trunk/src/test/resources/logging.properties
Removed:
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/Main.java
Modified:
    qpid/jms/trunk/pom.xml
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpConnection.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceivedMessage.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceiver.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSentMessage.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java

Modified: qpid/jms/trunk/pom.xml
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/pom.xml?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/pom.xml (original)
+++ qpid/jms/trunk/pom.xml Wed Jul 10 15:21:19 2013
@@ -45,6 +45,12 @@
       <artifactId>proton-j-impl</artifactId>
       <version>${proton-version}</version>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junit-version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -62,18 +68,12 @@
       </plugin>
       
       <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>exec-maven-plugin</artifactId>
-        <version>1.2.1</version>
-        <executions>
-          <execution>
-            <goals>
-              <goal>java</goal>
-            </goals>
-          </execution>
-        </executions>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
-          <mainClass>org.apache.qpid.jms.Main</mainClass>
+          <systemPropertyVariables>
+            <java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
+          </systemPropertyVariables>
         </configuration>
       </plugin>
     </plugins>

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpConnection.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpConnection.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpConnection.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpConnection.java Wed Jul 10
15:21:19 2013
@@ -42,7 +42,8 @@ import org.apache.qpid.proton.message.Me
 @SuppressWarnings("rawtypes")
 public class AmqpConnection
 {
-    public static final long TIMEOUT = 30000L;
+    /** default timeout in milliseconds */
+    public static final long TIMEOUT = 10000L;
 
     private static Logger _logger = Logger.getLogger("qpid.jms-client.connection");
 
@@ -209,7 +210,7 @@ public class AmqpConnection
                 amqpSession.setEstablished();
                 pendingSessions.remove();
                 updated = true;
-            }            
+            }
         }
 
         Iterator<Session> pendingCloseSessions = _pendingCloseSessions.iterator();
@@ -222,7 +223,7 @@ public class AmqpConnection
                 amqpSession.setClosed();
                 pendingCloseSessions.remove();
                 updated = true;
-            }            
+            }
         }
 
         //Links
@@ -258,7 +259,7 @@ public class AmqpConnection
     }
 
     private boolean processSasl()
-    {        
+    {
         boolean updated = false;
         switch(_sasl.getState())
         {
@@ -308,7 +309,7 @@ public class AmqpConnection
                 {
                     _authenticationError = true;
                     updated = true;
-                }                
+                }
                 break;
             default:
         }

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceivedMessage.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceivedMessage.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceivedMessage.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceivedMessage.java Wed Jul
10 15:21:19 2013
@@ -63,7 +63,7 @@ public class AmqpReceivedMessage
     /**
      * If using proton-j, returns true if locally or remotely settled.
      * If using proton-c, returns true if remotely settled.
-     * TODO - remove this hack when Proton-J and -C APIs are properly aligned 
+     * TODO - remove this hack when Proton-J and -C APIs are properly aligned
      * The C API defines isSettled as being true if the delivery has been settled locally
OR remotely
      */
     public boolean isSettled()

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceiver.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceiver.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceiver.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpReceiver.java Wed Jul 10 15:21:19
2013
@@ -31,7 +31,7 @@ public class AmqpReceiver extends AmqpLi
 
     public AmqpReceiver(AmqpSession amqpSession, Receiver protonReceiver)
     {
-        super(amqpSession, protonReceiver);        
+        super(amqpSession, protonReceiver);
         _protonReceiver = protonReceiver;
     }
 
@@ -79,10 +79,19 @@ public class AmqpReceiver extends AmqpLi
                         _protonReceiver.advance();
                         return amqpMessage;
                     }
-                }                
+                }
             }
         }
         return null;
     }
 
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("AmqpReceiver [_protonReceiver=").append(_protonReceiver)
+            .append("]");
+        return builder.toString();
+    }
+
 }

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSender.java Wed Jul 10 15:21:19
2013
@@ -32,9 +32,9 @@ public class AmqpSender extends AmqpLink
     private byte[] _buffer = new byte[1024];
     private final Sender _protonSender;
 
-    public AmqpSender(AmqpSession amqpSession, Sender protonSender) 
+    public AmqpSender(AmqpSession amqpSession, Sender protonSender)
     {
-        super(amqpSession, protonSender);        
+        super(amqpSession, protonSender);
         _protonSender = protonSender;
     }
 
@@ -71,4 +71,14 @@ public class AmqpSender extends AmqpLink
             return amqpSentMessage;
         }
     }
+
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("AmqpSender [tag=").append(tag)
+            .append(", _protonSender=").append(_protonSender)
+            .append("]");
+        return builder.toString();
+    }
 }

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSentMessage.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSentMessage.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSentMessage.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpSentMessage.java Wed Jul 10
15:21:19 2013
@@ -51,4 +51,13 @@ public class AmqpSentMessage
             _delivery.settle();
         }
     }
+
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("AmqpSentMessage [_delivery=").append(_delivery)
+            .append("]");
+        return builder.toString();
+    }
 }

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java Wed Jul 10 15:21:19
2013
@@ -62,9 +62,9 @@ public class ConnectionImpl
         });
     }
 
-    void waitUntil(Predicate condition, long timeout) throws TimeoutException, InterruptedException
+    void waitUntil(Predicate condition, long timeoutMillis) throws TimeoutException, InterruptedException
     {
-        long deadline = timeout < 0 ? Long.MAX_VALUE : System.currentTimeMillis() + timeout;
+        long deadline = timeoutMillis < 0 ? Long.MAX_VALUE : System.currentTimeMillis()
+ timeoutMillis;
 
         boolean wait = deadline > System.currentTimeMillis();
         boolean first = true;
@@ -76,17 +76,17 @@ public class ConnectionImpl
             {
                 if (wait && !done && !first)
                 {
-                    _amqpConnection.wait(timeout < 0 ? 0 : deadline - System.currentTimeMillis());
+                    _amqpConnection.wait(timeoutMillis < 0 ? 0 : deadline - System.currentTimeMillis());
                 }
 
                 wait = deadline > System.currentTimeMillis();
                 done = done || condition.test();
                 first = false;
             }
-        }
-        if (!done)
-        {
-            throw new TimeoutException();
+            if (!done)
+            {
+                throw new TimeoutException(timeoutMillis, condition.toString());
+            }
         }
     }
 
@@ -95,7 +95,7 @@ public class ConnectionImpl
         lock();
         try
         {
-            waitUntil(new Predicate()
+            waitUntil(new SimplePredicate("Connection established or failed", _amqpConnection)
             {
                 public boolean test()
                 {
@@ -133,7 +133,7 @@ public class ConnectionImpl
             stateChanged();
             while(!_amqpConnection.isClosed())
             {
-                waitUntil(new Predicate()
+                waitUntil(new SimplePredicate("Connection is closed", _amqpConnection)
                 {
                     public boolean test()
                     {

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java Wed Jul 10 15:21:19
2013
@@ -40,8 +40,9 @@ public class LinkImpl
 
     public void establish() throws TimeoutException, InterruptedException
     {
-        _connectionImpl.waitUntil(new Predicate()
+        _connectionImpl.waitUntil(new SimplePredicate("Link is closed", _amqpLink)
         {
+            @Override
             public boolean test()
             {
                 return _amqpLink.isEstablished();
@@ -51,15 +52,16 @@ public class LinkImpl
 
     public void close() throws TimeoutException, InterruptedException, ConnectionException
     {
-        _connectionImpl.lock();        
+        _connectionImpl.lock();
         try
         {
             _amqpLink.close();
             _connectionImpl.stateChanged();
             while(!_amqpLink.isClosed())
             {
-                _connectionImpl.waitUntil(new Predicate()
+                _connectionImpl.waitUntil(new SimplePredicate("Link is closed", _amqpLink)
                 {
+                    @Override
                     public boolean test()
                     {
                         return _amqpLink.isClosed();

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java Wed Jul 10 15:21:19
2013
@@ -20,6 +20,12 @@
  */
 package org.apache.qpid.jms.impl;
 
+/**
+ * A simple predicate.
+ *
+ * Used for general purpose logic so should provide a useful toString() implementation
+ * for logging purposes.
+ */
 interface Predicate
 {
     boolean test();

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java Wed Jul
10 15:21:19 2013
@@ -55,7 +55,7 @@ public class ReceivedMessageImpl
     }
 
     public void settle()
-    {       
+    {
         _receiverImpl.getConnectionImpl().lock();
         try
         {
@@ -73,7 +73,7 @@ public class ReceivedMessageImpl
         _receiverImpl.getConnectionImpl().lock();
         try
         {
-            _receiverImpl.getConnectionImpl().waitUntil(new Predicate()
+            _receiverImpl.getConnectionImpl().waitUntil(new SimplePredicate("Message is settled",
_amqpMessage)
             {
                 @Override
                 public boolean test()

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java Wed Jul 10 15:21:19
2013
@@ -65,10 +65,15 @@ public class ReceiverImpl extends LinkIm
         }
     }
 
-    private final class MessageReceivedPredicate implements Predicate
+    private final class MessageReceivedPredicate extends SimplePredicate
     {
         AmqpReceivedMessage _message;
 
+        public MessageReceivedPredicate()
+        {
+            super("Message received", _amqpReceiver);
+        }
+
         @Override
         public boolean test()
         {
@@ -76,7 +81,7 @@ public class ReceiverImpl extends LinkIm
             {
                 _message = _amqpReceiver.receiveNoWait();
             }
-            return _message != null;            
+            return _message != null;
         }
 
         public AmqpReceivedMessage getReceivedMessage()

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java Wed Jul 10
15:21:19 2013
@@ -37,7 +37,7 @@ public class SentMessageImpl
 
     public void waitUntilAccepted() throws TimeoutException, InterruptedException
     {
-        _sender.getConnectionImpl().waitUntil(new Predicate()
+        _sender.getConnectionImpl().waitUntil(new SimplePredicate("Remote delivery state
exists", _sentMessage)
         {
             @Override
             public boolean test()
@@ -47,4 +47,19 @@ public class SentMessageImpl
         }, AmqpConnection.TIMEOUT);
     }
 
+    /**
+     * {@inheritDoc}
+     * <br/>
+     * Not thread-safe
+     */
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("SentMessageImpl [_sentMessage=").append(_sentMessage)
+            .append("]");
+        return builder.toString();
+    }
+
+
 }

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java?rev=1501793&r1=1501792&r2=1501793&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java Wed Jul 10 15:21:19
2013
@@ -40,8 +40,9 @@ public class SessionImpl
 
     public void establish() throws TimeoutException, InterruptedException
     {
-        _connectionImpl.waitUntil(new Predicate()
+        _connectionImpl.waitUntil(new SimplePredicate("Session established")
         {
+            @Override
             public boolean test()
             {
                 return _amqpSession.isEstablished();
@@ -51,15 +52,16 @@ public class SessionImpl
 
     public void close() throws TimeoutException, InterruptedException, ConnectionException
     {
-        _connectionImpl.lock();        
+        _connectionImpl.lock();
         try
         {
             _amqpSession.close();
             _connectionImpl.stateChanged();
             while(!_amqpSession.isClosed())
             {
-                _connectionImpl.waitUntil(new Predicate()
+                _connectionImpl.waitUntil(new SimplePredicate("Session is closed", _amqpSession)
                 {
+                    @Override
                     public boolean test()
                     {
                         return _amqpSession.isClosed();

Added: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SimplePredicate.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SimplePredicate.java?rev=1501793&view=auto
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SimplePredicate.java (added)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SimplePredicate.java Wed Jul 10
15:21:19 2013
@@ -0,0 +1,73 @@
+/*
+ * 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.jms.impl;
+
+import java.util.Arrays;
+
+
+abstract class SimplePredicate implements Predicate
+{
+    private final String _description;
+    private final Object[] _predicatedObjects;
+
+    public SimplePredicate()
+    {
+        this("");
+    }
+
+    /**
+     * @param description human-readable description. Useful for logging in case things go
wrong.
+     * @param predicatedObject provided as a convenient way for toString() can hint at what
is being predicated
+     */
+    public SimplePredicate(String description, Object... predicatedObjects)
+    {
+        _description = description;
+        _predicatedObjects = predicatedObjects;
+    }
+
+    /** intended to be overridden to provide more useful information */
+    protected Object getCurrentState()
+    {
+        return getPredicatedObjects();
+    }
+
+    /**
+     * Returns the predicated objects as a list, or null if none exist
+     */
+    protected Object getPredicatedObjects()
+    {
+        if(_predicatedObjects == null)
+        {
+            return null;
+        }
+        else
+        {
+            return Arrays.asList(_predicatedObjects);
+        }
+    }
+
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("SimplePredicate [_description=").append(_description)
+            .append(", currentState=").append(getCurrentState()).append("]");
+        return builder.toString();
+    }
+}

Added: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/JmsTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/JmsTest.java?rev=1501793&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/JmsTest.java (added)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/JmsTest.java Wed Jul 10 15:21:19 2013
@@ -0,0 +1,90 @@
+/*
+ *
+ * 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.jms;
+
+import java.util.logging.Logger;
+
+import org.apache.qpid.jms.impl.ConnectionImpl;
+import org.apache.qpid.jms.impl.ReceivedMessageImpl;
+import org.apache.qpid.jms.impl.ReceiverImpl;
+import org.apache.qpid.jms.impl.SenderImpl;
+import org.apache.qpid.jms.impl.SessionImpl;
+import org.apache.qpid.proton.ProtonFactoryLoader;
+import org.apache.qpid.proton.amqp.messaging.AmqpValue;
+import org.apache.qpid.proton.message.Message;
+import org.apache.qpid.proton.message.MessageFactory;
+import org.junit.Test;
+
+/**
+ * VERY simple POC for a JMS-like client based on Proton-J
+ *
+ * Requires an AMQP 1.0 'broker' a localhost:5672 with a
+ * node called "queue" to which a message can be sent
+ * and received
+ */
+public class JmsTest
+{
+    //TODO: use another logger
+    private static Logger _logger = Logger.getLogger("qpid.jms-client.connection");
+
+    private final MessageFactory _messageFactory = new ProtonFactoryLoader<MessageFactory>(MessageFactory.class).loadFactory();
+
+    @Test
+    public void test() throws Exception
+    {
+        System.out.println("PHDEBUG " + System.getProperty("java.util.logging.config.file"));
+        ConnectionImpl connection =  new ConnectionImpl("clientName", "localhost", 5672,
"guest", "guest");
+        connection.connect();
+
+        SessionImpl session = connection.createSession();
+        session.establish();
+
+        SenderImpl sender = session.createSender("1","queue");
+        sender.establish();
+
+        Message message = _messageFactory.createMessage();
+        AmqpValue body = new AmqpValue("Hello World!");
+        message.setBody(body);
+        sender.sendMessage(message);
+
+        sender.close();
+
+        ReceiverImpl receiver = session.createReceiver("1", "queue");
+        receiver.credit(5);
+        receiver.establish();
+        ReceivedMessageImpl receivedMessage = receiver.receive(5000);
+        receivedMessage.accept(true);
+
+        _logger.info("=========================");
+        _logger.info(receivedMessage.getMessage().getBody().toString());
+        _logger.info("=========================");
+
+        receiver.close();
+
+        session.close();
+
+        _logger.info("About to close " + connection);
+
+        connection.close();
+        _logger.info("Closed connection.");
+    }
+
+}

Added: qpid/jms/trunk/src/test/resources/logging.properties
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/resources/logging.properties?rev=1501793&view=auto
==============================================================================
--- qpid/jms/trunk/src/test/resources/logging.properties (added)
+++ qpid/jms/trunk/src/test/resources/logging.properties Wed Jul 10 15:21:19 2013
@@ -0,0 +1,33 @@
+#
+# 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.
+#
+
+handlers = java.util.logging.ConsoleHandler
+
+java.util.logging.ConsoleHandler.level = ALL
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+# Note: the following line forces log statements to appear on a single line
+# when running on JDK 1.7 and later
+java.util.logging.SimpleFormatter.format = %1$tF %1$tT.%tL %4$s %3$s %5$s%n
+
+.level = INFO
+
+# TODO-PH remove
+org.apache.qpid.proton.logging.LoggingProtocolTracer.sent.level = ALL
+org.apache.qpid.proton.logging.LoggingProtocolTracer.received.level = ALL



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message