You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ph...@apache.org on 2013/04/04 12:50:59 UTC

svn commit: r1464428 [2/2] - in /qpid/proton/trunk: ./ proton-c/bindings/java/src/main/java/org/apache/qpid/proton/jni/ proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/ proton-j/proton-api/src/main/java/org/apache/qpid/proton/...

Added: qpid/proton/trunk/tests/java/org/apache/qpid/proton/systemtests/engine/TransportPumper.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/java/org/apache/qpid/proton/systemtests/engine/TransportPumper.java?rev=1464428&view=auto
==============================================================================
--- qpid/proton/trunk/tests/java/org/apache/qpid/proton/systemtests/engine/TransportPumper.java (added)
+++ qpid/proton/trunk/tests/java/org/apache/qpid/proton/systemtests/engine/TransportPumper.java Thu Apr  4 10:50:58 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.proton.systemtests.engine;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.qpid.proton.engine.Transport;
+
+public class TransportPumper
+{
+    private static final String SERVER_ROLE = "server";
+    private static final String CLIENT_ROLE = "client";
+
+    private final Transport _clientTransport;
+    private final Transport _serverTransport;
+
+    public TransportPumper(Transport clientTransport, Transport serverTransport)
+    {
+        _clientTransport = clientTransport;
+        _serverTransport = serverTransport;
+    }
+
+    public void pumpAll()
+    {
+        boolean bytesToTransfer = true;
+        while(bytesToTransfer)
+        {
+            int clientOutputLength = pumpOnceFromClientToServer();
+            int serverOutputLength = pumpOnceFromServerToClient();
+            bytesToTransfer = clientOutputLength > 0 || serverOutputLength > 0;
+        }
+    }
+
+    public int pumpOnceFromClientToServer()
+    {
+        return pumpOnce(_clientTransport, CLIENT_ROLE, _serverTransport, SERVER_ROLE);
+    }
+
+    public int pumpOnceFromServerToClient()
+    {
+        return pumpOnce(_serverTransport, SERVER_ROLE, _clientTransport, CLIENT_ROLE);
+    }
+
+    private int pumpOnce(Transport transportFrom, String fromRole, Transport transportTo, String toRole)
+    {
+        final byte[] output = new byte[1024];
+        int outputLength = transportFrom.output(output, 0, output.length);
+        if (outputLength > 0)
+        {
+            int numberConsumedByServer = transportTo.input(output, 0, outputLength);
+            assertEquals("Expecting " + toRole + " to consume all of " + fromRole + "'s output", outputLength, numberConsumedByServer);
+        }
+        return outputLength;
+    }
+
+}

