[jboss-cvs] JBoss Messaging SVN: r4647 - in trunk/tests/src/org/jboss/messaging/tests: timing and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 7 09:45:33 EDT 2008
Author: ataylor
Date: 2008-07-07 09:45:33 -0400 (Mon, 07 Jul 2008)
New Revision: 4647
Added:
trunk/tests/src/org/jboss/messaging/tests/timing/util/
trunk/tests/src/org/jboss/messaging/tests/timing/util/TokenBucketLimiterImplTest.java
trunk/tests/src/org/jboss/messaging/tests/timing/util/VariableLatchTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/
trunk/tests/src/org/jboss/messaging/tests/unit/util/ByteBufferWrapperTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/ConcurrentHashSetTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/MessagingBufferTestBase.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/ObjectInputStreamWithClassLoaderTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/UUIDTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/VariableLatchTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/VersionLoaderTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/XMLUtilTest.java
Removed:
trunk/tests/src/org/jboss/messaging/tests/timing/core/util/
trunk/tests/src/org/jboss/messaging/tests/timing/util/TokenBucketLimiterImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/util/
trunk/tests/src/org/jboss/messaging/tests/unit/jms/bridge/impl/timing/BridgeImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/ByteBufferWrapperTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/ConcurrentHashSetTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/MessagingBufferTestBase.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/ObjectInputStreamWithClassLoaderTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/UUIDTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/VariableLatchTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/VersionLoaderTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/util/XMLUtilTest.java
Modified:
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapper2Test.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java
Log:
moved util tests
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapper2Test.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapper2Test.java 2008-07-07 13:27:58 UTC (rev 4646)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapper2Test.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -23,7 +23,7 @@
package org.jboss.messaging.tests.integration.core.remoting.mina;
import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
-import org.jboss.messaging.tests.unit.core.util.MessagingBufferTestBase;
+import org.jboss.messaging.tests.unit.util.MessagingBufferTestBase;
import org.jboss.messaging.util.MessagingBuffer;
/**
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java 2008-07-07 13:27:58 UTC (rev 4646)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -24,7 +24,7 @@
import org.apache.mina.common.IoBuffer;
import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
-import org.jboss.messaging.tests.unit.core.util.MessagingBufferTestBase;
+import org.jboss.messaging.tests.unit.util.MessagingBufferTestBase;
import org.jboss.messaging.util.MessagingBuffer;
/**
Copied: trunk/tests/src/org/jboss/messaging/tests/timing/util (from rev 4641, trunk/tests/src/org/jboss/messaging/tests/timing/core/util)
Deleted: trunk/tests/src/org/jboss/messaging/tests/timing/util/TokenBucketLimiterImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/timing/core/util/TokenBucketLimiterImplTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/timing/util/TokenBucketLimiterImplTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,131 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.timing.core.util;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.util.TokenBucketLimiterImpl;
-
-/**
- *
- * A TokenBucketLimiterImplTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class TokenBucketLimiterImplTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(TokenBucketLimiterImplTest.class);
-
- public void testRateWithSpin1() throws Exception
- {
- testRate(1, true);
- }
-
- public void testRateWithSpin10() throws Exception
- {
- testRate(10, true);
- }
-
- public void testRateWithSpin100() throws Exception
- {
- testRate(100, true);
- }
-
- public void testRateWithSpin1000() throws Exception
- {
- testRate(1000, true);
- }
-
- public void testRateWithSpin10000() throws Exception
- {
- testRate(10000, true);
- }
-
- public void testRateWithSpin100000() throws Exception
- {
- testRate(100000, true);
- }
-
- public void testRateWithoutSpin1() throws Exception
- {
- testRate(1, false);
- }
-
- public void testRateWithoutSpin10() throws Exception
- {
- testRate(10, false);
- }
-
- public void testRateWithoutSpin100() throws Exception
- {
- testRate(100, false);
- }
-
- public void testRateWithoutSpin1000() throws Exception
- {
- testRate(1000, false);
- }
-
- public void testRateWithoutSpin10000() throws Exception
- {
- testRate(10000, false);
- }
-
- public void testRateWithoutSpin100000() throws Exception
- {
- testRate(100000, false);
- }
-
- private void testRate(int rate, boolean spin) throws Exception
- {
- final double error = 0.05; //Allow for 5% error
-
- TokenBucketLimiterImpl tbl = new TokenBucketLimiterImpl(rate, spin);
-
- long start = System.currentTimeMillis();
-
- long count = 0;
-
- final long measureTime = 5000;
-
- while (System.currentTimeMillis() - start < measureTime)
- {
- tbl.limit();
-
- count++;
- }
-
- long end = System.currentTimeMillis();
-
- double actualRate = ((double)(1000 * count)) / ( end - start);
-
- log.info("Desired rate: " + rate + " Actual rate " + actualRate + " invs/sec");
-
- assertTrue(actualRate > rate * (1 - error));
-
- assertTrue(actualRate < rate * (1 + error));
-
- }
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/timing/util/TokenBucketLimiterImplTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/timing/core/util/TokenBucketLimiterImplTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/timing/util/TokenBucketLimiterImplTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/timing/util/TokenBucketLimiterImplTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.timing.util;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.util.TokenBucketLimiterImpl;
+
+/**
+ *
+ * A TokenBucketLimiterImplTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class TokenBucketLimiterImplTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(TokenBucketLimiterImplTest.class);
+
+ public void testRateWithSpin1() throws Exception
+ {
+ testRate(1, true);
+ }
+
+ public void testRateWithSpin10() throws Exception
+ {
+ testRate(10, true);
+ }
+
+ public void testRateWithSpin100() throws Exception
+ {
+ testRate(100, true);
+ }
+
+ public void testRateWithSpin1000() throws Exception
+ {
+ testRate(1000, true);
+ }
+
+ public void testRateWithSpin10000() throws Exception
+ {
+ testRate(10000, true);
+ }
+
+ public void testRateWithSpin100000() throws Exception
+ {
+ testRate(100000, true);
+ }
+
+ public void testRateWithoutSpin1() throws Exception
+ {
+ testRate(1, false);
+ }
+
+ public void testRateWithoutSpin10() throws Exception
+ {
+ testRate(10, false);
+ }
+
+ public void testRateWithoutSpin100() throws Exception
+ {
+ testRate(100, false);
+ }
+
+ public void testRateWithoutSpin1000() throws Exception
+ {
+ testRate(1000, false);
+ }
+
+ public void testRateWithoutSpin10000() throws Exception
+ {
+ testRate(10000, false);
+ }
+
+ public void testRateWithoutSpin100000() throws Exception
+ {
+ testRate(100000, false);
+ }
+
+ private void testRate(int rate, boolean spin) throws Exception
+ {
+ final double error = 0.05; //Allow for 5% error
+
+ TokenBucketLimiterImpl tbl = new TokenBucketLimiterImpl(rate, spin);
+
+ long start = System.currentTimeMillis();
+
+ long count = 0;
+
+ final long measureTime = 5000;
+
+ while (System.currentTimeMillis() - start < measureTime)
+ {
+ tbl.limit();
+
+ count++;
+ }
+
+ long end = System.currentTimeMillis();
+
+ double actualRate = ((double)(1000 * count)) / ( end - start);
+
+ log.info("Desired rate: " + rate + " Actual rate " + actualRate + " invs/sec");
+
+ assertTrue(actualRate > rate * (1 - error));
+
+ assertTrue(actualRate < rate * (1 + error));
+
+ }
+}
Copied: trunk/tests/src/org/jboss/messaging/tests/timing/util/VariableLatchTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/timing/core/util/VariableLatchTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/timing/util/VariableLatchTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/timing/util/VariableLatchTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.tests.timing.util;
+
+import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.util.VariableLatch;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class VariableLatchTest extends UnitTestCase
+{
+ public void testTimeout() throws Exception
+ {
+ VariableLatch latch = new VariableLatch();
+
+ latch.up();
+
+ long start = System.currentTimeMillis();
+ try
+ {
+ latch.waitCompletion(1000);
+ fail("It was suppsoed to throw an exception");
+ } catch (Exception ignored)
+ {
+ }
+ long end = System.currentTimeMillis();
+
+ assertTrue("Timeout didn't work correctly", end - start >= 1000
+ && end - start < 2000);
+ }
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/jms/bridge/impl/timing/BridgeImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/bridge/impl/timing/BridgeImplTest.java 2008-07-07 13:27:58 UTC (rev 4646)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/bridge/impl/timing/BridgeImplTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,520 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.jms.bridge.impl.timing;
-
-import static org.easymock.EasyMock.anyBoolean;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.getCurrentArguments;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.transaction.TransactionManager;
-
-import junit.framework.TestCase;
-
-import org.easymock.IAnswer;
-import org.jboss.messaging.jms.bridge.ConnectionFactoryFactory;
-import org.jboss.messaging.jms.bridge.DestinationFactory;
-import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
-import org.jboss.messaging.jms.bridge.impl.BridgeImpl;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class BridgeImplTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testStartWithRepeatedFailure() throws Exception
- {
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
-
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andStubReturn(sourceDest);
- expect(targetDF.createDestination()).andStubReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andStubReturn(sourceCF);
- // the source connection can not be created
- expect(sourceCF.createConnection()).andStubThrow(
- new JMSException("unable to create a conn"));
-
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
-
- BridgeImpl bridge = new BridgeImpl();
-
- bridge.setSourceConnectionFactoryFactory(sourceCFF);
- bridge.setSourceDestinationFactory(sourceDF);
- bridge.setTargetConnectionFactoryFactory(targetCFF);
- bridge.setTargetDestinationFactory(targetDF);
- // retry after 10 ms
- bridge.setFailureRetryInterval(10);
- // retry only once
- bridge.setMaxRetries(1);
- bridge.setMaxBatchSize(1);
- bridge.setMaxBatchTime(-1);
- bridge.setTransactionManager(tm);
- bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
-
- assertFalse(bridge.isStarted());
- bridge.start();
-
- Thread.sleep(50);
- assertFalse(bridge.isStarted());
- assertTrue(bridge.isFailed());
-
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
- }
-
- public void testStartWithFailureThenSuccess() throws Exception
- {
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
-
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andStubReturn(sourceDest);
- expect(targetDF.createDestination()).andStubReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andStubReturn(sourceCF);
- // the source connection can not be created the 1st time...
- expect(sourceCF.createConnection()).andThrow(
- new JMSException("unable to create a conn"));
- // ... and it succeeds the 2nd time
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
-
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
-
- BridgeImpl bridge = new BridgeImpl();
-
- bridge.setSourceConnectionFactoryFactory(sourceCFF);
- bridge.setSourceDestinationFactory(sourceDF);
- bridge.setTargetConnectionFactoryFactory(targetCFF);
- bridge.setTargetDestinationFactory(targetDF);
- // retry after 10 ms
- bridge.setFailureRetryInterval(10);
- // retry only once
- bridge.setMaxRetries(1);
- bridge.setMaxBatchSize(1);
- bridge.setMaxBatchTime(-1);
- bridge.setTransactionManager(tm);
- bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
-
- assertFalse(bridge.isStarted());
- bridge.start();
-
- Thread.sleep(50);
- assertTrue(bridge.isStarted());
- assertFalse(bridge.isFailed());
-
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
- }
-
- /*
- * we receive only 1 message. The message is sent when the maxBatchTime
- * expires even if the maxBatchSize is not reached
- */
- public void testSendMessagesWhenMaxBatchTimeExpires() throws Exception
- {
- int maxBatchSize = 2;
- long maxBatchTime = 500;
-
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
- Message message = createNiceMock(Message.class);
-
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- SetMessageListenerAnswer answer = new SetMessageListenerAnswer();
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expectLastCall().andAnswer(answer);
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
-
- targetProducer.send(targetDest, message, 0, 0, 0);
- targetSession.commit();
-
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
- replay(message);
-
- BridgeImpl bridge = new BridgeImpl();
- assertNotNull(bridge);
-
- bridge.setSourceConnectionFactoryFactory(sourceCFF);
- bridge.setSourceDestinationFactory(sourceDF);
- bridge.setTargetConnectionFactoryFactory(targetCFF);
- bridge.setTargetDestinationFactory(targetDF);
- bridge.setFailureRetryInterval(-1);
- bridge.setMaxRetries(-1);
- bridge.setMaxBatchSize(maxBatchSize);
- bridge.setMaxBatchTime(maxBatchTime);
- bridge.setTransactionManager(tm);
- bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
-
- assertFalse(bridge.isStarted());
- bridge.start();
- assertTrue(bridge.isStarted());
-
- answer.listener.onMessage(message);
-
- Thread.sleep(3 * maxBatchTime);
-
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
- verify(message);
- }
-
- public void testExceptionOnSourceAndRetrySucceeds() throws Exception
- {
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
- Message message = createNiceMock(Message.class);
-
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- SetExceptionListenerAnswer exceptionListenerAnswer = new SetExceptionListenerAnswer();
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expectLastCall().andAnswer(exceptionListenerAnswer);
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
-
- //after failure detection, we retry to start the bridge:
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expectLastCall().andAnswer(exceptionListenerAnswer);
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
-
-
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
- replay(message);
-
- BridgeImpl bridge = new BridgeImpl();
- assertNotNull(bridge);
-
- bridge.setSourceConnectionFactoryFactory(sourceCFF);
- bridge.setSourceDestinationFactory(sourceDF);
- bridge.setTargetConnectionFactoryFactory(targetCFF);
- bridge.setTargetDestinationFactory(targetDF);
- bridge.setFailureRetryInterval(10);
- bridge.setMaxRetries(2);
- bridge.setMaxBatchSize(1);
- bridge.setMaxBatchTime(-1);
- bridge.setTransactionManager(tm);
- bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
-
- assertFalse(bridge.isStarted());
- bridge.start();
- assertTrue(bridge.isStarted());
-
- exceptionListenerAnswer.listener.onException(new JMSException("exception on the source"));
- Thread.sleep(4 * bridge.getFailureRetryInterval());
- // reconnection must have succeded
- assertTrue(bridge.isStarted());
-
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
- verify(message);
- }
-
- public void testExceptionOnSourceAndRetryFails() throws Exception
- {
- ConnectionFactoryFactory sourceCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory sourceCF = createStrictMock(ConnectionFactory.class);
- Connection sourceConn = createStrictMock(Connection.class);
- Session sourceSession = createStrictMock(Session.class);
- MessageConsumer sourceConsumer = createStrictMock(MessageConsumer.class);
- DestinationFactory sourceDF = createStrictMock(DestinationFactory.class);
- Destination sourceDest = createStrictMock(Destination.class);
- ConnectionFactoryFactory targetCFF = createStrictMock(ConnectionFactoryFactory.class);
- ConnectionFactory targetCF = createStrictMock(ConnectionFactory.class);
- Connection targetConn = createStrictMock(Connection.class);
- Session targetSession = createStrictMock(Session.class);
- MessageProducer targetProducer = createStrictMock(MessageProducer.class);
- DestinationFactory targetDF = createStrictMock(DestinationFactory.class);
- Destination targetDest = createStrictMock(Destination.class);
- TransactionManager tm = createStrictMock(TransactionManager.class);
- Message message = createNiceMock(Message.class);
-
- expect(tm.suspend()).andReturn(null);
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andReturn(sourceConn);
- SetExceptionListenerAnswer exceptionListenerAnswer = new SetExceptionListenerAnswer();
- sourceConn.setExceptionListener(isA(ExceptionListener.class));
- expectLastCall().andAnswer(exceptionListenerAnswer);
- expect(sourceConn.createSession(anyBoolean(), anyInt())).andReturn(
- sourceSession);
- expect(sourceSession.createConsumer(sourceDest))
- .andReturn(sourceConsumer);
- sourceConsumer.setMessageListener(isA(MessageListener.class));
- expect(targetCFF.createConnectionFactory()).andReturn(targetCF);
- expect(targetCF.createConnection()).andReturn(targetConn);
- targetConn.setExceptionListener(isA(ExceptionListener.class));
- expect(targetConn.createSession(anyBoolean(), anyInt())).andReturn(
- targetSession);
- expect(targetSession.createProducer(null)).andReturn(targetProducer);
- sourceConn.start();
-
- //after failure detection, we clean up...
- // and it is stopped
- sourceConn.close();
- targetConn.close();
- // ...retry to start the bridge but it fails...
- expect(sourceDF.createDestination()).andReturn(sourceDest);
- expect(targetDF.createDestination()).andReturn(targetDest);
- expect(sourceCFF.createConnectionFactory()).andReturn(sourceCF);
- expect(sourceCF.createConnection()).andThrow(new JMSException("exception while retrying to connect"));
- // ... so we clean up again...
- sourceConn.close();
- targetConn.close();
- // ... and finally stop the bridge
- sourceConn.close();
- targetConn.close();
-
- replay(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- replay(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- replay(tm);
- replay(message);
-
- BridgeImpl bridge = new BridgeImpl();
- assertNotNull(bridge);
-
- bridge.setSourceConnectionFactoryFactory(sourceCFF);
- bridge.setSourceDestinationFactory(sourceDF);
- bridge.setTargetConnectionFactoryFactory(targetCFF);
- bridge.setTargetDestinationFactory(targetDF);
- bridge.setFailureRetryInterval(10);
- bridge.setMaxRetries(1);
- bridge.setMaxBatchSize(1);
- bridge.setMaxBatchTime(-1);
- bridge.setTransactionManager(tm);
- bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
-
- assertFalse(bridge.isStarted());
- bridge.start();
- assertTrue(bridge.isStarted());
-
- exceptionListenerAnswer.listener.onException(new JMSException("exception on the source"));
- Thread.sleep(4 * bridge.getFailureRetryInterval());
- // reconnection must have failed
- assertFalse(bridge.isStarted());
-
- verify(sourceCFF, sourceCF, sourceConn, sourceSession, sourceConsumer,
- sourceDF, sourceDest);
- verify(targetCFF, targetCF, targetConn, targetSession, targetProducer,
- targetDF, targetDest);
- verify(tm);
- verify(message);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
- class SetExceptionListenerAnswer implements IAnswer
- {
- ExceptionListener listener = null;
-
- public Object answer() throws Throwable
- {
- listener = (ExceptionListener) getCurrentArguments()[0];
- return null;
- }
- }
-
- class SetMessageListenerAnswer implements IAnswer
- {
- MessageListener listener = null;
-
- public Object answer() throws Throwable
- {
- listener = (MessageListener) getCurrentArguments()[0];
- return null;
- }
- }
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util (from rev 4641, trunk/tests/src/org/jboss/messaging/tests/unit/core/util)
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/ByteBufferWrapperTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/ByteBufferWrapperTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import java.nio.ByteBuffer;
-
-import org.jboss.messaging.util.ByteBufferWrapper;
-import org.jboss.messaging.util.MessagingBuffer;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class ByteBufferWrapperTest extends MessagingBufferTestBase
-{
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- // MessagingBufferTestBase overrides -----------------------------
-
- @Override
- protected MessagingBuffer createBuffer()
- {
- return new ByteBufferWrapper(ByteBuffer.allocate(512));
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/ByteBufferWrapperTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/ByteBufferWrapperTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/ByteBufferWrapperTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import org.jboss.messaging.util.ByteBufferWrapper;
+import org.jboss.messaging.util.MessagingBuffer;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class ByteBufferWrapperTest extends MessagingBufferTestBase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // MessagingBufferTestBase overrides -----------------------------
+
+ @Override
+ protected MessagingBuffer createBuffer()
+ {
+ return new ByteBufferWrapper(ByteBuffer.allocate(512));
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/ConcurrentHashSetTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ConcurrentHashSetTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/ConcurrentHashSetTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,155 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import static org.jboss.messaging.tests.util.RandomUtil.randomString;
-
-import java.util.Iterator;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.util.ConcurrentHashSet;
-import org.jboss.messaging.util.ConcurrentSet;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class ConcurrentHashSetTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private ConcurrentSet<String> set;
- private String element;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testAdd() throws Exception
- {
- assertTrue(set.add(element));
- assertFalse(set.add(element));
- }
-
- public void testAddIfAbsent() throws Exception
- {
- assertTrue(set.addIfAbsent(element));
- assertFalse(set.addIfAbsent(element));
- }
-
- public void testRemove() throws Exception
- {
- assertTrue(set.add(element));
-
- assertTrue(set.remove(element));
- assertFalse(set.remove(element));
- }
-
- public void testContains() throws Exception
- {
- assertFalse(set.contains(element));
-
- assertTrue(set.add(element));
- assertTrue(set.contains(element));
-
- assertTrue(set.remove(element));
- assertFalse(set.contains(element));
- }
-
- public void testSize() throws Exception
- {
- assertEquals(0, set.size());
-
- assertTrue(set.add(element));
- assertEquals(1, set.size());
-
- assertTrue(set.remove(element));
- assertEquals(0, set.size());
- }
-
- public void testClear() throws Exception
- {
- assertTrue(set.add(element));
-
- assertTrue(set.contains(element));
- set.clear();
- assertFalse(set.contains(element));
- }
-
- public void testIsEmpty() throws Exception
- {
- assertTrue(set.isEmpty());
-
- assertTrue(set.add(element));
- assertFalse(set.isEmpty());
-
- set.clear();
- assertTrue(set.isEmpty());
- }
-
- public void testIterator() throws Exception
- {
- set.add(element);
-
- Iterator<String> iterator = set.iterator();
- while (iterator.hasNext())
- {
- String e = (String) iterator.next();
- assertEquals(element, e);
- }
- }
-
- // TestCase overrides --------------------------------------------
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- set = new ConcurrentHashSet<String>();
- element = randomString();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- set = null;
- element = null;
-
- super.tearDown();
- }
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/ConcurrentHashSetTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ConcurrentHashSetTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/ConcurrentHashSetTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/ConcurrentHashSetTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import org.jboss.messaging.util.ConcurrentHashSet;
+import org.jboss.messaging.util.ConcurrentSet;
+
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class ConcurrentHashSetTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private ConcurrentSet<String> set;
+ private String element;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testAdd() throws Exception
+ {
+ assertTrue(set.add(element));
+ assertFalse(set.add(element));
+ }
+
+ public void testAddIfAbsent() throws Exception
+ {
+ assertTrue(set.addIfAbsent(element));
+ assertFalse(set.addIfAbsent(element));
+ }
+
+ public void testRemove() throws Exception
+ {
+ assertTrue(set.add(element));
+
+ assertTrue(set.remove(element));
+ assertFalse(set.remove(element));
+ }
+
+ public void testContains() throws Exception
+ {
+ assertFalse(set.contains(element));
+
+ assertTrue(set.add(element));
+ assertTrue(set.contains(element));
+
+ assertTrue(set.remove(element));
+ assertFalse(set.contains(element));
+ }
+
+ public void testSize() throws Exception
+ {
+ assertEquals(0, set.size());
+
+ assertTrue(set.add(element));
+ assertEquals(1, set.size());
+
+ assertTrue(set.remove(element));
+ assertEquals(0, set.size());
+ }
+
+ public void testClear() throws Exception
+ {
+ assertTrue(set.add(element));
+
+ assertTrue(set.contains(element));
+ set.clear();
+ assertFalse(set.contains(element));
+ }
+
+ public void testIsEmpty() throws Exception
+ {
+ assertTrue(set.isEmpty());
+
+ assertTrue(set.add(element));
+ assertFalse(set.isEmpty());
+
+ set.clear();
+ assertTrue(set.isEmpty());
+ }
+
+ public void testIterator() throws Exception
+ {
+ set.add(element);
+
+ Iterator<String> iterator = set.iterator();
+ while (iterator.hasNext())
+ {
+ String e = (String) iterator.next();
+ assertEquals(element, e);
+ }
+ }
+
+ // TestCase overrides --------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ set = new ConcurrentHashSet<String>();
+ element = randomString();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ set = null;
+ element = null;
+
+ super.tearDown();
+ }
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/MessagingBufferTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/MessagingBufferTestBase.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/MessagingBufferTestBase.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,423 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
-import static org.jboss.messaging.tests.util.RandomUtil.randomBytes;
-import static org.jboss.messaging.tests.util.RandomUtil.randomDouble;
-import static org.jboss.messaging.tests.util.RandomUtil.randomFloat;
-import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
-import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
-import static org.jboss.messaging.tests.util.RandomUtil.randomString;
-import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
-import junit.framework.TestCase;
-
-import org.jboss.messaging.tests.util.RandomUtil;
-import org.jboss.messaging.util.MessagingBuffer;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- *
- * @version <tt>$Revision$</tt>
- */
-public abstract class MessagingBufferTestBase extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- private MessagingBuffer wrapper;
-
- @Override
- protected void setUp() throws Exception
- {
- wrapper = createBuffer();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- wrapper = null;
- }
-
- protected abstract MessagingBuffer createBuffer();
-
- public void testNullString() throws Exception
- {
- assertNull(putAndGetNullableString(null));
- }
-
- public void testEmptyString() throws Exception
- {
- String result = putAndGetNullableString("");
-
- assertNotNull(result);
- assertEquals("", result);
- }
-
- public void testNonEmptyString() throws Exception
- {
- String junk = randomString();
-
- String result = putAndGetNullableString(junk);
-
- assertNotNull(result);
- assertEquals(junk, result);
- }
-
- public void testNullSimpleString() throws Exception
- {
- assertNull(putAndGetNullableSimpleString(null));
- }
-
- public void testEmptySimpleString() throws Exception
- {
- SimpleString emptySimpleString = new SimpleString("");
- SimpleString result = putAndGetNullableSimpleString(emptySimpleString);
-
- assertNotNull(result);
- assertEqualsByteArrays(emptySimpleString.getData(), result.getData());
- }
-
- public void testNonEmptySimpleString() throws Exception
- {
- SimpleString junk = RandomUtil.randomSimpleString();
- SimpleString result = putAndGetNullableSimpleString(junk);
-
- assertNotNull(result);
- assertEqualsByteArrays(junk.getData(), result.getData());
- }
-
- public void testByte() throws Exception
- {
- byte b = randomByte();
- wrapper.putByte(b);
-
- wrapper.flip();
-
- assertEquals(b, wrapper.getByte());
- }
-
- public void testUnsignedByte() throws Exception
- {
- byte b = (byte) 0xff;
- wrapper.putByte(b);
-
- wrapper.flip();
-
- assertEquals(255, wrapper.getUnsignedByte());
-
- wrapper.rewind();
-
- b = (byte) 0xf;
- wrapper.putByte(b);
-
- wrapper.flip();
-
- assertEquals(b, wrapper.getUnsignedByte());
- }
-
-
-
- public void testBytes() throws Exception
- {
- byte[] bytes = randomBytes();
- wrapper.putBytes(bytes);
-
- wrapper.flip();
-
- byte[] b = new byte[bytes.length];
- wrapper.getBytes(b);
- assertEqualsByteArrays(bytes, b);
- }
-
- public void testBytesWithLength() throws Exception
- {
- byte[] bytes = randomBytes();
- // put only half of the bytes
- wrapper.putBytes(bytes, 0, bytes.length / 2);
-
- wrapper.flip();
-
- byte[] b = new byte[bytes.length / 2];
- wrapper.getBytes(b, 0, b.length);
- assertEqualsByteArrays(b.length, bytes, b);
- }
-
- public void testPutTrueBoolean() throws Exception
- {
- wrapper.putBoolean(true);
-
- wrapper.flip();
-
- assertTrue(wrapper.getBoolean());
- }
-
- public void testPutFalseBoolean() throws Exception
- {
- wrapper.putBoolean(false);
-
- wrapper.flip();
-
- assertFalse(wrapper.getBoolean());
- }
-
- public void testChar() throws Exception
- {
- wrapper.putChar('a');
-
- wrapper.flip();
-
- assertEquals('a', wrapper.getChar());
- }
-
- public void testInt() throws Exception
- {
- int i = randomInt();
- wrapper.putInt(i);
-
- wrapper.flip();
-
- assertEquals(i, wrapper.getInt());
- }
-
- public void testIntAtPosition() throws Exception
- {
- int firstInt = randomInt();
- int secondInt = randomInt();
-
- wrapper.putInt(secondInt);
- wrapper.putInt(secondInt);
- // rewrite firstInt at the beginning
- wrapper.putInt(0, firstInt);
-
- wrapper.flip();
-
- assertEquals(firstInt, wrapper.getInt());
- assertEquals(secondInt, wrapper.getInt());
- }
-
- public void testLong() throws Exception
- {
- long l = randomLong();
- wrapper.putLong(l);
-
- wrapper.flip();
-
- assertEquals(l, wrapper.getLong());
- }
-
- public void testUnsignedShort() throws Exception
- {
- short s1 = Short.MAX_VALUE;
-
- wrapper.putShort(s1);
-
- wrapper.flip();
-
- int s2 = wrapper.getUnsignedShort();
-
- assertEquals((int) s1, s2);
-
- wrapper.rewind();
-
- s1 = Short.MIN_VALUE;
-
- wrapper.putShort(s1);
-
- wrapper.flip();
-
- s2 = wrapper.getUnsignedShort();
-
- assertEquals(((int) s1) * -1, s2);
-
- wrapper.rewind();
-
- s1 = -1;
-
- wrapper.putShort(s1);
-
- wrapper.flip();
-
- s2 = wrapper.getUnsignedShort();
-
- // / The max of an unsigned short
- // (http://en.wikipedia.org/wiki/Unsigned_short)
- assertEquals(s2, 65535);
- }
-
- public void testShort() throws Exception
- {
- wrapper.putShort((short) 1);
-
- wrapper.flip();
-
- assertEquals((short)1, wrapper.getShort());
- }
-
- public void testDouble() throws Exception
- {
- double d = randomDouble();
- wrapper.putDouble(d);
-
- wrapper.flip();
-
- assertEquals(d, wrapper.getDouble());
- }
-
- public void testFloat() throws Exception
- {
- float f = randomFloat();
- wrapper.putFloat(f);
-
- wrapper.flip();
-
- assertEquals(f, wrapper.getFloat());
- }
-
- public void testUTF() throws Exception
- {
- String str = randomString();
- wrapper.putUTF(str);
-
- wrapper.flip();
-
- assertEquals(str, wrapper.getUTF());
- }
-
- public void testArray() throws Exception
- {
- byte[] bytes = randomBytes(128);
- wrapper.putBytes(bytes);
-
- wrapper.flip();
-
- byte[] array = wrapper.array();
- assertEquals(wrapper.capacity(), array.length);
- assertEqualsByteArrays(128, bytes, wrapper.array());
- }
-
- public void testRewind() throws Exception
- {
- int i = randomInt();
- wrapper.putInt(i);
-
- wrapper.flip();
-
- assertEquals(i, wrapper.getInt());
-
- wrapper.rewind();
-
- assertEquals(i, wrapper.getInt());
- }
-
- public void testRemaining() throws Exception
- {
- int capacity = wrapper.capacity();
- assertEquals(capacity, wrapper.remaining());
-
- // fill 1/3 of the buffer
- int fill = capacity / 3;
- byte[] bytes = randomBytes(fill);
- wrapper.putBytes(bytes);
-
- // check the remaining is 2/3
- assertEquals(capacity - fill, wrapper.remaining());
- }
-
- public void testPosition() throws Exception
- {
- assertEquals(0, wrapper.position());
-
- byte[] bytes = randomBytes(128);
- wrapper.putBytes(bytes);
-
- assertEquals(bytes.length, wrapper.position());
-
- wrapper.position(0);
- assertEquals(0, wrapper.position());
- }
-
- public void testLimit() throws Exception
- {
- assertEquals(wrapper.capacity(), wrapper.limit());
-
- byte[] bytes = randomBytes(128);
- wrapper.putBytes(bytes);
-
- assertEquals(wrapper.capacity(), wrapper.limit());
-
- wrapper.limit(128);
- assertEquals(128, wrapper.limit());
- }
-
- public void testSlice() throws Exception
- {
- byte[] bytes = randomBytes(128);
- wrapper.putBytes(bytes);
-
- wrapper.position(0);
- wrapper.limit(128);
-
- MessagingBuffer slicedBuffer = wrapper.slice();
- assertEquals(128, slicedBuffer.capacity());
-
- byte[] slicedBytes = new byte[128];
- slicedBuffer.getBytes(slicedBytes);
-
- assertEqualsByteArrays(bytes, slicedBytes);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private String putAndGetNullableString(String nullableString) throws Exception
- {
- wrapper.putNullableString(nullableString);
-
- wrapper.flip();
-
- return wrapper.getNullableString();
- }
-
- private SimpleString putAndGetNullableSimpleString(SimpleString nullableSimpleString) throws Exception
- {
- wrapper.putNullableSimpleString(nullableSimpleString);
-
- wrapper.flip();
-
- return wrapper.getNullableSimpleString();
- }
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/MessagingBufferTestBase.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/MessagingBufferTestBase.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/MessagingBufferTestBase.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/MessagingBufferTestBase.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,416 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.tests.util.RandomUtil;
+import static org.jboss.messaging.tests.util.RandomUtil.*;
+import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
+import org.jboss.messaging.util.MessagingBuffer;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ *
+ * @version <tt>$Revision$</tt>
+ */
+public abstract class MessagingBufferTestBase extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ private MessagingBuffer wrapper;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ wrapper = createBuffer();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ wrapper = null;
+ }
+
+ protected abstract MessagingBuffer createBuffer();
+
+ public void testNullString() throws Exception
+ {
+ assertNull(putAndGetNullableString(null));
+ }
+
+ public void testEmptyString() throws Exception
+ {
+ String result = putAndGetNullableString("");
+
+ assertNotNull(result);
+ assertEquals("", result);
+ }
+
+ public void testNonEmptyString() throws Exception
+ {
+ String junk = randomString();
+
+ String result = putAndGetNullableString(junk);
+
+ assertNotNull(result);
+ assertEquals(junk, result);
+ }
+
+ public void testNullSimpleString() throws Exception
+ {
+ assertNull(putAndGetNullableSimpleString(null));
+ }
+
+ public void testEmptySimpleString() throws Exception
+ {
+ SimpleString emptySimpleString = new SimpleString("");
+ SimpleString result = putAndGetNullableSimpleString(emptySimpleString);
+
+ assertNotNull(result);
+ assertEqualsByteArrays(emptySimpleString.getData(), result.getData());
+ }
+
+ public void testNonEmptySimpleString() throws Exception
+ {
+ SimpleString junk = RandomUtil.randomSimpleString();
+ SimpleString result = putAndGetNullableSimpleString(junk);
+
+ assertNotNull(result);
+ assertEqualsByteArrays(junk.getData(), result.getData());
+ }
+
+ public void testByte() throws Exception
+ {
+ byte b = randomByte();
+ wrapper.putByte(b);
+
+ wrapper.flip();
+
+ assertEquals(b, wrapper.getByte());
+ }
+
+ public void testUnsignedByte() throws Exception
+ {
+ byte b = (byte) 0xff;
+ wrapper.putByte(b);
+
+ wrapper.flip();
+
+ assertEquals(255, wrapper.getUnsignedByte());
+
+ wrapper.rewind();
+
+ b = (byte) 0xf;
+ wrapper.putByte(b);
+
+ wrapper.flip();
+
+ assertEquals(b, wrapper.getUnsignedByte());
+ }
+
+
+
+ public void testBytes() throws Exception
+ {
+ byte[] bytes = randomBytes();
+ wrapper.putBytes(bytes);
+
+ wrapper.flip();
+
+ byte[] b = new byte[bytes.length];
+ wrapper.getBytes(b);
+ assertEqualsByteArrays(bytes, b);
+ }
+
+ public void testBytesWithLength() throws Exception
+ {
+ byte[] bytes = randomBytes();
+ // put only half of the bytes
+ wrapper.putBytes(bytes, 0, bytes.length / 2);
+
+ wrapper.flip();
+
+ byte[] b = new byte[bytes.length / 2];
+ wrapper.getBytes(b, 0, b.length);
+ assertEqualsByteArrays(b.length, bytes, b);
+ }
+
+ public void testPutTrueBoolean() throws Exception
+ {
+ wrapper.putBoolean(true);
+
+ wrapper.flip();
+
+ assertTrue(wrapper.getBoolean());
+ }
+
+ public void testPutFalseBoolean() throws Exception
+ {
+ wrapper.putBoolean(false);
+
+ wrapper.flip();
+
+ assertFalse(wrapper.getBoolean());
+ }
+
+ public void testChar() throws Exception
+ {
+ wrapper.putChar('a');
+
+ wrapper.flip();
+
+ assertEquals('a', wrapper.getChar());
+ }
+
+ public void testInt() throws Exception
+ {
+ int i = randomInt();
+ wrapper.putInt(i);
+
+ wrapper.flip();
+
+ assertEquals(i, wrapper.getInt());
+ }
+
+ public void testIntAtPosition() throws Exception
+ {
+ int firstInt = randomInt();
+ int secondInt = randomInt();
+
+ wrapper.putInt(secondInt);
+ wrapper.putInt(secondInt);
+ // rewrite firstInt at the beginning
+ wrapper.putInt(0, firstInt);
+
+ wrapper.flip();
+
+ assertEquals(firstInt, wrapper.getInt());
+ assertEquals(secondInt, wrapper.getInt());
+ }
+
+ public void testLong() throws Exception
+ {
+ long l = randomLong();
+ wrapper.putLong(l);
+
+ wrapper.flip();
+
+ assertEquals(l, wrapper.getLong());
+ }
+
+ public void testUnsignedShort() throws Exception
+ {
+ short s1 = Short.MAX_VALUE;
+
+ wrapper.putShort(s1);
+
+ wrapper.flip();
+
+ int s2 = wrapper.getUnsignedShort();
+
+ assertEquals((int) s1, s2);
+
+ wrapper.rewind();
+
+ s1 = Short.MIN_VALUE;
+
+ wrapper.putShort(s1);
+
+ wrapper.flip();
+
+ s2 = wrapper.getUnsignedShort();
+
+ assertEquals(((int) s1) * -1, s2);
+
+ wrapper.rewind();
+
+ s1 = -1;
+
+ wrapper.putShort(s1);
+
+ wrapper.flip();
+
+ s2 = wrapper.getUnsignedShort();
+
+ // / The max of an unsigned short
+ // (http://en.wikipedia.org/wiki/Unsigned_short)
+ assertEquals(s2, 65535);
+ }
+
+ public void testShort() throws Exception
+ {
+ wrapper.putShort((short) 1);
+
+ wrapper.flip();
+
+ assertEquals((short)1, wrapper.getShort());
+ }
+
+ public void testDouble() throws Exception
+ {
+ double d = randomDouble();
+ wrapper.putDouble(d);
+
+ wrapper.flip();
+
+ assertEquals(d, wrapper.getDouble());
+ }
+
+ public void testFloat() throws Exception
+ {
+ float f = randomFloat();
+ wrapper.putFloat(f);
+
+ wrapper.flip();
+
+ assertEquals(f, wrapper.getFloat());
+ }
+
+ public void testUTF() throws Exception
+ {
+ String str = randomString();
+ wrapper.putUTF(str);
+
+ wrapper.flip();
+
+ assertEquals(str, wrapper.getUTF());
+ }
+
+ public void testArray() throws Exception
+ {
+ byte[] bytes = randomBytes(128);
+ wrapper.putBytes(bytes);
+
+ wrapper.flip();
+
+ byte[] array = wrapper.array();
+ assertEquals(wrapper.capacity(), array.length);
+ assertEqualsByteArrays(128, bytes, wrapper.array());
+ }
+
+ public void testRewind() throws Exception
+ {
+ int i = randomInt();
+ wrapper.putInt(i);
+
+ wrapper.flip();
+
+ assertEquals(i, wrapper.getInt());
+
+ wrapper.rewind();
+
+ assertEquals(i, wrapper.getInt());
+ }
+
+ public void testRemaining() throws Exception
+ {
+ int capacity = wrapper.capacity();
+ assertEquals(capacity, wrapper.remaining());
+
+ // fill 1/3 of the buffer
+ int fill = capacity / 3;
+ byte[] bytes = randomBytes(fill);
+ wrapper.putBytes(bytes);
+
+ // check the remaining is 2/3
+ assertEquals(capacity - fill, wrapper.remaining());
+ }
+
+ public void testPosition() throws Exception
+ {
+ assertEquals(0, wrapper.position());
+
+ byte[] bytes = randomBytes(128);
+ wrapper.putBytes(bytes);
+
+ assertEquals(bytes.length, wrapper.position());
+
+ wrapper.position(0);
+ assertEquals(0, wrapper.position());
+ }
+
+ public void testLimit() throws Exception
+ {
+ assertEquals(wrapper.capacity(), wrapper.limit());
+
+ byte[] bytes = randomBytes(128);
+ wrapper.putBytes(bytes);
+
+ assertEquals(wrapper.capacity(), wrapper.limit());
+
+ wrapper.limit(128);
+ assertEquals(128, wrapper.limit());
+ }
+
+ public void testSlice() throws Exception
+ {
+ byte[] bytes = randomBytes(128);
+ wrapper.putBytes(bytes);
+
+ wrapper.position(0);
+ wrapper.limit(128);
+
+ MessagingBuffer slicedBuffer = wrapper.slice();
+ assertEquals(128, slicedBuffer.capacity());
+
+ byte[] slicedBytes = new byte[128];
+ slicedBuffer.getBytes(slicedBytes);
+
+ assertEqualsByteArrays(bytes, slicedBytes);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private String putAndGetNullableString(String nullableString) throws Exception
+ {
+ wrapper.putNullableString(nullableString);
+
+ wrapper.flip();
+
+ return wrapper.getNullableString();
+ }
+
+ private SimpleString putAndGetNullableSimpleString(SimpleString nullableSimpleString) throws Exception
+ {
+ wrapper.putNullableSimpleString(nullableSimpleString);
+
+ wrapper.flip();
+
+ return wrapper.getNullableSimpleString();
+ }
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/ObjectInputStreamWithClassLoaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ObjectInputStreamWithClassLoaderTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/ObjectInputStreamWithClassLoaderTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,144 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.util.ObjectInputStreamWithClassLoader;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * @author <a href="mailto:csuconic at redhat.com">Clebert Suconic</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class ObjectInputStreamWithClassLoaderTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- public static ClassLoader newClassLoader(Class anyUserClass) throws Exception
- {
- URL classLocation = anyUserClass.getProtectionDomain().getCodeSource().getLocation();
- StringTokenizer tokenString = new StringTokenizer(System.getProperty("java.class.path"),
- File.pathSeparator);
- String pathIgnore = System.getProperty("java.home");
- if (pathIgnore == null)
- {
- pathIgnore = classLocation.toString();
- }
-
- List<URL> urls = new ArrayList<URL>();
- while (tokenString.hasMoreElements())
- {
- String value = tokenString.nextToken();
- URL itemLocation = new File(value).toURL();
- if (!itemLocation.equals(classLocation) &&
- itemLocation.toString().indexOf(pathIgnore) >= 0)
- {
- urls.add(itemLocation);
- }
- }
-
- URL[] urlArray = (URL[]) urls.toArray(new URL[urls.size()]);
-
- ClassLoader masterClassLoader = URLClassLoader.newInstance(urlArray, null);
- ClassLoader appClassLoader = URLClassLoader.newInstance(new URL[]{classLocation},
- masterClassLoader);
- return appClassLoader;
- }
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testClassLoaderIsolation() throws Exception
- {
-
- ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- AnObject obj = new AnObject();
- byte[] bytes = toBytes(obj);
-
- ClassLoader testClassLoader = newClassLoader(obj.getClass());
- Thread.currentThread().setContextClassLoader(testClassLoader);
-
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais);
-
- Object deserializedObj= ois.readObject();
-
- assertNotSame(obj, deserializedObj);
- assertNotSame(obj.getClass(), deserializedObj.getClass());
- assertNotSame(obj.getClass().getClassLoader(),
- deserializedObj.getClass().getClassLoader());
- assertSame(testClassLoader,
- deserializedObj.getClass().getClassLoader());
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(originalClassLoader);
- }
-
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private static byte[] toBytes(Object obj) throws IOException
- {
- assertTrue(obj instanceof Serializable);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(obj);
- oos.flush();
- return baos.toByteArray();
- }
-
- // Inner classes -------------------------------------------------
-
- private static class AnObject implements Serializable
- {
- private static final long serialVersionUID = -5172742084489525256L;
- }
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/ObjectInputStreamWithClassLoaderTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ObjectInputStreamWithClassLoaderTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/ObjectInputStreamWithClassLoaderTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/ObjectInputStreamWithClassLoaderTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,138 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.util.ObjectInputStreamWithClassLoader;
+
+import java.io.*;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * @author <a href="mailto:csuconic at redhat.com">Clebert Suconic</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class ObjectInputStreamWithClassLoaderTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ public static ClassLoader newClassLoader(Class anyUserClass) throws Exception
+ {
+ URL classLocation = anyUserClass.getProtectionDomain().getCodeSource().getLocation();
+ StringTokenizer tokenString = new StringTokenizer(System.getProperty("java.class.path"),
+ File.pathSeparator);
+ String pathIgnore = System.getProperty("java.home");
+ if (pathIgnore == null)
+ {
+ pathIgnore = classLocation.toString();
+ }
+
+ List<URL> urls = new ArrayList<URL>();
+ while (tokenString.hasMoreElements())
+ {
+ String value = tokenString.nextToken();
+ URL itemLocation = new File(value).toURL();
+ if (!itemLocation.equals(classLocation) &&
+ itemLocation.toString().indexOf(pathIgnore) >= 0)
+ {
+ urls.add(itemLocation);
+ }
+ }
+
+ URL[] urlArray = (URL[]) urls.toArray(new URL[urls.size()]);
+
+ ClassLoader masterClassLoader = URLClassLoader.newInstance(urlArray, null);
+ ClassLoader appClassLoader = URLClassLoader.newInstance(new URL[]{classLocation},
+ masterClassLoader);
+ return appClassLoader;
+ }
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testClassLoaderIsolation() throws Exception
+ {
+
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ AnObject obj = new AnObject();
+ byte[] bytes = toBytes(obj);
+
+ ClassLoader testClassLoader = newClassLoader(obj.getClass());
+ Thread.currentThread().setContextClassLoader(testClassLoader);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais);
+
+ Object deserializedObj= ois.readObject();
+
+ assertNotSame(obj, deserializedObj);
+ assertNotSame(obj.getClass(), deserializedObj.getClass());
+ assertNotSame(obj.getClass().getClassLoader(),
+ deserializedObj.getClass().getClassLoader());
+ assertSame(testClassLoader,
+ deserializedObj.getClass().getClassLoader());
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private static byte[] toBytes(Object obj) throws IOException
+ {
+ assertTrue(obj instanceof Serializable);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(obj);
+ oos.flush();
+ return baos.toByteArray();
+ }
+
+ // Inner classes -------------------------------------------------
+
+ private static class AnObject implements Serializable
+ {
+ private static final long serialVersionUID = -5172742084489525256L;
+ }
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SimpleStringTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,243 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import static org.jboss.messaging.tests.util.RandomUtil.randomString;
-import junit.framework.TestCase;
-
-import org.jboss.messaging.tests.util.RandomUtil;
-import org.jboss.messaging.util.DataConstants;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A SimpleStringTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class SimpleStringTest extends TestCase
-{
- public void testString() throws Exception
- {
- final String str = "hello123ABC__524`16254`6125!%^$!%$!%$!%$!%!$%!$$!\uA324";
-
- SimpleString s = new SimpleString(str);
-
- assertEquals(str, s.toString());
-
- assertEquals(2 * str.length(), s.getData().length);
-
- byte[] data = s.getData();
-
- SimpleString s2 = new SimpleString(data);
-
- assertEquals(str, s2.toString());
- }
-
- public void testStartsWith() throws Exception
- {
- SimpleString s1 = new SimpleString("abcdefghi");
-
- assertTrue(s1.startsWith(new SimpleString("abc")));
-
- assertTrue(s1.startsWith(new SimpleString("abcdef")));
-
- assertTrue(s1.startsWith(new SimpleString("abcdefghi")));
-
- assertFalse(s1.startsWith(new SimpleString("abcdefghijklmn")));
-
- assertFalse(s1.startsWith(new SimpleString("aardvark")));
-
- assertFalse(s1.startsWith(new SimpleString("z")));
- }
-
- public void testCharSequence() throws Exception
- {
- String s = "abcdefghijkl";
- SimpleString s1 = new SimpleString(s);
-
- assertEquals('a', s1.charAt(0));
- assertEquals('b', s1.charAt(1));
- assertEquals('c', s1.charAt(2));
- assertEquals('k', s1.charAt(10));
- assertEquals('l', s1.charAt(11));
-
- try
- {
- s1.charAt(-1);
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
-
- try
- {
- s1.charAt(-2);
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
-
- try
- {
- s1.charAt(s.length());
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
-
- try
- {
- s1.charAt(s.length() + 1);
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
-
- assertEquals(s.length(), s1.length());
-
- CharSequence ss = s1.subSequence(0, s1.length());
-
- assertEquals(ss, s1);
-
- ss = s1.subSequence(1, 4);
- assertEquals(ss, new SimpleString("bcd"));
-
- ss = s1.subSequence(5, 10);
- assertEquals(ss, new SimpleString("fghij"));
-
- ss = s1.subSequence(5, 12);
- assertEquals(ss, new SimpleString("fghijkl"));
-
- try
- {
- s1.subSequence(-1, 2);
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
-
- try
- {
- s1.subSequence(-4, -2);
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
-
- try
- {
- s1.subSequence(0, s1.length() + 1);
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
-
- try
- {
- s1.subSequence(0, s1.length() + 2);
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
-
- try
- {
- s1.subSequence(5, 1);
- fail("Should throw exception");
- }
- catch (IndexOutOfBoundsException e)
- {
- //OK
- }
- }
-
- public void testEquals() throws Exception
- {
- assertFalse(new SimpleString("abcdef").equals(new Object()));
-
- assertEquals(new SimpleString("abcdef"), new SimpleString("abcdef"));
-
- assertFalse(new SimpleString("abcdef").equals(new SimpleString("abggcdef")));
- assertFalse(new SimpleString("abcdef").equals(new SimpleString("ghijkl")));
- }
-
- public void testHashcode() throws Exception
- {
- SimpleString str = new SimpleString("abcdef");
- SimpleString sameStr = new SimpleString("abcdef");
- SimpleString differentStr = new SimpleString("ghijk");
-
- assertTrue(str.hashCode() == sameStr.hashCode());
- assertFalse(str.hashCode() == differentStr.hashCode());
- }
-
- public void testUnicode() throws Exception
- {
- String myString = "abcdef&^*&!^ghijkl\uB5E2\uCAC7\uB2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
-
- SimpleString s = new SimpleString(myString);
- byte[] data = s.getData();
- s = new SimpleString(data);
-
- assertEquals(myString, s.toString());
- }
-
- public void testUnicodeWithSurrogates() throws Exception
- {
- String myString = "abcdef&^*&!^ghijkl\uD900\uDD00";
-
- SimpleString s = new SimpleString(myString);
- byte[] data = s.getData();
- s = new SimpleString(data);
-
- assertEquals(myString, s.toString());
- }
-
- public void testSizeofString() throws Exception
- {
- assertEquals(DataConstants.SIZE_INT, SimpleString.sizeofString(null));
- assertEquals(DataConstants.SIZE_INT, SimpleString.sizeofString(new SimpleString("")));
-
- SimpleString str = new SimpleString(randomString());
- assertEquals(DataConstants.SIZE_INT + str.getData().length, SimpleString.sizeofString(str));
-
- }
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SimpleStringTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/SimpleStringTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,241 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A SimpleStringTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SimpleStringTest extends TestCase
+{
+ public void testString() throws Exception
+ {
+ final String str = "hello123ABC__524`16254`6125!%^$!%$!%$!%$!%!$%!$$!\uA324";
+
+ SimpleString s = new SimpleString(str);
+
+ assertEquals(str, s.toString());
+
+ assertEquals(2 * str.length(), s.getData().length);
+
+ byte[] data = s.getData();
+
+ SimpleString s2 = new SimpleString(data);
+
+ assertEquals(str, s2.toString());
+ }
+
+ public void testStartsWith() throws Exception
+ {
+ SimpleString s1 = new SimpleString("abcdefghi");
+
+ assertTrue(s1.startsWith(new SimpleString("abc")));
+
+ assertTrue(s1.startsWith(new SimpleString("abcdef")));
+
+ assertTrue(s1.startsWith(new SimpleString("abcdefghi")));
+
+ assertFalse(s1.startsWith(new SimpleString("abcdefghijklmn")));
+
+ assertFalse(s1.startsWith(new SimpleString("aardvark")));
+
+ assertFalse(s1.startsWith(new SimpleString("z")));
+ }
+
+ public void testCharSequence() throws Exception
+ {
+ String s = "abcdefghijkl";
+ SimpleString s1 = new SimpleString(s);
+
+ assertEquals('a', s1.charAt(0));
+ assertEquals('b', s1.charAt(1));
+ assertEquals('c', s1.charAt(2));
+ assertEquals('k', s1.charAt(10));
+ assertEquals('l', s1.charAt(11));
+
+ try
+ {
+ s1.charAt(-1);
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+
+ try
+ {
+ s1.charAt(-2);
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+
+ try
+ {
+ s1.charAt(s.length());
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+
+ try
+ {
+ s1.charAt(s.length() + 1);
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+
+ assertEquals(s.length(), s1.length());
+
+ CharSequence ss = s1.subSequence(0, s1.length());
+
+ assertEquals(ss, s1);
+
+ ss = s1.subSequence(1, 4);
+ assertEquals(ss, new SimpleString("bcd"));
+
+ ss = s1.subSequence(5, 10);
+ assertEquals(ss, new SimpleString("fghij"));
+
+ ss = s1.subSequence(5, 12);
+ assertEquals(ss, new SimpleString("fghijkl"));
+
+ try
+ {
+ s1.subSequence(-1, 2);
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+
+ try
+ {
+ s1.subSequence(-4, -2);
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+
+ try
+ {
+ s1.subSequence(0, s1.length() + 1);
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+
+ try
+ {
+ s1.subSequence(0, s1.length() + 2);
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+
+ try
+ {
+ s1.subSequence(5, 1);
+ fail("Should throw exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ //OK
+ }
+ }
+
+ public void testEquals() throws Exception
+ {
+ assertFalse(new SimpleString("abcdef").equals(new Object()));
+
+ assertEquals(new SimpleString("abcdef"), new SimpleString("abcdef"));
+
+ assertFalse(new SimpleString("abcdef").equals(new SimpleString("abggcdef")));
+ assertFalse(new SimpleString("abcdef").equals(new SimpleString("ghijkl")));
+ }
+
+ public void testHashcode() throws Exception
+ {
+ SimpleString str = new SimpleString("abcdef");
+ SimpleString sameStr = new SimpleString("abcdef");
+ SimpleString differentStr = new SimpleString("ghijk");
+
+ assertTrue(str.hashCode() == sameStr.hashCode());
+ assertFalse(str.hashCode() == differentStr.hashCode());
+ }
+
+ public void testUnicode() throws Exception
+ {
+ String myString = "abcdef&^*&!^ghijkl\uB5E2\uCAC7\uB2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
+
+ SimpleString s = new SimpleString(myString);
+ byte[] data = s.getData();
+ s = new SimpleString(data);
+
+ assertEquals(myString, s.toString());
+ }
+
+ public void testUnicodeWithSurrogates() throws Exception
+ {
+ String myString = "abcdef&^*&!^ghijkl\uD900\uDD00";
+
+ SimpleString s = new SimpleString(myString);
+ byte[] data = s.getData();
+ s = new SimpleString(data);
+
+ assertEquals(myString, s.toString());
+ }
+
+ public void testSizeofString() throws Exception
+ {
+ assertEquals(DataConstants.SIZE_INT, SimpleString.sizeofString(null));
+ assertEquals(DataConstants.SIZE_INT, SimpleString.sizeofString(new SimpleString("")));
+
+ SimpleString str = new SimpleString(randomString());
+ assertEquals(DataConstants.SIZE_INT + str.getData().length, SimpleString.sizeofString(str));
+
+ }
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/TypedPropertiesTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,327 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
-import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
-import static org.jboss.messaging.tests.util.RandomUtil.randomBytes;
-import static org.jboss.messaging.tests.util.RandomUtil.randomChar;
-import static org.jboss.messaging.tests.util.RandomUtil.randomDouble;
-import static org.jboss.messaging.tests.util.RandomUtil.randomFloat;
-import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
-import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
-import static org.jboss.messaging.tests.util.RandomUtil.randomShort;
-import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
-import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
-
-import java.util.Iterator;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
-import org.jboss.messaging.tests.util.UnitTestCase;
-import org.jboss.messaging.util.MessagingBuffer;
-import org.jboss.messaging.util.SimpleString;
-import org.jboss.messaging.util.TypedProperties;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class TypedPropertiesTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- private static void assertEqualsTypeProperties(TypedProperties expected,
- TypedProperties actual)
- {
- assertNotNull(expected);
- assertNotNull(actual);
- assertEquals(expected.getEncodeSize(), actual.getEncodeSize());
- assertEquals(expected.getPropertyNames(), actual.getPropertyNames());
- Iterator<SimpleString> iterator = actual.getPropertyNames().iterator();
- while (iterator.hasNext())
- {
- SimpleString key = (SimpleString) iterator.next();
- Object expectedValue = expected.getProperty(key);
- Object actualValue = actual.getProperty(key);
- if ((expectedValue instanceof byte[])
- && (actualValue instanceof byte[]))
- {
- byte[] expectedBytes = (byte[]) expectedValue;
- byte[] actualBytes = (byte[]) actualValue;
- UnitTestCase.assertEqualsByteArrays(expectedBytes, actualBytes);
- } else
- {
- assertEquals(expectedValue, actualValue);
- }
- }
- }
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- private TypedProperties props;
- private SimpleString key;
-
- public void testCopyContructor() throws Exception
- {
- props.putStringProperty(key, randomSimpleString());
-
- TypedProperties copy = new TypedProperties(props);
-
- assertEquals(props.getEncodeSize(), copy.getEncodeSize());
- assertEquals(props.getPropertyNames(), copy.getPropertyNames());
-
- assertTrue(copy.containsProperty(key));
- assertEquals(props.getProperty(key), copy.getProperty(key));
- }
-
- public void testRemove() throws Exception
- {
- props.putStringProperty(key, randomSimpleString());
-
- assertTrue(props.containsProperty(key));
- assertNotNull(props.getProperty(key));
-
- props.removeProperty(key);
-
- assertFalse(props.containsProperty(key));
- assertNull(props.getProperty(key));
- }
-
- public void testClear() throws Exception
- {
- props.putStringProperty(key, randomSimpleString());
-
- assertTrue(props.containsProperty(key));
- assertNotNull(props.getProperty(key));
-
- props.clear();
-
- assertFalse(props.containsProperty(key));
- assertNull(props.getProperty(key));
- }
-
- public void testKey() throws Exception
- {
- props.putBooleanProperty(key, true);
- boolean bool = (Boolean) props.getProperty(key);
- assertEquals(true, bool);
-
- props.putCharProperty(key, 'a');
- char c = (Character) props.getProperty(key);
- assertEquals('a', c);
- }
-
- public void testGetPropertyOnEmptyProperties() throws Exception
- {
- assertFalse(props.containsProperty(key));
- assertNull(props.getProperty(key));
- }
-
- public void testRemovePropertyOnEmptyProperties() throws Exception
- {
- assertFalse(props.containsProperty(key));
- assertNull(props.removeProperty(key));
- }
-
- public void testNullProperty() throws Exception
- {
- props.putStringProperty(key, null);
- assertTrue(props.containsProperty(key));
- assertNull(props.getProperty(key));
- }
-
- public void testBooleanProperty() throws Exception
- {
- props.putBooleanProperty(key, true);
- boolean bool = (Boolean) props.getProperty(key);
- assertEquals(true, bool);
-
- props.putBooleanProperty(key, false);
- bool = (Boolean) props.getProperty(key);
- assertEquals(false, bool);
- }
-
- public void testByteProperty() throws Exception
- {
- byte b = randomByte();
- props.putByteProperty(key, b);
- byte bb = (Byte) props.getProperty(key);
- assertEquals(b, bb);
- }
-
- public void testBytesProperty() throws Exception
- {
- byte[] b = randomBytes();
- props.putBytesProperty(key, b);
- byte[] bb = (byte[]) props.getProperty(key);
- assertEqualsByteArrays(b, bb);
- }
-
- public void testBytesPropertyWithNull() throws Exception
- {
- props.putBytesProperty(key, null);
-
- assertTrue(props.containsProperty(key));
- byte[] bb = (byte[]) props.getProperty(key);
- assertNull(bb);
- }
-
- public void testFloatProperty() throws Exception
- {
- float f = randomFloat();
- props.putFloatProperty(key, f);
- float ff = (Float) props.getProperty(key);
- assertEquals(f, ff);
- }
-
- public void testDoubleProperty() throws Exception
- {
- double d = randomDouble();
- props.putDoubleProperty(key, d);
- double dd = (Double) props.getProperty(key);
- assertEquals(d, dd);
- }
-
- public void testShortProperty() throws Exception
- {
- short s = randomShort();
- props.putShortProperty(key, s);
- short ss = (Short) props.getProperty(key);
- assertEquals(s, ss);
- }
-
- public void testIntProperty() throws Exception
- {
- int i = randomInt();
- props.putIntProperty(key, i);
- int ii = (Integer) props.getProperty(key);
- assertEquals(i, ii);
- }
-
- public void testLongProperty() throws Exception
- {
- long l = randomLong();
- props.putLongProperty(key, l);
- long ll = (Long) props.getProperty(key);
- assertEquals(l, ll);
- }
-
- public void testCharProperty() throws Exception
- {
- char c = randomChar();
- props.putCharProperty(key, c);
- char cc = (Character) props.getProperty(key);
- assertEquals(c, cc);
- }
-
- public void testEncodeDecode() throws Exception
- {
- props.putByteProperty(randomSimpleString(), randomByte());
- props.putBytesProperty(randomSimpleString(), randomBytes());
- props.putBytesProperty(randomSimpleString(), null);
- props.putBooleanProperty(randomSimpleString(), randomBoolean());
- props.putShortProperty(randomSimpleString(), randomShort());
- props.putIntProperty(randomSimpleString(), randomInt());
- props.putLongProperty(randomSimpleString(), randomLong());
- props.putFloatProperty(randomSimpleString(), randomFloat());
- props.putDoubleProperty(randomSimpleString(), randomDouble());
- props.putCharProperty(randomSimpleString(), randomChar());
- props.putStringProperty(randomSimpleString(), randomSimpleString());
- props.putStringProperty(randomSimpleString(), null);
- SimpleString keyToRemove = randomSimpleString();
- props.putStringProperty(keyToRemove, randomSimpleString());
-
- MessagingBuffer buffer = new IoBufferWrapper(1024);
- props.encode(buffer);
-
- assertEquals(props.getEncodeSize(), buffer.position());
-
- buffer.flip();
-
- TypedProperties decodedProps = new TypedProperties();
- decodedProps.decode(buffer);
-
- assertEqualsTypeProperties(props, decodedProps);
-
- buffer.flip();
-
- // After removing a property, you should still be able to encode the Property
- props.removeProperty(keyToRemove);
- props.encode(buffer);
-
- assertEquals(props.getEncodeSize(), buffer.position());
- }
-
- public void testEncodeDecodeEmpty() throws Exception
- {
- TypedProperties emptyProps = new TypedProperties();
-
- MessagingBuffer buffer = new IoBufferWrapper(1024);
- emptyProps.encode(buffer);
-
- assertEquals(props.getEncodeSize(), buffer.position());
-
- buffer.flip();
-
- TypedProperties decodedProps = new TypedProperties();
- decodedProps.decode(buffer);
-
- assertEqualsTypeProperties(emptyProps, decodedProps);
- }
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
-
- props = new TypedProperties();
- key = randomSimpleString();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- key = null;
- props = null;
-
- super.tearDown();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/TypedPropertiesTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/TypedPropertiesTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,316 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
+import static org.jboss.messaging.tests.util.RandomUtil.*;
+import org.jboss.messaging.tests.util.UnitTestCase;
+import static org.jboss.messaging.tests.util.UnitTestCase.assertEqualsByteArrays;
+import org.jboss.messaging.util.MessagingBuffer;
+import org.jboss.messaging.util.SimpleString;
+import org.jboss.messaging.util.TypedProperties;
+
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class TypedPropertiesTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ private static void assertEqualsTypeProperties(TypedProperties expected,
+ TypedProperties actual)
+ {
+ assertNotNull(expected);
+ assertNotNull(actual);
+ assertEquals(expected.getEncodeSize(), actual.getEncodeSize());
+ assertEquals(expected.getPropertyNames(), actual.getPropertyNames());
+ Iterator<SimpleString> iterator = actual.getPropertyNames().iterator();
+ while (iterator.hasNext())
+ {
+ SimpleString key = (SimpleString) iterator.next();
+ Object expectedValue = expected.getProperty(key);
+ Object actualValue = actual.getProperty(key);
+ if ((expectedValue instanceof byte[])
+ && (actualValue instanceof byte[]))
+ {
+ byte[] expectedBytes = (byte[]) expectedValue;
+ byte[] actualBytes = (byte[]) actualValue;
+ UnitTestCase.assertEqualsByteArrays(expectedBytes, actualBytes);
+ } else
+ {
+ assertEquals(expectedValue, actualValue);
+ }
+ }
+ }
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ private TypedProperties props;
+ private SimpleString key;
+
+ public void testCopyContructor() throws Exception
+ {
+ props.putStringProperty(key, randomSimpleString());
+
+ TypedProperties copy = new TypedProperties(props);
+
+ assertEquals(props.getEncodeSize(), copy.getEncodeSize());
+ assertEquals(props.getPropertyNames(), copy.getPropertyNames());
+
+ assertTrue(copy.containsProperty(key));
+ assertEquals(props.getProperty(key), copy.getProperty(key));
+ }
+
+ public void testRemove() throws Exception
+ {
+ props.putStringProperty(key, randomSimpleString());
+
+ assertTrue(props.containsProperty(key));
+ assertNotNull(props.getProperty(key));
+
+ props.removeProperty(key);
+
+ assertFalse(props.containsProperty(key));
+ assertNull(props.getProperty(key));
+ }
+
+ public void testClear() throws Exception
+ {
+ props.putStringProperty(key, randomSimpleString());
+
+ assertTrue(props.containsProperty(key));
+ assertNotNull(props.getProperty(key));
+
+ props.clear();
+
+ assertFalse(props.containsProperty(key));
+ assertNull(props.getProperty(key));
+ }
+
+ public void testKey() throws Exception
+ {
+ props.putBooleanProperty(key, true);
+ boolean bool = (Boolean) props.getProperty(key);
+ assertEquals(true, bool);
+
+ props.putCharProperty(key, 'a');
+ char c = (Character) props.getProperty(key);
+ assertEquals('a', c);
+ }
+
+ public void testGetPropertyOnEmptyProperties() throws Exception
+ {
+ assertFalse(props.containsProperty(key));
+ assertNull(props.getProperty(key));
+ }
+
+ public void testRemovePropertyOnEmptyProperties() throws Exception
+ {
+ assertFalse(props.containsProperty(key));
+ assertNull(props.removeProperty(key));
+ }
+
+ public void testNullProperty() throws Exception
+ {
+ props.putStringProperty(key, null);
+ assertTrue(props.containsProperty(key));
+ assertNull(props.getProperty(key));
+ }
+
+ public void testBooleanProperty() throws Exception
+ {
+ props.putBooleanProperty(key, true);
+ boolean bool = (Boolean) props.getProperty(key);
+ assertEquals(true, bool);
+
+ props.putBooleanProperty(key, false);
+ bool = (Boolean) props.getProperty(key);
+ assertEquals(false, bool);
+ }
+
+ public void testByteProperty() throws Exception
+ {
+ byte b = randomByte();
+ props.putByteProperty(key, b);
+ byte bb = (Byte) props.getProperty(key);
+ assertEquals(b, bb);
+ }
+
+ public void testBytesProperty() throws Exception
+ {
+ byte[] b = randomBytes();
+ props.putBytesProperty(key, b);
+ byte[] bb = (byte[]) props.getProperty(key);
+ assertEqualsByteArrays(b, bb);
+ }
+
+ public void testBytesPropertyWithNull() throws Exception
+ {
+ props.putBytesProperty(key, null);
+
+ assertTrue(props.containsProperty(key));
+ byte[] bb = (byte[]) props.getProperty(key);
+ assertNull(bb);
+ }
+
+ public void testFloatProperty() throws Exception
+ {
+ float f = randomFloat();
+ props.putFloatProperty(key, f);
+ float ff = (Float) props.getProperty(key);
+ assertEquals(f, ff);
+ }
+
+ public void testDoubleProperty() throws Exception
+ {
+ double d = randomDouble();
+ props.putDoubleProperty(key, d);
+ double dd = (Double) props.getProperty(key);
+ assertEquals(d, dd);
+ }
+
+ public void testShortProperty() throws Exception
+ {
+ short s = randomShort();
+ props.putShortProperty(key, s);
+ short ss = (Short) props.getProperty(key);
+ assertEquals(s, ss);
+ }
+
+ public void testIntProperty() throws Exception
+ {
+ int i = randomInt();
+ props.putIntProperty(key, i);
+ int ii = (Integer) props.getProperty(key);
+ assertEquals(i, ii);
+ }
+
+ public void testLongProperty() throws Exception
+ {
+ long l = randomLong();
+ props.putLongProperty(key, l);
+ long ll = (Long) props.getProperty(key);
+ assertEquals(l, ll);
+ }
+
+ public void testCharProperty() throws Exception
+ {
+ char c = randomChar();
+ props.putCharProperty(key, c);
+ char cc = (Character) props.getProperty(key);
+ assertEquals(c, cc);
+ }
+
+ public void testEncodeDecode() throws Exception
+ {
+ props.putByteProperty(randomSimpleString(), randomByte());
+ props.putBytesProperty(randomSimpleString(), randomBytes());
+ props.putBytesProperty(randomSimpleString(), null);
+ props.putBooleanProperty(randomSimpleString(), randomBoolean());
+ props.putShortProperty(randomSimpleString(), randomShort());
+ props.putIntProperty(randomSimpleString(), randomInt());
+ props.putLongProperty(randomSimpleString(), randomLong());
+ props.putFloatProperty(randomSimpleString(), randomFloat());
+ props.putDoubleProperty(randomSimpleString(), randomDouble());
+ props.putCharProperty(randomSimpleString(), randomChar());
+ props.putStringProperty(randomSimpleString(), randomSimpleString());
+ props.putStringProperty(randomSimpleString(), null);
+ SimpleString keyToRemove = randomSimpleString();
+ props.putStringProperty(keyToRemove, randomSimpleString());
+
+ MessagingBuffer buffer = new IoBufferWrapper(1024);
+ props.encode(buffer);
+
+ assertEquals(props.getEncodeSize(), buffer.position());
+
+ buffer.flip();
+
+ TypedProperties decodedProps = new TypedProperties();
+ decodedProps.decode(buffer);
+
+ assertEqualsTypeProperties(props, decodedProps);
+
+ buffer.flip();
+
+ // After removing a property, you should still be able to encode the Property
+ props.removeProperty(keyToRemove);
+ props.encode(buffer);
+
+ assertEquals(props.getEncodeSize(), buffer.position());
+ }
+
+ public void testEncodeDecodeEmpty() throws Exception
+ {
+ TypedProperties emptyProps = new TypedProperties();
+
+ MessagingBuffer buffer = new IoBufferWrapper(1024);
+ emptyProps.encode(buffer);
+
+ assertEquals(props.getEncodeSize(), buffer.position());
+
+ buffer.flip();
+
+ TypedProperties decodedProps = new TypedProperties();
+ decodedProps.decode(buffer);
+
+ assertEqualsTypeProperties(emptyProps, decodedProps);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ props = new TypedProperties();
+ key = randomSimpleString();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ key = null;
+ props = null;
+
+ super.tearDown();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/UUIDTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/UUIDTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/UUIDTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.util.UUIDGenerator;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class UUIDTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- private static final int MANY_TIMES = 100000;
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testManyUUIDs() throws Exception
- {
- List<String> uuids = new ArrayList<String>(MANY_TIMES);
-
- UUIDGenerator gen = UUIDGenerator.getInstance();
- InetAddress addr = InetAddress.getLocalHost();
-
- for (int i = 0; i < MANY_TIMES; i++)
- {
- uuids.add(gen.generateTimeBasedUUID(addr).toString());
- }
-
- // we put them in a set to check duplicates
- Set<String> uuidsSet = new HashSet<String>(uuids);
- assertEquals(MANY_TIMES, uuidsSet.size());
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/UUIDTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/UUIDTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/UUIDTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/UUIDTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.util.UUIDGenerator;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class UUIDTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ private static final int MANY_TIMES = 100000;
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testManyUUIDs() throws Exception
+ {
+ List<String> uuids = new ArrayList<String>(MANY_TIMES);
+
+ UUIDGenerator gen = UUIDGenerator.getInstance();
+ InetAddress addr = InetAddress.getLocalHost();
+
+ for (int i = 0; i < MANY_TIMES; i++)
+ {
+ uuids.add(gen.generateTimeBasedUUID(addr).toString());
+ }
+
+ // we put them in a set to check duplicates
+ Set<String> uuidsSet = new HashSet<String>(uuids);
+ assertEquals(MANY_TIMES, uuidsSet.size());
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/VariableLatchTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/VariableLatchTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/VariableLatchTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,317 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import java.util.concurrent.CountDownLatch;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.util.VariableLatch;
-
-/**
- *
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-public class VariableLatchTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(VariableLatchTest.class);
-
- public void testLatchOnSingleThread() throws Exception
- {
- VariableLatch latch = new VariableLatch();
-
- for (int i = 1; i <= 10000; i++)
- {
- latch.up();
- assertEquals(i, latch.getCount());
- }
-
- for (int i = 10000; i > 0; i--)
- {
- assertEquals(i, latch.getCount());
- latch.down();
- assertEquals(i - 1, latch.getCount());
- }
-
- latch.waitCompletion();
- }
-
- public void testTimeout() throws Exception
- {
- VariableLatch latch = new VariableLatch();
-
- latch.up();
-
- long start = System.currentTimeMillis();
- try
- {
- latch.waitCompletion(1000);
- fail("It was suppsoed to throw an exception");
- } catch (Exception ignored)
- {
- }
- long end = System.currentTimeMillis();
-
- assertTrue("Timeout didn't work correctly", end - start >= 1000
- && end - start < 2000);
- }
-
- /**
- *
- * This test will open numberOfThreads threads, and add numberOfAdds on the
- * VariableLatch After those addthreads are finished, the latch count should
- * be numberOfThreads * numberOfAdds Then it will open numberOfThreads
- * threads again releasing numberOfAdds on the VariableLatch After those
- * releaseThreads are finished, the latch count should be 0 And all the
- * waiting threads should be finished also
- *
- * @throws Exception
- */
- public void testLatchOnMultiThread() throws Exception
- {
- final VariableLatch latch = new VariableLatch();
-
- latch.up(); // We hold at least one, so ThreadWaits won't go away
-
- final int numberOfThreads = 100;
- final int numberOfAdds = 1000;
-
- class ThreadWait extends Thread
- {
- private volatile boolean waiting = true;
-
- public void run()
- {
- try
- {
- latch.waitCompletion(5000);
- } catch (Exception e)
- {
- log.error(e);
- }
- waiting = false;
- }
- }
-
- class ThreadAdd extends Thread
- {
- private final CountDownLatch latchReady;
- private final CountDownLatch latchStart;
-
- ThreadAdd(final CountDownLatch latchReady, final CountDownLatch latchStart)
- {
- this.latchReady = latchReady;
- this.latchStart = latchStart;
- }
-
- public void run()
- {
- try
- {
- latchReady.countDown();
- // Everybody should start at the same time, to worse concurrency
- // effects
- latchStart.await();
- for (int i = 0; i < numberOfAdds; i++)
- {
- latch.up();
- }
- } catch (Exception e)
- {
- log.error(e.getMessage(), e);
- }
- }
- }
-
- CountDownLatch latchReady = new CountDownLatch(numberOfThreads);
- CountDownLatch latchStart = new CountDownLatch(1);
-
- ThreadAdd[] threadAdds = new ThreadAdd[numberOfThreads];
- ThreadWait waits[] = new ThreadWait[numberOfThreads];
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- threadAdds[i] = new ThreadAdd(latchReady, latchStart);
- threadAdds[i].start();
- waits[i] = new ThreadWait();
- waits[i].start();
- }
-
- latchReady.await();
- latchStart.countDown();
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- threadAdds[i].join();
- }
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- assertTrue(waits[i].waiting);
- }
-
- assertEquals(numberOfThreads * numberOfAdds + 1, latch.getCount());
-
- class ThreadDown extends Thread
- {
- private final CountDownLatch latchReady;
- private final CountDownLatch latchStart;
-
- ThreadDown(final CountDownLatch latchReady, final CountDownLatch latchStart)
- {
- this.latchReady = latchReady;
- this.latchStart = latchStart;
- }
-
- public void run()
- {
- try
- {
- latchReady.countDown();
- // Everybody should start at the same time, to worse concurrency
- // effects
- latchStart.await();
- for (int i = 0; i < numberOfAdds; i++)
- {
- latch.down();
- }
- } catch (Exception e)
- {
- log.error(e.getMessage(), e);
- }
- }
- }
-
- latchReady = new CountDownLatch(numberOfThreads);
- latchStart = new CountDownLatch(1);
-
- ThreadDown down[] = new ThreadDown[numberOfThreads];
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- down[i] = new ThreadDown(latchReady, latchStart);
- down[i].start();
- }
-
- latchReady.await();
- latchStart.countDown();
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- down[i].join();
- }
-
- assertEquals(1, latch.getCount());
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- assertTrue(waits[i].waiting);
- }
-
- latch.down();
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- waits[i].join();
- }
-
- assertEquals(0, latch.getCount());
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- assertFalse(waits[i].waiting);
- }
- }
-
- public void testReuseLatch() throws Exception
- {
- final VariableLatch latch = new VariableLatch();
- latch.up();
-
- class ThreadWait extends Thread
- {
- private volatile boolean waiting = false;
- private volatile Exception e;
- private final CountDownLatch readyLatch = new CountDownLatch(1);
-
- public void run()
- {
- waiting = true;
- readyLatch.countDown();
- try
- {
- latch.waitCompletion(1000);
- } catch (Exception e)
- {
- log.error(e);
- this.e = e;
- }
- waiting = false;
- }
- }
-
- ThreadWait t = new ThreadWait();
- t.start();
-
- t.readyLatch.await();
-
- assertEquals(true, t.waiting);
-
- latch.down();
-
- t.join();
-
- assertEquals(false, t.waiting);
-
- assertNull(t.e);
-
- latch.up();
-
- t = new ThreadWait();
- t.start();
-
- t.readyLatch.await();
-
- assertEquals(true, t.waiting);
-
- latch.down();
-
- t.join();
-
- assertEquals(false, t.waiting);
-
- assertNull(t.e);
-
- latch.waitCompletion(1000);
-
- assertEquals(0, latch.getCount());
-
- latch.down();
-
- assertEquals(0, latch.getCount());
-
- }
-
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/VariableLatchTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/VariableLatchTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/VariableLatchTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/VariableLatchTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,296 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.util.VariableLatch;
+
+import java.util.concurrent.CountDownLatch;
+
+/**
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ *
+ */
+public class VariableLatchTest extends TestCase
+{
+ private static final Logger log = Logger.getLogger(VariableLatchTest.class);
+
+ public void testLatchOnSingleThread() throws Exception
+ {
+ VariableLatch latch = new VariableLatch();
+
+ for (int i = 1; i <= 10000; i++)
+ {
+ latch.up();
+ assertEquals(i, latch.getCount());
+ }
+
+ for (int i = 10000; i > 0; i--)
+ {
+ assertEquals(i, latch.getCount());
+ latch.down();
+ assertEquals(i - 1, latch.getCount());
+ }
+
+ latch.waitCompletion();
+ }
+
+ /**
+ *
+ * This test will open numberOfThreads threads, and add numberOfAdds on the
+ * VariableLatch After those addthreads are finished, the latch count should
+ * be numberOfThreads * numberOfAdds Then it will open numberOfThreads
+ * threads again releasing numberOfAdds on the VariableLatch After those
+ * releaseThreads are finished, the latch count should be 0 And all the
+ * waiting threads should be finished also
+ *
+ * @throws Exception
+ */
+ public void testLatchOnMultiThread() throws Exception
+ {
+ final VariableLatch latch = new VariableLatch();
+
+ latch.up(); // We hold at least one, so ThreadWaits won't go away
+
+ final int numberOfThreads = 100;
+ final int numberOfAdds = 1000;
+
+ class ThreadWait extends Thread
+ {
+ private volatile boolean waiting = true;
+
+ public void run()
+ {
+ try
+ {
+ latch.waitCompletion(5000);
+ } catch (Exception e)
+ {
+ log.error(e);
+ }
+ waiting = false;
+ }
+ }
+
+ class ThreadAdd extends Thread
+ {
+ private final CountDownLatch latchReady;
+ private final CountDownLatch latchStart;
+
+ ThreadAdd(final CountDownLatch latchReady, final CountDownLatch latchStart)
+ {
+ this.latchReady = latchReady;
+ this.latchStart = latchStart;
+ }
+
+ public void run()
+ {
+ try
+ {
+ latchReady.countDown();
+ // Everybody should start at the same time, to worse concurrency
+ // effects
+ latchStart.await();
+ for (int i = 0; i < numberOfAdds; i++)
+ {
+ latch.up();
+ }
+ } catch (Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ CountDownLatch latchReady = new CountDownLatch(numberOfThreads);
+ CountDownLatch latchStart = new CountDownLatch(1);
+
+ ThreadAdd[] threadAdds = new ThreadAdd[numberOfThreads];
+ ThreadWait waits[] = new ThreadWait[numberOfThreads];
+
+ for (int i = 0; i < numberOfThreads; i++)
+ {
+ threadAdds[i] = new ThreadAdd(latchReady, latchStart);
+ threadAdds[i].start();
+ waits[i] = new ThreadWait();
+ waits[i].start();
+ }
+
+ latchReady.await();
+ latchStart.countDown();
+
+ for (int i = 0; i < numberOfThreads; i++)
+ {
+ threadAdds[i].join();
+ }
+
+ for (int i = 0; i < numberOfThreads; i++)
+ {
+ assertTrue(waits[i].waiting);
+ }
+
+ assertEquals(numberOfThreads * numberOfAdds + 1, latch.getCount());
+
+ class ThreadDown extends Thread
+ {
+ private final CountDownLatch latchReady;
+ private final CountDownLatch latchStart;
+
+ ThreadDown(final CountDownLatch latchReady, final CountDownLatch latchStart)
+ {
+ this.latchReady = latchReady;
+ this.latchStart = latchStart;
+ }
+
+ public void run()
+ {
+ try
+ {
+ latchReady.countDown();
+ // Everybody should start at the same time, to worse concurrency
+ // effects
+ latchStart.await();
+ for (int i = 0; i < numberOfAdds; i++)
+ {
+ latch.down();
+ }
+ } catch (Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ latchReady = new CountDownLatch(numberOfThreads);
+ latchStart = new CountDownLatch(1);
+
+ ThreadDown down[] = new ThreadDown[numberOfThreads];
+
+ for (int i = 0; i < numberOfThreads; i++)
+ {
+ down[i] = new ThreadDown(latchReady, latchStart);
+ down[i].start();
+ }
+
+ latchReady.await();
+ latchStart.countDown();
+
+ for (int i = 0; i < numberOfThreads; i++)
+ {
+ down[i].join();
+ }
+
+ assertEquals(1, latch.getCount());
+
+ for (int i = 0; i < numberOfThreads; i++)
+ {
+ assertTrue(waits[i].waiting);
+ }
+
+ latch.down();
+
+ for (int i = 0; i < numberOfThreads; i++)
+ {
+ waits[i].join();
+ }
+
+ assertEquals(0, latch.getCount());
+
+ for (int i = 0; i < numberOfThreads; i++)
+ {
+ assertFalse(waits[i].waiting);
+ }
+ }
+
+ public void testReuseLatch() throws Exception
+ {
+ final VariableLatch latch = new VariableLatch();
+ latch.up();
+
+ class ThreadWait extends Thread
+ {
+ private volatile boolean waiting = false;
+ private volatile Exception e;
+ private final CountDownLatch readyLatch = new CountDownLatch(1);
+
+ public void run()
+ {
+ waiting = true;
+ readyLatch.countDown();
+ try
+ {
+ latch.waitCompletion(1000);
+ } catch (Exception e)
+ {
+ log.error(e);
+ this.e = e;
+ }
+ waiting = false;
+ }
+ }
+
+ ThreadWait t = new ThreadWait();
+ t.start();
+
+ t.readyLatch.await();
+
+ assertEquals(true, t.waiting);
+
+ latch.down();
+
+ t.join();
+
+ assertEquals(false, t.waiting);
+
+ assertNull(t.e);
+
+ latch.up();
+
+ t = new ThreadWait();
+ t.start();
+
+ t.readyLatch.await();
+
+ assertEquals(true, t.waiting);
+
+ latch.down();
+
+ t.join();
+
+ assertEquals(false, t.waiting);
+
+ assertNull(t.e);
+
+ latch.waitCompletion(1000);
+
+ assertEquals(0, latch.getCount());
+
+ latch.down();
+
+ assertEquals(0, latch.getCount());
+
+ }
+
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/VersionLoaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/VersionLoaderTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/VersionLoaderTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import static java.lang.Integer.parseInt;
-
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.version.Version;
-import org.jboss.messaging.util.VersionLoader;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class VersionLoaderTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public void testLoadVersion() throws Exception
- {
- Version version = VersionLoader.load();
- Properties props = new Properties();
- props.load(ClassLoader.getSystemResourceAsStream("version.properties"));
-
- assertEquals(props.get("messaging.version.versionName"), version.getVersionName());
- assertEquals(props.get("messaging.version.versionSuffix"), version.getVersionSuffix());
-
- assertEquals(parseInt((String) props.get("messaging.version.majorVersion")), version.getMajorVersion());
- assertEquals(parseInt((String) props.get("messaging.version.minorVersion")), version.getMinorVersion());
- assertEquals(parseInt((String) props.get("messaging.version.microVersion")), version.getMicroVersion());
- assertEquals(parseInt((String) props.get("messaging.version.incrementingVersion")), version.getIncrementingVersion());
- }
-
-
- // Z implementation ----------------------------------------------
-
- // Y overrides ---------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/VersionLoaderTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/VersionLoaderTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/VersionLoaderTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/VersionLoaderTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.core.version.Version;
+import org.jboss.messaging.util.VersionLoader;
+
+import static java.lang.Integer.parseInt;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class VersionLoaderTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testLoadVersion() throws Exception
+ {
+ Version version = VersionLoader.load();
+ Properties props = new Properties();
+ props.load(ClassLoader.getSystemResourceAsStream("version.properties"));
+
+ assertEquals(props.get("messaging.version.versionName"), version.getVersionName());
+ assertEquals(props.get("messaging.version.versionSuffix"), version.getVersionSuffix());
+
+ assertEquals(parseInt((String) props.get("messaging.version.majorVersion")), version.getMajorVersion());
+ assertEquals(parseInt((String) props.get("messaging.version.minorVersion")), version.getMinorVersion());
+ assertEquals(parseInt((String) props.get("messaging.version.microVersion")), version.getMicroVersion());
+ assertEquals(parseInt((String) props.get("messaging.version.incrementingVersion")), version.getIncrementingVersion());
+ }
+
+
+ // Z implementation ----------------------------------------------
+
+ // Y overrides ---------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/util/XMLUtilTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/XMLUtilTest.java 2008-07-07 11:43:18 UTC (rev 4641)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/XMLUtilTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -1,280 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.tests.unit.core.util;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.util.XMLUtil;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @version <tt>$Revision$</tt>
- */
-public class XMLUtilTest extends TestCase
-{
- // Constructors --------------------------------------------------
-
- public XMLUtilTest(String name)
- {
- super(name);
- }
-
- // Public --------------------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void testGetTextContext_1() throws Exception
- {
- String document = "<blah>foo</blah>";
-
- Element e = XMLUtil.stringToElement(document);
-
- assertEquals("foo", XMLUtil.getTextContent(e));
- }
-
- public void testGetTextContext_2() throws Exception
- {
- String document = "<blah someattribute=\"somevalue\">foo</blah>";
-
- Element e = XMLUtil.stringToElement(document);
-
- assertEquals("foo", XMLUtil.getTextContent(e));
- }
-
- public void testGetTextContext_3() throws Exception
- {
- String document = "<blah someattribute=\"somevalue\"><a/></blah>";
-
- Element e = XMLUtil.stringToElement(document);
-
- String s = XMLUtil.getTextContent(e);
-
- Element subelement = XMLUtil.stringToElement(s);
-
- assertEquals("a", subelement.getNodeName());
- }
-
- public void testGetTextContext_4() throws Exception
- {
- String document = "<blah someattribute=\"somevalue\"><a></a></blah>";
-
- Element e = XMLUtil.stringToElement(document);
-
- String s = XMLUtil.getTextContent(e);
-
- Element subelement = XMLUtil.stringToElement(s);
-
- assertEquals("a", subelement.getNodeName());
- }
-
- public void testGetTextContext_5() throws Exception
- {
- String document = "<blah someattribute=\"somevalue\"><a><b/></a></blah>";
-
- Element e = XMLUtil.stringToElement(document);
-
- String s = XMLUtil.getTextContent(e);
-
- Element subelement = XMLUtil.stringToElement(s);
-
- assertEquals("a", subelement.getNodeName());
- NodeList nl = subelement.getChildNodes();
-
- // try to find <b>
- boolean found = false;
- for(int i = 0; i < nl.getLength(); i++)
- {
- Node n = nl.item(i);
- if ("b".equals(n.getNodeName()))
- {
- found = true;
- }
- }
- assertTrue(found);
- }
-
-
- public void testEquivalent_1() throws Exception
- {
- String s = "<a/>";
- String s2 = "<a/>";
-
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_2() throws Exception
- {
- String s = "<a></a>";
- String s2 = "<a/>";
-
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_3() throws Exception
- {
- String s = "<a attr1=\"val1\" attr2=\"val2\"/>";
- String s2 = "<a attr2=\"val2\"/>";
-
- try
- {
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
- fail("this should throw exception");
- }
- catch(IllegalArgumentException e)
- {
- // OK
- e.printStackTrace();
- }
- }
-
- public void testEquivalent_4() throws Exception
- {
- String s = "<a attr1=\"val1\" attr2=\"val2\"/>";
- String s2 = "<a attr2=\"val2\" attr1=\"val1\"/>";
-
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_5() throws Exception
- {
- String s = "<a><b/></a>";
- String s2 = "<a><b/></a>";
-
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_6() throws Exception
- {
- String s = "<enclosing><a attr1=\"val1\" attr2=\"val2\"/></enclosing>";
- String s2 = "<enclosing><a attr2=\"val2\" attr1=\"val1\"/></enclosing>";
-
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
- }
-
- public void testEquivalent_7() throws Exception
- {
- String s = "<a><b/><c/></a>";
- String s2 = "<a><c/><b/></a>";
-
- try
- {
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
- fail("this should throw exception");
- }
- catch(IllegalArgumentException e)
- {
- // OK
- e.printStackTrace();
- }
- }
-
- public void testEquivalent_8() throws Exception
- {
- String s = "<a><!-- some comment --><b/><!--some other comment --><c/><!-- blah --></a>";
- String s2 = "<a><b/><!--blah blah--><c/></a>";
-
- XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
- }
-
- public void testElementToString_1() throws Exception
- {
- String s = "<a b=\"something\">somethingelse</a>";
- Element e = XMLUtil.stringToElement(s);
- String tostring = XMLUtil.elementToString(e);
- Element convertedAgain = XMLUtil.stringToElement(tostring);
- XMLUtil.assertEquivalent(e, convertedAgain);
- }
-
- public void testElementToString_2() throws Exception
- {
- String s = "<a b=\"something\"></a>";
- Element e = XMLUtil.stringToElement(s);
- String tostring = XMLUtil.elementToString(e);
- Element convertedAgain = XMLUtil.stringToElement(tostring);
- XMLUtil.assertEquivalent(e, convertedAgain);
- }
-
- public void testElementToString_3() throws Exception
- {
- String s = "<a b=\"something\"/>";
- Element e = XMLUtil.stringToElement(s);
- String tostring = XMLUtil.elementToString(e);
- Element convertedAgain = XMLUtil.stringToElement(tostring);
- XMLUtil.assertEquivalent(e, convertedAgain);
- }
-
- public void testElementToString_4() throws Exception
- {
- String s = "<a><![CDATA[somedata]]></a>";
- Element e = XMLUtil.stringToElement(s);
- String tostring = XMLUtil.elementToString(e);
- Element convertedAgain = XMLUtil.stringToElement(tostring);
- XMLUtil.assertEquivalent(e, convertedAgain);
- }
-
- public void testReplaceSystemProperties()
- {
- String before = "<deployment>\n" +
- " <test name=\"${sysprop1}\">content1</test>\n" +
- " <test name=\"test2\">content2</test>\n" +
- " <test name=\"test3\">content3</test>\n" +
- " <test name=\"test4\">${sysprop2}</test>\n" +
- " <test name=\"test5\">content5</test>\n" +
- " <test name=\"test6\">content6</test>\n" +
- "</deployment>";
- String after = "<deployment>\n" +
- " <test name=\"test1\">content1</test>\n" +
- " <test name=\"test2\">content2</test>\n" +
- " <test name=\"test3\">content3</test>\n" +
- " <test name=\"test4\">content4</test>\n" +
- " <test name=\"test5\">content5</test>\n" +
- " <test name=\"test6\">content6</test>\n" +
- "</deployment>";
- System.setProperty("sysprop1", "test1");
- System.setProperty("sysprop2", "content4");
- String replaced = XMLUtil.replaceSystemProps(before);
- assertEquals(after, replaced);
- }
-
- public void testStripCDATA() throws Exception
- {
- String xml = "<![CDATA[somedata]]>";
- String stripped = XMLUtil.stripCDATA(xml);
-
- assertEquals("somedata", stripped);
- }
-
-
-}
Copied: trunk/tests/src/org/jboss/messaging/tests/unit/util/XMLUtilTest.java (from rev 4646, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/XMLUtilTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/util/XMLUtilTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/util/XMLUtilTest.java 2008-07-07 13:45:33 UTC (rev 4647)
@@ -0,0 +1,279 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.util;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.util.XMLUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ */
+public class XMLUtilTest extends TestCase
+{
+ // Constructors --------------------------------------------------
+
+ public XMLUtilTest(String name)
+ {
+ super(name);
+ }
+
+ // Public --------------------------------------------------------
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public void testGetTextContext_1() throws Exception
+ {
+ String document = "<blah>foo</blah>";
+
+ Element e = XMLUtil.stringToElement(document);
+
+ assertEquals("foo", XMLUtil.getTextContent(e));
+ }
+
+ public void testGetTextContext_2() throws Exception
+ {
+ String document = "<blah someattribute=\"somevalue\">foo</blah>";
+
+ Element e = XMLUtil.stringToElement(document);
+
+ assertEquals("foo", XMLUtil.getTextContent(e));
+ }
+
+ public void testGetTextContext_3() throws Exception
+ {
+ String document = "<blah someattribute=\"somevalue\"><a/></blah>";
+
+ Element e = XMLUtil.stringToElement(document);
+
+ String s = XMLUtil.getTextContent(e);
+
+ Element subelement = XMLUtil.stringToElement(s);
+
+ assertEquals("a", subelement.getNodeName());
+ }
+
+ public void testGetTextContext_4() throws Exception
+ {
+ String document = "<blah someattribute=\"somevalue\"><a></a></blah>";
+
+ Element e = XMLUtil.stringToElement(document);
+
+ String s = XMLUtil.getTextContent(e);
+
+ Element subelement = XMLUtil.stringToElement(s);
+
+ assertEquals("a", subelement.getNodeName());
+ }
+
+ public void testGetTextContext_5() throws Exception
+ {
+ String document = "<blah someattribute=\"somevalue\"><a><b/></a></blah>";
+
+ Element e = XMLUtil.stringToElement(document);
+
+ String s = XMLUtil.getTextContent(e);
+
+ Element subelement = XMLUtil.stringToElement(s);
+
+ assertEquals("a", subelement.getNodeName());
+ NodeList nl = subelement.getChildNodes();
+
+ // try to find <b>
+ boolean found = false;
+ for(int i = 0; i < nl.getLength(); i++)
+ {
+ Node n = nl.item(i);
+ if ("b".equals(n.getNodeName()))
+ {
+ found = true;
+ }
+ }
+ assertTrue(found);
+ }
+
+
+ public void testEquivalent_1() throws Exception
+ {
+ String s = "<a/>";
+ String s2 = "<a/>";
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_2() throws Exception
+ {
+ String s = "<a></a>";
+ String s2 = "<a/>";
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_3() throws Exception
+ {
+ String s = "<a attr1=\"val1\" attr2=\"val2\"/>";
+ String s2 = "<a attr2=\"val2\"/>";
+
+ try
+ {
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
+ fail("this should throw exception");
+ }
+ catch(IllegalArgumentException e)
+ {
+ // OK
+ e.printStackTrace();
+ }
+ }
+
+ public void testEquivalent_4() throws Exception
+ {
+ String s = "<a attr1=\"val1\" attr2=\"val2\"/>";
+ String s2 = "<a attr2=\"val2\" attr1=\"val1\"/>";
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_5() throws Exception
+ {
+ String s = "<a><b/></a>";
+ String s2 = "<a><b/></a>";
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_6() throws Exception
+ {
+ String s = "<enclosing><a attr1=\"val1\" attr2=\"val2\"/></enclosing>";
+ String s2 = "<enclosing><a attr2=\"val2\" attr1=\"val1\"/></enclosing>";
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
+ }
+
+ public void testEquivalent_7() throws Exception
+ {
+ String s = "<a><b/><c/></a>";
+ String s2 = "<a><c/><b/></a>";
+
+ try
+ {
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
+ fail("this should throw exception");
+ }
+ catch(IllegalArgumentException e)
+ {
+ // OK
+ e.printStackTrace();
+ }
+ }
+
+ public void testEquivalent_8() throws Exception
+ {
+ String s = "<a><!-- some comment --><b/><!--some other comment --><c/><!-- blah --></a>";
+ String s2 = "<a><b/><!--blah blah--><c/></a>";
+
+ XMLUtil.assertEquivalent(XMLUtil.stringToElement(s), XMLUtil.stringToElement(s2));
+ }
+
+ public void testElementToString_1() throws Exception
+ {
+ String s = "<a b=\"something\">somethingelse</a>";
+ Element e = XMLUtil.stringToElement(s);
+ String tostring = XMLUtil.elementToString(e);
+ Element convertedAgain = XMLUtil.stringToElement(tostring);
+ XMLUtil.assertEquivalent(e, convertedAgain);
+ }
+
+ public void testElementToString_2() throws Exception
+ {
+ String s = "<a b=\"something\"></a>";
+ Element e = XMLUtil.stringToElement(s);
+ String tostring = XMLUtil.elementToString(e);
+ Element convertedAgain = XMLUtil.stringToElement(tostring);
+ XMLUtil.assertEquivalent(e, convertedAgain);
+ }
+
+ public void testElementToString_3() throws Exception
+ {
+ String s = "<a b=\"something\"/>";
+ Element e = XMLUtil.stringToElement(s);
+ String tostring = XMLUtil.elementToString(e);
+ Element convertedAgain = XMLUtil.stringToElement(tostring);
+ XMLUtil.assertEquivalent(e, convertedAgain);
+ }
+
+ public void testElementToString_4() throws Exception
+ {
+ String s = "<a><![CDATA[somedata]]></a>";
+ Element e = XMLUtil.stringToElement(s);
+ String tostring = XMLUtil.elementToString(e);
+ Element convertedAgain = XMLUtil.stringToElement(tostring);
+ XMLUtil.assertEquivalent(e, convertedAgain);
+ }
+
+ public void testReplaceSystemProperties()
+ {
+ String before = "<deployment>\n" +
+ " <test name=\"${sysprop1}\">content1</test>\n" +
+ " <test name=\"test2\">content2</test>\n" +
+ " <test name=\"test3\">content3</test>\n" +
+ " <test name=\"test4\">${sysprop2}</test>\n" +
+ " <test name=\"test5\">content5</test>\n" +
+ " <test name=\"test6\">content6</test>\n" +
+ "</deployment>";
+ String after = "<deployment>\n" +
+ " <test name=\"test1\">content1</test>\n" +
+ " <test name=\"test2\">content2</test>\n" +
+ " <test name=\"test3\">content3</test>\n" +
+ " <test name=\"test4\">content4</test>\n" +
+ " <test name=\"test5\">content5</test>\n" +
+ " <test name=\"test6\">content6</test>\n" +
+ "</deployment>";
+ System.setProperty("sysprop1", "test1");
+ System.setProperty("sysprop2", "content4");
+ String replaced = XMLUtil.replaceSystemProps(before);
+ assertEquals(after, replaced);
+ }
+
+ public void testStripCDATA() throws Exception
+ {
+ String xml = "<![CDATA[somedata]]>";
+ String stripped = XMLUtil.stripCDATA(xml);
+
+ assertEquals("somedata", stripped);
+ }
+
+
+}
More information about the jboss-cvs-commits
mailing list