Author: gsim
Date: Tue Nov  6 09:27:27 2007
New Revision: 592494

URL: http://svn.apache.org/viewvc?rev=592494&view=rev
Log:
Add support for array type to c++ (and python, decode only for now)
Change the type of the in-doubt field in dtx-coordination.recover to an array 
(to bring in line with amqp spec)


Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.h   (with props)
    incubator/qpid/trunk/qpid/cpp/src/tests/Array.cpp   (with props)
Modified:
    incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxHandlerImpl.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/amqp_types_full.h
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/njms/XAResourceImpl.java
    incubator/qpid/trunk/qpid/python/qpid/codec.py
    incubator/qpid/trunk/qpid/python/qpid/spec.py
    incubator/qpid/trunk/qpid/python/tests_0-10/dtx.py
    incubator/qpid/trunk/qpid/specs/amqp.0-10-preview.xml

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/cppgen.rb Tue Nov  6 09:27:27 2007
@@ -122,6 +122,7 @@
     "longstr"=>CppType.new("string").passcref.retcref.code("LongString"),
     "shortstr"=>CppType.new("string").passcref.retcref.code("ShortString"),
     "table"=>CppType.new("FieldTable").passcref.retcref,
+    "array"=>CppType.new("Array").passcref.retcref,
     "content"=>CppType.new("Content").passcref.retcref,
     "rfc1982-long-set"=>CppType.new("SequenceNumberSet").passcref.retcref,
     "long-struct"=>CppType.new("string").passcref.retcref.code("LongString"),

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Tue Nov  6 09:27:27 2007
@@ -98,6 +98,7 @@
   qpid/framing/AMQFrame.cpp \
   qpid/framing/AMQHeaderBody.cpp \
   qpid/framing/AMQHeartbeatBody.cpp \
+  qpid/framing/Array.cpp \
   qpid/framing/BasicHeaderProperties.cpp \
   qpid/framing/BodyHandler.cpp \
   qpid/framing/ChannelAdapter.cpp \
@@ -337,6 +338,7 @@
   qpid/framing/AMQMethodBody.h \
   qpid/framing/AMQP_HighestVersion.h \
   qpid/framing/AccumulatedAck.h \
+  qpid/framing/Array.h \
   qpid/framing/BasicHeaderProperties.h \
   qpid/framing/Blob.h \
   qpid/framing/BodyHandler.h \

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxHandlerImpl.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxHandlerImpl.cpp?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxHandlerImpl.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DtxHandlerImpl.cpp Tue Nov  6 
09:27:27 2007
@@ -20,6 +20,7 @@
 #include <boost/format.hpp>
 #include "Broker.h"
 #include "qpid/framing/constants.h"
+#include "qpid/framing/Array.h"
 
 using namespace qpid::broker;
 using namespace qpid::framing;
@@ -136,25 +137,14 @@
     // strictly 'legal', but that is ok for testing
     std::set<std::string> xids;
     getBroker().getStore().collectPreparedXids(xids);        
-    uint size(0);
-    for (std::set<std::string>::iterator i = xids.begin(); i != xids.end(); 
i++) {
-        size += i->size() + 1/*shortstr size*/;        
-    }
 
-    char* bytes = static_cast<char*>(::alloca(size + 4/*longstr size*/));
-    Buffer wbuffer(bytes, size + 4/*longstr size*/);
-    wbuffer.putLong(size);
+    //TODO: remove the need to copy from one container type to another
+    std::vector<std::string> data;
     for (std::set<std::string>::iterator i = xids.begin(); i != xids.end(); 
i++) {
-        wbuffer.putShortString(*i);
+        data.push_back(*i);
     }
