You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ar...@apache.org on 2008/10/02 14:34:46 UTC
svn commit: r701107 - in /incubator/qpid/trunk/qpid/dotnet/client-010:
client/ client/transport/codec/ client/transport/util/ test/ test/interop/
Author: arnaudsimon
Date: Thu Oct 2 05:34:45 2008
New Revision: 701107
URL: http://svn.apache.org/viewvc?rev=701107&view=rev
Log:
qpid-1277: fixed header conversion issues + added test
Added:
incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs
Modified:
incubator/qpid/trunk/qpid/dotnet/client-010/client/client.suo
incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs
incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs
incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs
incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs
incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs
incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs
incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj
incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/TestCase.cs
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/client.suo
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/client.suo?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
Binary files - no diff available.
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractDecoder.cs Thu Oct 2 05:34:45 2008
@@ -341,17 +341,17 @@
case Code.INT32:
return (int) readUint32();
- case Code.FLOAT:
- return (float) readUint32();
-
+ case Code.FLOAT:
+ return (float)BitConverter.Int64BitsToDouble(readUint32() << 32);
+
case Code.BIN64:
case Code.UINT64:
case Code.INT64:
case Code.DATETIME:
return readUint64();
- case Code.DOUBLE:
- return (double) readUint64();
+ case Code.DOUBLE:
+ return BitConverter.Int64BitsToDouble(readUint64());
case Code.UUID:
return readUuid();
case Code.STR8:
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs Thu Oct 2 05:34:45 2008
@@ -23,7 +23,6 @@
using System.Diagnostics;
using System.IO;
using System.Text;
-using org.apache.qpid.transport.codec;
using org.apache.qpid.transport.util;
namespace org.apache.qpid.transport.codec
@@ -482,7 +481,8 @@
put((Byte) value);
break;
case Code.CHAR:
- put((byte) value);
+ byte[] b = BitConverter.GetBytes((char) value);
+ put(b[0]);
break;
case Code.BOOLEAN:
if ((bool) value)
@@ -516,18 +516,18 @@
break;
case Code.FLOAT:
- writeUint32((long) value);
+ writeUint32(BitConverter.DoubleToInt64Bits((float) value) >> 32);
break;
case Code.BIN64:
case Code.UINT64:
- case Code.INT64:
+ case Code.INT64:
case Code.DATETIME:
writeUint64((long) value);
break;
case Code.DOUBLE:
- writeUint64((long) value);
+ writeUint64( BitConverter.DoubleToInt64Bits((double) value));
break;
case Code.UUID:
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs Thu Oct 2 05:34:45 2008
@@ -76,7 +76,7 @@
public override long readUint64()
{
- return (long) ByteEncoder.GetBigEndian((Double) reader.ReadInt64());
+ return (long) ByteEncoder.GetBigEndian(reader.ReadInt64());
}
}
}
\ No newline at end of file
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs Thu Oct 2 05:34:45 2008
@@ -90,7 +90,7 @@
public override void writeUint64(long l)
{
- _writer.Write(ByteEncoder.GetBigEndian((Double) l));
+ _writer.Write(ByteEncoder.GetBigEndian(l));
}
protected override int beginSize8()
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs Thu Oct 2 05:34:45 2008
@@ -63,7 +63,7 @@
/// </summary>
/// <param name="value">Value to encode.</param>
/// <returns>Big-endian encoded value.</returns>
- public static Double GetBigEndian(Double value)
+ public static long GetBigEndian(long value)
{
if (BitConverter.IsLittleEndian)
{
@@ -131,7 +131,7 @@
/// </summary>
/// <param name="value">Value to encode.</param>
/// <returns>Little-endian encoded value.</returns>
- public static Double GetLittleEndian(Double value)
+ public static Double GetLittleEndian(long value)
{
if (BitConverter.IsLittleEndian)
{
@@ -187,11 +187,11 @@
/// </summary>
/// <param name="value"><see cref="Double"/> to swap.</param>
/// <returns>Byte order swapped <see cref="Double"/> value.</returns>
- private static Double swapByteOrder(Double value)
+ private static long swapByteOrder(long value)
{
Byte[] buffer = BitConverter.GetBytes(value);
Array.Reverse(buffer, 0, buffer.Length);
- return BitConverter.ToDouble(buffer, 0);
+ return BitConverter.ToInt64(buffer, 0);
}
#endregion
}
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/CircularBuffer.cs Thu Oct 2 05:34:45 2008
@@ -24,7 +24,7 @@
namespace common.org.apache.qpid.transport.util
{
- internal class CircularBuffer<T>
+ public class CircularBuffer<T>
{
private readonly T[] buffer;
private Int32 nrp, nwp;
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj Thu Oct 2 05:34:45 2008
@@ -42,6 +42,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="interop\Admin.cs" />
+ <Compile Include="interop\ApplicationHeaders.cs" />
<Compile Include="interop\Message.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="interop\TestCase.cs" />
Added: incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs?rev=701107&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs (added)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/ApplicationHeaders.cs Thu Oct 2 05:34:45 2008
@@ -0,0 +1,83 @@
+/*
+*
+* 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.
+*
+*/
+using System;
+using common.org.apache.qpid.transport.util;
+using NUnit.Framework;
+using org.apache.qpid.client;
+using org.apache.qpid.transport.util;
+
+namespace test.interop
+{
+ public class ApplicationHeaders:TestCase
+ {
+ private static readonly Logger _log = Logger.get(typeof(ApplicationHeaders));
+
+ [Test]
+ public void setHeaders()
+ {
+ _log.debug("Running: setHeaders");
+ ClientSession ssn = Client.createSession(0);
+ ssn.queueDeclare("queue1");
+ ssn.exchangeBind("queue1", "amq.direct", "queue1");
+ ssn.sync();
+ CircularBuffer<IMessage> buff = new CircularBuffer<IMessage>(10);
+ SyncListener listener = new SyncListener(ssn, buff);
+ ssn.attachMessageListener(listener, "queue1");
+ ssn.messageSubscribe("queue1");
+
+ IMessage message = new org.apache.qpid.client.Message();
+ message.DeliveryProperties.setRoutingKey("queue1");
+ const long someLong = 14444444;
+ message.ApplicationHeaders.Add("someLong", someLong);
+ const int someInt = 14;
+ message.ApplicationHeaders.Add("soneInt", someInt);
+ const float someFloat = 14.001F;
+ message.ApplicationHeaders.Add("soneFloat", someFloat);
+ const double someDouble = 14.5555555;
+ message.ApplicationHeaders.Add("someDouble", someDouble);
+ const byte someByte = 2;
+ message.ApplicationHeaders.Add("someByte", someByte);
+ const string someString = "someString";
+ message.ApplicationHeaders.Add("someString", someString);
+ const char someChar = 'a';
+ message.ApplicationHeaders.Add("someChar", someChar);
+ const Boolean someBoolean = true;
+ message.ApplicationHeaders.Add("someBoolean", someBoolean);
+
+ // transfer the message
+ ssn.messageTransfer("amq.direct", message);
+
+ // get the message and check the headers
+ IMessage messageBack = buff.Dequeue();
+ Assert.IsTrue(((string) messageBack.ApplicationHeaders["someString"]).Equals(someString));
+ Assert.IsTrue(((char)messageBack.ApplicationHeaders["someChar"]).Equals(someChar));
+ Assert.IsTrue((long)messageBack.ApplicationHeaders["someLong"] == someLong);
+ Assert.IsTrue((int)messageBack.ApplicationHeaders["soneInt"] == someInt);
+ Assert.IsTrue((double)messageBack.ApplicationHeaders["someDouble"] == someDouble);
+ Assert.IsTrue((byte) messageBack.ApplicationHeaders["someByte"] == someByte);
+ Assert.IsTrue((Boolean)messageBack.ApplicationHeaders["someBoolean"]);
+ // c# has an conversion precision issue with decimal
+ Assert.IsTrue((float) messageBack.ApplicationHeaders["soneFloat"] <= someFloat);
+ float b = (float) messageBack.ApplicationHeaders["soneFloat"];
+ Assert.IsTrue(Convert.ToInt32(b) == Convert.ToInt32(someFloat));
+ }
+ }
+}
Modified: incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/TestCase.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/TestCase.cs?rev=701107&r1=701106&r2=701107&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/TestCase.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/test/interop/TestCase.cs Thu Oct 2 05:34:45 2008
@@ -22,10 +22,14 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Threading;
using System.Xml;
+using common.org.apache.qpid.transport.util;
using log4net.Config;
using NUnit.Framework;
using org.apache.qpid.client;
+using org.apache.qpid.transport;
+using org.apache.qpid.transport.util;
namespace test.interop
{
@@ -85,7 +89,29 @@
public Dictionary<string,string> Properties
{
get { return _properties; }
- }
+ }
+
+ public class SyncListener : IMessageListener
+ {
+ private static readonly Logger _log = Logger.get(typeof(SyncListener));
+ private readonly CircularBuffer<IMessage> _buffer;
+ private readonly RangeSet _range = new RangeSet();
+ private readonly ClientSession _session;
+
+ public SyncListener(ClientSession session, CircularBuffer<IMessage> buffer)
+ {
+ _buffer = buffer;
+ _session = session;
+ }
+
+ public void messageTransfer(IMessage m)
+ {
+ _range.clear();
+ _range.add(m.Id);
+ _session.messageAccept(_range);
+ _buffer.Enqueue(m);
+ }
+ }
}
}