You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2018/04/01 20:26:35 UTC
[28/30] qpid-broker-j git commit: QPID-8151: [Broker-J] [Unit tests]
Factor out QpidTestCase
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
----------------------------------------------------------------------
diff --git a/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java b/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
index 13c1ac0..67bf9bd 100644
--- a/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
+++ b/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
@@ -20,6 +20,11 @@
*/
package org.apache.qpid.server.virtualhostnode.berkeleydb;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeThat;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@@ -33,6 +38,9 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.hamcrest.Description;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.apache.qpid.server.logging.EventLogger;
@@ -43,42 +51,47 @@ import org.apache.qpid.server.model.AbstractConfigurationChangeListener;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.SystemConfig;
import org.apache.qpid.test.utils.PortHelper;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
+import org.apache.qpid.test.utils.VirtualHostNodeStoreType;
+
/**
* Class to test that specific VHN operations result in the expected Operational Log message(s) being performed.
*/
-public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
+public class BDBHAVirtualHostNodeOperationalLoggingTest extends UnitTestBase
{
private BDBHAVirtualHostNodeTestHelper _helper;
private EventLogger _eventLogger;
private PortHelper _portHelper = new PortHelper();
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
- super.setUp();
+ assumeThat(getVirtualHostNodeStoreType(), is(equalTo(VirtualHostNodeStoreType.BDB)));
+
_helper = new BDBHAVirtualHostNodeTestHelper(getTestName());
_eventLogger = mock(EventLogger.class);
SystemConfig<?> context = (SystemConfig<?>) _helper.getBroker().getParent();
when(context.getEventLogger()).thenReturn(_eventLogger);
}
- @Override
- protected void tearDown() throws Exception
+ @After
+ public void tearDown() throws Exception
{
try
{
- _helper.tearDown();
+ if (_helper != null)
+ {
+ _helper.tearDown();
+ }
}
finally
{
- super.tearDown();
+ _portHelper.waitUntilAllocatedPortsAreFree();
}
-
- _portHelper.waitUntilAllocatedPortsAreFree();
}
+ @Test
public void testCreate() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
@@ -94,7 +107,10 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
// stop node to avoid running into race when role change is reported after we performed the check
node1.stop();
- assertEquals("Unexpected VHN log subject", "[grp(/group)/vhn(/node1)] ", node1.getVirtualHostNodeLogSubject().getLogString());
+ assertEquals("Unexpected VHN log subject",
+ "[grp(/group)/vhn(/node1)] ",
+ node1.getVirtualHostNodeLogSubject().getLogString());
+
assertEquals("Unexpected group log subject", "[grp(/group)] ", node1.getGroupLogSubject().getLogString());
String expectedMessage = HighAvailabilityMessages.CREATED().toString();
@@ -106,6 +122,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
argThat(new LogMessageMatcher(expectedMessage, HighAvailabilityMessages.ROLE_CHANGED_LOG_HIERARCHY)));
}
+ @Test
public void testDelete() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
@@ -127,6 +144,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
}
+ @Test
public void testSetPriority() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
@@ -150,6 +168,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
argThat(new LogMessageMatcher(expectedMessage, HighAvailabilityMessages.PRIORITY_CHANGED_LOG_HIERARCHY)));
}
+ @Test
public void testSetQuorumOverride() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
@@ -173,6 +192,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
argThat(new LogMessageMatcher(expectedMessage, HighAvailabilityMessages.QUORUM_OVERRIDE_CHANGED_LOG_HIERARCHY)));
}
+ @Test
public void testSetDesignatedPrimary() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
@@ -196,6 +216,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
argThat(new LogMessageMatcher(expectedMessage, HighAvailabilityMessages.DESIGNATED_PRIMARY_CHANGED_LOG_HIERARCHY)));
}
+ @Test
public void testRemoteNodeAdded() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
@@ -224,6 +245,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
argThat(new LogMessageMatcher(expectedMessage, HighAvailabilityMessages.ADDED_LOG_HIERARCHY)));
}
+ @Test
public void testRemoteNodeRemoved() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
@@ -256,6 +278,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
argThat(new LogMessageMatcher(expectedMessage, HighAvailabilityMessages.REMOVED_LOG_HIERARCHY)));
}
+ @Test
public void testRemoteNodeDetached() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
@@ -283,8 +306,8 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes);
- assertTrue("Remote node was not added during expected period of time", remoteNodeAdded.await(10, TimeUnit.SECONDS));
-
+ assertTrue("Remote node was not added during expected period of time",
+ remoteNodeAdded.await(10, TimeUnit.SECONDS));
BDBHARemoteReplicationNodeImpl remoteNode = (BDBHARemoteReplicationNodeImpl)node1.getRemoteReplicationNodes().iterator().next();
waitForRemoteNodeToAttainRole(remoteNode, EnumSet.of(NodeRole.REPLICA));
@@ -308,6 +331,7 @@ public class BDBHAVirtualHostNodeOperationalLoggingTest extends QpidTestCase
}
+ @Test
public void testRemoteNodeReAttached() throws Exception
{
int node1PortNumber = _portHelper.getNextAvailable();
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
----------------------------------------------------------------------
diff --git a/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java b/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
index 22b080d..ecd9e07 100644
--- a/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
+++ b/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
@@ -47,6 +47,7 @@ import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.configuration.updater.TaskExecutorImpl;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.BrokerModel;
+import org.apache.qpid.server.model.BrokerTestHelper;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
import org.apache.qpid.server.model.RemoteReplicationNode;
@@ -55,12 +56,11 @@ import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.store.ConfiguredObjectRecordImpl;
import org.apache.qpid.server.store.UnresolvedConfiguredObject;
-import org.apache.qpid.server.model.BrokerTestHelper;
+import org.apache.qpid.server.util.FileUtils;
import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHostImpl;
import org.apache.qpid.server.virtualhost.berkeleydb.BDBVirtualHost;
import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode;
import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.server.util.FileUtils;
/**
* Helper class to make the tests of BDB HA Virtual Host Nodes simpler and more concise.
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBVirtualHostNodeTest.java
----------------------------------------------------------------------
diff --git a/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBVirtualHostNodeTest.java b/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBVirtualHostNodeTest.java
index ff717c3..0c77bac 100644
--- a/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBVirtualHostNodeTest.java
+++ b/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBVirtualHostNodeTest.java
@@ -20,6 +20,11 @@
*/
package org.apache.qpid.server.virtualhostnode.berkeleydb;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeThat;
import static org.mockito.Mockito.when;
import java.io.File;
@@ -27,24 +32,30 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.BrokerTestHelper;
-import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.test.utils.TestFileUtils;
import org.apache.qpid.server.util.FileUtils;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.apache.qpid.test.utils.UnitTestBase;
+import org.apache.qpid.test.utils.VirtualHostNodeStoreType;
-public class BDBVirtualHostNodeTest extends QpidTestCase
+public class BDBVirtualHostNodeTest extends UnitTestBase
{
private Broker<?> _broker;
private File _storePath;
- @Override
+ @Before
public void setUp() throws Exception
{
- super.setUp();
+ assumeThat(getVirtualHostNodeStoreType(), is(equalTo(VirtualHostNodeStoreType.BDB)));
+
_broker = BrokerTestHelper.createBrokerMock();
TaskExecutor taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
@@ -53,22 +64,16 @@ public class BDBVirtualHostNodeTest extends QpidTestCase
_storePath = TestFileUtils.createTestDirectory();
}
- @Override
- public void tearDown() throws Exception
+ @After
+ public void tearDown() throws Exception
{
- try
- {
- if (_storePath != null)
- {
- FileUtils.delete(_storePath, true);
- }
- }
- finally
+ if (_storePath != null)
{
- super.tearDown();
+ FileUtils.delete(_storePath, true);
}
}
+ @Test
public void testValidateOnCreateForInvalidStorePath() throws Exception
{
String nodeName = getTestName();
@@ -88,7 +93,8 @@ public class BDBVirtualHostNodeTest extends QpidTestCase
}
catch (IllegalConfigurationException e)
{
- assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open node configuration store"));
+ assertTrue("Unexpected exception " + e.getMessage(),
+ e.getMessage().startsWith("Cannot open node configuration store"));
}
}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/QpidExceptionTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/QpidExceptionTest.java b/broker-core/src/test/java/org/apache/qpid/server/QpidExceptionTest.java
index b6b6e8f..2e3b985 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/QpidExceptionTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/QpidExceptionTest.java
@@ -20,25 +20,32 @@
*/
package org.apache.qpid.server;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import org.apache.qpid.server.protocol.ErrorCodes;
import org.apache.qpid.server.protocol.v0_8.AMQFrameDecodingException;
import org.apache.qpid.server.protocol.v0_8.AMQShortString;
-import org.apache.qpid.server.protocol.ErrorCodes;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
+
/**
* This test is to ensure that when an AMQException is rethrown that the specified exception is correctly wrapped up.
- *
+ * <p>
* There are three cases:
* Re-throwing an AMQException
* Re-throwing a Subclass of AMQException
* Re-throwing a Subclass of AMQException that does not have the default AMQException constructor which will force the
* creation of an AMQException.
*/
-public class QpidExceptionTest extends QpidTestCase
+public class QpidExceptionTest extends UnitTestBase
{
/**
* Test that an AMQException will be correctly created and rethrown.
*/
+ @Test
public void testRethrowGeneric()
{
QpidException test = new QpidException("refused", new RuntimeException());
@@ -46,12 +53,12 @@ public class QpidExceptionTest extends QpidTestCase
QpidException e = reThrowException(test);
assertEquals("Exception not of correct class", QpidException.class, e.getClass());
-
}
/**
* Test that a subclass of AMQException that has the default constructor will be correctly created and rethrown.
*/
+ @Test
public void testRethrowAMQESubclass()
{
AMQFrameDecodingException test = new AMQFrameDecodingException(
@@ -66,6 +73,7 @@ public class QpidExceptionTest extends QpidTestCase
* Test that a subclass of AMQException that doesnot have the default constructor will be correctly rethrown as an
* AMQException
*/
+ @Test
public void testRethrowAMQESubclassNoConstructor()
{
AMQExceptionSubclass test = new AMQExceptionSubclass("Invalid Argument Exception");
@@ -85,15 +93,20 @@ public class QpidExceptionTest extends QpidTestCase
QpidException amqe = test.cloneForCurrentThread();
if(test instanceof AMQException)
{
- assertEquals("Error code does not match.", ((AMQException)test).getErrorCode(), ((AMQException)amqe).getErrorCode());
+ assertEquals("Error code does not match.",
+ (long) ((AMQException) test).getErrorCode(),
+ (long) ((AMQException) amqe).getErrorCode());
+
}
- assertTrue("Exception message does not start as expected.", amqe.getMessage().startsWith(test.getMessage()));
+ assertTrue("Exception message does not start as expected.",
+ amqe.getMessage().startsWith(test.getMessage()));
assertEquals("Test Exception is not set as the cause", test, amqe.getCause());
assertEquals("Cause is not correct", test.getCause(), amqe.getCause().getCause());
return amqe;
}
+ @Test
public void testGetMessageAsString()
{
StringBuilder sb = new StringBuilder();
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/SelectorParserTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/SelectorParserTest.java b/broker-core/src/test/java/org/apache/qpid/server/SelectorParserTest.java
index 20d041f..313d468 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/SelectorParserTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/SelectorParserTest.java
@@ -21,45 +21,56 @@
package org.apache.qpid.server;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+import org.apache.qpid.server.filter.JMSSelectorFilter;
import org.apache.qpid.server.filter.SelectorParsingException;
import org.apache.qpid.server.filter.selector.ParseException;
-import org.apache.qpid.server.filter.JMSSelectorFilter;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class SelectorParserTest extends QpidTestCase
+public class SelectorParserTest extends UnitTestBase
{
+ @Test
public void testSelectorWithHyphen()
{
testPass("Cost = 2 AND \"property-with-hyphen\" = 'wibble'");
}
+ @Test
public void testLike()
{
testFail("Cost LIKE 2");
testPass("Cost LIKE 'Hello'");
}
+ @Test
public void testStringQuoted()
{
testPass("string = 'Test'");
}
+ @Test
public void testProperty()
{
testPass("prop1 = prop2");
}
+ @Test
public void testPropertyInvalid()
{
testFail("prop1 = prop2 foo AND string = 'Test'");
}
+ @Test
public void testPropertyNames()
{
testPass("$min= TRUE AND _max= FALSE AND Prop_2 = true AND prop$3 = false");
}
+ @Test
public void testProtected()
{
testFail("NULL = 0 ");
@@ -76,33 +87,39 @@ public class SelectorParserTest extends QpidTestCase
}
+ @Test
public void testBoolean()
{
testPass("min= TRUE AND max= FALSE ");
testPass("min= true AND max= false");
}
+ @Test
public void testDouble()
{
testPass("positive=31E2 AND negative=-31.4E3");
testPass("min=" + Double.MIN_VALUE + " AND max=" + Double.MAX_VALUE);
}
+ @Test
public void testLong()
{
testPass("minLong=" + Long.MIN_VALUE + "L AND maxLong=" + Long.MAX_VALUE + "L");
}
+ @Test
public void testInt()
{
testPass("minInt=" + Integer.MIN_VALUE + " AND maxInt=" + Integer.MAX_VALUE);
}
+ @Test
public void testSigned()
{
testPass("negative=-42 AND positive=+42");
}
+ @Test
public void testOctal()
{
testPass("octal=042");
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/SystemLauncherTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/SystemLauncherTest.java b/broker-core/src/test/java/org/apache/qpid/server/SystemLauncherTest.java
index 3eee76a..d7f9a58 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/SystemLauncherTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/SystemLauncherTest.java
@@ -21,6 +21,10 @@
package org.apache.qpid.server;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
@@ -28,17 +32,20 @@ import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.apache.qpid.server.logging.messages.BrokerMessages;
import org.apache.qpid.server.model.BrokerModel;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.JsonSystemConfigImpl;
import org.apache.qpid.server.model.SystemConfig;
-import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.test.utils.TestFileUtils;
import org.apache.qpid.server.util.FileUtils;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class SystemLauncherTest extends QpidTestCase
+public class SystemLauncherTest extends UnitTestBase
{
private static final String INITIAL_SYSTEM_PROPERTY = "test";
private static final String INITIAL_SYSTEM_PROPERTY_VALUE = "testValue";
@@ -48,10 +55,9 @@ public class SystemLauncherTest extends QpidTestCase
private File _brokerWork;
private SystemLauncher _systemLauncher;
- @Override
+ @Before
public void setUp() throws Exception
{
- super.setUp();
// create empty initial configuration
Map<String,Object> initialConfig = new HashMap<>();
@@ -68,12 +74,11 @@ public class SystemLauncherTest extends QpidTestCase
setTestSystemProperty("QPID_WORK", _brokerWork.getAbsolutePath());
}
- @Override
+ @After
public void tearDown() throws Exception
{
try
{
- super.tearDown();
}
finally
{
@@ -88,6 +93,7 @@ public class SystemLauncherTest extends QpidTestCase
}
}
+ @Test
public void testInitialSystemPropertiesAreSetOnBrokerStartup() throws Exception
{
Map<String,Object> attributes = new HashMap<>();
@@ -99,20 +105,28 @@ public class SystemLauncherTest extends QpidTestCase
_systemLauncher.startup(attributes);
// test JVM system property should be set from initial system config file
- assertEquals("Unexpected JVM system property", INITIAL_SYSTEM_PROPERTY_VALUE, System.getProperty(INITIAL_SYSTEM_PROPERTY));
+ assertEquals("Unexpected JVM system property",
+ INITIAL_SYSTEM_PROPERTY_VALUE,
+ System.getProperty(INITIAL_SYSTEM_PROPERTY));
+
// existing system property should not be overridden
- assertEquals("Unexpected QPID_WORK system property", _brokerWork.getAbsolutePath(), System.getProperty("QPID_WORK"));
+ assertEquals("Unexpected QPID_WORK system property",
+ _brokerWork.getAbsolutePath(),
+ System.getProperty("QPID_WORK"));
}
+ @Test
public void testConsoleLogsOnSuccessfulStartup() throws Exception
{
byte[] outputBytes = startBrokerAndCollectSystemOutput();
String output = new String(outputBytes);
assertFalse("Detected unexpected Exception: " + output, output.contains("Exception"));
- assertTrue("Output does not contain Broker Ready Message", output.contains(BrokerMessages.READY().toString()));
+ assertTrue("Output does not contain Broker Ready Message",
+ output.contains(BrokerMessages.READY().toString()));
}
+ @Test
public void testConsoleLogsOnUnsuccessfulStartup() throws Exception
{
Map<String,Object> initialConfig = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferOutputStreamTest.java b/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferOutputStreamTest.java
index f723524..f90f373 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferOutputStreamTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferOutputStreamTest.java
@@ -21,32 +21,35 @@
package org.apache.qpid.server.bytebuffer;
+import static org.junit.Assert.assertEquals;
+
import java.nio.charset.StandardCharsets;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class QpidByteBufferOutputStreamTest extends QpidTestCase
+public class QpidByteBufferOutputStreamTest extends UnitTestBase
{
private static final int BUFFER_SIZE = 10;
private static final int POOL_SIZE = 20;
private static final double SPARSITY_FRACTION = 0.5;
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
- super.setUp();
QpidByteBuffer.deinitialisePool();
QpidByteBuffer.initialisePool(BUFFER_SIZE, POOL_SIZE, SPARSITY_FRACTION);
}
- @Override
+ @After
public void tearDown() throws Exception
{
try
{
- super.tearDown();
}
finally
{
@@ -54,6 +57,7 @@ public class QpidByteBufferOutputStreamTest extends QpidTestCase
}
}
+ @Test
public void testWriteByteByByte() throws Exception
{
boolean direct = false;
@@ -66,6 +70,7 @@ public class QpidByteBufferOutputStreamTest extends QpidTestCase
}
}
+ @Test
public void testWriteByteArrays() throws Exception
{
boolean direct = false;
@@ -78,6 +83,7 @@ public class QpidByteBufferOutputStreamTest extends QpidTestCase
}
}
+ @Test
public void testWriteMixed() throws Exception
{
boolean direct = true;
@@ -91,6 +97,7 @@ public class QpidByteBufferOutputStreamTest extends QpidTestCase
}
+ @Test
public void testWriteByteArrays_ArrayTooLargeForSingleBuffer() throws Exception
{
boolean direct = false;
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java b/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java
index 2c38918..0bbbfd4 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java
@@ -20,6 +20,12 @@
package org.apache.qpid.server.bytebuffer;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -34,12 +40,15 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import com.google.common.io.ByteStreams;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.mockito.internal.util.Primitives;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class QpidByteBufferTest extends QpidTestCase
+public class QpidByteBufferTest extends UnitTestBase
{
private static final int BUFFER_FRAGMENT_SIZE = 5;
private static final int BUFFER_SIZE = 10;
@@ -50,21 +59,19 @@ public class QpidByteBufferTest extends QpidTestCase
private QpidByteBuffer _slicedBuffer;
private QpidByteBuffer _parent;
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
- super.setUp();
QpidByteBuffer.deinitialisePool();
QpidByteBuffer.initialisePool(BUFFER_FRAGMENT_SIZE, POOL_SIZE, SPARSITY_FRACTION);
_parent = QpidByteBuffer.allocateDirect(BUFFER_SIZE);
}
- @Override
+ @After
public void tearDown() throws Exception
{
try
{
- super.tearDown();
}
finally
{
@@ -80,6 +87,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testPutGetByIndex() throws Exception
{
testPutGetByIndex(double.class, 1.0);
@@ -91,6 +99,7 @@ public class QpidByteBufferTest extends QpidTestCase
testPutGetByIndex(byte.class, (byte)1);
}
+ @Test
public void testPutGet() throws Exception
{
testPutGet(double.class, false, 1.0);
@@ -106,18 +115,20 @@ public class QpidByteBufferTest extends QpidTestCase
testPutGet(byte.class, true, (short)1);
}
+ @Test
public void testMarkReset() throws Exception
{
_slicedBuffer = createSlice();
_slicedBuffer.mark();
_slicedBuffer.position(_slicedBuffer.position() + 1);
- assertEquals("Unexpected position after move", 1, _slicedBuffer.position());
+ assertEquals("Unexpected position after move", (long) 1, (long) _slicedBuffer.position());
_slicedBuffer.reset();
- assertEquals("Unexpected position after reset", 0, _slicedBuffer.position());
+ assertEquals("Unexpected position after reset", (long) 0, (long) _slicedBuffer.position());
}
+ @Test
public void testMarkResetAcrossFragmentBoundary() throws Exception
{
for (int i = 0; i < BUFFER_SIZE; ++i)
@@ -128,23 +139,24 @@ public class QpidByteBufferTest extends QpidTestCase
_parent.mark();
for (int i = 0; i < BUFFER_FRAGMENT_SIZE + 2; ++i)
{
- assertEquals("Unexpected value", i, _parent.get());
+ assertEquals("Unexpected value", (long) i, (long) _parent.get());
}
_parent.reset();
for (int i = 0; i < BUFFER_SIZE; ++i)
{
- assertEquals("Unexpected value", i, _parent.get());
+ assertEquals("Unexpected value", (long) i, (long) _parent.get());
}
}
+ @Test
public void testPosition() throws Exception
{
_slicedBuffer = createSlice();
- assertEquals("Unexpected position for new slice", 0, _slicedBuffer.position());
+ assertEquals("Unexpected position for new slice", (long) 0, (long) _slicedBuffer.position());
_slicedBuffer.position(1);
- assertEquals("Unexpected position after advance", 1, _slicedBuffer.position());
+ assertEquals("Unexpected position after advance", (long) 1, (long) _slicedBuffer.position());
final int oldLimit = _slicedBuffer.limit();
_slicedBuffer.limit(oldLimit - 1);
@@ -159,6 +171,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testSettingPositionBackwardsResetsMark()
{
_parent.position(8);
@@ -175,6 +188,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testSettingPositionForwardDoeNotResetMark()
{
final int originalPosition = 3;
@@ -184,9 +198,10 @@ public class QpidByteBufferTest extends QpidTestCase
_parent.reset();
- assertEquals("Unexpected position", originalPosition, _parent.position());
+ assertEquals("Unexpected position", (long) originalPosition, (long) _parent.position());
}
+ @Test
public void testRewind() throws Exception
{
final int expectedLimit = 7;
@@ -197,8 +212,8 @@ public class QpidByteBufferTest extends QpidTestCase
_parent.rewind();
- assertEquals("Unexpected position", 0, _parent.position());
- assertEquals("Unexpected limit", expectedLimit, _parent.limit());
+ assertEquals("Unexpected position", (long) 0, (long) _parent.position());
+ assertEquals("Unexpected limit", (long) expectedLimit, (long) _parent.limit());
try
{
_parent.reset();
@@ -210,6 +225,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testBulkPutGet() throws Exception
{
_slicedBuffer = createSlice();
@@ -240,7 +256,7 @@ public class QpidByteBufferTest extends QpidTestCase
// pass
}
- assertEquals("Position should be unchanged after failed put", 1, _slicedBuffer.position());
+ assertEquals("Position should be unchanged after failed put", (long) 1, (long) _slicedBuffer.position());
try
{
@@ -252,11 +268,10 @@ public class QpidByteBufferTest extends QpidTestCase
// pass
}
- assertEquals("Position should be unchanged after failed get", 1, _slicedBuffer.position());
-
-
+ assertEquals("Position should be unchanged after failed get", (long) 1, (long) _slicedBuffer.position());
}
+ @Test
public void testPutQpidByteBufferMultipleIntoMultiple() throws Exception
{
_slicedBuffer = createSlice();
@@ -276,6 +291,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testPutQpidByteBufferMultipleIntoSingle() throws Exception
{
_slicedBuffer = createSlice();
@@ -295,6 +311,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testPutQpidByteBufferSingleIntoMultiple() throws Exception
{
_slicedBuffer = createSlice();
@@ -312,6 +329,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testPutByteBuffer() throws Exception
{
final byte[] source = getTestBytes(_parent.remaining() - 1);
@@ -326,6 +344,7 @@ public class QpidByteBufferTest extends QpidTestCase
Assert.assertArrayEquals("Unexpected but ByteBuffer result", source, target);
}
+ @Test
public void testDuplicate()
{
_slicedBuffer = createSlice();
@@ -335,18 +354,21 @@ public class QpidByteBufferTest extends QpidTestCase
try (QpidByteBuffer duplicate = _slicedBuffer.duplicate())
{
- assertEquals("Unexpected position", _slicedBuffer.position(), duplicate.position() );
- assertEquals("Unexpected limit", _slicedBuffer.limit(), duplicate.limit() );
- assertEquals("Unexpected capacity", _slicedBuffer.capacity(), duplicate.capacity() );
+ assertEquals("Unexpected position", (long) _slicedBuffer.position(), (long) duplicate.position());
+ assertEquals("Unexpected limit", (long) _slicedBuffer.limit(), (long) duplicate.limit());
+ assertEquals("Unexpected capacity", (long) _slicedBuffer.capacity(), (long) duplicate.capacity());
duplicate.position(2);
duplicate.limit(originalLimit - 2);
- assertEquals("Unexpected position in the original", 1, _slicedBuffer.position());
- assertEquals("Unexpected limit in the original", originalLimit -1, _slicedBuffer.limit());
+ assertEquals("Unexpected position in the original", (long) 1, (long) _slicedBuffer.position());
+ assertEquals("Unexpected limit in the original",
+ (long) (originalLimit - 1),
+ (long) _slicedBuffer.limit());
}
}
+ @Test
public void testCopyToByteBuffer()
{
_slicedBuffer = createSlice();
@@ -358,12 +380,15 @@ public class QpidByteBufferTest extends QpidTestCase
ByteBuffer destination = ByteBuffer.allocate(source.length);
_slicedBuffer.copyTo(destination);
- assertEquals("Unexpected remaining in original QBB", originalRemaining, _slicedBuffer.remaining());
- assertEquals("Unexpected remaining in destination", 0, destination.remaining());
+ assertEquals("Unexpected remaining in original QBB",
+ (long) originalRemaining,
+ (long) _slicedBuffer.remaining());
+ assertEquals("Unexpected remaining in destination", (long) 0, (long) destination.remaining());
Assert.assertArrayEquals("Unexpected copyTo result", source, destination.array());
}
+ @Test
public void testCopyToArray()
{
_slicedBuffer = createSlice();
@@ -375,11 +400,14 @@ public class QpidByteBufferTest extends QpidTestCase
byte[] destination = new byte[source.length];
_slicedBuffer.copyTo(destination);
- assertEquals("Unexpected remaining in original QBB", originalRemaining, _slicedBuffer.remaining());
+ assertEquals("Unexpected remaining in original QBB",
+ (long) originalRemaining,
+ (long) _slicedBuffer.remaining());
Assert.assertArrayEquals("Unexpected copyTo result", source, destination);
}
+ @Test
public void testPutCopyOfSingleIntoMultiple()
{
_slicedBuffer = createSlice();
@@ -388,8 +416,10 @@ public class QpidByteBufferTest extends QpidTestCase
QpidByteBuffer sourceQpidByteBuffer = QpidByteBuffer.wrap(source);
_slicedBuffer.putCopyOf(sourceQpidByteBuffer);
- assertEquals("Copied buffer should not be changed", source.length, sourceQpidByteBuffer.remaining());
- assertEquals("Buffer should be full", 0, _slicedBuffer.remaining());
+ assertEquals("Copied buffer should not be changed",
+ (long) source.length,
+ (long) sourceQpidByteBuffer.remaining());
+ assertEquals("Buffer should be full", (long) 0, (long) _slicedBuffer.remaining());
_slicedBuffer.flip();
byte[] destination = new byte[source.length];
@@ -398,6 +428,7 @@ public class QpidByteBufferTest extends QpidTestCase
Assert.assertArrayEquals("Unexpected putCopyOf result", source, destination);
}
+ @Test
public void testPutCopyOfMultipleIntoSingle()
{
_slicedBuffer = createSlice();
@@ -409,8 +440,10 @@ public class QpidByteBufferTest extends QpidTestCase
{
target.putCopyOf(_slicedBuffer);
- assertEquals("Copied buffer should not be changed", source.length, _slicedBuffer.remaining());
- assertEquals("Unexpected remaining", 1, target.remaining());
+ assertEquals("Copied buffer should not be changed",
+ (long) source.length,
+ (long) _slicedBuffer.remaining());
+ assertEquals("Unexpected remaining", (long) 1, (long) target.remaining());
target.flip();
byte[] destination = new byte[source.length];
@@ -420,6 +453,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testPutCopyOfMultipleIntoMultiple()
{
_slicedBuffer = createSlice();
@@ -431,8 +465,10 @@ public class QpidByteBufferTest extends QpidTestCase
{
target.putCopyOf(_slicedBuffer);
- assertEquals("Copied buffer should not be changed", source.length, _slicedBuffer.remaining());
- assertEquals("Unexpected remaining", 2, target.remaining());
+ assertEquals("Copied buffer should not be changed",
+ (long) source.length,
+ (long) _slicedBuffer.remaining());
+ assertEquals("Unexpected remaining", (long) 2, (long) target.remaining());
target.flip();
byte[] destination = new byte[source.length];
@@ -442,6 +478,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testCompact()
{
_slicedBuffer = createSlice();
@@ -454,8 +491,8 @@ public class QpidByteBufferTest extends QpidTestCase
int remaining = _slicedBuffer.remaining();
_slicedBuffer.compact();
- assertEquals("Unexpected position", remaining, _slicedBuffer.position());
- assertEquals("Unexpected limit", _slicedBuffer.capacity(), _slicedBuffer.limit());
+ assertEquals("Unexpected position", (long) remaining, (long) _slicedBuffer.position());
+ assertEquals("Unexpected limit", (long) _slicedBuffer.capacity(), (long) _slicedBuffer.limit());
_slicedBuffer.flip();
@@ -469,6 +506,7 @@ public class QpidByteBufferTest extends QpidTestCase
Assert.assertArrayEquals("Unexpected compact result", expected, destination);
}
+ @Test
public void testSliceOfSlice()
{
_slicedBuffer = createSlice();
@@ -482,11 +520,13 @@ public class QpidByteBufferTest extends QpidTestCase
try (QpidByteBuffer newSlice = _slicedBuffer.slice())
{
- assertEquals("Unexpected position in original", 1, _slicedBuffer.position());
- assertEquals("Unexpected limit in original", source.length - 1, _slicedBuffer.limit());
- assertEquals("Unexpected position", 0, newSlice.position());
- assertEquals("Unexpected limit", remaining, newSlice.limit());
- assertEquals("Unexpected capacity", remaining, newSlice.capacity());
+ assertEquals("Unexpected position in original", (long) 1, (long) _slicedBuffer.position());
+ assertEquals("Unexpected limit in original",
+ (long) (source.length - 1),
+ (long) _slicedBuffer.limit());
+ assertEquals("Unexpected position", (long) 0, (long) newSlice.position());
+ assertEquals("Unexpected limit", (long) remaining, (long) newSlice.limit());
+ assertEquals("Unexpected capacity", (long) remaining, (long) newSlice.capacity());
byte[] destination = new byte[newSlice.remaining()];
newSlice.get(destination);
@@ -497,6 +537,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testViewOfSlice()
{
_slicedBuffer = createSlice();
@@ -508,12 +549,14 @@ public class QpidByteBufferTest extends QpidTestCase
try (QpidByteBuffer view = _slicedBuffer.view(0, _slicedBuffer.remaining()))
{
- assertEquals("Unexpected position in original", 1, _slicedBuffer.position());
- assertEquals("Unexpected limit in original", source.length - 1, _slicedBuffer.limit());
+ assertEquals("Unexpected position in original", (long) 1, (long) _slicedBuffer.position());
+ assertEquals("Unexpected limit in original",
+ (long) (source.length - 1),
+ (long) _slicedBuffer.limit());
- assertEquals("Unexpected position", 0, view.position());
- assertEquals("Unexpected limit", _slicedBuffer.remaining(), view.limit());
- assertEquals("Unexpected capacity", _slicedBuffer.remaining(), view.capacity());
+ assertEquals("Unexpected position", (long) 0, (long) view.position());
+ assertEquals("Unexpected limit", (long) _slicedBuffer.remaining(), (long) view.limit());
+ assertEquals("Unexpected capacity", (long) _slicedBuffer.remaining(), (long) view.capacity());
byte[] destination = new byte[view.remaining()];
view.get(destination);
@@ -525,12 +568,14 @@ public class QpidByteBufferTest extends QpidTestCase
try (QpidByteBuffer view = _slicedBuffer.view(1, _slicedBuffer.remaining() - 2))
{
- assertEquals("Unexpected position in original", 1, _slicedBuffer.position());
- assertEquals("Unexpected limit in original", source.length - 1, _slicedBuffer.limit());
+ assertEquals("Unexpected position in original", (long) 1, (long) _slicedBuffer.position());
+ assertEquals("Unexpected limit in original",
+ (long) (source.length - 1),
+ (long) _slicedBuffer.limit());
- assertEquals("Unexpected position", 0, view.position());
- assertEquals("Unexpected limit", _slicedBuffer.remaining() - 2, view.limit());
- assertEquals("Unexpected capacity", _slicedBuffer.remaining() - 2, view.capacity());
+ assertEquals("Unexpected position", (long) 0, (long) view.position());
+ assertEquals("Unexpected limit", (long) (_slicedBuffer.remaining() - 2), (long) view.limit());
+ assertEquals("Unexpected capacity", (long) (_slicedBuffer.remaining() - 2), (long) view.capacity());
byte[] destination = new byte[view.remaining()];
view.get(destination);
@@ -541,6 +586,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testAsInputStream() throws Exception
{
_slicedBuffer = createSlice();
@@ -589,9 +635,9 @@ public class QpidByteBufferTest extends QpidTestCase
_slicedBuffer = _parent.slice();
_parent.limit(_parent.capacity());
- assertEquals("Unexpected position ", 0, _slicedBuffer.position());
- assertEquals("Unexpected limit ", size, _slicedBuffer.limit());
- assertEquals("Unexpected capacity ", size, _slicedBuffer.capacity());
+ assertEquals("Unexpected position ", (long) 0, (long) _slicedBuffer.position());
+ assertEquals("Unexpected limit ", (long) size, (long) _slicedBuffer.limit());
+ assertEquals("Unexpected capacity ", (long) size, (long) _slicedBuffer.capacity());
String methodSuffix = getMethodSuffix(primitiveTargetClass, unsigned);
Method put = _slicedBuffer.getClass().getMethod("put" + methodSuffix, Primitives.primitiveTypeOf(value.getClass()));
@@ -602,7 +648,9 @@ public class QpidByteBufferTest extends QpidTestCase
QpidByteBuffer rv = (QpidByteBuffer) put.invoke(_slicedBuffer, value);
assertEquals("Unexpected builder return value for type " + methodSuffix, _slicedBuffer, rv);
- assertEquals("Unexpected position for type " + methodSuffix, size, _slicedBuffer.position());
+ assertEquals("Unexpected position for type " + methodSuffix,
+ (long) size,
+ (long) _slicedBuffer.position());
try
{
@@ -616,7 +664,7 @@ public class QpidByteBufferTest extends QpidTestCase
_slicedBuffer.reset();
- assertEquals("Unexpected position after reset", 0, _slicedBuffer.position());
+ assertEquals("Unexpected position after reset", (long) 0, (long) _slicedBuffer.position());
Object retrievedValue = get.invoke(_slicedBuffer);
assertEquals("Unexpected value retrieved from get method for " + methodSuffix, value, retrievedValue);
@@ -651,7 +699,9 @@ public class QpidByteBufferTest extends QpidTestCase
assertEquals("Unexpected builder return value for type " + methodSuffix, _slicedBuffer, rv);
Object retrievedValue = get.invoke(_slicedBuffer, 0);
- assertEquals("Unexpected value retrieved from index get method for " + methodSuffix, value, retrievedValue);
+ assertEquals("Unexpected value retrieved from index get method for " + methodSuffix,
+ value,
+ retrievedValue);
try
{
@@ -767,6 +817,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testPooledBufferIsZeroedLoan() throws Exception
{
try (QpidByteBuffer buffer = QpidByteBuffer.allocateDirect(BUFFER_SIZE))
@@ -777,43 +828,47 @@ public class QpidByteBufferTest extends QpidTestCase
try (QpidByteBuffer buffer = QpidByteBuffer.allocateDirect(BUFFER_SIZE))
{
buffer.limit(1);
- assertEquals("Pooled QpidByteBuffer is not zeroed.", (byte) 0x0, buffer.get());
+ assertEquals("Pooled QpidByteBuffer is not zeroed.", (long) (byte) 0x0, (long) buffer.get());
}
}
+ @Test
public void testAllocateDirectOfSameSize() throws Exception
{
int bufferSize = BUFFER_SIZE;
try (QpidByteBuffer buffer = QpidByteBuffer.allocateDirect(bufferSize))
{
- assertEquals("Unexpected buffer size", bufferSize, buffer.capacity());
- assertEquals("Unexpected position on newly created buffer", 0, buffer.position());
- assertEquals("Unexpected limit on newly created buffer", bufferSize, buffer.limit());
+ assertEquals("Unexpected buffer size", (long) bufferSize, (long) buffer.capacity());
+ assertEquals("Unexpected position on newly created buffer", (long) 0, (long) buffer.position());
+ assertEquals("Unexpected limit on newly created buffer", (long) bufferSize, (long) buffer.limit());
}
}
+ @Test
public void testAllocateDirectOfSmallerSize() throws Exception
{
int bufferSize = BUFFER_SIZE - 1;
try (QpidByteBuffer buffer = QpidByteBuffer.allocateDirect(bufferSize))
{
- assertEquals("Unexpected buffer size", bufferSize, buffer.capacity());
- assertEquals("Unexpected position on newly created buffer", 0, buffer.position());
- assertEquals("Unexpected limit on newly created buffer", bufferSize, buffer.limit());
+ assertEquals("Unexpected buffer size", (long) bufferSize, (long) buffer.capacity());
+ assertEquals("Unexpected position on newly created buffer", (long) 0, (long) buffer.position());
+ assertEquals("Unexpected limit on newly created buffer", (long) bufferSize, (long) buffer.limit());
}
}
+ @Test
public void testAllocateDirectOfLargerSize() throws Exception
{
int bufferSize = BUFFER_SIZE + 1;
try (QpidByteBuffer buffer = QpidByteBuffer.allocateDirect(bufferSize))
{
- assertEquals("Unexpected buffer size", bufferSize, buffer.capacity());
- assertEquals("Unexpected position on newly created buffer", 0, buffer.position());
- assertEquals("Unexpected limit on newly created buffer", bufferSize, buffer.limit());
+ assertEquals("Unexpected buffer size", (long) bufferSize, (long) buffer.capacity());
+ assertEquals("Unexpected position on newly created buffer", (long) 0, (long) buffer.position());
+ assertEquals("Unexpected limit on newly created buffer", (long) bufferSize, (long) buffer.limit());
}
}
+ @Test
public void testAllocateDirectWithNegativeSize() throws Exception
{
try
@@ -827,6 +882,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testSettingUpPoolTwice() throws Exception
{
try
@@ -840,6 +896,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testDeflateInflateDirect() throws Exception
{
byte[] input = "aaabbbcccddddeeeffff".getBytes();
@@ -848,12 +905,13 @@ public class QpidByteBufferTest extends QpidTestCase
inputBuf.put(input);
inputBuf.flip();
- assertEquals(input.length, inputBuf.remaining());
+ assertEquals((long) input.length, (long) inputBuf.remaining());
doDeflateInflate(input, inputBuf, true);
}
}
+ @Test
public void testDeflateInflateHeap() throws Exception
{
byte[] input = "aaabbbcccddddeeeffff".getBytes();
@@ -864,6 +922,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testInflatingUncompressedBytes_ThrowsZipException() throws Exception
{
byte[] input = "not_a_compressed_stream".getBytes();
@@ -879,6 +938,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testSlice() throws Exception
{
try (QpidByteBuffer directBuffer = QpidByteBuffer.allocate(true, 6))
@@ -888,13 +948,14 @@ public class QpidByteBufferTest extends QpidTestCase
try (QpidByteBuffer directSlice = directBuffer.slice())
{
assertTrue("Direct slice should be direct too", directSlice.isDirect());
- assertEquals("Unexpected capacity", 3, directSlice.capacity());
- assertEquals("Unexpected limit", 3, directSlice.limit());
- assertEquals("Unexpected position", 0, directSlice.position());
+ assertEquals("Unexpected capacity", (long) 3, (long) directSlice.capacity());
+ assertEquals("Unexpected limit", (long) 3, (long) directSlice.limit());
+ assertEquals("Unexpected position", (long) 0, (long) directSlice.position());
}
}
}
+ @Test
public void testView() throws Exception
{
byte[] content = "ABCDEF".getBytes();
@@ -907,9 +968,9 @@ public class QpidByteBufferTest extends QpidTestCase
try (QpidByteBuffer view = buffer.view(0, buffer.remaining()))
{
assertTrue("Unexpected view direct", view.isDirect());
- assertEquals("Unexpected capacity", 3, view.capacity());
- assertEquals("Unexpected limit", 3, view.limit());
- assertEquals("Unexpected position", 0, view.position());
+ assertEquals("Unexpected capacity", (long) 3, (long) view.capacity());
+ assertEquals("Unexpected limit", (long) 3, (long) view.limit());
+ assertEquals("Unexpected position", (long) 0, (long) view.position());
final byte[] destination = new byte[view.remaining()];
view.get(destination);
@@ -925,6 +986,7 @@ public class QpidByteBufferTest extends QpidTestCase
}
}
+ @Test
public void testSparsity()
{
assertFalse("Unexpected sparsity after creation", _parent.isSparse());
@@ -942,20 +1004,24 @@ public class QpidByteBufferTest extends QpidTestCase
grandChild.dispose();
}
+ @Test
public void testAsQpidByteBuffers() throws IOException
{
byte[] dataForTwoBufs = "01234567890".getBytes(StandardCharsets.US_ASCII);
try (QpidByteBuffer qpidByteBuffer = QpidByteBuffer.asQpidByteBuffer(new ByteArrayInputStream(dataForTwoBufs)))
{
- assertEquals("Unexpected remaining in buf", 11, qpidByteBuffer.remaining());
+ assertEquals("Unexpected remaining in buf", (long) 11, (long) qpidByteBuffer.remaining());
}
try (QpidByteBuffer bufsForEmptyBytes = QpidByteBuffer.asQpidByteBuffer(new ByteArrayInputStream(new byte[]{})))
{
- assertEquals("Unexpected remaining in buf for empty buffer", 0, bufsForEmptyBytes.remaining());
+ assertEquals("Unexpected remaining in buf for empty buffer",
+ (long) 0,
+ (long) bufsForEmptyBytes.remaining());
}
}
+ @Test
public void testConcatenate() throws Exception
{
try (QpidByteBuffer buffer1 = QpidByteBuffer.allocateDirect(10);
@@ -971,11 +1037,11 @@ public class QpidByteBufferTest extends QpidTestCase
try (QpidByteBuffer concatenate = QpidByteBuffer.concatenate(buffer1, buffer2))
{
- assertEquals("Unexpected capacity", 6, concatenate.capacity());
- assertEquals("Unexpected position", 0, concatenate.position());
- assertEquals("Unexpected limit", 6, concatenate.limit());
- assertEquals("Unexpected value 1", buffer1Value, concatenate.getShort());
- assertEquals("Unexpected value 2", buffer2Value, concatenate.getChar(4));
+ assertEquals("Unexpected capacity", (long) 6, (long) concatenate.capacity());
+ assertEquals("Unexpected position", (long) 0, (long) concatenate.position());
+ assertEquals("Unexpected limit", (long) 6, (long) concatenate.limit());
+ assertEquals("Unexpected value 1", (long) buffer1Value, (long) concatenate.getShort());
+ assertEquals("Unexpected value 2", (long) buffer2Value, (long) concatenate.getChar(4));
}
}
}
@@ -999,7 +1065,9 @@ public class QpidByteBufferTest extends QpidTestCase
byte[] expectedBytes = Arrays.copyOfRange(input, 0, inflatedBytes.length);
Assert.assertArrayEquals("Inflated buf has unexpected content", expectedBytes, inflatedBytes);
- assertEquals("Unexpected number of inflated bytes", input.length, inflatedBytesCount);
+ assertEquals("Unexpected number of inflated bytes",
+ (long) input.length,
+ (long) inflatedBytesCount);
}
}
}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java b/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java
index 5ca9f83..7db67d9 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java
@@ -20,7 +20,9 @@
*/
package org.apache.qpid.server.configuration.startup;
-import static org.mockito.Matchers.eq;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -29,6 +31,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import org.junit.Before;
+import org.junit.Test;
+
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor;
import org.apache.qpid.server.configuration.updater.TaskExecutor;
@@ -44,16 +49,15 @@ import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.virtualhost.TestMemoryVirtualHost;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class VirtualHostCreationTest extends QpidTestCase
+public class VirtualHostCreationTest extends UnitTestBase
{
private VirtualHostNode _virtualHostNode;
- @Override
+ @Before
public void setUp() throws Exception
{
- super.setUp();
EventLogger eventLogger = mock(EventLogger.class);
TaskExecutor executor = CurrentThreadTaskExecutor.newStartedInstance();
@@ -83,10 +87,11 @@ public class VirtualHostCreationTest extends QpidTestCase
when(_virtualHostNode.getChildExecutor()).thenReturn(executor);
}
+ @Test
public void testCreateVirtualHostFromStoreConfigAttributes()
{
Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.NAME, getTestName());
attributes.put(VirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
attributes.put(VirtualHost.ID, UUID.randomUUID());
@@ -94,14 +99,15 @@ public class VirtualHostCreationTest extends QpidTestCase
host.open();
assertNotNull("Null is returned", host);
- assertEquals("Unexpected name", getName(), host.getName());
+ assertEquals("Unexpected name", getTestName(), host.getName());
host.close();
}
+ @Test
public void testCreateWithoutMandatoryAttributesResultsInException()
{
Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(VirtualHost.NAME, getName());
+ attributes.put(VirtualHost.NAME, getTestName());
attributes.put(VirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
String[] mandatoryAttributes = {VirtualHost.NAME};
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java b/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
index cf553af..33e04a4 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
@@ -20,6 +20,9 @@
*/
package org.apache.qpid.server.configuration.store;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.doAnswer;
@@ -38,6 +41,9 @@ import java.util.UUID;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -60,9 +66,9 @@ import org.apache.qpid.server.store.ConfiguredObjectRecord;
import org.apache.qpid.server.store.ConfiguredObjectRecordImpl;
import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class ManagementModeStoreHandlerTest extends QpidTestCase
+public class ManagementModeStoreHandlerTest extends UnitTestBase
{
private ManagementModeStoreHandler _handler;
private Map<String,Object> _systemConfigAttributes;
@@ -73,10 +79,9 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
private SystemConfig _systemConfig;
private TaskExecutor _taskExecutor;
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
- super.setUp();
_rootId = UUID.randomUUID();
_portEntryId = UUID.randomUUID();
_store = mock(DurableConfigurationStore.class);
@@ -159,12 +164,11 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
return new ManagementModeStoreHandler(_store, _systemConfig);
}
- @Override
+ @After
public void tearDown() throws Exception
{
_taskExecutor.stop();
_systemConfig.close();
- super.tearDown();
}
private Collection<ConfiguredObjectRecord> openAndGetRecords()
@@ -230,6 +234,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
return childIds;
}
+ @Test
public void testGetRootEntryWithEmptyOptions()
{
Collection<ConfiguredObjectRecord> records = openAndGetRecords();
@@ -238,6 +243,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
assertEquals("Unexpected children", Collections.singleton(_portEntryId), getChildrenIds(records, root));
}
+ @Test
public void testGetRootEntryWithHttpPortOverriden()
{
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE,9090);
@@ -248,10 +254,11 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
ConfiguredObjectRecord root = getRootEntry(records);
assertEquals("Unexpected root id", _rootId, root.getId());
Collection<UUID> childrenIds = getChildrenIds(records, root);
- assertEquals("Unexpected children size", 2, childrenIds.size());
+ assertEquals("Unexpected children size", (long) 2, (long) childrenIds.size());
assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
}
+ @Test
public void testGetRootEntryWithManagementPortsOverriden()
{
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE,1000);
@@ -262,10 +269,11 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
ConfiguredObjectRecord root = getRootEntry(records);
assertEquals("Unexpected root id", _rootId, root.getId());
Collection<UUID> childrenIds = getChildrenIds(records, root);
- assertEquals("Unexpected children size", 2, childrenIds.size());
+ assertEquals("Unexpected children size", (long) 2, (long) childrenIds.size());
assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId));
}
+ @Test
public void testGetEntryByRootId()
{
Collection<ConfiguredObjectRecord> records = openAndGetRecords();
@@ -275,6 +283,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
assertEquals("Unexpected children", Collections.singleton(_portEntryId), getChildrenIds(records, root));
}
+ @Test
public void testGetEntryByPortId()
{
Collection<ConfiguredObjectRecord> records = openAndGetRecords();
@@ -285,6 +294,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
}
+ @Test
public void testGetEntryByCLIHttpPortId()
{
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE,9090);
@@ -298,6 +308,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
assertCLIPortEntry(records, portEntry, optionsPort, Protocol.HTTP);
}
+ @Test
public void testHttpPortEntryIsQuiesced()
{
Map<String, Object> attributes = new HashMap<String, Object>();
@@ -313,11 +324,13 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE));
}
+ @Test
public void testVirtualHostEntryIsNotQuiescedByDefault()
{
virtualHostEntryQuiescedStatusTestImpl(false);
}
+ @Test
public void testVirtualHostEntryIsQuiescedWhenRequested()
{
virtualHostEntryQuiescedStatusTestImpl(true);
@@ -377,6 +390,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
(Collection<Protocol>) attributes.get(Port.PROTOCOLS)));
}
+ @Test
public void testSavePort()
{
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE,1000);
@@ -393,6 +407,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
verify(_store).create(any(ConfiguredObjectRecord.class));
}
+ @Test
public void testSaveRoot()
{
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE,1000);
@@ -409,6 +424,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
verify(_store).update(anyBoolean(), any(ConfiguredObjectRecord.class));
}
+ @Test
public void testSaveCLIHttpPort()
{
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE,1000);
@@ -434,6 +450,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
}
}
+ @Test
public void testRemove()
{
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE,1000);
@@ -471,6 +488,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
verify(_store).remove(record);
}
+ @Test
public void testRemoveCLIPort()
{
_systemConfigAttributes.put(SystemConfig.MANAGEMENT_MODE_HTTP_PORT_OVERRIDE,1000);
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java b/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
index 27122c2..44b5be5 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/configuration/store/StoreConfigurationChangeListenerTest.java
@@ -30,6 +30,9 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.UUID;
+import org.junit.Before;
+import org.junit.Test;
+
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Model;
@@ -38,21 +41,21 @@ import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.store.ConfiguredObjectRecord;
import org.apache.qpid.server.store.DurableConfigurationStore;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class StoreConfigurationChangeListenerTest extends QpidTestCase
+public class StoreConfigurationChangeListenerTest extends UnitTestBase
{
private DurableConfigurationStore _store;
private StoreConfigurationChangeListener _listener;
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
- super.setUp();
_store = mock(DurableConfigurationStore.class);
_listener = new StoreConfigurationChangeListener(_store);
}
+ @Test
public void testStateChanged()
{
notifyBrokerStarted();
@@ -66,6 +69,7 @@ public class StoreConfigurationChangeListenerTest extends QpidTestCase
verify(_store).remove(record);
}
+ @Test
public void testChildAdded()
{
notifyBrokerStarted();
@@ -83,6 +87,7 @@ public class StoreConfigurationChangeListenerTest extends QpidTestCase
verify(_store).update(eq(true), any(ConfiguredObjectRecord.class));
}
+ @Test
public void testAttributeSet()
{
notifyBrokerStarted();
@@ -93,6 +98,7 @@ public class StoreConfigurationChangeListenerTest extends QpidTestCase
verify(_store).update(eq(false), any(ConfiguredObjectRecord.class));
}
+ @Test
public void testChildAddedWhereParentManagesChildStorage()
{
notifyBrokerStarted();
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java b/broker-core/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
index 7f0f9a7..6d9f4a3 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
@@ -20,6 +20,13 @@
*/
package org.apache.qpid.server.configuration.updater;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.concurrent.BlockingQueue;
@@ -33,22 +40,25 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.security.auth.Subject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import org.apache.qpid.server.util.ServerScopedRuntimeException;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class TaskExecutorTest extends QpidTestCase
+public class TaskExecutorTest extends UnitTestBase
{
private TaskExecutorImpl _executor;
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
- super.setUp();
_executor = new TaskExecutorImpl();
}
- @Override
- protected void tearDown() throws Exception
+ @After
+ public void tearDown() throws Exception
{
try
{
@@ -56,21 +66,23 @@ public class TaskExecutorTest extends QpidTestCase
}
finally
{
- super.tearDown();
}
}
+ @Test
public void testGetState()
{
assertFalse("Unexpected initial state", _executor.isRunning());
}
+ @Test
public void testStart()
{
_executor.start();
assertTrue("Unexpected started state", _executor.isRunning());
}
+ @Test
public void testStopImmediately() throws Exception
{
_executor.start();
@@ -113,8 +125,11 @@ public class TaskExecutorTest extends QpidTestCase
final long timeout = 2000l;
boolean awaitSubmissions = submitLatch.await(timeout, TimeUnit.MILLISECONDS);
- assertTrue(submitLatch.getCount() + " task(s) have not been submitted within expected time", awaitSubmissions);
- assertTrue("The first task has not been triggered", waitForCallLatch.await(timeout, TimeUnit.MILLISECONDS));
+ assertTrue(submitLatch.getCount() + " task(s) have not been submitted within expected time",
+ awaitSubmissions);
+
+ assertTrue("The first task has not been triggered",
+ waitForCallLatch.await(timeout, TimeUnit.MILLISECONDS));
_executor.stopImmediately();
assertFalse("Unexpected stopped state", _executor.isRunning());
@@ -124,15 +139,18 @@ public class TaskExecutorTest extends QpidTestCase
Exception e2 = submitExceptions.poll(timeout, TimeUnit.MILLISECONDS);
assertNotNull("The task execution was not interrupted or cancelled", e2);
- assertTrue("One of the exceptions should be CancellationException:", e2 instanceof CancellationException
- || e instanceof CancellationException);
- assertTrue("One of the exceptions should be InterruptedException:", e2 instanceof InterruptedException
- || e instanceof InterruptedException);
+ final boolean condition1 = e2 instanceof CancellationException
+ || e instanceof CancellationException;
+ assertTrue("One of the exceptions should be CancellationException:", condition1);
+ final boolean condition = e2 instanceof InterruptedException
+ || e instanceof InterruptedException;
+ assertTrue("One of the exceptions should be InterruptedException:", condition);
t1.join(timeout);
t2.join(timeout);
}
+ @Test
public void testStop()
{
_executor.start();
@@ -140,6 +158,7 @@ public class TaskExecutorTest extends QpidTestCase
assertFalse("Unexpected stopped state", _executor.isRunning());
}
+ @Test
public void testSubmitAndWait() throws Exception
{
_executor.start();
@@ -172,6 +191,7 @@ public class TaskExecutorTest extends QpidTestCase
assertEquals("Unexpected task execution result", "DONE", result);
}
+ @Test
public void testSubmitAndWaitInNotAuthorizedContext()
{
_executor.start();
@@ -179,6 +199,7 @@ public class TaskExecutorTest extends QpidTestCase
assertNull("Subject must be null", subject);
}
+ @Test
public void testSubmitAndWaitInAuthorizedContext()
{
_executor.start();
@@ -194,6 +215,7 @@ public class TaskExecutorTest extends QpidTestCase
assertEquals("Unexpected subject", subject, result);
}
+ @Test
public void testSubmitAndWaitInAuthorizedContextWithNullSubject()
{
_executor.start();
@@ -208,6 +230,7 @@ public class TaskExecutorTest extends QpidTestCase
assertEquals("Unexpected subject", null, result);
}
+ @Test
public void testSubmitAndWaitReThrowsOriginalRuntimeException()
{
final RuntimeException exception = new RuntimeException();
@@ -249,6 +272,7 @@ public class TaskExecutorTest extends QpidTestCase
}
}
+ @Test
public void testSubmitAndWaitCurrentActorAndSecurityManagerSubjectAreRespected() throws Exception
{
_executor.start();
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d0dcd3fc/broker-core/src/test/java/org/apache/qpid/server/connection/ConnectionVersionValidatorTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/connection/ConnectionVersionValidatorTest.java b/broker-core/src/test/java/org/apache/qpid/server/connection/ConnectionVersionValidatorTest.java
index 5628eab..2b9072f 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/connection/ConnectionVersionValidatorTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/connection/ConnectionVersionValidatorTest.java
@@ -20,6 +20,8 @@
*/
package org.apache.qpid.server.connection;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.eq;
@@ -35,15 +37,18 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+
import org.apache.qpid.server.logging.EventLogger;
import org.apache.qpid.server.logging.LogMessage;
import org.apache.qpid.server.logging.messages.ConnectionMessages;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.transport.AMQPConnection;
import org.apache.qpid.server.virtualhost.QueueManagingVirtualHost;
-import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.UnitTestBase;
-public class ConnectionVersionValidatorTest extends QpidTestCase
+public class ConnectionVersionValidatorTest extends UnitTestBase
{
private QueueManagingVirtualHost _virtualHostMock;
@@ -51,10 +56,9 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
private EventLogger _eventLoggerMock;
private ConnectionVersionValidator _connectionValidator;
- @Override
+ @Before
public void setUp() throws Exception
{
- super.setUp();
_connectionValidator = new ConnectionVersionValidator();
_virtualHostMock = mock(QueueManagingVirtualHost.class);
@@ -75,6 +79,7 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
}
}
+ @Test
public void testInvalidRegex()
{
Map<String, List<String>> contextValues = new HashMap<>();
@@ -86,17 +91,20 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
// TODO: We should verify that the invalid regex is logged
}
+ @Test
public void testNullClientDefaultAllowed()
{
assertTrue(_connectionValidator.validateConnectionCreation(_connectionMock, _virtualHostMock));
}
+ @Test
public void testClientDefaultAllowed()
{
when(_connectionMock.getClientVersion()).thenReturn("foo");
assertTrue(_connectionValidator.validateConnectionCreation(_connectionMock, _virtualHostMock));
}
+ @Test
public void testEmptyList()
{
Map<String, List<String>> contextValues = new HashMap<>();
@@ -107,6 +115,7 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
verify(_eventLoggerMock, never()).message(any(LogMessage.class));
}
+ @Test
public void testEmptyString()
{
Map<String, List<String>> contextValues = new HashMap<>();
@@ -121,6 +130,7 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
verify(_eventLoggerMock).message(ConnectionMessages.CLIENT_VERSION_REJECT(null));
}
+ @Test
public void testClientRejected()
{
when(_connectionMock.getClientVersion()).thenReturn("foo");
@@ -131,6 +141,7 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
verify(_eventLoggerMock).message(ConnectionMessages.CLIENT_VERSION_REJECT("foo"));
}
+ @Test
public void testClientLogged()
{
when(_connectionMock.getClientVersion()).thenReturn("foo");
@@ -141,6 +152,7 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
verify(_eventLoggerMock).message(ConnectionMessages.CLIENT_VERSION_LOG("foo"));
}
+ @Test
public void testAllowedTakesPrecedence()
{
when(_connectionMock.getClientVersion()).thenReturn("foo");
@@ -153,6 +165,7 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
verify(_eventLoggerMock, never()).message(any(LogMessage.class));
}
+ @Test
public void testLoggedTakesPrecedenceOverRejected()
{
when(_connectionMock.getClientVersion()).thenReturn("foo");
@@ -164,6 +177,7 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
verify(_eventLoggerMock).message(ConnectionMessages.CLIENT_VERSION_LOG("foo"));
}
+ @Test
public void testRegex()
{
Map<String, List<String>> contextValues = new HashMap<>();
@@ -181,6 +195,7 @@ public class ConnectionVersionValidatorTest extends QpidTestCase
verify(_eventLoggerMock, never()).message(ConnectionMessages.CLIENT_VERSION_LOG("baz"));
}
+ @Test
public void testRegexLists()
{
Map<String, List<String>> contextValues = new HashMap<>();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org