http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/org/apache/qpid/proton/InteropTest.java ---------------------------------------------------------------------- diff --git a/tests/java/org/apache/qpid/proton/InteropTest.java b/tests/java/org/apache/qpid/proton/InteropTest.java deleted file mode 100644 index e9b8c58..0000000 --- a/tests/java/org/apache/qpid/proton/InteropTest.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * 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; - -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.DescribedType; -import org.apache.qpid.proton.amqp.Symbol; -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.codec.AMQPDefinedTypes; -import org.apache.qpid.proton.codec.Decoder; -import org.apache.qpid.proton.codec.DecoderImpl; -import org.apache.qpid.proton.codec.EncoderImpl; -import org.apache.qpid.proton.message.Message; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertArrayEquals; -import org.junit.Test; -import java.lang.System; -import java.nio.ByteBuffer; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Vector; -import java.util.List; -import java.util.ArrayList; -import java.util.Map; -import java.util.HashMap; - -public class InteropTest -{ - - static private File findTestsInteropDir() - { - File f = new File(System.getProperty("user.dir")); - while (f != null && !f.getName().equals("tests")) - f = f.getParentFile(); - if (f != null && f.isDirectory()) - return new File(f, "interop"); - else - throw new Error("Cannot find tests/interop directory"); - } - - static File testsInteropDir = findTestsInteropDir(); - - byte[] getBytes(String name) throws IOException - { - File f = new File(testsInteropDir, name + ".amqp"); - byte[] data = new byte[(int) f.length()]; - FileInputStream fi = new FileInputStream(f); - assertEquals(f.length(), fi.read(data)); - fi.close(); - return data; - } - - Message decodeMessage(String name) throws IOException - { - byte[] data = getBytes(name); - Message m = Proton.message(); - m.decode(data, 0, data.length); - return m; - } - - Decoder createDecoder(byte[] data) - { - DecoderImpl decoder = new DecoderImpl(); - AMQPDefinedTypes.registerAllTypes(decoder, new EncoderImpl(decoder)); - ByteBuffer buffer = ByteBuffer.allocate(data.length); - buffer.put(data); - buffer.rewind(); - decoder.setByteBuffer(buffer); - - return decoder; - } - - @Test - public void testMessage() throws IOException - { - Message m = decodeMessage("message"); - Binary b = (Binary) (((AmqpValue) m.getBody()).getValue()); - String s = createDecoder(b.getArray()).readString(); - assertEquals("hello", s); - } - - @Test - public void testPrimitives() throws IOException - { - Decoder d = createDecoder(getBytes("primitives")); - assertEquals(true, d.readBoolean()); - assertEquals(false, d.readBoolean()); - assertEquals(d.readUnsignedByte().intValue(), 42); - assertEquals(42, d.readUnsignedShort().intValue()); - assertEquals(-42, d.readShort().intValue()); - assertEquals(12345, d.readUnsignedInteger().intValue()); - assertEquals(-12345, d.readInteger().intValue()); - assertEquals(12345, d.readUnsignedLong().longValue()); - assertEquals(-12345, d.readLong().longValue()); - assertEquals(0.125, d.readFloat().floatValue(), 0e-10); - assertEquals(0.125, d.readDouble().doubleValue(), 0e-10); - } - - @Test - public void testStrings() throws IOException - { - Decoder d = createDecoder(getBytes("strings")); - assertEquals(new Binary("abc\0defg".getBytes("UTF-8")), d.readBinary()); - assertEquals("abcdefg", d.readString()); - assertEquals(Symbol.valueOf("abcdefg"), d.readSymbol()); - assertEquals(new Binary(new byte[0]), d.readBinary()); - assertEquals("", d.readString()); - assertEquals(Symbol.valueOf(""), d.readSymbol()); - } - - @Test - public void testDescribed() throws IOException - { - Decoder d = createDecoder(getBytes("described")); - DescribedType dt = (DescribedType) (d.readObject()); - assertEquals(Symbol.valueOf("foo-descriptor"), dt.getDescriptor()); - assertEquals("foo-value", dt.getDescribed()); - - dt = (DescribedType) (d.readObject()); - assertEquals(12, dt.getDescriptor()); - assertEquals(13, dt.getDescribed()); - } - - @Test - public void testDescribedArray() throws IOException - { - Decoder d = createDecoder(getBytes("described_array")); - DescribedType a[] = (DescribedType[]) (d.readArray()); - for (int i = 0; i < 10; ++i) - { - assertEquals(Symbol.valueOf("int-array"), a[i].getDescriptor()); - assertEquals(i, a[i].getDescribed()); - } - } - - @Test - public void testArrays() throws IOException - { - Decoder d = createDecoder(getBytes("arrays")); - - // int array - Vector<Integer> ints = new Vector<Integer>(); - for (int i = 0; i < 100; ++i) - ints.add(new Integer(i)); - assertArrayEquals(ints.toArray(), d.readArray()); - - // String array - String strings[] = - { "a", "b", "c" }; - assertArrayEquals(strings, d.readArray()); - - // Empty array - assertArrayEquals(new Integer[0], d.readArray()); - } - - @Test - public void testLists() throws IOException - { - Decoder d = createDecoder(getBytes("lists")); - List<Object> l = new ArrayList<Object>() - { - { - add(new Integer(32)); - add("foo"); - add(new Boolean(true)); - } - }; - assertEquals(l, d.readList()); - l.clear(); - assertEquals(l, d.readList()); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test - public void testMaps() throws IOException - { - Decoder d = createDecoder(getBytes("maps")); - Map map = new HashMap() - { - { - put("one", 1); - put("two", 2); - put("three", 3); - } - }; - assertEquals(map, d.readMap()); - - map = new HashMap() - { - { - put(1, "one"); - put(2, "two"); - put(3, "three"); - } - }; - assertEquals(map, d.readMap()); - - map = new HashMap(); - assertEquals(map, d.readMap()); - } -}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/org/apache/qpid/proton/JythonTest.java ---------------------------------------------------------------------- diff --git a/tests/java/org/apache/qpid/proton/JythonTest.java b/tests/java/org/apache/qpid/proton/JythonTest.java deleted file mode 100644 index 23eceab..0000000 --- a/tests/java/org/apache/qpid/proton/JythonTest.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * - * 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; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.Test; -import org.python.core.PyException; -import org.python.core.PyString; -import org.python.core.PySystemState; -import org.python.util.PythonInterpreter; - -/** - * Runs all the python tests, or just those that match the system property {@value #TEST_PATTERN_SYSTEM_PROPERTY} - * if it exists. - * Use {@value #TEST_INVOCATIONS_SYSTEM_PROPERTY} to specify the number of repetitions, or use 0 - * for unlimited repetitions. - */ -public class JythonTest -{ - public interface PathBuilder { - public PathBuilder append(String path); - } - private static final Logger LOGGER = Logger.getLogger(JythonTest.class.getName()); - - /* System properties expected to be defined in test/pom.xml */ - private static final String PROTON_JYTHON_BINDING = "protonJythonBinding"; - private static final String PROTON_JYTHON_SHIM = "protonJythonShim"; - private static final String PROTON_JYTHON_TEST_ROOT = "protonJythonTestRoot"; - private static final String PROTON_JYTHON_TEST_SCRIPT = "protonJythonTestScript"; - private static final String PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY = "protonJythonTestXmlOutputDirectory"; - private static final String PROTON_JYTHON_IGNORE_FILE = "protonJythonIgnoreFile"; - - /** Name of the junit style xml report to be written by the python test script */ - private static final String XML_REPORT_NAME = "TEST-jython-test-results.xml"; - - public static final String TEST_PATTERN_SYSTEM_PROPERTY = "proton.pythontest.pattern"; - public static final String IGNORE_FILE_SYSTEM_PROPERTY = "proton.pythontest.ignore_file"; - - /** The number of times to run the test, or forever if zero */ - public static final String TEST_INVOCATIONS_SYSTEM_PROPERTY = "proton.pythontest.invocations"; - - public static final String ALWAYS_COLORIZE_SYSTEM_PROPERTY = "proton.pythontest.always_colorize"; - - @Test - public void test() throws Exception - { - String testScript = getJythonTestScript(); - String testRoot = getJythonTestRoot(); - String xmlReportFile = getOptionalXmlReportFilename(); - String ignoreFile = getOptionalIgnoreFile(); - - final PythonInterpreter interp = createInterpreterWithArgs(xmlReportFile, ignoreFile); - PathBuilder pathBuilder = new PathBuilder() { - @Override - public PathBuilder append(String path) { - interp.getSystemState().path.insert(0, new PyString(path)); - return this; - } - }; - extendPath(pathBuilder); - - LOGGER.info("About to call Jython test script: '" + testScript - + "' with '" + testRoot + "' added to Jython path"); - - int maxInvocations = Integer.getInteger(TEST_INVOCATIONS_SYSTEM_PROPERTY, 1); - assertTrue("Number of invocations should be non-negative", maxInvocations >= 0); - boolean loopForever = maxInvocations == 0; - if(maxInvocations > 1) - { - LOGGER.info("Will invoke Python test " + maxInvocations + " times"); - } - if(loopForever) - { - LOGGER.info("Will repeatedly invoke Python test forever"); - } - int invocations = 1; - while(loopForever || invocations++ <= maxInvocations) - { - runTestOnce(testScript, interp, invocations); - } - } - - protected void extendPath(PathBuilder pathBuilder) throws Exception { - String binding = getJythonBinding(); - String shim = getJythonShim(); - String testRoot = getJythonTestRoot(); - pathBuilder.append(binding).append(shim).append(testRoot); - - } - - private void runTestOnce(String testScript, PythonInterpreter interp, int invocationsSoFar) - { - try - { - interp.execfile(testScript); - } - catch (PyException e) - { - if( e.type.toString().equals("<type 'exceptions.SystemExit'>") && e.value.toString().equals("0") ) - { - // Build succeeded. - } - else - { - if (LOGGER.isLoggable(Level.FINE)) - { - LOGGER.log(Level.FINE, "Jython interpreter failed. Test failures?", e); - } - - // This unusual code is necessary because PyException toString() contains the useful Python traceback - // and getMessage() is usually null - fail("Caught PyException on invocation number " + invocationsSoFar + ": " + e.toString() + " with message: " + e.getMessage()); - } - } - } - - private PythonInterpreter createInterpreterWithArgs(String xmlReportFile, String ignoreFile) - { - PySystemState systemState = new PySystemState(); - - if (xmlReportFile != null) - { - systemState.argv.append(new PyString("--xml")); - systemState.argv.append(new PyString(xmlReportFile)); - } - - if(ignoreFile == null) - { - ignoreFile = System.getProperty(IGNORE_FILE_SYSTEM_PROPERTY); - } - - if(ignoreFile != null) - { - systemState.argv.append(new PyString("-I")); - systemState.argv.append(new PyString(ignoreFile)); - } - - String testPattern = System.getProperty(TEST_PATTERN_SYSTEM_PROPERTY); - if(testPattern != null) - { - systemState.argv.append(new PyString(testPattern)); - } - - if(Boolean.getBoolean(ALWAYS_COLORIZE_SYSTEM_PROPERTY)) - { - systemState.argv.append(new PyString("--always-colorize")); - } - - PythonInterpreter interp = new PythonInterpreter(null, systemState); - return interp; - } - - private String getJythonTestScript() throws FileNotFoundException - { - String testScriptString = getNonNullSystemProperty(PROTON_JYTHON_TEST_SCRIPT, "System property '%s' must provide the location of the python test script"); - File testScript = new File(testScriptString); - if (!testScript.canRead()) - { - throw new FileNotFoundException("Can't read python test script " + testScript); - } - return testScript.getAbsolutePath(); - } - - private String getJythonBinding() throws FileNotFoundException - { - String str = getNonNullSystemProperty(PROTON_JYTHON_BINDING, "System property '%s' must provide the location of the proton python binding"); - File file = new File(str); - if (!file.isDirectory()) - { - throw new FileNotFoundException("Binding location '" + file + "' should be a directory."); - } - return file.getAbsolutePath(); - } - - private String getJythonShim() throws FileNotFoundException - { - String str = getNonNullSystemProperty(PROTON_JYTHON_SHIM, "System property '%s' must provide the location of the proton jython shim"); - File file = new File(str); - if (!file.isDirectory()) - { - throw new FileNotFoundException("Shim location '" + file + "' should be a directory."); - } - return file.getAbsolutePath(); - } - - - private String getJythonTestRoot() throws FileNotFoundException - { - String testRootString = getNonNullSystemProperty(PROTON_JYTHON_TEST_ROOT, "System property '%s' must provide the location of the python test root"); - File testRoot = new File(testRootString); - if (!testRoot.isDirectory()) - { - throw new FileNotFoundException("Test root '" + testRoot + "' should be a directory."); - } - return testRoot.getAbsolutePath(); - } - - private String getOptionalIgnoreFile() - { - String ignoreFile = System.getProperty(PROTON_JYTHON_IGNORE_FILE); - - if(ignoreFile != null) - { - File f = new File(ignoreFile); - if(f.exists() && f.canRead()) - { - return ignoreFile; - } - else - { - LOGGER.info(PROTON_JYTHON_IGNORE_FILE + " system property set to " + ignoreFile + " but this cannot be read."); - } - } - return null; - - } - - private String getOptionalXmlReportFilename() - { - String xmlOutputDirString = System.getProperty(PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY); - if (xmlOutputDirString == null) - { - LOGGER.info(PROTON_JYTHON_TESTS_XML_OUTPUT_DIRECTORY + " system property not set; xml output will not be written"); - } - - File xmlOutputDir = new File(xmlOutputDirString); - createXmlOutputDirectoryIfNecessary(xmlOutputDirString, xmlOutputDir); - return new File(xmlOutputDir, XML_REPORT_NAME).getAbsolutePath(); - } - - private void createXmlOutputDirectoryIfNecessary(String xmlOutputDirString, File xmlOutputDir) - { - if (!xmlOutputDir.isDirectory()) - { - boolean success = xmlOutputDir.mkdirs(); - if (!success) - { - LOGGER.warning("Failed to create directory " + xmlOutputDir + " Thread name :" + Thread.currentThread().getName()); - } - - if (!xmlOutputDir.isDirectory()) - { - throw new RuntimeException("Failed to create one or more directories with path " + xmlOutputDirString); - } - } - } - - protected String getNonNullSystemProperty(String systemProperty, String messageWithStringFormatToken) - { - String testScriptString = System.getProperty(systemProperty); - if (testScriptString == null) - { - String message = messageWithStringFormatToken; - throw new IllegalStateException(String.format(message, systemProperty)); - } - return testScriptString; - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/org/apache/qpid/proton/ProtonJInterop.java ---------------------------------------------------------------------- diff --git a/tests/java/org/apache/qpid/proton/ProtonJInterop.java b/tests/java/org/apache/qpid/proton/ProtonJInterop.java deleted file mode 100644 index 58a9c31..0000000 --- a/tests/java/org/apache/qpid/proton/ProtonJInterop.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * - * 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; - -import java.io.IOException; -import java.nio.BufferOverflowException; - -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.transport.ErrorCondition; -import org.apache.qpid.proton.engine.BaseHandler; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Delivery; -import org.apache.qpid.proton.engine.EndpointState; -import org.apache.qpid.proton.engine.Event; -import org.apache.qpid.proton.engine.Receiver; -import org.apache.qpid.proton.engine.Sender; -import org.apache.qpid.proton.engine.Session; -import org.apache.qpid.proton.message.Message; -import org.apache.qpid.proton.reactor.Acceptor; -import org.apache.qpid.proton.reactor.FlowController; -import org.apache.qpid.proton.reactor.Handshaker; -import org.apache.qpid.proton.reactor.Reactor; - -public class ProtonJInterop { - - private static class SendHandler extends BaseHandler { - - private int numMsgs; - private int count = 0; - private boolean result = false; - - private SendHandler(int numMsgs) { - this.numMsgs = numMsgs; - add(new Handshaker()); - } - - @Override - public void onConnectionInit(Event event) { - Connection conn = event.getConnection(); - Session ssn = conn.session(); - Sender snd = ssn.sender("sender"); - conn.open(); - ssn.open(); - snd.open(); - } - - @Override - public void onLinkFlow(Event event) { - Sender snd = (Sender)event.getLink(); - if (snd.getCredit() > 0 && snd.getLocalState() != EndpointState.CLOSED) { - Message message = Proton.message(); - ++count; - message.setBody(new AmqpValue("message-"+count)); - byte[] msgData = new byte[1024]; - int length; - while(true) { - try { - length = message.encode(msgData, 0, msgData.length); - break; - } catch(BufferOverflowException e) { - msgData = new byte[msgData.length * 2]; - } - } - byte[] tag = String.valueOf(count).getBytes(); - Delivery dlv = snd.delivery(tag); - snd.send(msgData, 0, length); - dlv.settle(); - snd.advance(); - if (count == numMsgs) { - snd.close(); - snd.getSession().close(); - snd.getSession().getConnection().close(); - result = true; - } - } - } - - @Override - public void onTransportError(Event event) { - result = false; - ErrorCondition condition = event.getTransport().getCondition(); - if (condition != null) { - System.err.println("Error: " + condition.getDescription()); - } else { - System.err.println("Error (no description returned)."); - } - } - } - - private static class Send extends BaseHandler { - private final SendHandler sendHandler; - private final String host; - private final int port; - - private Send(String host, int port, int numMsgs) { - this.host = host; - this.port = port; - sendHandler = new SendHandler(numMsgs); - } - - @Override - public void onReactorInit(Event event) { - Reactor r = event.getReactor(); - r.connectionToHost(host, port, sendHandler); - } - - public boolean getResult() { - return sendHandler.result; - } - } - - private static class Recv extends BaseHandler { - private final int port; - private final int numMsgs; - private int count = 0; - private Acceptor acceptor = null; - - private Recv(int port, int numMsgs) { - this.port = port; - this.numMsgs = numMsgs; - add(new Handshaker()); - add(new FlowController()); - } - - @Override - public void onReactorInit(Event event) { - try { - acceptor = event.getReactor().acceptor("localhost", port); - } catch(IOException ioException) { - throw new RuntimeException(ioException); - } - } - - @Override - public void onDelivery(Event event) { - Receiver recv = (Receiver)event.getLink(); - Delivery delivery = recv.current(); - if (delivery.isReadable() && !delivery.isPartial()) { - int size = delivery.pending(); - byte[] buffer = new byte[size]; - int read = recv.recv(buffer, 0, buffer.length); - recv.advance(); - - Message msg = Proton.message(); - msg.decode(buffer, 0, read); - - ++count; - String msgBody = ((AmqpValue)msg.getBody()).getValue().toString(); - String expected = "message-" + count; - if (!expected.equals(msgBody)) { - throw new RuntimeException("Received message body '" + msgBody + "', expected: '" + expected + "'"); - } - - if (count == numMsgs) { - recv.close(); - recv.getSession().close(); - recv.getSession().getConnection().close(); - acceptor.close(); - } - } - } - } - - public static void main(String[] args) throws IOException { - try { - int port = Integer.valueOf(args[1]); - int numMsgs = Integer.valueOf(args[2]); - boolean result = false; - - if ("send".equalsIgnoreCase(args[0])) { - Send send = new Send("localhost", port, numMsgs); - Reactor r = Proton.reactor(send); - r.run(); - result = send.getResult(); - } else { - Reactor r = Proton.reactor(new Recv(port, numMsgs)); - r.run(); - result = true; - } - System.exit(result ? 0 : 1); - } catch(Throwable t) { - t.printStackTrace(); - System.exit(1); - } - } -} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/pythonTests.ignore ---------------------------------------------------------------------- diff --git a/tests/java/pythonTests.ignore b/tests/java/pythonTests.ignore deleted file mode 100644 index 7911176..0000000 --- a/tests/java/pythonTests.ignore +++ /dev/null @@ -1,4 +0,0 @@ -proton_tests.reactor_interop.* -proton_tests.soak.* -proton_tests.ssl.SslTest.test_defaults_messenger_app -proton_tests.ssl.SslTest.test_server_authentication_messenger_app http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/ccodec.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/ccodec.py b/tests/java/shim/ccodec.py deleted file mode 100644 index 0aa9499..0000000 --- a/tests/java/shim/ccodec.py +++ /dev/null @@ -1,356 +0,0 @@ -# -# 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. -# -from org.apache.qpid.proton import Proton -from org.apache.qpid.proton.amqp import Symbol, UnsignedByte, UnsignedInteger, \ - UnsignedShort, UnsignedLong, Decimal32, Decimal64, Decimal128 -from org.apache.qpid.proton.codec.Data import DataType -from cerror import * - -from java.util import UUID as JUUID, Date as JDate -from java.nio import ByteBuffer -from compat import array, zeros - -# from proton/codec.h -PN_NULL = 1 -PN_BOOL = 2 -PN_UBYTE = 3 -PN_BYTE = 4 -PN_USHORT = 5 -PN_SHORT = 6 -PN_UINT = 7 -PN_INT = 8 -PN_CHAR = 9 -PN_ULONG = 10 -PN_LONG = 11 -PN_TIMESTAMP = 12 -PN_FLOAT = 13 -PN_DOUBLE = 14 -PN_DECIMAL32 = 15 -PN_DECIMAL64 = 16 -PN_DECIMAL128 = 17 -PN_UUID = 18 -PN_BINARY = 19 -PN_STRING = 20 -PN_SYMBOL = 21 -PN_DESCRIBED = 22 -PN_ARRAY = 23 -PN_LIST = 24 -PN_MAP = 25 - -DATA_TYPES_J2P = {} -DATA_TYPES_P2J = {} - -def DATA_TYPES(jtype, ptype): - DATA_TYPES_J2P[jtype] = ptype - DATA_TYPES_P2J[ptype] = jtype - -DATA_TYPES(DataType.NULL, PN_NULL) -DATA_TYPES(DataType.BOOL, PN_BOOL) -DATA_TYPES(DataType.BYTE, PN_BYTE) -DATA_TYPES(DataType.UBYTE, PN_UBYTE) -DATA_TYPES(DataType.USHORT, PN_USHORT) -DATA_TYPES(DataType.UINT, PN_UINT) -DATA_TYPES(DataType.ULONG, PN_ULONG) -DATA_TYPES(DataType.SHORT, PN_SHORT) -DATA_TYPES(DataType.INT, PN_INT) -DATA_TYPES(DataType.LONG, PN_LONG) -DATA_TYPES(DataType.CHAR, PN_CHAR) -DATA_TYPES(DataType.TIMESTAMP, PN_TIMESTAMP) -DATA_TYPES(DataType.FLOAT, PN_FLOAT) -DATA_TYPES(DataType.DOUBLE, PN_DOUBLE) -DATA_TYPES(DataType.DECIMAL32, PN_DECIMAL32) -DATA_TYPES(DataType.DECIMAL64, PN_DECIMAL64) -DATA_TYPES(DataType.DECIMAL128, PN_DECIMAL128) -DATA_TYPES(DataType.BINARY, PN_BINARY) -DATA_TYPES(DataType.STRING, PN_STRING) -DATA_TYPES(DataType.SYMBOL, PN_SYMBOL) -DATA_TYPES(DataType.UUID, PN_UUID) -DATA_TYPES(DataType.LIST, PN_LIST) -DATA_TYPES(DataType.MAP, PN_MAP) -DATA_TYPES(DataType.ARRAY, PN_ARRAY) -DATA_TYPES(DataType.DESCRIBED, PN_DESCRIBED) - -def pn_data(capacity): - return Proton.data(capacity) - -def pn_data_put_null(data): - data.putNull() - return 0 - -def pn_data_put_bool(data, b): - data.putBoolean(b) - return 0 - -def pn_data_get_bool(data): - return data.getBoolean() - -def pn_data_get_byte(data): - return data.getByte() - -def pn_data_put_byte(data, u): - data.putByte(u) - return 0 - -def pn_data_get_ubyte(data): - return data.getUnsignedByte().longValue() - -def pn_data_put_ubyte(data, u): - data.putUnsignedByte(UnsignedByte.valueOf(u)) - return 0 - -def pn_data_get_ushort(data): - return data.getUnsignedShort().longValue() - -def pn_data_put_ushort(data, u): - data.putUnsignedShort(UnsignedShort.valueOf(u)) - return 0 - -def pn_data_get_uint(data): - return data.getUnsignedInteger().longValue() - -def pn_data_put_uint(data, u): - data.putUnsignedInteger(UnsignedInteger.valueOf(u)) - return 0 - -def pn_data_put_ulong(data, u): - data.putUnsignedLong(UnsignedLong.valueOf(u)) - return 0 - -BITS_64 = 2**64 - 1; - -def pn_data_get_ulong(data): - value = data.getUnsignedLong().longValue() - if value < 0: - return value & BITS_64; - return value - -def pn_data_get_short(data): - return data.getShort() - -def pn_data_put_short(data, s): - data.putShort(s) - return 0 - -def pn_data_put_int(data, i): - data.putInt(i) - return 0 - -def pn_data_get_int(data): - return data.getInt() - -def pn_data_put_long(data, l): - data.putLong(l) - return 0 - -def pn_data_get_long(data): - return data.getLong() - -def pn_data_put_char(data, c): - data.putChar(c) - return 0 - -def pn_data_get_char(data): - return data.getChar() - -def pn_data_put_timestamp(data, t): - data.putTimestamp(JDate(t)) - return 0 - -def pn_data_get_timestamp(data): - return data.getTimestamp().getTime() - -def pn_data_put_float(data, f): - data.putFloat(f) - return 0 - -def pn_data_get_float(data): - return data.getFloat() - -def pn_data_put_double(data, d): - data.putDouble(d) - return 0 - -def pn_data_get_double(data): - return data.getDouble() - -def pn_data_put_decimal32(data, d): - data.putDecimal32(Decimal32(d)) - return 0 - -def pn_data_get_decimal32(data): - return data.getDecimal32().getBits() - -def pn_data_put_decimal64(data, d): - data.putDecimal64(Decimal64(d)) - return 0 - -def pn_data_get_decimal64(data): - return data.getDecimal64().getBits() - -def pn_data_put_decimal128(data, d): - data.putDecimal128(Decimal128(array(d, 'b'))) - return 0 - -def pn_data_get_decimal128(data): - return data.getDecimal128().asBytes().tostring() - -def pn_data_put_binary(data, b): - data.putBinary(array(b, 'b')) - return 0 - -def pn_data_get_binary(data): - return data.getBinary().getArray().tostring() - -def pn_data_put_string(data, s): - data.putString(s) - return 0 - -def pn_data_get_string(data): - return data.getString() - -def pn_data_put_symbol(data, s): - data.putSymbol(Symbol.valueOf(s)) - return 0 - -def pn_data_get_symbol(data): - return data.getSymbol().toString() - -def pn_data_put_uuid(data, u): - bb = ByteBuffer.wrap(array(u, 'b')) - first = bb.getLong() - second = bb.getLong() - data.putUUID(JUUID(first, second)) - return 0 - -def pn_data_get_uuid(data): - u = data.getUUID() - ba = zeros(16, 'b') - bb = ByteBuffer.wrap(ba) - bb.putLong(u.getMostSignificantBits()) - bb.putLong(u.getLeastSignificantBits()) - return ba.tostring() - -def pn_data_put_list(data): - data.putList() - return 0 - -def pn_data_get_list(data): - return data.getList() - -def pn_data_put_map(data): - data.putMap() - return 0 - -def pn_data_put_array(data, described, type): - data.putArray(described, DATA_TYPES_P2J[type]) - return 0 - -def pn_data_get_array(data): - return data.getArray() - -def pn_data_is_array_described(data): - return data.isArrayDescribed() - -def pn_data_get_array_type(data): - return DATA_TYPES_J2P[data.getArrayType()] - -def pn_data_put_described(data): - data.putDescribed() - return 0 - -def pn_data_rewind(data): - data.rewind() - -def pn_data_next(data): - t = data.next() - return t != None - -def pn_data_enter(data): - return data.enter() - -def pn_data_exit(data): - return data.exit() - -def pn_data_type(data): - t = data.type() - if t is None: - return -1 - else: - return DATA_TYPES_J2P[t] - -def pn_data_encode(data, size): - enc = data.encode().getArray().tostring() - if len(enc) > size: - return PN_OVERFLOW, None - else: - return len(enc), enc - -def pn_data_encoded_size(data): - return data.encodedSize() - -def pn_data_decode(data, encoded): - return data.decode(ByteBuffer.wrap(array(encoded, 'b'))) - -def pn_data_narrow(data): - data.narrow() - -def pn_data_widen(data): - data.widen() - -def pn_data_copy(data, src): - data.copy(src) - -def pn_data_format(data, n): - return 0, data.format() - -def pn_data_clear(data): - data.clear() - -def pn_data_free(data): - pass - -def dat2obj(dat): - dat.rewind() - if dat.next(): - return dat.getObject() - else: - return None - -def obj2dat(obj, dat=None): - if dat is None: - dat = pn_data(0) - else: - dat.clear() - if obj: - dat.putObject(obj) - dat.rewind() - return dat - -def array2dat(ary, atype, dat=None): - if dat is None: - dat = pn_data(0) - else: - dat.clear() - if ary: - pn_data_put_array(dat, False, atype) - pn_data_enter(dat) - for o in ary: - dat.putObject(o) - dat.rewind() - return dat http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/cengine.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/cengine.py b/tests/java/shim/cengine.py deleted file mode 100644 index 141c482..0000000 --- a/tests/java/shim/cengine.py +++ /dev/null @@ -1,1139 +0,0 @@ -# -# 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. -# -from org.apache.qpid.proton import Proton -from org.apache.qpid.proton.amqp import Symbol -from org.apache.qpid.proton.amqp.messaging import Source, Target, \ - TerminusDurability, TerminusExpiryPolicy, Received, Accepted, \ - Rejected, Released, Modified -from org.apache.qpid.proton.amqp.transaction import Coordinator -from org.apache.qpid.proton.amqp.transport import ErrorCondition, \ - SenderSettleMode, ReceiverSettleMode -from org.apache.qpid.proton.engine import EndpointState, Sender, \ - Receiver, Transport as _Transport, TransportException, EventType - -from java.util import EnumSet -from compat import array, zeros - -from cerror import * -from ccodec import * - -# from proton/engine.h -PN_LOCAL_UNINIT = 1 -PN_LOCAL_ACTIVE = 2 -PN_LOCAL_CLOSED = 4 -PN_REMOTE_UNINIT = 8 -PN_REMOTE_ACTIVE = 16 -PN_REMOTE_CLOSED = 32 - -PN_SND_UNSETTLED = 0 -PN_SND_SETTLED = 1 -PN_SND_MIXED = 2 - -PN_RCV_FIRST = 0 -PN_RCV_SECOND = 1 - -PN_UNSPECIFIED = 0 -PN_SOURCE = 1 -PN_TARGET = 2 -PN_COORDINATOR = 3 - -PN_NONDURABLE = 0 -PN_CONFIGURATION = 1 -PN_DELIVERIES = 2 - -PN_EXPIRE_WITH_LINK = 0 -PN_EXPIRE_WITH_SESSION = 1 -PN_EXPIRE_WITH_CONNECTION = 2 -PN_EXPIRE_NEVER = 3 - -PN_DIST_MODE_UNSPECIFIED = 0 -PN_DIST_MODE_COPY = 1 -PN_DIST_MODE_MOVE = 2 - -PN_RECEIVED = (0x0000000000000023) -PN_ACCEPTED = (0x0000000000000024) -PN_REJECTED = (0x0000000000000025) -PN_RELEASED = (0x0000000000000026) -PN_MODIFIED = (0x0000000000000027) - -PN_TRACE_OFF = _Transport.TRACE_OFF -PN_TRACE_RAW = _Transport.TRACE_RAW -PN_TRACE_FRM = _Transport.TRACE_FRM -PN_TRACE_DRV = _Transport.TRACE_DRV - -def wrap(obj, wrapper): - if obj: - ctx = obj.getContext() - if not ctx: - ctx = wrapper(obj) - obj.setContext(ctx) - return ctx - -class pn_condition: - - def __init__(self): - self.name = None - self.description = None - self.info = pn_data(0) - - def decode(self, impl): - if impl is None: - self.name = None - self.description = None - self.info.clear() - else: - cond = impl.getCondition() - if cond is None: - self.name = None - else: - self.name = cond.toString() - self.description = impl.getDescription() - obj2dat(impl.getInfo(), self.info) - - def encode(self): - if self.name is None: - return None - else: - impl = ErrorCondition() - impl.setCondition(Symbol.valueOf(self.name)) - impl.setDescription(self.description) - impl.setInfo(dat2obj(self.info)) - return impl - -def pn_condition_is_set(cond): - return bool(cond.name) - -def pn_condition_get_name(cond): - return cond.name - -def pn_condition_set_name(cond, name): - cond.name = name - -def pn_condition_get_description(cond): - return cond.description - -def pn_condition_set_description(cond, description): - cond.description = description - -def pn_condition_clear(cond): - cond.name = None - cond.description = None - cond.info.clear() - -def pn_condition_info(cond): - return cond.info - -class endpoint_wrapper: - - def __init__(self, impl): - self.impl = impl - self.condition = pn_condition() - self.remote_condition = pn_condition() - - def on_close(self): - cond = self.condition.encode() - if cond: - self.impl.setCondition(cond) - -def remote_condition(self): - self.remote_condition.decode(self.impl.getRemoteCondition()) - return self.remote_condition - -class pn_connection_wrapper(endpoint_wrapper): - - def __init__(self, impl): - endpoint_wrapper.__init__(self, impl) - self.properties = pn_data(0) - self.offered_capabilities = pn_data(0) - self.desired_capabilities = pn_data(0) - -def pn_connection(): - return wrap(Proton.connection(), pn_connection_wrapper) - -def set2mask(local, remote): - mask = 0 - if local.contains(EndpointState.UNINITIALIZED): - mask |= PN_LOCAL_UNINIT - if local.contains(EndpointState.ACTIVE): - mask |= PN_LOCAL_ACTIVE - if local.contains(EndpointState.CLOSED): - mask |= PN_LOCAL_CLOSED - if remote.contains(EndpointState.UNINITIALIZED): - mask |= PN_REMOTE_UNINIT - if remote.contains(EndpointState.ACTIVE): - mask |= PN_REMOTE_ACTIVE - if remote.contains(EndpointState.CLOSED): - mask |= PN_REMOTE_CLOSED - return mask - -def endpoint_state(impl): - return set2mask(EnumSet.of(impl.getLocalState()), - EnumSet.of(impl.getRemoteState())) - -def pn_connection_state(conn): - return endpoint_state(conn.impl) - -def pn_connection_condition(conn): - return conn.condition - -def pn_connection_remote_condition(conn): - return remote_condition(conn) - -def pn_connection_properties(conn): - return conn.properties - -def pn_connection_remote_properties(conn): - return obj2dat(conn.impl.getRemoteProperties()) - -def pn_connection_offered_capabilities(conn): - return conn.offered_capabilities - -def pn_connection_remote_offered_capabilities(conn): - return array2dat(conn.impl.getRemoteOfferedCapabilities(), PN_SYMBOL) - -def pn_connection_desired_capabilities(conn): - return conn.desired_capabilities - -def pn_connection_remote_desired_capabilities(conn): - return array2dat(conn.impl.getRemoteDesiredCapabilities(), PN_SYMBOL) - -def pn_connection_attachments(conn): - return conn.impl.attachments() - -def pn_connection_set_container(conn, name): - conn.impl.setContainer(name) - -def pn_connection_get_container(conn): - return conn.impl.getContainer() - -def pn_connection_remote_container(conn): - return conn.impl.getRemoteContainer() - -def pn_connection_get_hostname(conn): - return conn.impl.getHostname() - -def pn_connection_set_hostname(conn, name): - conn.impl.setHostname(name) - -def pn_connection_remote_hostname(conn): - return conn.impl.getRemoteHostname() - -def pn_connection_open(conn): - props = dat2obj(conn.properties) - offered = dat2obj(conn.offered_capabilities) - desired = dat2obj(conn.desired_capabilities) - if props: - conn.impl.setProperties(props) - if offered: - conn.impl.setOfferedCapabilities(array(list(offered), Symbol)) - if desired: - conn.impl.setDesiredCapabilities(array(list(desired), Symbol)) - conn.impl.open() - -def pn_connection_close(conn): - conn.on_close() - conn.impl.close() - -def pn_connection_release(conn): - conn.impl.free() - -def pn_connection_transport(conn): - return wrap(conn.impl.getTransport(), pn_transport_wrapper) - -class pn_session_wrapper(endpoint_wrapper): - pass - -def pn_session(conn): - return wrap(conn.impl.session(), pn_session_wrapper) - -def pn_session_attachments(ssn): - return ssn.impl.attachments() - -def pn_session_state(ssn): - return endpoint_state(ssn.impl) - -def pn_session_get_incoming_capacity(ssn): - return ssn.impl.getIncomingCapacity() - -def pn_session_set_incoming_capacity(ssn, capacity): - ssn.impl.setIncomingCapacity(capacity) - -def pn_session_incoming_bytes(ssn): - return ssn.impl.getIncomingBytes() - -def pn_session_outgoing_bytes(ssn): - return ssn.impl.getOutgoingBytes() - -def pn_session_get_outgoing_window(ssn): - return ssn.impl.getOutgoingWindow() - -def pn_session_set_outgoing_window(ssn, window): - ssn.impl.setOutgoingWindow(window) - -def pn_session_condition(ssn): - return ssn.condition - -def pn_session_remote_condition(ssn): - return remote_condition(ssn) - -def pn_session_open(ssn): - ssn.impl.open() - -def pn_session_close(ssn): - ssn.on_close() - ssn.impl.close() - -def mask2set(mask): - local = [] - remote = [] - if PN_LOCAL_UNINIT & mask: - local.append(EndpointState.UNINITIALIZED) - if PN_LOCAL_ACTIVE & mask: - local.append(EndpointState.ACTIVE) - if PN_LOCAL_CLOSED & mask: - local.append(EndpointState.CLOSED) - if PN_REMOTE_UNINIT & mask: - remote.append(EndpointState.UNINITIALIZED) - if PN_REMOTE_ACTIVE & mask: - remote.append(EndpointState.ACTIVE) - if PN_REMOTE_CLOSED & mask: - remote.append(EndpointState.CLOSED) - - if local: - local = EnumSet.of(*local) - else: - local = None - if remote: - remote = EnumSet.of(*remote) - else: - remote = None - - return local, remote - -def pn_session_head(conn, mask): - local, remote = mask2set(mask) - return wrap(conn.impl.sessionHead(local, remote), pn_session_wrapper) - -def pn_session_connection(ssn): - return wrap(ssn.impl.getConnection(), pn_connection_wrapper) - -def pn_sender(ssn, name): - return wrap(ssn.impl.sender(name), pn_link_wrapper) - -def pn_receiver(ssn, name): - return wrap(ssn.impl.receiver(name), pn_link_wrapper) - -def pn_session_free(ssn): - ssn.impl.free() - -TERMINUS_TYPES_J2P = { - Source: PN_SOURCE, - Target: PN_TARGET, - Coordinator: PN_COORDINATOR, - None.__class__: PN_UNSPECIFIED -} - -TERMINUS_TYPES_P2J = { - PN_SOURCE: Source, - PN_TARGET: Target, - PN_COORDINATOR: Coordinator, - PN_UNSPECIFIED: lambda: None -} - -DURABILITY_P2J = { - PN_NONDURABLE: TerminusDurability.NONE, - PN_CONFIGURATION: TerminusDurability.CONFIGURATION, - PN_DELIVERIES: TerminusDurability.UNSETTLED_STATE -} - -DURABILITY_J2P = { - TerminusDurability.NONE: PN_NONDURABLE, - TerminusDurability.CONFIGURATION: PN_CONFIGURATION, - TerminusDurability.UNSETTLED_STATE: PN_DELIVERIES -} - -EXPIRY_POLICY_P2J = { - PN_EXPIRE_WITH_LINK: TerminusExpiryPolicy.LINK_DETACH, - PN_EXPIRE_WITH_SESSION: TerminusExpiryPolicy.SESSION_END, - PN_EXPIRE_WITH_CONNECTION: TerminusExpiryPolicy.CONNECTION_CLOSE, - PN_EXPIRE_NEVER: TerminusExpiryPolicy.NEVER -} - -EXPIRY_POLICY_J2P = { - TerminusExpiryPolicy.LINK_DETACH: PN_EXPIRE_WITH_LINK, - TerminusExpiryPolicy.SESSION_END: PN_EXPIRE_WITH_SESSION, - TerminusExpiryPolicy.CONNECTION_CLOSE: PN_EXPIRE_WITH_CONNECTION, - TerminusExpiryPolicy.NEVER: PN_EXPIRE_NEVER -} - -DISTRIBUTION_MODE_P2J = { - PN_DIST_MODE_UNSPECIFIED: None, - PN_DIST_MODE_COPY: Symbol.valueOf("copy"), - PN_DIST_MODE_MOVE: Symbol.valueOf("move") -} - -DISTRIBUTION_MODE_J2P = { - None: PN_DIST_MODE_UNSPECIFIED, - Symbol.valueOf("copy"): PN_DIST_MODE_COPY, - Symbol.valueOf("move"): PN_DIST_MODE_MOVE -} - -class pn_terminus: - - def __init__(self, type): - self.type = type - self.address = None - self.durability = PN_NONDURABLE - self.expiry_policy = PN_EXPIRE_WITH_SESSION - self.distribution_mode = PN_DIST_MODE_UNSPECIFIED - self.timeout = 0 - self.dynamic = False - self.properties = pn_data(0) - self.capabilities = pn_data(0) - self.outcomes = pn_data(0) - self.filter = pn_data(0) - - def copy(self, src): - self.type = src.type - self.address = src.address - self.durability = src.durability - self.expiry_policy = src.expiry_policy - self.timeout = src.timeout - self.dynamic = src.dynamic - self.properties = src.properties - self.capabilities = src.capabilities - self.outcomes = src.outcomes - self.filter = src.filter - - def decode(self, impl): - if impl is not None: - self.type = TERMINUS_TYPES_J2P[impl.__class__] - if self.type in (PN_SOURCE, PN_TARGET): - self.address = impl.getAddress() - self.durability = DURABILITY_J2P[impl.getDurable()] - self.expiry_policy = EXPIRY_POLICY_J2P[impl.getExpiryPolicy()] - self.timeout = impl.getTimeout().longValue() - self.dynamic = impl.getDynamic() - obj2dat(impl.getDynamicNodeProperties(), self.properties) - array2dat(impl.getCapabilities(), PN_SYMBOL, self.capabilities) - if self.type == PN_SOURCE: - self.distribution_mode = DISTRIBUTION_MODE_J2P[impl.getDistributionMode()] - array2dat(impl.getOutcomes(), PN_SYMBOL, self.outcomes) - obj2dat(impl.getFilter(), self.filter) - - def encode(self): - impl = TERMINUS_TYPES_P2J[self.type]() - if self.type in (PN_SOURCE, PN_TARGET): - impl.setAddress(self.address) - impl.setDurable(DURABILITY_P2J[self.durability]) - impl.setExpiryPolicy(EXPIRY_POLICY_P2J[self.expiry_policy]) - impl.setTimeout(UnsignedInteger.valueOf(self.timeout)) - impl.setDynamic(self.dynamic) - props = dat2obj(self.properties) - caps = dat2obj(self.capabilities) - if props: impl.setDynamicNodeProperties(props) - if caps: - impl.setCapabilities(*array(list(caps), Symbol)) - if self.type == PN_SOURCE: - impl.setDistributionMode(DISTRIBUTION_MODE_P2J[self.distribution_mode]) - outcomes = dat2obj(self.outcomes) - filter = dat2obj(self.filter) - if outcomes: impl.setOutcomes(outcomes) - if filter: impl.setFilter(filter) - return impl - -def pn_terminus_get_type(terminus): - return terminus.type - -def pn_terminus_set_type(terminus, type): - terminus.type = type - return 0 - -def pn_terminus_get_address(terminus): - return terminus.address - -def pn_terminus_set_address(terminus, address): - terminus.address = address - return 0 - -def pn_terminus_get_durability(terminus): - return terminus.durability - -def pn_terminus_get_expiry_policy(terminus): - return terminus.expiry_policy - -def pn_terminus_set_timeout(terminus, timeout): - terminus.timeout = timeout - return 0 - -def pn_terminus_get_timeout(terminus): - return terminus.timeout - -def pn_terminus_get_distribution_mode(terminus): - return terminus.distribution_mode - -def pn_terminus_set_distribution_mode(terminus, mode): - terminus.distribution_mode = mode - return 0 - -def pn_terminus_is_dynamic(terminus): - return terminus.dynamic - -def pn_terminus_set_dynamic(terminus, dynamic): - terminus.dynamic = dynamic - return 0 - -def pn_terminus_properties(terminus): - return terminus.properties - -def pn_terminus_capabilities(terminus): - return terminus.capabilities - -def pn_terminus_outcomes(terminus): - return terminus.outcomes - -def pn_terminus_filter(terminus): - return terminus.filter - -def pn_terminus_copy(terminus, src): - terminus.copy(src) - return 0 - -class pn_link_wrapper(endpoint_wrapper): - - def __init__(self, impl): - endpoint_wrapper.__init__(self, impl) - self.source = pn_terminus(PN_SOURCE) - self.remote_source = pn_terminus(PN_UNSPECIFIED) - self.target = pn_terminus(PN_TARGET) - self.remote_target = pn_terminus(PN_UNSPECIFIED) - - def on_open(self): - self.impl.setSource(self.source.encode()) - self.impl.setTarget(self.target.encode()) - -def pn_link_attachments(link): - return link.impl.attachments() - -def pn_link_source(link): - link.source.decode(link.impl.getSource()) - return link.source - -def pn_link_remote_source(link): - link.remote_source.decode(link.impl.getRemoteSource()) - return link.remote_source - -def pn_link_target(link): - link.target.decode(link.impl.getTarget()) - return link.target - -def pn_link_remote_target(link): - link.remote_target.decode(link.impl.getRemoteTarget()) - return link.remote_target - -def pn_link_condition(link): - return link.condition - -def pn_link_remote_condition(link): - return remote_condition(link) - -SND_SETTLE_MODE_P2J = { - PN_SND_UNSETTLED: SenderSettleMode.UNSETTLED, - PN_SND_SETTLED: SenderSettleMode.SETTLED, - PN_SND_MIXED: SenderSettleMode.MIXED, - None: None -} - -SND_SETTLE_MODE_J2P = { - SenderSettleMode.UNSETTLED: PN_SND_UNSETTLED, - SenderSettleMode.SETTLED: PN_SND_SETTLED, - SenderSettleMode.MIXED: PN_SND_MIXED, - None: None -} - -def pn_link_set_snd_settle_mode(link, mode): - link.impl.setSenderSettleMode(SND_SETTLE_MODE_P2J[mode]) - -def pn_link_snd_settle_mode(link): - return SND_SETTLE_MODE_J2P[link.impl.getSenderSettleMode()] - -def pn_link_remote_snd_settle_mode(link): - return SND_SETTLE_MODE_J2P[link.impl.getRemoteSenderSettleMode()] - -RCV_SETTLE_MODE_P2J = { - PN_RCV_FIRST: ReceiverSettleMode.FIRST, - PN_RCV_SECOND: ReceiverSettleMode.SECOND, - None: None -} - -RCV_SETTLE_MODE_J2P = { - ReceiverSettleMode.FIRST: PN_RCV_FIRST, - ReceiverSettleMode.SECOND: PN_RCV_SECOND, - None: None -} - -def pn_link_set_rcv_settle_mode(link, mode): - link.impl.setReceiverSettleMode(RCV_SETTLE_MODE_P2J[mode]) - -def pn_link_rcv_settle_mode(link): - return RCV_SETTLE_MODE_J2P[link.impl.getReceiverSettleMode()] - -def pn_link_remote_rcv_settle_mode(link): - return RCV_SETTLE_MODE_J2P[link.impl.getRemoteReceiverSettleMode()] - -def pn_link_is_sender(link): - return isinstance(link.impl, Sender) - -def pn_link_is_receiver(link): - return isinstance(link.impl, Receiver) - -def pn_link_head(conn, mask): - local, remote = mask2set(mask) - return wrap(conn.impl.linkHead(local, remote), pn_link_wrapper) - -def pn_link_next(link, mask): - local, remote = mask2set(mask) - return wrap(link.impl.next(local, remote), pn_link_wrapper) - -def pn_link_session(link): - return wrap(link.impl.getSession(), pn_session_wrapper) - -def pn_link_state(link): - return endpoint_state(link.impl) - -def pn_link_name(link): - return link.impl.getName() - -def pn_link_open(link): - link.on_open() - link.impl.open() - -def pn_link_close(link): - link.on_close() - link.impl.close() - -def pn_link_detach(link): - link.on_close() - link.impl.detach() - -def pn_link_flow(link, n): - link.impl.flow(n) - -def pn_link_drain(link, n): - link.impl.drain(n) - -def pn_link_drained(link): - return link.impl.drained() - -def pn_link_draining(link): - return link.impl.draining() - -def pn_link_credit(link): - return link.impl.getCredit() - -def pn_link_queued(link): - return link.impl.getQueued() - -def pn_link_get_drain(link): - return link.impl.getDrain(); - -def pn_link_set_drain(link, drain): - return link.impl.setDrain(drain); - -def pn_link_unsettled(link): - return link.impl.getUnsettled() - -def pn_link_send(link, bytes): - return link.impl.send(array(bytes, 'b'), 0, len(bytes)) - -def pn_link_recv(link, limit): - ary = zeros(limit, 'b') - n = link.impl.recv(ary, 0, limit) - if n >= 0: - bytes = ary[:n].tostring() - else: - bytes = None - return n, bytes - -def pn_link_advance(link): - return link.impl.advance() - -def pn_link_current(link): - return wrap(link.impl.current(), pn_delivery_wrapper) - -def pn_link_free(link): - link.impl.free() - -def pn_work_head(conn): - return wrap(conn.impl.getWorkHead(), pn_delivery_wrapper) - -def pn_work_next(dlv): - return wrap(dlv.impl.getWorkNext(), pn_delivery_wrapper) - -DELIVERY_STATES = { - Received: PN_RECEIVED, - Accepted: PN_ACCEPTED, - Rejected: PN_REJECTED, - Released: PN_RELEASED, - Modified: PN_MODIFIED, - None.__class__: 0 - } - -DISPOSITIONS = { - PN_RECEIVED: Received, - PN_ACCEPTED: Accepted, - PN_REJECTED: Rejected, - PN_RELEASED: Released, - PN_MODIFIED: Modified, - 0: lambda: None -} - -class pn_disposition: - - def __init__(self): - self.type = 0 - self.data = pn_data(0) - self.failed = False - self.undeliverable = False - self.annotations = pn_data(0) - self.condition = pn_condition() - self.section_number = 0 - self.section_offset = 0 - - def decode(self, impl): - self.type = DELIVERY_STATES[impl.__class__] - - if self.type == PN_REJECTED: - self.condition.decode(impl.getError()) - else: - pn_condition_clear(self.condition) - - if self.type == PN_MODIFIED: - self.failed = impl.getDeliveryFailed() - self.undeliverable = impl.getUndeliverableHere() - obj2dat(impl.getMessageAnnotations(), self.annotations) - else: - self.failed = False - self.undeliverable = False - pn_data_clear(self.annotations) - - if self.type == PN_RECEIVED: - self.section_number = impl.getSectionNumber().longValue() - self.section_offset = impl.getSectionOffset().longValue() - else: - self.section_number = 0 - self.section_offset = 0 - - self.data.clear() - if impl: - # XXX - #self.data.putObject(impl) - pass - self.data.rewind() - - def encode(self): - if self.type not in DISPOSITIONS: - raise Skipped() - impl = DISPOSITIONS[self.type]() - - if impl is None: - return impl - - if self.type == PN_REJECTED: - impl.setError(self.condition.encode()) - - if self.type == PN_MODIFIED: - impl.setDeliveryFailed(self.failed) - impl.setUndeliverableHere(self.undeliverable) - ann = dat2obj(self.annotations) - if ann: impl.setMessageAnnotations(ann) - - if self.type == PN_RECEIVED: - if self.section_number: - impl.setSectionNumber(UnsignedInteger.valueOf(self.section_number)) - if self.section_offset: - impl.setSectionOffset(UnsignedLong.valueOf(self.section_offset)) - - return impl - -def pn_disposition_type(dsp): - return dsp.type - -def pn_disposition_is_failed(dsp): - return dsp.failed - -def pn_disposition_set_failed(dsp, failed): - dsp.failed = failed - -def pn_disposition_is_undeliverable(dsp): - return dsp.undeliverable - -def pn_disposition_set_undeliverable(dsp, undeliverable): - dsp.undeliverable = undeliverable - -def pn_disposition_data(dsp): - return dsp.data - -def pn_disposition_annotations(dsp): - return dsp.annotations - -def pn_disposition_condition(dsp): - return dsp.condition - -def pn_disposition_get_section_number(dsp): - return dsp.section_number - -def pn_disposition_set_section_number(dsp, number): - dsp.section_number = number - -def pn_disposition_get_section_offset(dsp): - return dsp.section_offset - -def pn_disposition_set_section_offset(dsp, offset): - dsp.section_offset = offset - -class pn_delivery_wrapper: - - def __init__(self, impl): - self.impl = impl - self.local = pn_disposition() - self.remote = pn_disposition() - -def pn_delivery(link, tag): - return wrap(link.impl.delivery(array(tag, 'b')), pn_delivery_wrapper) - -def pn_delivery_tag(dlv): - return dlv.impl.getTag().tostring() - -def pn_delivery_attachments(dlv): - return dlv.impl.attachments() - -def pn_delivery_partial(dlv): - return dlv.impl.isPartial() - -def pn_delivery_pending(dlv): - return dlv.impl.pending() - -def pn_delivery_writable(dlv): - return dlv.impl.isWritable() - -def pn_delivery_readable(dlv): - return dlv.impl.isReadable() - -def pn_delivery_updated(dlv): - return dlv.impl.isUpdated() - -def pn_delivery_settled(dlv): - return dlv.impl.remotelySettled() - -def pn_delivery_local(dlv): - dlv.local.decode(dlv.impl.getLocalState()) - return dlv.local - -def pn_delivery_local_state(dlv): - dlv.local.decode(dlv.impl.getLocalState()) - return dlv.local.type - -def pn_delivery_remote(dlv): - dlv.remote.decode(dlv.impl.getRemoteState()) - return dlv.remote - -def pn_delivery_remote_state(dlv): - dlv.remote.decode(dlv.impl.getRemoteState()) - return dlv.remote.type - -def pn_delivery_update(dlv, state): - dlv.local.type = state - dlv.impl.disposition(dlv.local.encode()) - -def pn_delivery_link(dlv): - return wrap(dlv.impl.getLink(), pn_link_wrapper) - -def pn_delivery_settle(dlv): - dlv.impl.settle() - -class pn_transport_wrapper: - def __init__(self, impl): - self.impl = impl - self.server = False - self.condition = pn_condition() - -def pn_transport(): - return wrap(Proton.transport(), pn_transport_wrapper) - -def pn_transport_get_pytracer(trans): - raise Skipped() - -def pn_transport_attachments(trans): - return trans.impl.attachments() - -def pn_transport_set_server(trans): - trans.server = True; - -def pn_transport_get_max_frame(trans): - return trans.impl.getMaxFrameSize() - -def pn_transport_set_max_frame(trans, value): - trans.impl.setMaxFrameSize(value) - -def pn_transport_get_remote_max_frame(trans): - return trans.impl.getRemoteMaxFrameSize() - -def pn_transport_set_idle_timeout(trans, value): - trans.impl.setIdleTimeout(value); - -def pn_transport_get_idle_timeout(trans): - return trans.impl.getIdleTimeout() - -def pn_transport_get_remote_idle_timeout(trans): - return trans.impl.getRemoteIdleTimeout() - -def pn_transport_get_frames_input(trans): - return trans.impl.getFramesInput() - -def pn_transport_get_frames_output(trans): - return trans.impl.getFramesOutput() - -def pn_transport_set_channel_max(trans, n): - trans.impl.setChannelMax(n) - -def pn_transport_get_channel_max(trans): - return trans.impl.getChannelMax() - -def pn_transport_remote_channel_max(trans): - return trans.impl.getRemoteChannelMax() - -def pn_transport_tick(trans, now): - return trans.impl.tick(now); - -def pn_transport_bind(trans, conn): - trans.impl.bind(conn.impl) - return 0 - -def pn_transport_unbind(trans): - trans.impl.unbind() - return 0 - -def pn_transport_set_pytracer(trans, tracer): - import warnings - warnings.warn("TODO pn_transport_set_tracer", stacklevel=2) - -def pn_transport_trace(trans, n): - trans.impl.trace(n) - -def pn_transport_pending(trans): - return trans.impl.pending() - -def pn_transport_peek(trans, size): - size = min(trans.impl.pending(), size) - ba = zeros(size, 'b') - if size: - bb = trans.impl.head() - bb.get(ba) - bb.position(0) - return 0, ba.tostring() - -def pn_transport_pop(trans, size): - trans.impl.pop(size) - -def pn_transport_capacity(trans): - return trans.impl.capacity() - -def pn_transport_push(trans, input): - result = 0 - while input: - cap = pn_transport_capacity(trans) - if cap < 0: - return cap - elif len(input) > cap: - trimmed = input[:cap] - else: - trimmed = input - - bb = trans.impl.tail() - bb.put(array(trimmed, 'b')) - trans.impl.process() - input = input[cap:] - result += len(trimmed) - return result - -def pn_transport_close_head(trans): - trans.impl.close_head() - return 0 - -def pn_transport_close_tail(trans): - trans.impl.close_tail() - return 0 - -def pn_transport_closed(trans): - return trans.impl.isClosed() - -def pn_transport_condition(trans): - trans.condition.decode(trans.impl.getCondition()) - return trans.condition - -from org.apache.qpid.proton.engine import Event - -PN_REACTOR_INIT = Event.Type.REACTOR_INIT -PN_REACTOR_QUIESCED = Event.Type.REACTOR_QUIESCED -PN_REACTOR_FINAL = Event.Type.REACTOR_FINAL - -PN_TIMER_TASK = Event.Type.TIMER_TASK - -PN_CONNECTION_INIT = Event.Type.CONNECTION_INIT -PN_CONNECTION_BOUND = Event.Type.CONNECTION_BOUND -PN_CONNECTION_UNBOUND = Event.Type.CONNECTION_UNBOUND -PN_CONNECTION_LOCAL_OPEN = Event.Type.CONNECTION_LOCAL_OPEN -PN_CONNECTION_REMOTE_OPEN = Event.Type.CONNECTION_REMOTE_OPEN -PN_CONNECTION_LOCAL_CLOSE = Event.Type.CONNECTION_LOCAL_CLOSE -PN_CONNECTION_REMOTE_CLOSE = Event.Type.CONNECTION_REMOTE_CLOSE -PN_CONNECTION_FINAL = Event.Type.CONNECTION_FINAL -PN_SESSION_INIT = Event.Type.SESSION_INIT -PN_SESSION_LOCAL_OPEN = Event.Type.SESSION_LOCAL_OPEN -PN_SESSION_REMOTE_OPEN = Event.Type.SESSION_REMOTE_OPEN -PN_SESSION_LOCAL_CLOSE = Event.Type.SESSION_LOCAL_CLOSE -PN_SESSION_REMOTE_CLOSE = Event.Type.SESSION_REMOTE_CLOSE -PN_SESSION_FINAL = Event.Type.SESSION_FINAL -PN_LINK_INIT = Event.Type.LINK_INIT -PN_LINK_LOCAL_OPEN = Event.Type.LINK_LOCAL_OPEN -PN_LINK_REMOTE_OPEN = Event.Type.LINK_REMOTE_OPEN -PN_LINK_LOCAL_CLOSE = Event.Type.LINK_LOCAL_CLOSE -PN_LINK_REMOTE_CLOSE = Event.Type.LINK_REMOTE_CLOSE -PN_LINK_LOCAL_DETACH = Event.Type.LINK_LOCAL_DETACH -PN_LINK_REMOTE_DETACH = Event.Type.LINK_REMOTE_DETACH -PN_LINK_FLOW = Event.Type.LINK_FLOW -PN_LINK_FINAL = Event.Type.LINK_FINAL -PN_DELIVERY = Event.Type.DELIVERY -PN_TRANSPORT = Event.Type.TRANSPORT -PN_TRANSPORT_ERROR = Event.Type.TRANSPORT_ERROR -PN_TRANSPORT_HEAD_CLOSED = Event.Type.TRANSPORT_HEAD_CLOSED -PN_TRANSPORT_TAIL_CLOSED = Event.Type.TRANSPORT_TAIL_CLOSED -PN_TRANSPORT_CLOSED = Event.Type.TRANSPORT_CLOSED -PN_SELECTABLE_INIT = Event.Type.SELECTABLE_INIT -PN_SELECTABLE_UPDATED = Event.Type.SELECTABLE_UPDATED -PN_SELECTABLE_READABLE = Event.Type.SELECTABLE_READABLE -PN_SELECTABLE_WRITABLE = Event.Type.SELECTABLE_WRITABLE -PN_SELECTABLE_EXPIRED = Event.Type.SELECTABLE_EXPIRED -PN_SELECTABLE_ERROR = Event.Type.SELECTABLE_ERROR -PN_SELECTABLE_FINAL = Event.Type.SELECTABLE_FINAL - -def pn_collector(): - return Proton.collector() - -def pn_connection_collect(conn, coll): - conn.impl.collect(coll) - -class pn_event: - - def __init__(self, impl): - self.impl = impl - - def copy(self): - return pn_event(self.impl.copy()) - -def pn_collector_peek(coll): - ev = coll.peek() - if ev: - return pn_event(ev.copy()) - else: - return None - -def pn_collector_pop(coll): - coll.pop() - -def pn_collector_free(coll): - pass - -def pn_event_reactor(event): - return event.impl.getReactor() - -def pn_event_connection(event): - return wrap(event.impl.getConnection(), pn_connection_wrapper) - -def pn_event_session(event): - return wrap(event.impl.getSession(), pn_session_wrapper) - -def pn_event_link(event): - return wrap(event.impl.getLink(), pn_link_wrapper) - -def pn_event_delivery(event): - return wrap(event.impl.getDelivery(), pn_delivery_wrapper) - -def pn_event_transport(event): - return wrap(event.impl.getTransport(), pn_transport_wrapper) - -from org.apache.qpid.proton.engine.impl import ConnectionImpl, SessionImpl, \ - SenderImpl, ReceiverImpl, DeliveryImpl, TransportImpl -from org.apache.qpid.proton.reactor.impl import TaskImpl, SelectableImpl - -J2C = { - ConnectionImpl: "pn_connection", - SessionImpl: "pn_session", - SenderImpl: "pn_link", - ReceiverImpl: "pn_link", - DeliveryImpl: "pn_delivery", - TransportImpl: "pn_transport", - TaskImpl: "pn_task", - SelectableImpl: "pn_selectable" -} - -wrappers = { - "pn_connection": lambda x: wrap(x, pn_connection_wrapper), - "pn_session": lambda x: wrap(x, pn_session_wrapper), - "pn_link": lambda x: wrap(x, pn_link_wrapper), - "pn_delivery": lambda x: wrap(x, pn_delivery_wrapper), - "pn_transport": lambda x: wrap(x, pn_transport_wrapper), - "pn_task": lambda x: x, - "pn_selectable": lambda x: x, - "pn_void": lambda x: x -} - -def pn_event_class(event): - ctx = event.impl.getContext() - return J2C.get(ctx.getClass(), "pn_void") - -def pn_event_context(event): - return wrappers[pn_event_class(event)](event.impl.getContext()) - -def pn_event_type(event): - return event.impl.getEventType() - -def pn_event_root(event): - return event.impl.getRootHandler() - -def pn_event_type_name(etype): - return str(etype) - -def pn_event_category(event): - return event.impl.getCategory() - -def pn_event_attachments(event): - return event.impl.attachments() - -def pn_event_copy(event): - return event.copy() - -class TypeExtender: - def __init__(self, number): - pass - def next(self): - class CustomEvent(EventType): - def isValid(self): - return True - return CustomEvent() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/cerror.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/cerror.py b/tests/java/shim/cerror.py deleted file mode 100644 index c87681c..0000000 --- a/tests/java/shim/cerror.py +++ /dev/null @@ -1,48 +0,0 @@ -# -# 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. -# - -# from proton/error.h -PN_EOS = -1 -PN_ERR = -2 -PN_OVERFLOW = -3 -PN_UNDERFLOW = -4 -PN_STATE_ERR = -5 -PN_ARG_ERR = -6 -PN_TIMEOUT =-7 -PN_INTR = -8 -PN_INPROGRESS =-9 - -class pn_error: - - def __init__(self, code, text): - self.code = code - self.text = text - - def set(self, code, text): - self.code = code - self.text = text - return self.code - -def pn_error_code(err): - return err.code - -def pn_error_text(err): - return err.text - -from unittest import SkipTest as Skipped http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/chandlers.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/chandlers.py b/tests/java/shim/chandlers.py deleted file mode 100644 index 272990f..0000000 --- a/tests/java/shim/chandlers.py +++ /dev/null @@ -1,55 +0,0 @@ -# -# 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. -# - -import sys -from cerror import Skipped -from org.apache.qpid.proton.reactor import FlowController, Handshaker -from org.apache.qpid.proton.engine import BaseHandler, HandlerException - -# from proton/handlers.h -def pn_flowcontroller(window): - return FlowController(window) - -def pn_handshaker(): - return Handshaker() - -def pn_iohandler(): - raise Skipped() - -from cengine import pn_event, pn_event_type - -class pn_pyhandler(BaseHandler): - - def __init__(self, pyobj): - self.pyobj = pyobj - - def onUnhandled(self, event): - ev = pn_event(event) - try: - self.pyobj.dispatch(ev, pn_event_type(ev)) - except HandlerException: - ex = sys.exc_info(); - cause = ex[1].cause - if hasattr(cause, "value"): - cause = cause.value - t = type(cause) - self.pyobj.exception(t, cause, ex[2]) - except: - ex = sys.exc_info() - self.pyobj.exception(*ex) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/cmessage.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/cmessage.py b/tests/java/shim/cmessage.py deleted file mode 100644 index d406bea..0000000 --- a/tests/java/shim/cmessage.py +++ /dev/null @@ -1,250 +0,0 @@ -# -# 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. -# -from org.apache.qpid.proton import Proton -from org.apache.qpid.proton.amqp.messaging import AmqpValue, AmqpSequence, \ - Data as DataSection, ApplicationProperties, MessageAnnotations, DeliveryAnnotations - -from ccodec import * -from cerror import * -from org.apache.qpid.proton.amqp import Binary - -# from proton/message.h -PN_DATA = 0 -PN_TEXT = 1 -PN_AMQP = 2 -PN_JSON = 3 - -PN_DEFAULT_PRIORITY = 4 - -class pn_message_wrapper: - - def __init__(self): - self.inferred = False - self.impl = Proton.message() - self.id = pn_data(0) - self.correlation_id = pn_data(0) - self.instructions = pn_data(0) - self.annotations = pn_data(0) - self.properties = pn_data(0) - self.body = pn_data(0) - - def decode(self, impl): - self.impl = impl - self.post_decode() - - def post_decode(self): - obj2dat(self.impl.getMessageId(), self.id) - self.id.next() - obj2dat(self.impl.getCorrelationId(), self.correlation_id) - self.correlation_id.next() - def peel(x): - if x is not None: - return x.getValue() - return None - obj2dat(peel(self.impl.getDeliveryAnnotations()), self.instructions) - obj2dat(peel(self.impl.getMessageAnnotations()), self.annotations) - obj2dat(peel(self.impl.getApplicationProperties()), self.properties) - bod = self.impl.getBody() - if bod is not None: bod = bod.getValue() - obj2dat(bod, self.body) - - def pre_encode(self): - self.impl.setMessageId(dat2obj(self.id)) - self.impl.setCorrelationId(dat2obj(self.correlation_id)) - def wrap(x, wrapper): - if x is not None: - return wrapper(x) - return None - self.impl.setDeliveryAnnotations(wrap(dat2obj(self.instructions), DeliveryAnnotations)) - self.impl.setMessageAnnotations(wrap(dat2obj(self.annotations), MessageAnnotations)) - self.impl.setApplicationProperties(wrap(dat2obj(self.properties), ApplicationProperties)) - bod = dat2obj(self.body) - if self.inferred: - if isinstance(bod, bytes): - bod = DataSection(Binary(array(bod, 'b'))) - elif isinstance(bod, list): - bod = AmqpSequence(bod) - else: - bod = AmqpValue(bod) - else: - bod = AmqpValue(bod) - self.impl.setBody(bod) - - def __repr__(self): - return self.impl.toString() - -def pn_message(): - return pn_message_wrapper() - -def pn_message_id(msg): - return msg.id - -def pn_message_correlation_id(msg): - return msg.correlation_id - -def pn_message_get_address(msg): - return msg.impl.getAddress() - -def pn_message_set_address(msg, address): - msg.impl.setAddress(address) - return 0 - -def pn_message_get_reply_to(msg): - return msg.impl.getReplyTo() - -def pn_message_set_reply_to(msg, address): - msg.impl.setReplyTo(address) - return 0 - -def pn_message_get_reply_to_group_id(msg): - return msg.impl.getReplyToGroupId() - -def pn_message_set_reply_to_group_id(msg, id): - msg.impl.setReplyToGroupId(id) - return 0 - -def pn_message_get_group_sequence(msg): - return msg.impl.getGroupSequence() - -def pn_message_set_group_sequence(msg, seq): - msg.impl.setGroupSequence(seq) - return 0 - -def pn_message_get_group_id(msg): - return msg.impl.getGroupId() - -def pn_message_set_group_id(msg, id): - msg.impl.setGroupId(id) - return 0 - -def pn_message_is_first_acquirer(msg): - return msg.impl.isFirstAcquirer() - -def pn_message_set_first_acquirer(msg, b): - msg.impl.setFirstAcquirer(b) - return 0 - -def pn_message_is_durable(msg): - return msg.impl.isDurable() - -def pn_message_set_durable(msg, b): - msg.impl.setDurable(b) - return 0 - -def pn_message_get_delivery_count(msg): - return msg.impl.getDeliveryCount() - -def pn_message_set_delivery_count(msg, c): - msg.impl.setDeliveryCount(c) - return 0 - -def pn_message_get_creation_time(msg): - return msg.impl.getCreationTime() - -def pn_message_set_creation_time(msg, t): - msg.impl.setCreationTime(t) - return 0 - -def pn_message_get_expiry_time(msg): - return msg.impl.getExpiryTime() - -def pn_message_set_expiry_time(msg, t): - msg.impl.setExpiryTime(t) - return 0 - -def pn_message_get_content_type(msg): - return msg.impl.getContentType() - -def pn_message_set_content_type(msg, ct): - msg.impl.setContentType(ct) - return 0 - -def pn_message_get_content_encoding(msg): - return msg.impl.getContentEncoding() - -def pn_message_set_content_encoding(msg, ct): - msg.impl.setContentEncoding(ct) - return 0 - -def pn_message_get_subject(msg): - return msg.impl.getSubject() - -def pn_message_set_subject(msg, value): - msg.impl.setSubject(value) - return 0 - -def pn_message_get_priority(msg): - return msg.impl.getPriority() - -def pn_message_set_priority(msg, p): - msg.impl.setPriority(p) - return 0 - -def pn_message_get_ttl(msg): - return msg.impl.getTtl() - -def pn_message_set_ttl(msg, ttl): - msg.impl.setTtl(ttl) - return 0 - -def pn_message_get_user_id(msg): - uid = msg.impl.getUserId() - if uid is None: - return "" - else: - return uid.tostring() - -def pn_message_set_user_id(msg, uid): - msg.impl.setUserId(uid) - return 0 - -def pn_message_instructions(msg): - return msg.instructions - -def pn_message_annotations(msg): - return msg.annotations - -def pn_message_properties(msg): - return msg.properties - -def pn_message_body(msg): - return msg.body - -def pn_message_decode(msg, data): - n = msg.impl.decode(array(data, 'b'), 0, len(data)) - msg.post_decode() - return n - -from java.nio import BufferOverflowException - -def pn_message_encode(msg, size): - msg.pre_encode() - ba = zeros(size, 'b') - # XXX: shouldn't have to use the try/catch - try: - n = msg.impl.encode(ba, 0, size) - if n >= 0: - return n, ba[:n].tostring() - else: - return n - except BufferOverflowException, e: - return PN_OVERFLOW, None - -def pn_message_clear(msg): - msg.impl.clear() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/cmessenger.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/cmessenger.py b/tests/java/shim/cmessenger.py deleted file mode 100644 index 249e0dc..0000000 --- a/tests/java/shim/cmessenger.py +++ /dev/null @@ -1,225 +0,0 @@ -# -# 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. -# -from org.apache.qpid.proton import Proton -from org.apache.qpid.proton.messenger import Messenger, Status -from org.apache.qpid.proton import InterruptException, TimeoutException - -from cerror import * - -# from proton/messenger.h -PN_STATUS_UNKNOWN = 0 -PN_STATUS_PENDING = 1 -PN_STATUS_ACCEPTED = 2 -PN_STATUS_REJECTED = 3 -PN_STATUS_RELEASED = 4 -PN_STATUS_MODIFIED = 5 -PN_STATUS_ABORTED = 6 -PN_STATUS_SETTLED = 7 - -PN_CUMULATIVE = 1 - -class pn_messenger_wrapper: - - def __init__(self, impl): - self.impl = impl - self.error = pn_error(0, None) - -def pn_messenger(name): - if name is None: - return pn_messenger_wrapper(Proton.messenger()) - else: - return pn_messenger_wrapper(Proton.messenger(name)) - -def pn_messenger_error(m): - return m.error - -def pn_messenger_set_timeout(m, t): - m.impl.setTimeout(t) - return 0 - -def pn_messenger_set_blocking(m, b): - m.impl.setBlocking(b) - return 0 - -def pn_messenger_set_certificate(m, c): - m.impl.setCertificate(c) - return 0 - -def pn_messenger_set_private_key(m, p): - m.impl.setPrivateKey(p) - return 0 - -def pn_messenger_set_password(m, p): - m.impl.setPassword(p) - return 0 - -def pn_messenger_set_trusted_certificates(m, t): - m.impl.setTrustedCertificates(t) - return 0 - -def pn_messenger_set_incoming_window(m, w): - m.impl.setIncomingWindow(w) - return 0 - -def pn_messenger_set_outgoing_window(m, w): - m.impl.setOutgoingWindow(w) - return 0 - -def pn_messenger_start(m): - m.impl.start() - return 0 - -# XXX: ??? -def pn_messenger_work(m, t): - try: - if m.impl.work(t): - return 1 - else: - return PN_TIMEOUT - except InterruptException, e: - return PN_INTR - -class pn_subscription: - - def __init__(self): - pass - -def pn_messenger_subscribe(m, source): - m.impl.subscribe(source) - return pn_subscription() - -def pn_messenger_route(m, pattern, address): - m.impl.route(pattern, address) - return 0 - -def pn_messenger_rewrite(m, pattern, address): - m.impl.rewrite(pattern, address) - return 0 - -def pn_messenger_interrupt(m): - m.impl.interrupt() - return 0 - -def pn_messenger_buffered(m, t): - raise Skipped() - -from org.apache.qpid.proton.engine import TransportException - -def pn_messenger_stop(m): - m.impl.stop() - return 0 - -def pn_messenger_stopped(m): - return m.impl.stopped() - -def pn_messenger_put(m, msg): - msg.pre_encode() - m.impl.put(msg.impl) - return 0 - -def pn_messenger_outgoing_tracker(m): - return m.impl.outgoingTracker() - -def pn_messenger_send(m, n): - try: - m.impl.send(n) - return 0 - except InterruptException, e: - return PN_INTR - except TimeoutException, e: - return PN_TIMEOUT - -def pn_messenger_recv(m, n): - try: - m.impl.recv(n) - return 0 - except InterruptException, e: - return PN_INTR - except TimeoutException, e: - return PN_TIMEOUT - -def pn_messenger_receiving(m): - return m.impl.receiving() - -def pn_messenger_incoming(m): - return m.impl.incoming() - -def pn_messenger_outgoing(m): - return m.impl.outgoing() - -def pn_messenger_get(m, msg): - mimpl = m.impl.get() - if msg: - msg.decode(mimpl) - return 0 - -def pn_messenger_incoming_tracker(m): - return m.impl.incomingTracker() - -def pn_messenger_accept(m, tracker, flags): - if flags: - m.impl.accept(tracker, Messenger.CUMULATIVE) - else: - m.impl.accept(tracker, 0) - return 0 - -def pn_messenger_reject(m, tracker, flags): - if flags: - m.impl.reject(tracker, Messenger.CUMULATIVE) - else: - m.impl.reject(tracker, 0) - return 0 - -def pn_messenger_settle(m, tracker, flags): - if flags: - m.impl.settle(tracker, Messenger.CUMULATIVE) - else: - m.impl.settle(tracker, 0) - return 0 - -STATUS_P2J = { - PN_STATUS_UNKNOWN: Status.UNKNOWN, - PN_STATUS_PENDING: Status.PENDING, - PN_STATUS_ACCEPTED: Status.ACCEPTED, - PN_STATUS_REJECTED: Status.REJECTED, - PN_STATUS_RELEASED: Status.RELEASED, - PN_STATUS_MODIFIED: Status.MODIFIED, - PN_STATUS_ABORTED: Status.ABORTED, - PN_STATUS_SETTLED: Status.SETTLED -} - -STATUS_J2P = { - Status.UNKNOWN: PN_STATUS_UNKNOWN, - Status.PENDING: PN_STATUS_PENDING, - Status.ACCEPTED: PN_STATUS_ACCEPTED, - Status.REJECTED: PN_STATUS_REJECTED, - Status.RELEASED: PN_STATUS_RELEASED, - Status.MODIFIED: PN_STATUS_MODIFIED, - Status.ABORTED: PN_STATUS_ABORTED, - Status.SETTLED: PN_STATUS_SETTLED -} - -def pn_messenger_status(m, tracker): - return STATUS_J2P[m.impl.getStatus(tracker)] - -def pn_messenger_set_passive(m, passive): - raise Skipped() - -def pn_messenger_selectable(m): - raise Skipped() http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/cobject.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/cobject.py b/tests/java/shim/cobject.py deleted file mode 100644 index 33ab438..0000000 --- a/tests/java/shim/cobject.py +++ /dev/null @@ -1,91 +0,0 @@ -# -# 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. -# - -def pn_class_name(cls): - return cls - -def pn_void2py(obj): - return obj - -def pn_py2void(obj): - return obj - -def pn_cast_pn_connection(obj): - return obj - -def pn_cast_pn_session(obj): - return obj - -def pn_cast_pn_link(obj): - return obj - -def pn_cast_pn_delivery(obj): - return obj - -def pn_cast_pn_transport(obj): - return obj - -def pn_cast_pn_reactor(obj): - return obj - -def pn_cast_pn_task(obj): - return obj - -def pn_cast_pn_selectable(obj): - return obj - -PN_PYREF = None - -def pn_record_def(record, key, clazz): - pass - -from java.lang import Object - -def pn_record_get(record, key): - return record.get(key, Object) - -def pn_record_set(record, key, value): - record.set(key, Object, value) - -def pn_incref(obj): - pass - -def pn_decref(obj): - pass - -def pn_free(obj): - pass - -from java.lang import StringBuilder - -def pn_string(st): - sb = StringBuilder() - if st: - sb.append(st) - return sb - -def pn_string_get(sb): - return sb.toString() - -def pn_inspect(obj, st): - if obj is None: - st.append("null") - else: - st.append(repr(obj)) - return 0 http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/compat.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/compat.py b/tests/java/shim/compat.py deleted file mode 100644 index 7bff3ba..0000000 --- a/tests/java/shim/compat.py +++ /dev/null @@ -1,26 +0,0 @@ -# -# 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. -# -import sys -from jarray import zeros, array as _array - -if (sys.version_info[0] == 2 and sys.version_info[1] == 5): - array = _array -else: - def array(obj, code): - return obj http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/tests/java/shim/cproton.py ---------------------------------------------------------------------- diff --git a/tests/java/shim/cproton.py b/tests/java/shim/cproton.py deleted file mode 100644 index d5ed574..0000000 --- a/tests/java/shim/cproton.py +++ /dev/null @@ -1,42 +0,0 @@ -# -# 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. -# - -""" -The cproton module defines a java implementation of the C interface as -exposed to python via swig. This allows tests defined in python to run -against both the C and Java protocol implementations. -""" - -# @todo(kgiusti) dynamically set these via filters in the pom.xml file -PN_VERSION_MAJOR = 0 -PN_VERSION_MINOR = 0 -PN_VERSION_POINT = 0 - -from ctypes import * -from cobject import * -from cerror import * -from ccodec import * -from cengine import * -from csasl import * -from cssl import * -from cmessenger import * -from cmessage import * -from curl import * -from creactor import * -from chandlers import * --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org