-
-    Buffer rbuffer(bytes, size + 4/*longstr size*/);
-    string data;
-    rbuffer.getLongString(data);
-
-    FieldTable response;
-    response.setString("xids", data);
-    return DtxCoordinationRecoverResult(response);
+    Array indoubt(data);
+    return DtxCoordinationRecoverResult(indoubt);
 }
 
 void DtxHandlerImpl::forget(u_int16_t /*ticket*/,

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.cpp?rev=592494&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.cpp Tue Nov  6 
09:27:27 2007
@@ -0,0 +1,114 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "Array.h"
+#include "Buffer.h"
+#include "FieldValue.h"
+#include "qpid/Exception.h"
+#include "qpid/framing/reply_exceptions.h"
+#include <assert.h>
+
+namespace qpid {
+namespace framing {
+
+Array::Array() : typeOctet(0xF0/*void*/) {}
+
+Array::Array(const std::vector<std::string>& in)
+{
+    typeOctet = 0xA4;
+    for (std::vector<std::string>::const_iterator i = in.begin(); i != 
in.end(); ++i) {
+        ValuePtr value(new StringValue(*i));
+        values.push_back(value);
+    }
+} 
+
+uint32_t Array::size() const {
+    //note: size is only included when used as a 'top level' type
+    uint32_t len(4/*size*/ + 1/*type*/ + 4/*count*/);
+    for(ValueVector::const_iterator i = values.begin(); i != values.end(); 
++i) {
+       len += (*i)->getData().size();
+    }
+    return len;
+}
+
+int Array::count() const {
+    return values.size();
+}
+
+std::ostream& operator<<(std::ostream& out, const Array& t) {
+    out << "{";
+    for(Array::ValueVector::const_iterator i = t.values.begin(); i != 
t.values.end(); ++i) {
+        if (i != t.values.begin()) out << ", ";
+        out << *(i->get());
+    }
+    return out << "}";
+}
+
+void Array::encode(Buffer& buffer) const{
+    buffer.putLong(size() - 4);//size added only when array is a top-level type
+    buffer.putOctet(typeOctet);
+    buffer.putLong(count());
+    for (ValueVector::const_iterator i = values.begin(); i!=values.end(); ++i) 
{
+       (*i)->getData().encode(buffer);
+    }
+}
+
+void Array::decode(Buffer& buffer){
+    uint32_t size = buffer.getLong();//size added only when array is a 
top-level type
+    uint32_t available = buffer.available();
+    if (available < size) {
+        throw SyntaxErrorException(QPID_MSG("Not enough data for array, 
expected " 
+                                            << size << " bytes but only " << 
available << " available"));
+    }
+    typeOctet = buffer.getOctet();
+    uint32_t count = buffer.getLong();
+
+    FieldValue dummy;
+    dummy.setType(typeOctet);
+    available = buffer.available();
+    if (available < count * dummy.getData().size()) {
+        throw SyntaxErrorException(QPID_MSG("Not enough data for array, 
expected " 
+                                            << count << " items of " << 
dummy.getData().size()
+                                            << " bytes each  but only " << 
available << " bytes available"));
+    }
+
+    for (uint32_t i = 0; i < count; i++) {
+        ValuePtr value(new FieldValue);
+        value->setType(typeOctet);
+        value->getData().decode(buffer);
+        values.push_back(ValuePtr(value));
+    }    
+}
+
+
+bool Array::operator==(const Array& x) const {
+    if (typeOctet != x.typeOctet) return false;
+    if (values.size() != x.values.size()) return false;
+
+    for (ValueVector::const_iterator i =  values.begin(), j = 
x.values.begin(); i != values.end(); ++i, ++j) {
+        if (*(i->get()) != *(j->get())) return false;
+    }
+
+    return true;
+}
+
+
+}
+}

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.h?rev=592494&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.h Tue Nov  6 09:27:27 
2007
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include <iostream>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include "amqp_types.h"
+#include "FieldValue.h"
+
+#ifndef _Array_
+#define _Array_
+
+namespace qpid {
+namespace framing {
+
+class Buffer;
+
+class Array
+{
+  public:
+    typedef boost::shared_ptr<FieldValue> ValuePtr;
+    typedef std::vector<ValuePtr> ValueVector;
+
+    uint32_t size() const;
+    void encode(Buffer& buffer) const;
+    void decode(Buffer& buffer);
+
+    int count() const;
+    bool operator==(const Array& other) const;
+
+    Array();
+    //only long string arrays can currently be created (any type can be 
decoded)
+    Array(const std::vector<std::string>& in);
+
+    template <class T>
+    void collect(std::vector<T>& out)
+    {
+        for (ValueVector::const_iterator i = values.begin(); i != 
values.end(); ++i) {
+            out.push_back((*i)->get<T>());
+        }
+    }
+    
+  private:
+    uint8_t typeOctet;
+    ValueVector values;
+
+    ValueVector::const_iterator begin() const { return values.begin(); }
+    ValueVector::const_iterator end() const { return values.end(); }
+
+    friend std::ostream& operator<<(std::ostream& out, const Array& body);
+};
+
+}
+}
+
+
+#endif

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/Array.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.cpp Tue Nov  6 
09:27:27 2007
@@ -25,9 +25,9 @@
 namespace qpid {
 namespace framing {
 
-void FieldValue::decode(Buffer& buffer)
+void FieldValue::setType(uint8_t type)
 {
-    typeOctet = buffer.getOctet();
+    typeOctet = type;
     
     uint8_t lenType = typeOctet >> 4;
     switch(lenType){
@@ -76,6 +76,11 @@
       default:
         throw SyntaxErrorException(QPID_MSG("Unknown field table value type: " 
<< (int)typeOctet));
     }
+}
+
+void FieldValue::decode(Buffer& buffer)
+{
+    setType(buffer.getOctet());
     data->decode(buffer);
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FieldValue.h Tue Nov  6 
09:27:27 2007
@@ -78,6 +78,8 @@
 
     FieldValue(): data(0) {};
     // Default assignment operator is fine
+    void setType(uint8_t type);
+    Data& getData() { return *data; }
     uint32_t size() const { return 1 + data->size(); };
     bool empty() const { return data.get() == 0; } 
     void encode(Buffer& buffer);

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/amqp_types_full.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/amqp_types_full.h?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/amqp_types_full.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/amqp_types_full.h Tue Nov  6 
09:27:27 2007
@@ -30,6 +30,7 @@
  */
 
 #include "amqp_types.h"
+#include "Array.h"
 #include "FramingContent.h"
 #include "FieldTable.h"
 #include "SequenceNumberSet.h"

Added: incubator/qpid/trunk/qpid/cpp/src/tests/Array.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Array.cpp?rev=592494&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Array.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Array.cpp Tue Nov  6 09:27:27 2007
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include <iostream>
+#include <sstream>
+#include "qpid/framing/Array.h"
+#include "qpid/framing/FieldValue.h"
+
+#include <boost/test/auto_unit_test.hpp>
+BOOST_AUTO_TEST_SUITE(Array);
+
+using namespace qpid::framing;
+
+void populate(std::vector<std::string>& data, int count = 10)
+{
+    for (int i = 0; i < count; i++) {
+        std::stringstream out;
+        out << "item-" << i;
+        data.push_back(out.str());
+    }
+}
+
+BOOST_AUTO_TEST_CASE(testEncodeDecode)
+{
+    std::vector<std::string> data;
+    populate(data);
+
+    Array a(data);
+
+    char buff[200];
+    Buffer wbuffer(buff, 200);
+    a.encode(wbuffer);
+
+    Array b;
+    Buffer rbuffer(buff, 200);
+    b.decode(rbuffer);
+    BOOST_CHECK_EQUAL(a, b);
+
+    std::vector<std::string> data2;
+    b.collect(data2);
+    //BOOST_CHECK_EQUAL(data, data2);
+    BOOST_CHECK(data == data2);
+}
+
+BOOST_AUTO_TEST_CASE(testAssignment)
+{
+    std::vector<std::string> data;
+    populate(data);
+    Array b;
+    {
+        Array a(data);
+        b = a;
+        BOOST_CHECK_EQUAL(a, b);
+    }        
+    std::vector<std::string> data2;
+    b.collect(data2);
+    //BOOST_CHECK_EQUAL(data, data2);
+    BOOST_CHECK(data == data2);
+}
+
+BOOST_AUTO_TEST_SUITE_END();

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/Array.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/Array.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Tue Nov  6 09:27:27 2007
@@ -31,7 +31,7 @@
        RefCounted.cpp RefCountedMap.cpp \
        SessionState.cpp Blob.cpp logging.cpp \
        Url.cpp Uuid.cpp \
-       Shlib.cpp FieldValue.cpp FieldTable.cpp
+       Shlib.cpp FieldValue.cpp FieldTable.cpp Array.cpp
 
 check_LTLIBRARIES += libshlibtest.la
 libshlibtest_la_LDFLAGS = -module -rpath $(abs_builddir)

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/XAResourceImpl.java
 Tue Nov  6 09:27:27 2007
@@ -335,9 +335,9 @@
         int i = 0;
         try
         {
-            for (String xid : res.getInDoubt().keySet())
+            for (Object xid : res.getInDoubt())
             {
-                result[i] = new XidImpl(xid);
+                result[i] = new XidImpl((String) xid);
                 i++;
             }
         }

Modified: 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/njms/XAResourceImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/njms/XAResourceImpl.java?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/njms/XAResourceImpl.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpidity/njms/XAResourceImpl.java
 Tue Nov  6 09:27:27 2007
@@ -335,9 +335,9 @@
         int i = 0;
         try
         {
-            for (String xid : res.getInDoubt().keySet())
+            for (Object xid : res.getInDoubt())
             {
-                result[i] = new XidImpl(xid);
+                result[i] = new XidImpl((String) xid);
                 i++;
             }
         }

Modified: incubator/qpid/trunk/qpid/python/qpid/codec.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/codec.py?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/codec.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/codec.py Tue Nov  6 09:27:27 2007
@@ -510,6 +510,23 @@
     type = self.spec.structs[codec.decode_short()]
     return codec.decode_struct_body(type)
 
+  def decode_array(self):
+    size = self.decode_long()
+    code = self.decode_octet()
+    count = self.decode_long()
+    result = []
+    for i in range(0, count):
+      if self.types.has_key(code):
+        value = self.decode(self.types[code])
+      else:
+        w = width(code)
+        if fixed(code):
+          value = self.read(w)
+        else:
+          value = self.read(self.dec_num(w))
+      result.append(value)
+    return result
+
 def fixed(code):
   return (code >> 6) != 2
 

Modified: incubator/qpid/trunk/qpid/python/qpid/spec.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/spec.py?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/spec.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/spec.py Tue Nov  6 09:27:27 2007
@@ -255,6 +255,7 @@
               "shortstr": "",
               "longstr": "",
               "table": {},
+              "array": [],
               "octet": 0,
               "short": 0,
               "long": 0,

Modified: incubator/qpid/trunk/qpid/python/tests_0-10/dtx.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/tests_0-10/dtx.py?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/tests_0-10/dtx.py (original)
+++ incubator/qpid/trunk/qpid/python/tests_0-10/dtx.py Tue Nov  6 09:27:27 2007
@@ -304,6 +304,38 @@
         self.assertMessageId("a", "two")
         self.assertMessageId("b", "one")
 
+    def test_suspend_start_end_resume(self):        
+        """
+        Test suspension and resumption of an association with work
+        done on another transaction when the first transaction is
+        suspended
+        """
+        channel = self.channel
+        channel.dtx_demarcation_select()
+
+        #setup
+        channel.queue_declare(queue="one", exclusive=True, auto_delete=True)
+        channel.queue_declare(queue="two", exclusive=True, auto_delete=True)
+        
channel.message_transfer(content=Content(properties={'routing_key':"one", 
'message_id':"a"}, body="DtxMessage"))
+        
channel.message_transfer(content=Content(properties={'routing_key':"two", 
'message_id':"b"}, body="DtxMessage"))
+
+        tx = self.xid("dummy")
+
+        channel.dtx_demarcation_start(xid=tx)
+        self.swap(channel, "one", "two")#swap 'a' from 'one' to 'two'
+        channel.dtx_demarcation_end(xid=tx, suspend=True)
+
+        channel.dtx_demarcation_start(xid=tx, resume=True)
+        self.swap(channel, "two", "one")#swap 'b' from 'two' to 'one'
+        channel.dtx_demarcation_end(xid=tx)
+        
+        #commit and check
+        channel.dtx_coordination_commit(xid=tx, one_phase=True)
+        self.assertMessageCount(1, "one")
+        self.assertMessageCount(1, "two")
+        self.assertMessageId("a", "two")
+        self.assertMessageId("b", "one")
+
     def test_end_suspend_and_fail(self):
         """        
         Verify that the correct error is signalled if the suspend and
@@ -538,18 +570,7 @@
             else:    
                 channel.dtx_coordination_rollback(xid=tx)
 
-        indoubt = channel.dtx_coordination_recover().in_doubt
-        #convert indoubt table to a list of xids (note: this will change for 
0-10)
-        data = indoubt["xids"]
-        xids = []
-        pos = 0
-        while pos < len(data):
-            size = unpack("!B", data[pos])[0]
-            start = pos + 1
-            end = start + size
-            xid = data[start:end]
-            xids.append(xid)
-            pos = end
+        xids = channel.dtx_coordination_recover().in_doubt
         
         #rollback the prepared transactions returned by recover
         for x in xids:
@@ -566,6 +587,16 @@
             for x in missing:
                 channel.dtx_coordination_rollback(xid=x)            
             self.fail("Recovered xids not as expected. missing: %s; extra: %s" 
% (missing, extra))
+
+    def test_bad_resume(self):
+        """
+        Test that a resume on a session not selected for use with dtx fails
+        """
+        channel = self.channel
+        try:
+            channel.dtx_demarcation_start(resume=True)
+        except Closed, e:
+            self.assertConnectionException(503, e.args[0])
 
     def xid(self, txid):
         DtxTests.tx_counter += 1

Modified: incubator/qpid/trunk/qpid/specs/amqp.0-10-preview.xml
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/specs/amqp.0-10-preview.xml?rev=592494&r1=592493&r2=592494&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/specs/amqp.0-10-preview.xml (original)
+++ incubator/qpid/trunk/qpid/specs/amqp.0-10-preview.xml Tue Nov  6 09:27:27 
2007
@@ -1310,6 +1310,7 @@
   <domain name="timestamp" type="timestamp" label="64-bit POSIX timestamp" />
   <domain name="table" type="table" label="field table" />
   <domain name="uuid" type="uuid" label="UUID (RFC4122 section 4.1.2) - 16 
octets" />
+  <domain name="array" type="array" label="array"/>
 
   <domain name="content" type="content" label="message content">
     <doc>
@@ -5912,19 +5913,10 @@
             are in a prepared or heuristically completed state.
           </doc>
 
-          <field name="in-doubt" domain="table" label="Table of xids to be 
recovered">
+          <field name="in-doubt" domain="array" label="array of xids to be 
recovered">
             <doc>
-              Table containing the sequence of xids to be recovered (xids that 
are in a prepared or
-              heuristically completed state).
+              xids to be recovered (xids that are in a prepared or 
heuristically completed state).
             </doc>
-
-            <rule name="xid-sequence">
-              <doc>
-                The field table must contain a field called 'xids' of type 
sequence of longstrs
-                representing the xids that are in a prepared or heuristically 
completed state.
-              </doc>
-            </rule>
-
             <assert check="notnull" />
           </field>
         </struct>


Reply via email to