Added: qpid/proton/trunk/tests/java/org/apache/qpid/proton/systemtests/engine/TransportTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/java/org/apache/qpid/proton/systemtests/engine/TransportTest.java?rev=1464428&view=auto
==============================================================================
--- qpid/proton/trunk/tests/java/org/apache/qpid/proton/systemtests/engine/TransportTest.java (added)
+++ qpid/proton/trunk/tests/java/org/apache/qpid/proton/systemtests/engine/TransportTest.java Thu Apr  4 10:50:58 2013
@@ -0,0 +1,88 @@
+/*
+ * 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.proton.systemtests.engine;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.qpid.proton.engine.EngineFactory;
+import org.apache.qpid.proton.engine.Transport;
+import org.apache.qpid.proton.engine.TransportException;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * TODO add test for 2.3.1 "The frame is malformed if the size is less than the size of the frame header (8 bytes)"
+ * TODO add test using empty byte arrays (calling {@link Transport#input(byte[], int, int)} with empty byte array in Proton-j-impl currently throws "TransportException Unexpected EOS")
+ */
+public class TransportTest
+{
+    private final ProtonFactoryTestFixture _protonFactoryTestFixture = new ProtonFactoryTestFixture();
+    private final EngineFactory _factory = _protonFactoryTestFixture.getFactory1();
+    private final Transport _transport = _factory.createTransport();
+
+    /**
+     * Note that Proton does not yet give the application explicit control over protocol version negotiation
+     * TODO does Proton give *visibility* of the negotiated protocol version?
+     */
+    public void testReceiptOfHeaderContainingUnsupportedProtocolVersionNumber_causesAmqp10Response()
+    {
+    }
+
+    @Test
+    @Ignore("Reinstate once it is agreed how error condition will be reported by to use of API")
+    public void testReceiptOfNonAmqpHeader_causesAmqp10Response()
+    {
+        byte[] nonAmqpHeader = "HTTP/1.0".getBytes();
+        try
+        {
+            _transport.input(nonAmqpHeader, 0, nonAmqpHeader.length);
+
+            // TODO Proton-c gives  rv PN_ERROR and a pn_transport_error "AMQP header mismatch: 'HTTP/1.0'" and then
+            // jni layer turns this into a TransportException.
+            // Proton-j just throws TransportException
+        }
+        catch (TransportException te)
+        {
+            // TODO - exception should not be thrown
+        }
+
+        byte[] buf = new byte[255];
+        int bytesWritten = _transport.output(buf, 0, buf.length);
+        byte[] response = new byte[bytesWritten];
+        System.arraycopy(buf, 0, response, 0, bytesWritten);
+        assertArrayEquals("AMQP\0\1\0\0".getBytes(), response);
+
+        // how should further input be handled??
+
+        assertTransportRefusesFurtherInputOutput(_transport);
+    }
+
+    private void assertTransportRefusesFurtherInputOutput(Transport transport)
+    {
+        byte[] sourceBufferThatShouldBeUnread = "REFUSEME".getBytes();
+        int bytesConsumed = transport.input(sourceBufferThatShouldBeUnread, 0, sourceBufferThatShouldBeUnread.length);
+        // assertEquals(-1, bytesConsumed); // TODO reinstate with testReceiptOfNonAmqpHeader_causesAmqp10Response
+
+        byte[] destBufferThatShouldRemainUnwritten = new byte[255];
+        int bytesWritten = transport.output(destBufferThatShouldRemainUnwritten, 0, destBufferThatShouldRemainUnwritten.length);
+        assertEquals(-1, bytesWritten);
+    }
+}

Modified: qpid/proton/trunk/tests/pom.xml
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/pom.xml?rev=1464428&r1=1464427&r2=1464428&view=diff
==============================================================================
--- qpid/proton/trunk/tests/pom.xml (original)
+++ qpid/proton/trunk/tests/pom.xml Thu Apr  4 10:50:58 2013
@@ -88,9 +88,19 @@ To override this, run Maven like so: &qu
       <activation>
         <activeByDefault>true</activeByDefault>
       </activation>
-      <properties>
-        <protonJythonXmlOutput>wibble</protonJythonXmlOutput>
-      </properties>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <systemPropertyVariables>
+                <qpid.proton.implementationtype>PROTON_J</qpid.proton.implementationtype>
+              </systemPropertyVariables>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
       <dependencies>
         <dependency>
           <groupId>org.apache.qpid</groupId>
@@ -117,6 +127,9 @@ To override this, run Maven like so: &qu
             <configuration>
               <forkMode>once</forkMode>
               <argLine>-Djava.library.path=${jni-native-path}</argLine>
+              <systemPropertyVariables>
+                <qpid.proton.implementationtype>PROTON_C</qpid.proton.implementationtype>
+              </systemPropertyVariables>
             </configuration>
           </plugin>
         </plugins>
@@ -129,6 +142,13 @@ To override this, run Maven like so: &qu
           <scope>system</scope>
           <systemPath>${jni-jar}</systemPath>
         </dependency>
+        <!-- proton-j-impl is required so we can use EncoderImpl and DecoderImpl to generate test data -->
+        <dependency>
+          <groupId>org.apache.qpid</groupId>
+          <artifactId>proton-j-impl</artifactId>
+          <version>1.0-SNAPSHOT</version>
+          <scope>runtime</scope>
+        </dependency>
       </dependencies>
     </profile>
   </profiles>



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