From c2b15bd68f4e6fe060b29cccd93d249c2314bb17 Mon Sep 17 00:00:00 2001 From: Arnaud Simon Date: Thu, 11 Sep 2008 11:39:47 +0000 Subject: qpid-1277: added tests and fixed rangeSet + future issue because of the nonvariant nature of C# generics git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@694220 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/dotnet/client-010/client/transport/Channel.cs | 3 +- .../client-010/client/transport/ChannelDelegate.cs | 24 ++- qpid/dotnet/client-010/client/transport/Future.cs | 4 +- qpid/dotnet/client-010/client/transport/Range.cs | 44 +++--- .../dotnet/client-010/client/transport/RangeSet.cs | 175 ++++++++++----------- qpid/dotnet/client-010/client/transport/Session.cs | 11 +- .../client/transport/network/io/IoReceiver.cs | 3 +- .../client/transport/util/ResultFuture.cs | 8 +- qpid/dotnet/client-010/default.build | 5 + qpid/dotnet/client-010/gentool/Invoker.tpl | 6 +- qpid/dotnet/client-010/log.xml | 26 +++ qpid/dotnet/client-010/test/interop/Admin.cs | 90 +++++++++++ qpid/dotnet/client-010/test/interop/TestCase.cs | 93 +++++++++++ qpid/dotnet/client-010/test/test.config | 10 ++ .../client-010/test/transport/util/UUIDTest.cs | 21 ++- 15 files changed, 385 insertions(+), 138 deletions(-) create mode 100644 qpid/dotnet/client-010/log.xml create mode 100644 qpid/dotnet/client-010/test/interop/Admin.cs create mode 100644 qpid/dotnet/client-010/test/interop/TestCase.cs create mode 100644 qpid/dotnet/client-010/test/test.config (limited to 'qpid') diff --git a/qpid/dotnet/client-010/client/transport/Channel.cs b/qpid/dotnet/client-010/client/transport/Channel.cs index d7ccc6eec8..6915c123e7 100644 --- a/qpid/dotnet/client-010/client/transport/Channel.cs +++ b/qpid/dotnet/client-010/client/transport/Channel.cs @@ -21,7 +21,6 @@ using System; using org.apache.qpid.transport.network; using org.apache.qpid.transport.util; -using SessionDelegate=org.apache.qpid.transport.SessionDelegate; namespace org.apache.qpid.transport { @@ -162,7 +161,7 @@ namespace org.apache.qpid.transport method(m); } - public override Future invoke(Method m, Future future) + public override Future invoke(Method m, Future future) { throw new Exception("UnsupportedOperation"); } diff --git a/qpid/dotnet/client-010/client/transport/ChannelDelegate.cs b/qpid/dotnet/client-010/client/transport/ChannelDelegate.cs index 5e9fad6e40..34126ddbf4 100644 --- a/qpid/dotnet/client-010/client/transport/ChannelDelegate.cs +++ b/qpid/dotnet/client-010/client/transport/ChannelDelegate.cs @@ -20,14 +20,22 @@ */ namespace org.apache.qpid.transport { - - - /// - /// ChannelDelegate - /// - /// - - class ChannelDelegate : MethodDelegate + /// + /// ChannelDelegate + /// + /// + internal class ChannelDelegate : MethodDelegate { + public override void sessionDetached(Channel channel, SessionDetached closed) + { + channel.closed(); + } + + public override void sessionDetach(Channel channel, SessionDetach dtc) + { + channel.Session.closed(); + channel.sessionDetached(dtc.getName(), SessionDetachCode.NORMAL); + channel.closed(); + } } } \ No newline at end of file diff --git a/qpid/dotnet/client-010/client/transport/Future.cs b/qpid/dotnet/client-010/client/transport/Future.cs index f636e91914..ddb07f1dda 100644 --- a/qpid/dotnet/client-010/client/transport/Future.cs +++ b/qpid/dotnet/client-010/client/transport/Future.cs @@ -24,9 +24,9 @@ namespace org.apache.qpid.transport /// /// Future /// - public interface Future + public interface Future { - T Result + Struct Result { get; set; } diff --git a/qpid/dotnet/client-010/client/transport/Range.cs b/qpid/dotnet/client-010/client/transport/Range.cs index 37e0761794..a5bc4f0488 100644 --- a/qpid/dotnet/client-010/client/transport/Range.cs +++ b/qpid/dotnet/client-010/client/transport/Range.cs @@ -32,66 +32,66 @@ namespace org.apache.qpid.transport public sealed class Range { - private int lower; - private int upper; + private int _lower; + private int _upper; public Range(int lower, int upper) { - this.lower = lower; - this.upper = upper; + _lower = lower; + _upper = upper; } public int Lower { - get { return lower; } - set { lower = value; } + get { return _lower; } + set { _lower = value; } } public int Upper { - get { return upper; } - set { upper = value; } + get { return _upper; } + set { _upper = value; } } public bool includes(int value) { - return Serial.le(lower, value) && Serial.le(value, upper); + return Serial.le(_lower, value) && Serial.le(value, _upper); } public bool includes(Range range) { - return includes(range.lower) && includes(range.upper); + return includes(range._lower) && includes(range._upper); } public bool intersects(Range range) { - return (includes(range.lower) || includes(range.upper) || - range.includes(lower) || range.includes(upper)); + return (includes(range._lower) || includes(range._upper) || + range.includes(_lower) || range.includes(_upper)); } public bool touches(Range range) { return (intersects(range) || - includes(range.upper + 1) || includes(range.lower - 1) || - range.includes(upper + 1) || range.includes(lower - 1)); + includes(range._upper + 1) || includes(range._lower - 1) || + range.includes(_upper + 1) || range.includes(_lower - 1)); } public Range span(Range range) { - return new Range(Serial.min(lower, range.lower), Serial.max(upper, range.upper)); + return new Range(Serial.min(_lower, range._lower), Serial.max(_upper, range._upper)); } public List subtract(Range range) { List result = new List(); - if (includes(range.lower) && Serial.le(lower, range.lower - 1)) + if (includes(range._lower) && Serial.le(_lower, range._lower - 1)) { - result.Add(new Range(lower, range.lower - 1)); + result.Add(new Range(_lower, range._lower - 1)); } - if (includes(range.upper) && Serial.le(range.upper + 1, upper)) + if (includes(range._upper) && Serial.le(range._upper + 1, _upper)) { - result.Add(new Range(range.upper + 1, upper)); + result.Add(new Range(range._upper + 1, _upper)); } if (result.Count == 0 && !range.includes(this)) @@ -104,14 +104,14 @@ namespace org.apache.qpid.transport public Range intersect(Range range) { - int l = Serial.max(lower, range.lower); - int r = Serial.min(upper, range.upper); + int l = Serial.max(_lower, range._lower); + int r = Serial.min(_upper, range._upper); return Serial.gt(l, r) ? null : new Range(l, r); } public String toString() { - return "[" + lower + ", " + upper + "]"; + return "[" + _lower + ", " + _upper + "]"; } } } \ No newline at end of file diff --git a/qpid/dotnet/client-010/client/transport/RangeSet.cs b/qpid/dotnet/client-010/client/transport/RangeSet.cs index d0ee1d4916..0c502541ec 100644 --- a/qpid/dotnet/client-010/client/transport/RangeSet.cs +++ b/qpid/dotnet/client-010/client/transport/RangeSet.cs @@ -27,127 +27,124 @@ using org.apache.qpid.transport.util; namespace org.apache.qpid.transport { - - - /// + /// /// RangeSet - /// - - public sealed class RangeSet : IEnumerable - { - private readonly LinkedList ranges = new LinkedList(); + /// + public sealed class RangeSet : IEnumerable + { + private readonly List _ranges = new List(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } - public IEnumerator GetEnumerator() - { - return ranges.GetEnumerator(); - } + public IEnumerator GetEnumerator() + { + return _ranges.GetEnumerator(); + } - public int size() - { - return ranges.Count; - } + public int size() + { + return _ranges.Count; + } - - public Range getFirst() - { - return ranges.First.Value; - } + public Range getFirst() + { + return _ranges[0]; + } - public bool includes(Range range) - { - foreach (Range r in this) + public bool includes(Range range) { - if (r.includes(range)) + foreach (Range r in this) { - return true; + if (r.includes(range)) + { + return true; + } } - } - return false; - } + return false; + } - public bool includes(int n) - { - foreach (Range r in this) + public bool includes(int n) { - if (r.includes(n)) + foreach (Range r in this) { - return true; + if (r.includes(n)) + { + return true; + } } - } - return false; - } + return false; + } - public void add(Range range) - { - foreach (Range r in ranges) + public void add(Range range) { - if (range.touches(r)) + for (int i = 0; i < _ranges.Count; i++) { - ranges.Remove(r); - range = range.span(r); - } - else if (Serial.lt(range.Upper, r.Lower )) - { - ranges.AddBefore(ranges.Find(r), range); - return; + Range r = _ranges[i]; + if (range.touches(r)) + { + _ranges.Remove(r); + range = range.span(r); + } + else if (Serial.lt(range.Upper, r.Lower)) + { + _ranges.Insert(i - 1 , range); + return; + } } + _ranges.Add(range); } - ranges.AddLast(range); - } - - public void add(int lower, int upper) - { - add(new Range(lower, upper)); - } - public void add(int value) - { - add(value, value); - } + public void add(int lower, int upper) + { + add(new Range(lower, upper)); + } - public void clear() - { - ranges.Clear(); - } + public void add(int value) + { + add(value, value); + } - public RangeSet copy() - { - RangeSet copy = new RangeSet(); - foreach( Range r in ranges) + public void clear() { - copy.ranges.AddLast(r); - } - return copy; - } + _ranges.Clear(); + } - public String toString() - { - StringBuilder str = new StringBuilder(); - str.Append("{"); - bool first = true; - foreach (Range range in ranges) + public RangeSet copy() { - if (first) + RangeSet copy = new RangeSet(); + foreach (Range r in _ranges) { - first = false; + copy._ranges.Add(r); } - else + return copy; + } + + public String toString() + { + StringBuilder str = new StringBuilder(); + str.Append("{"); + bool first = true; + foreach (Range range in _ranges) { - str.Append(", "); + if (first) + { + first = false; + } + else + { + str.Append(", "); + } + str.Append(range); } - str.Append(range); + str.Append("}"); + return str.ToString(); } - str.Append("}"); - return str.ToString(); } - } } \ No newline at end of file diff --git a/qpid/dotnet/client-010/client/transport/Session.cs b/qpid/dotnet/client-010/client/transport/Session.cs index 54c5c2c462..81c984bb4d 100644 --- a/qpid/dotnet/client-010/client/transport/Session.cs +++ b/qpid/dotnet/client-010/client/transport/Session.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Threading; +using common.org.apache.qpid.transport.util; using org.apache.qpid.transport; using org.apache.qpid.transport.util; using Frame = org.apache.qpid.transport.network.Frame; @@ -77,7 +78,7 @@ namespace org.apache.qpid.transport private int _maxComplete = - 1; private bool _needSync = false; private bool _closed; - private readonly Dictionary> _results = new Dictionary>(); + private readonly Dictionary _results = new Dictionary(); private readonly List _exceptions = new List(); @@ -383,7 +384,7 @@ namespace org.apache.qpid.transport public void result(int command, Struct result) { - Future future; + Future future; lock (_results) { if (_results.ContainsKey(command)) @@ -422,7 +423,7 @@ namespace org.apache.qpid.transport } } - public override Future invoke(Method m, Future future) + public override Future invoke(Method m, Future future) { lock (_commands) { @@ -430,7 +431,7 @@ namespace org.apache.qpid.transport int command = _commandsOut; lock (_results) { - _results.Add(command, (Future) future); + _results.Add(command, future); } invoke(m); } @@ -493,7 +494,7 @@ namespace org.apache.qpid.transport } lock (_results) { - foreach (Future result in _results.Values) + foreach (Future result in _results.Values) { lock (result) { diff --git a/qpid/dotnet/client-010/client/transport/network/io/IoReceiver.cs b/qpid/dotnet/client-010/client/transport/network/io/IoReceiver.cs index b4544fe072..d71093ea55 100644 --- a/qpid/dotnet/client-010/client/transport/network/io/IoReceiver.cs +++ b/qpid/dotnet/client-010/client/transport/network/io/IoReceiver.cs @@ -168,8 +168,7 @@ namespace org.apache.qpid.transport.network.io log.debug("Receiver thread terminating"); } catch (Exception t) - { - Console.WriteLine(t); + { if (ExceptionReading != null) { ExceptionReading(this, new ExceptionArgs(t)); diff --git a/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs b/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs index 8a38cdb356..11e57ed821 100644 --- a/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs +++ b/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs @@ -5,12 +5,12 @@ using org.apache.qpid.transport.util; namespace common.org.apache.qpid.transport.util { - public class ResultFuture : Future where T : Struct + public class ResultFuture : Future { const long _timeout = 60000; private Struct _result; private Session _session; - private static readonly Logger log = Logger.get(typeof(ResultFuture)); + private static readonly Logger log = Logger.get(typeof(ResultFuture)); public Struct get(long timeout) { @@ -32,9 +32,9 @@ namespace common.org.apache.qpid.transport.util return _result; } - public T Result + public Struct Result { - get { return (T) get(_timeout); } + get { return get(_timeout); } set { lock (this) diff --git a/qpid/dotnet/client-010/default.build b/qpid/dotnet/client-010/default.build index 095b6de2e9..74d53f1f35 100644 --- a/qpid/dotnet/client-010/default.build +++ b/qpid/dotnet/client-010/default.build @@ -155,6 +155,11 @@ + + + + + diff --git a/qpid/dotnet/client-010/gentool/Invoker.tpl b/qpid/dotnet/client-010/gentool/Invoker.tpl index f1909d2e29..96f58b49ea 100644 --- a/qpid/dotnet/client-010/gentool/Invoker.tpl +++ b/qpid/dotnet/client-010/gentool/Invoker.tpl @@ -9,7 +9,7 @@ namespace org.apache.qpid.transport public abstract class Invoker { protected abstract void invoke(Method method); - public abstract Future invoke(Method method, Future resultClass); + public abstract Future invoke(Method method, Future resultClass); ${ from dotnetgenutil import * @@ -25,9 +25,9 @@ for c in composites: rname = cname(result["struct"]) else: rname = cname(result, "@type") - jresult = "Future<%s>" % rname + jresult = "Future" jreturn = "return " - jclass = ", new ResultFuture<%s>()" % rname + jclass = ", new ResultFuture()" jinvoke = "invoke" else: jinvoke = "invoke" diff --git a/qpid/dotnet/client-010/log.xml b/qpid/dotnet/client-010/log.xml new file mode 100644 index 0000000000..12365f7eb8 --- /dev/null +++ b/qpid/dotnet/client-010/log.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qpid/dotnet/client-010/test/interop/Admin.cs b/qpid/dotnet/client-010/test/interop/Admin.cs new file mode 100644 index 0000000000..93b24ea505 --- /dev/null +++ b/qpid/dotnet/client-010/test/interop/Admin.cs @@ -0,0 +1,90 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +* +*/ + +using NUnit.Framework; +using org.apache.qpid.client; +using org.apache.qpid.transport; +using org.apache.qpid.transport.util; + +namespace test.interop +{ + public class Admin:TestCase + { + private static readonly Logger _log = Logger.get(typeof(Admin)); + + [Test] + public void createSession() + { + _log.debug("Running: createSession"); + ClientSession ssn = Client.createSession(0); + ssn.close(); + // This test fails if an exception is thrown + } + + [Test] + public void queueLifecycle() + { + _log.debug("Running: queueLifecycle"); + ClientSession ssn = Client.createSession(0); + ssn.queueDeclare("queue1", null, null); + ssn.sync(); + ssn.queueDelete("queue1"); + ssn.sync(); + try + { + ssn.exchangeBind("queue1", "amq.direct", "queue1", null); + ssn.sync(); + } + catch (SessionException e) + { + // as expected + } + // This test fails if an exception is thrown + } + + [Test] + public void exchangeCheck() + { + _log.debug("Running: exchangeCheck"); + ClientSession ssn = Client.createSession(0); + ExchangeQueryResult query = (ExchangeQueryResult) ssn.exchangeQuery("amq.direct").Result; + Assert.IsFalse(query.getNotFound()); + Assert.IsTrue(query.getDurable()); + query = (ExchangeQueryResult)ssn.exchangeQuery("amq.topic").Result; + Assert.IsFalse(query.getNotFound()); + Assert.IsTrue(query.getDurable()); + query = (ExchangeQueryResult) ssn.exchangeQuery("foo").Result; + Assert.IsTrue(query.getNotFound()); + } + + [Test] + public void exchangeBind() + { + _log.debug("Running: exchangeBind"); + ClientSession ssn = Client.createSession(0); + ssn.queueDeclare("queue1", null, null); + ssn.exchangeBind("queue1", "amq.direct", "queue1", null); + // This test fails if an exception is thrown + } + + + } +} diff --git a/qpid/dotnet/client-010/test/interop/TestCase.cs b/qpid/dotnet/client-010/test/interop/TestCase.cs new file mode 100644 index 0000000000..02f5a327f6 --- /dev/null +++ b/qpid/dotnet/client-010/test/interop/TestCase.cs @@ -0,0 +1,93 @@ +/* +* +* 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 System.Collections.Generic; +using System.IO; +using System.Xml; +using log4net.Config; +using NUnit.Framework; +using org.apache.qpid.client; + +namespace test.interop +{ + [TestFixture] + + public class TestCase + { + private readonly Dictionary _properties = new Dictionary(); + private Client _client; + + [TestFixtureSetUp] + public void Init() + { + XmlConfigurator.Configure(new FileInfo(".\\log.xml")); + // populate default properties + _properties.Add("UserName", "guest"); + _properties.Add("Password", "guest"); + _properties.Add("Host", "192.168.1.14"); + _properties.Add("Port", "5673"); + _properties.Add("VirtualHost", "test"); + //Read the test config file + XmlTextReader reader = new XmlTextReader(Environment.CurrentDirectory + ".\\test.config"); + while (reader.Read()) + { + XmlNodeType nType = reader.NodeType; + // if node type is an element + if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("add")) + { + Console.WriteLine("Element:" + reader.Name.ToString()); + if (_properties.ContainsKey(reader.GetAttribute("key"))) + { + _properties[reader.GetAttribute("key")] = reader.GetAttribute("value"); + } + else + { + _properties.Add(reader.GetAttribute("key"), reader.GetAttribute("value")); + } + + } + } + // create a client and connect to the broker + _client = new Client(); + _client.connect(Properties["Host"], Convert.ToInt16(Properties["Port"]), Properties["VirtualHost"], + Properties["UserName"], Properties["Password"]); + + } + + [TestFixtureTearDown] + public void Cleanup() + { + _client.close(); + } + + public Client Client + { + get{ return _client;} + } + + public Dictionary Properties + { + get { return _properties; } + } + + } +} diff --git a/qpid/dotnet/client-010/test/test.config b/qpid/dotnet/client-010/test/test.config new file mode 100644 index 0000000000..dc284f25f1 --- /dev/null +++ b/qpid/dotnet/client-010/test/test.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/qpid/dotnet/client-010/test/transport/util/UUIDTest.cs b/qpid/dotnet/client-010/test/transport/util/UUIDTest.cs index 6ece267e07..c073f1139a 100644 --- a/qpid/dotnet/client-010/test/transport/util/UUIDTest.cs +++ b/qpid/dotnet/client-010/test/transport/util/UUIDTest.cs @@ -1,4 +1,23 @@ - +/* +* +* 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 NUnit.Framework; using org.apache.qpid.transport.util; -- cgit v1.2.1