From 10f23aca8dab83f51cb4fce341dc7fef7dac44b9 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 29 Jul 2008 19:03:34 +0000 Subject: QPID-1072: renamed org.apache.qpidity -> org.apache.qpid git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@680803 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/transport/ConnectionTest.java | 118 ++++++++++ .../org/apache/qpid/transport/RangeSetTest.java | 238 +++++++++++++++++++++ .../apache/qpidity/transport/ConnectionTest.java | 118 ---------- .../org/apache/qpidity/transport/RangeSetTest.java | 238 --------------------- 4 files changed, 356 insertions(+), 356 deletions(-) create mode 100644 java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java create mode 100644 java/common/src/test/java/org/apache/qpid/transport/RangeSetTest.java delete mode 100644 java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java delete mode 100644 java/common/src/test/java/org/apache/qpidity/transport/RangeSetTest.java (limited to 'java/common/src/test') diff --git a/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java b/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java new file mode 100644 index 0000000000..a211b1d937 --- /dev/null +++ b/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java @@ -0,0 +1,118 @@ +/* + * + * 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.transport; + +import org.apache.mina.util.AvailablePortFinder; + +import org.apache.qpid.util.concurrent.Condition; + +import org.apache.qpid.transport.network.io.IoTransport; +import org.apache.qpid.transport.network.mina.MinaHandler; +import org.apache.qpid.transport.util.Logger; + +import junit.framework.TestCase; + +import java.util.Random; + +/** + * ConnectionTest + */ + +public class ConnectionTest extends TestCase +{ + + private static final Logger log = Logger.get(ConnectionTest.class); + + private int port; + + protected void setUp() throws Exception + { + super.setUp(); + + port = AvailablePortFinder.getNextAvailable(12000); + + ConnectionDelegate server = new ConnectionDelegate() { + public void init(Channel ch, ProtocolHeader hdr) { + ch.getConnection().close(); + } + + public SessionDelegate getSessionDelegate() { + return new SessionDelegate() {}; + } + public void exception(Throwable t) { + log.error(t, "exception caught"); + } + public void closed() {} + }; + + MinaHandler.accept("localhost", port, server); + } + + private Connection connect(final Condition closed) + { + Connection conn = IoTransport.connect("localhost", port, new ConnectionDelegate() + { + public SessionDelegate getSessionDelegate() + { + return new SessionDelegate() {}; + } + public void exception(Throwable t) + { + t.printStackTrace(); + } + public void closed() + { + if (closed != null) + { + closed.set(); + } + } + }); + + conn.send(new ProtocolHeader(1, 0, 10)); + return conn; + } + + public void testClosedNotificationAndWriteToClosed() throws Exception + { + Condition closed = new Condition(); + Connection conn = connect(closed); + if (!closed.get(3000)) + { + fail("never got notified of connection close"); + } + + Channel ch = conn.getChannel(0); + Session ssn = new Session("test".getBytes()); + ssn.attach(ch); + + try + { + ssn.sessionAttach(ssn.getName()); + fail("writing to a closed socket succeeded"); + } + catch (TransportException e) + { + // expected + } + } + +} diff --git a/java/common/src/test/java/org/apache/qpid/transport/RangeSetTest.java b/java/common/src/test/java/org/apache/qpid/transport/RangeSetTest.java new file mode 100644 index 0000000000..ad45d00e46 --- /dev/null +++ b/java/common/src/test/java/org/apache/qpid/transport/RangeSetTest.java @@ -0,0 +1,238 @@ +/* + * + * 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.transport; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import junit.framework.TestCase; + +import static org.apache.qpid.util.Serial.*; + +/** + * RangeSetTest + * + */ + +public class RangeSetTest extends TestCase +{ + + private void check(RangeSet ranges) + { + List posts = new ArrayList(); + for (Range range : ranges) + { + posts.add(range.getLower()); + posts.add(range.getUpper()); + } + + List sorted = new ArrayList(posts); + Collections.sort(sorted, COMPARATOR); + + assertEquals(posts, sorted); + + int idx = 1; + while (idx + 1 < posts.size()) + { + assertTrue(!eq(posts.get(idx) + 1, posts.get(idx+1))); + idx += 2; + } + } + + public void test1() + { + RangeSet ranges = new RangeSet(); + ranges.add(5, 10); + check(ranges); + ranges.add(15, 20); + check(ranges); + ranges.add(23, 25); + check(ranges); + ranges.add(12, 14); + check(ranges); + ranges.add(0, 1); + check(ranges); + ranges.add(3, 11); + check(ranges); + } + + public void test2() + { + RangeSet rs = new RangeSet(); + check(rs); + + rs.add(1); + assertTrue(rs.includes(1)); + assertTrue(!rs.includes(2)); + assertTrue(!rs.includes(0)); + check(rs); + + rs.add(2); + assertTrue(!rs.includes(0)); + assertTrue(rs.includes(1)); + assertTrue(rs.includes(2)); + assertTrue(!rs.includes(3)); + check(rs); + + rs.add(0); + + assertTrue(!rs.includes(-1)); + assertTrue(rs.includes(0)); + assertTrue(rs.includes(1)); + assertTrue(rs.includes(2)); + assertTrue(!rs.includes(3)); + check(rs); + + rs.add(37); + + assertTrue(!rs.includes(-1)); + assertTrue(rs.includes(0)); + assertTrue(rs.includes(1)); + assertTrue(rs.includes(2)); + assertTrue(!rs.includes(3)); + assertTrue(!rs.includes(36)); + assertTrue(rs.includes(37)); + assertTrue(!rs.includes(38)); + check(rs); + + rs.add(-1); + check(rs); + + rs.add(-3); + check(rs); + + rs.add(1, 20); + assertTrue(!rs.includes(21)); + assertTrue(rs.includes(20)); + check(rs); + } + + public void testAddSelf() + { + RangeSet a = new RangeSet(); + a.add(0, 8); + check(a); + a.add(0, 8); + check(a); + assertEquals(a.size(), 1); + Range range = a.iterator().next(); + assertEquals(range.getLower(), 0); + assertEquals(range.getUpper(), 8); + } + + public void testIntersect1() + { + Range a = new Range(0, 10); + Range b = new Range(9, 20); + Range i1 = a.intersect(b); + Range i2 = b.intersect(a); + assertEquals(i1.getUpper(), 10); + assertEquals(i2.getUpper(), 10); + assertEquals(i1.getLower(), 9); + assertEquals(i2.getLower(), 9); + } + + public void testIntersect2() + { + Range a = new Range(0, 10); + Range b = new Range(11, 20); + assertNull(a.intersect(b)); + assertNull(b.intersect(a)); + } + + public void testIntersect3() + { + Range a = new Range(0, 10); + Range b = new Range(3, 5); + Range i1 = a.intersect(b); + Range i2 = b.intersect(a); + assertEquals(i1.getUpper(), 5); + assertEquals(i2.getUpper(), 5); + assertEquals(i1.getLower(), 3); + assertEquals(i2.getLower(), 3); + } + + public void testSubtract1() + { + Range a = new Range(0, 10); + assertTrue(a.subtract(a).isEmpty()); + } + + public void testSubtract2() + { + Range a = new Range(0, 10); + Range b = new Range(20, 30); + List ranges = a.subtract(b); + assertEquals(ranges.size(), 1); + Range d = ranges.get(0); + assertEquals(d.getLower(), a.getLower()); + assertEquals(d.getUpper(), a.getUpper()); + } + + public void testSubtract3() + { + Range a = new Range(20, 30); + Range b = new Range(0, 10); + List ranges = a.subtract(b); + assertEquals(ranges.size(), 1); + Range d = ranges.get(0); + assertEquals(d.getLower(), a.getLower()); + assertEquals(d.getUpper(), a.getUpper()); + } + + public void testSubtract4() + { + Range a = new Range(0, 10); + Range b = new Range(3, 5); + List ranges = a.subtract(b); + assertEquals(ranges.size(), 2); + Range low = ranges.get(0); + Range high = ranges.get(1); + assertEquals(low.getLower(), 0); + assertEquals(low.getUpper(), 2); + assertEquals(high.getLower(), 6); + assertEquals(high.getUpper(), 10); + } + + public void testSubtract5() + { + Range a = new Range(0, 10); + Range b = new Range(3, 20); + List ranges = a.subtract(b); + assertEquals(ranges.size(), 1); + Range d = ranges.get(0); + assertEquals(d.getLower(), 0); + assertEquals(d.getUpper(), 2); + } + + public void testSubtract6() + { + Range a = new Range(0, 10); + Range b = new Range(-10, 5); + List ranges = a.subtract(b); + assertEquals(ranges.size(), 1); + Range d = ranges.get(0); + assertEquals(d.getLower(), 6); + assertEquals(d.getUpper(), 10); + } + +} diff --git a/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java b/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java deleted file mode 100644 index c604aaf3e4..0000000000 --- a/java/common/src/test/java/org/apache/qpidity/transport/ConnectionTest.java +++ /dev/null @@ -1,118 +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.qpidity.transport; - -import org.apache.mina.util.AvailablePortFinder; - -import org.apache.qpid.util.concurrent.Condition; - -import org.apache.qpidity.transport.network.io.IoTransport; -import org.apache.qpidity.transport.network.mina.MinaHandler; -import org.apache.qpidity.transport.util.Logger; - -import junit.framework.TestCase; - -import java.util.Random; - -/** - * ConnectionTest - */ - -public class ConnectionTest extends TestCase -{ - - private static final Logger log = Logger.get(ConnectionTest.class); - - private int port; - - protected void setUp() throws Exception - { - super.setUp(); - - port = AvailablePortFinder.getNextAvailable(12000); - - ConnectionDelegate server = new ConnectionDelegate() { - public void init(Channel ch, ProtocolHeader hdr) { - ch.getConnection().close(); - } - - public SessionDelegate getSessionDelegate() { - return new SessionDelegate() {}; - } - public void exception(Throwable t) { - log.error(t, "exception caught"); - } - public void closed() {} - }; - - MinaHandler.accept("localhost", port, server); - } - - private Connection connect(final Condition closed) - { - Connection conn = IoTransport.connect("localhost", port, new ConnectionDelegate() - { - public SessionDelegate getSessionDelegate() - { - return new SessionDelegate() {}; - } - public void exception(Throwable t) - { - t.printStackTrace(); - } - public void closed() - { - if (closed != null) - { - closed.set(); - } - } - }); - - conn.send(new ProtocolHeader(1, 0, 10)); - return conn; - } - - public void testClosedNotificationAndWriteToClosed() throws Exception - { - Condition closed = new Condition(); - Connection conn = connect(closed); - if (!closed.get(3000)) - { - fail("never got notified of connection close"); - } - - Channel ch = conn.getChannel(0); - Session ssn = new Session("test".getBytes()); - ssn.attach(ch); - - try - { - ssn.sessionAttach(ssn.getName()); - fail("writing to a closed socket succeeded"); - } - catch (TransportException e) - { - // expected - } - } - -} diff --git a/java/common/src/test/java/org/apache/qpidity/transport/RangeSetTest.java b/java/common/src/test/java/org/apache/qpidity/transport/RangeSetTest.java deleted file mode 100644 index 474d47d8d7..0000000000 --- a/java/common/src/test/java/org/apache/qpidity/transport/RangeSetTest.java +++ /dev/null @@ -1,238 +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.qpidity.transport; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import junit.framework.TestCase; - -import static org.apache.qpid.util.Serial.*; - -/** - * RangeSetTest - * - */ - -public class RangeSetTest extends TestCase -{ - - private void check(RangeSet ranges) - { - List posts = new ArrayList(); - for (Range range : ranges) - { - posts.add(range.getLower()); - posts.add(range.getUpper()); - } - - List sorted = new ArrayList(posts); - Collections.sort(sorted, COMPARATOR); - - assertEquals(posts, sorted); - - int idx = 1; - while (idx + 1 < posts.size()) - { - assertTrue(!eq(posts.get(idx) + 1, posts.get(idx+1))); - idx += 2; - } - } - - public void test1() - { - RangeSet ranges = new RangeSet(); - ranges.add(5, 10); - check(ranges); - ranges.add(15, 20); - check(ranges); - ranges.add(23, 25); - check(ranges); - ranges.add(12, 14); - check(ranges); - ranges.add(0, 1); - check(ranges); - ranges.add(3, 11); - check(ranges); - } - - public void test2() - { - RangeSet rs = new RangeSet(); - check(rs); - - rs.add(1); - assertTrue(rs.includes(1)); - assertTrue(!rs.includes(2)); - assertTrue(!rs.includes(0)); - check(rs); - - rs.add(2); - assertTrue(!rs.includes(0)); - assertTrue(rs.includes(1)); - assertTrue(rs.includes(2)); - assertTrue(!rs.includes(3)); - check(rs); - - rs.add(0); - - assertTrue(!rs.includes(-1)); - assertTrue(rs.includes(0)); - assertTrue(rs.includes(1)); - assertTrue(rs.includes(2)); - assertTrue(!rs.includes(3)); - check(rs); - - rs.add(37); - - assertTrue(!rs.includes(-1)); - assertTrue(rs.includes(0)); - assertTrue(rs.includes(1)); - assertTrue(rs.includes(2)); - assertTrue(!rs.includes(3)); - assertTrue(!rs.includes(36)); - assertTrue(rs.includes(37)); - assertTrue(!rs.includes(38)); - check(rs); - - rs.add(-1); - check(rs); - - rs.add(-3); - check(rs); - - rs.add(1, 20); - assertTrue(!rs.includes(21)); - assertTrue(rs.includes(20)); - check(rs); - } - - public void testAddSelf() - { - RangeSet a = new RangeSet(); - a.add(0, 8); - check(a); - a.add(0, 8); - check(a); - assertEquals(a.size(), 1); - Range range = a.iterator().next(); - assertEquals(range.getLower(), 0); - assertEquals(range.getUpper(), 8); - } - - public void testIntersect1() - { - Range a = new Range(0, 10); - Range b = new Range(9, 20); - Range i1 = a.intersect(b); - Range i2 = b.intersect(a); - assertEquals(i1.getUpper(), 10); - assertEquals(i2.getUpper(), 10); - assertEquals(i1.getLower(), 9); - assertEquals(i2.getLower(), 9); - } - - public void testIntersect2() - { - Range a = new Range(0, 10); - Range b = new Range(11, 20); - assertNull(a.intersect(b)); - assertNull(b.intersect(a)); - } - - public void testIntersect3() - { - Range a = new Range(0, 10); - Range b = new Range(3, 5); - Range i1 = a.intersect(b); - Range i2 = b.intersect(a); - assertEquals(i1.getUpper(), 5); - assertEquals(i2.getUpper(), 5); - assertEquals(i1.getLower(), 3); - assertEquals(i2.getLower(), 3); - } - - public void testSubtract1() - { - Range a = new Range(0, 10); - assertTrue(a.subtract(a).isEmpty()); - } - - public void testSubtract2() - { - Range a = new Range(0, 10); - Range b = new Range(20, 30); - List ranges = a.subtract(b); - assertEquals(ranges.size(), 1); - Range d = ranges.get(0); - assertEquals(d.getLower(), a.getLower()); - assertEquals(d.getUpper(), a.getUpper()); - } - - public void testSubtract3() - { - Range a = new Range(20, 30); - Range b = new Range(0, 10); - List ranges = a.subtract(b); - assertEquals(ranges.size(), 1); - Range d = ranges.get(0); - assertEquals(d.getLower(), a.getLower()); - assertEquals(d.getUpper(), a.getUpper()); - } - - public void testSubtract4() - { - Range a = new Range(0, 10); - Range b = new Range(3, 5); - List ranges = a.subtract(b); - assertEquals(ranges.size(), 2); - Range low = ranges.get(0); - Range high = ranges.get(1); - assertEquals(low.getLower(), 0); - assertEquals(low.getUpper(), 2); - assertEquals(high.getLower(), 6); - assertEquals(high.getUpper(), 10); - } - - public void testSubtract5() - { - Range a = new Range(0, 10); - Range b = new Range(3, 20); - List ranges = a.subtract(b); - assertEquals(ranges.size(), 1); - Range d = ranges.get(0); - assertEquals(d.getLower(), 0); - assertEquals(d.getUpper(), 2); - } - - public void testSubtract6() - { - Range a = new Range(0, 10); - Range b = new Range(-10, 5); - List ranges = a.subtract(b); - assertEquals(ranges.size(), 1); - Range d = ranges.get(0); - assertEquals(d.getLower(), 6); - assertEquals(d.getUpper(), 10); - } - -} -- cgit v1.2.1