From fd6bd8b5dee6807e7890f4eda578a73b4b1bb4dc Mon Sep 17 00:00:00 2001 From: Alex Rudyy Date: Wed, 10 Dec 2014 17:34:24 +0000 Subject: QPID-6265: Change system tests to have one log per file configured using Log4j, simplify QBTC git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1644492 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/server/BrokerStartupTest.java | 4 +- .../qpid/server/logging/BrokerLoggingTest.java | 119 ++++----------------- .../server/security/acl/AbstractACLTestCase.java | 2 +- .../management/jmx/LoggingManagementTest.java | 20 +++- .../management/jmx/ManagementLoggingTest.java | 8 +- .../apache/qpid/systest/rest/KeyStoreRestTest.java | 4 +- .../apache/qpid/systest/rest/LogViewerTest.java | 49 ++++++--- .../qpid/systest/rest/TrustStoreRestTest.java | 4 +- 8 files changed, 83 insertions(+), 127 deletions(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java index e267bf439b..c475432113 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java @@ -77,7 +77,7 @@ public class BrokerStartupTest extends AbstractTestLogging brokerConfigFile.delete(); } - startBroker(port, null); + startBroker(port, null, null); AMQConnectionURL url = new AMQConnectionURL(String.format("amqp://" + GUEST_USERNAME @@ -209,7 +209,7 @@ public class BrokerStartupTest extends AbstractTestLogging brokerConfigFile.delete(); } - startBroker(port, null); + startBroker(port, null, null); AMQConnectionURL url = new AMQConnectionURL(String.format("amqp://" + GUEST_USERNAME diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java index 4952c4e10e..f7953e56d1 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java @@ -22,13 +22,15 @@ package org.apache.qpid.server.logging; import junit.framework.AssertionFailedError; -import org.apache.qpid.server.BrokerOptions; +import org.apache.log4j.FileAppender; +import org.apache.log4j.LogManager; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Transport; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.transport.ConnectionException; import org.apache.qpid.util.LogMonitor; +import java.io.File; import java.io.IOException; import java.net.Socket; import java.util.Collections; @@ -59,6 +61,7 @@ public class BrokerLoggingTest extends AbstractTestLogging private static final Pattern BROKER_MESSAGE_LOG_PATTERN = Pattern.compile(BROKER_MESSAGE_LOG_REG_EXP); private static final String BRK_LOG_PREFIX = "BRK-"; + @Override public void setUp() throws Exception { setLogMessagePrefix(); @@ -144,94 +147,6 @@ public class BrokerLoggingTest extends AbstractTestLogging return getPathRelativeToWorkingDirectory(getTestConfigFile(DEFAULT_PORT)); } - /** - * Description: - * On startup the broker must report correctly report the log4j file in use. This is important as it can help diagnose why logging messages are not being reported. - * Input: - * No custom -l value should be provided on the command line so that the default value is correctly reported. - * Output: - * - * MESSAGE BRK-1007 : Using logging configuration : <$QPID_HOME>/etc/log4j.xml - * - * Validation Steps: - * - * 1. The BRK ID is correct - * 2. This occurs before the BRK-1001 startup message. - * 3. The log4j file is the full path to the file specified on the commandline. - * - * @throws Exception caused by broker startup - */ - public void testBrokerStartupDefaultLog4j() throws Exception - { - if (isJavaBroker() && isExternalBroker() && !isInternalBroker()) - { - String TESTID = "BRK-1007"; - - _brokerCommandHelper.removeBrokerCommandLog4JFile(); - - startBroker(); - - // Now we can create the monitor as _outputFile will now be defined - _monitor = new LogMonitor(_outputFile); - - // Ensure broker has fully started up. - getConnection(); - - // Ensure we wait for TESTID to be logged - waitAndFindMatches(TESTID); - - List results = waitAndFindMatches(BRK_LOG_PREFIX); - try - { - // Validation - - assertTrue("BRKer message not logged", results.size() > 0); - - boolean validation = false; - for (String rawLog : results) - { - // We don't care about messages after we have our log config - if (validation) - { - break; - } - - String log = getLog(rawLog); - - // Ensure we do not have a BRK-1001 message before - if (!getMessageID(log).equals(TESTID)) - { - assertFalse(getMessageID(log).equals("BRK-1001")); - continue; - } - - //1 - validateMessageID(TESTID, log); - - //2 - //There will be 1 copy of this startup message (via SystemOut) - assertEquals("Unexpected log4j configuration message count.", - 1, findMatches(TESTID).size()); - - //3 - String defaultLog4j = System.getProperty(QPID_HOME) + "/" + BrokerOptions.DEFAULT_LOG_CONFIG_FILE; - assertTrue("Log4j file(" + defaultLog4j + ") details not correctly logged:" + getMessageString(log), - getMessageString(log).endsWith(defaultLog4j)); - - validation = true; - } - - assertTrue("Validation not performed: " + TESTID + " not logged", validation); - } - catch (AssertionFailedError afe) - { - dumpLogs(results, _monitor); - - throw afe; - } - } - } - /** * Description: * On startup the broker must report correctly report the log4j file in use. This is important as it can help diagnose why logging messages are not being reported. The broker must also be capable of correctly recognising the command line property to specify the custom logging configuration. @@ -254,11 +169,17 @@ public class BrokerLoggingTest extends AbstractTestLogging // This logging startup code only occurs when you run a Java broker if (isJavaBroker()) { - String customLog4j = getBrokerCommandLog4JFile().getAbsolutePath(); + // Log4j properties expects this to be set + System.setProperty("qpid.testMethod", "-" + getName() + ".customLog4j"); + System.setProperty("qpid.testClass", getClass().getName() ); + + String customLog4j = System.getProperty("log4j.configuration.file"); String TESTID = "BRK-1007"; - startBroker(); + startBroker(0, false, customLog4j); + _outputFile = new File(((FileAppender) LogManager.getRootLogger().getAllAppenders().nextElement()).getFile()); + // Now we can create the monitor as _outputFile will now be defined _monitor = new LogMonitor(_outputFile); @@ -385,7 +306,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 //There will be 2 copies of the startup message (one via SystemOut, and one via Log4J) assertEquals("Unexpected startup message count", - 2, findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); validation = true; } @@ -471,9 +392,8 @@ public class BrokerLoggingTest extends AbstractTestLogging assertEquals("Incorrect message", TESTID, id); //2 - //There will be 2 copies of the startup message (one via SystemOut, and one via Log4J) assertEquals("Unexpected listen message count", - 2, findMatches(TESTID).size()); + 1, findMatches(TESTID).size()); //3 String message = getMessageString(log); @@ -587,7 +507,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //There will be 4 copies of the startup message (two via SystemOut, and two via Log4J) List listenMessages = findMatches(TESTID); assertEquals("Four listen messages should be found.", - 4, listenMessages .size()); + 2, listenMessages .size()); int tcpStarted = 0; int sslStarted = 0; @@ -604,8 +524,8 @@ public class BrokerLoggingTest extends AbstractTestLogging } } - assertEquals("Unexpected number of logs 'Listening on TCP port'", 2, tcpStarted); - assertEquals("Unexpected number of logs 'Listening on SSL port'", 2, sslStarted); + assertEquals("Unexpected number of logs 'Listening on TCP port'", 1, tcpStarted); + assertEquals("Unexpected number of logs 'Listening on SSL port'", 1, sslStarted); //4 Test ports open testSocketOpen(getPort()); @@ -690,10 +610,9 @@ public class BrokerLoggingTest extends AbstractTestLogging //2 assertEquals("Ready message not present", "Qpid Broker Ready", getMessageString(log)); - //There will be 2 copies of the startup message (one via SystemOut, and one via Log4J) assertEquals("Unexpected ready message count", - 2, findMatches(TESTID).size()); - assertEquals("The ready messages should have been the last 2 messages", results.size() - 2, i); + 1, findMatches(TESTID).size()); + assertEquals("The ready messages should have been the last 2 messages", results.size() - 1, i); validationComplete = true; break; diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java b/qpid/java/systests/src/test/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java index 789ad420d8..f7722a8384 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java @@ -59,7 +59,7 @@ public abstract class AbstractACLTestCase extends QpidBrokerTestCase implements @Override public void setUp() throws Exception { - getBrokerConfiguration().addGroupFileConfiguration(System.getProperty(QPID_HOME) + "/etc/groups-systests"); + getBrokerConfiguration().addGroupFileConfiguration(QPID_HOME + "/etc/groups-systests"); // run test specific setup String testSetup = StringUtils.replace(getName(), "test", "setUp"); diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java index 3717c1594d..a06ed7be52 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java @@ -25,6 +25,7 @@ import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; import org.apache.qpid.management.common.mbeans.LoggingManagement; +import org.apache.qpid.server.configuration.BrokerProperties; import org.apache.qpid.server.logging.log4j.LoggingManagementFacadeTest; import org.apache.qpid.test.utils.JMXTestUtils; import org.apache.qpid.test.utils.QpidBrokerTestCase; @@ -35,7 +36,6 @@ import org.apache.qpid.util.LogMonitor; * System test for Logging Management. These tests rely on value set within * test-profiles/log4j-test.xml. * - * @see LoggingManagementMBeanTest * @see LoggingManagementFacadeTest * */ @@ -44,7 +44,9 @@ public class LoggingManagementTest extends QpidBrokerTestCase private JMXTestUtils _jmxUtils; private LoggingManagement _loggingManagement; private LogMonitor _monitor; + private File _logConfig; + @Override public void setUp() throws Exception { getBrokerConfiguration().addJmxManagementConfiguration(); @@ -56,8 +58,9 @@ public class LoggingManagementTest extends QpidBrokerTestCase File tmpLogFile = File.createTempFile("log4j" + "." + getName(), ".xml"); tmpLogFile.deleteOnExit(); - FileUtils.copy(getBrokerCommandLog4JFile(), tmpLogFile); + FileUtils.copy(new File(System.getProperty("log4j.configuration.file")), tmpLogFile); setBrokerCommandLog4JFile(tmpLogFile); + _logConfig = tmpLogFile; super.setUp(); _jmxUtils.open(); @@ -66,6 +69,12 @@ public class LoggingManagementTest extends QpidBrokerTestCase _monitor = new LogMonitor(_outputFile); } + public void startBroker() throws Exception + { + super.startBroker(0, false, _logConfig.getAbsolutePath()); + } + + @Override public void tearDown() throws Exception { try @@ -74,6 +83,11 @@ public class LoggingManagementTest extends QpidBrokerTestCase { _jmxUtils.close(); } + + if (_logConfig != null) + { + _logConfig.delete(); + } } finally { @@ -122,7 +136,7 @@ public class LoggingManagementTest extends QpidBrokerTestCase _loggingManagement.setConfigFileLoggerLevel(operationalLoggingLogger, "OFF"); List matches = _monitor.waitAndFindMatches("Setting level to OFF for logger 'qpid.message'", 5000); - assertEquals(1, matches.size()); + assertTrue(matches.size()>=1); assertEffectiveLoggingLevel(operationalLoggingLogger, "INFO"); diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java index cb6eae013e..4df81845d8 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java @@ -104,7 +104,7 @@ public class ManagementLoggingTest extends AbstractTestLogging //There will be 2 copies of the startup message (one via SystemOut, and one via Log4J) results = findMatches("MNG-1001"); assertEquals("Unexpected startup message count.", - 2, results.size()); + 1, results.size()); //3 assertEquals("Startup log message is not 'Startup'.", "JMX Management Startup", @@ -185,7 +185,7 @@ public class ManagementLoggingTest extends AbstractTestLogging // Validation //There will be 4 startup messages (two via SystemOut, and two via Log4J) - assertEquals("Unexpected MNG-1002 message count", 4, results.size()); + assertEquals("Unexpected MNG-1002 message count", 2, results.size()); String log = getLogMessage(results, 0); @@ -197,7 +197,7 @@ public class ManagementLoggingTest extends AbstractTestLogging assertTrue("RMI Registry port not as expected(" + mPort + ").:" + getMessageString(log), getMessageString(log).endsWith(String.valueOf(mPort))); - log = getLogMessage(results, 2); + log = getLogMessage(results, 1); //1 validateMessageID("MNG-1002", log); @@ -243,7 +243,7 @@ public class ManagementLoggingTest extends AbstractTestLogging // Validate we only have two MNG-1002 (one via stdout, one via log4j) results = findMatches("MNG-1006"); assertEquals("Upexpected SSL Keystore message count", - 2, results.size()); + 1, results.size()); // Validate the keystore path is as expected assertTrue("SSL Keystore entry expected.:" + getMessageString(log), diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java index 4b881d1e9f..169ece986e 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java @@ -56,7 +56,7 @@ public class KeyStoreRestTest extends QpidRestTestCase Map keystore = keyStores.get(0); assertKeyStoreAttributes(keystore, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE, - System.getProperty(QPID_HOME) + "/../" + TestSSLConstants.BROKER_KEYSTORE, null); + QPID_HOME + "/../" + TestSSLConstants.BROKER_KEYSTORE, null); } public void testCreate() throws Exception @@ -98,7 +98,7 @@ public class KeyStoreRestTest extends QpidRestTestCase List> keyStores = assertNumberOfKeyStores(1); Map keystore = keyStores.get(0); assertKeyStoreAttributes(keystore, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE, - System.getProperty(QPID_HOME) + "/../" + TestSSLConstants.BROKER_KEYSTORE, null); + QPID_HOME + "/../" + TestSSLConstants.BROKER_KEYSTORE, null); } public void testDeleteFailsWhenKeyStoreInUse() throws Exception diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/LogViewerTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/LogViewerTest.java index f2fb2581f7..a7bf743e72 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/LogViewerTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/LogViewerTest.java @@ -28,25 +28,40 @@ import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import org.apache.qpid.server.BrokerOptions; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.apache.qpid.server.configuration.BrokerProperties; public class LogViewerTest extends QpidRestTestCase { - public static final String DEFAULT_FILE_APPENDER_NAME = "FileAppender"; private String _expectedLogFileName; + private FileAppender _fileAppender; + private String _appenderName; + @Override public void setUp() throws Exception { - setSystemProperty("logsuffix", "-" + getTestQueueName()); - _expectedLogFileName = System.getProperty("logprefix", "") + "qpid" + System.getProperty("logsuffix", "") + ".log"; - - // use real broker log file - File brokerLogFile = new File(System.getProperty(QPID_HOME), BrokerOptions.DEFAULT_LOG_CONFIG_FILE); - setBrokerCommandLog4JFile(brokerLogFile); + _appenderName = getTestQueueName(); + _expectedLogFileName = "qpid-" + _appenderName + ".log"; + _fileAppender = new FileAppender(new SimpleLayout(), + System.getProperty(BrokerProperties.PROPERTY_QPID_WORK) + File.separator + _expectedLogFileName, false); + _fileAppender.setName(_appenderName); + Logger.getRootLogger().addAppender(_fileAppender); super.setUp(); } + @Override + public void tearDown() throws Exception + { + if (_fileAppender != null) + { + Logger.getRootLogger().removeAppender(_fileAppender); + } + super.tearDown(); + } + public void testGetLogFiles() throws Exception { List> logFiles = getRestTestHelper().getJsonAsList("/service/logfilenames"); @@ -54,24 +69,32 @@ public class LogViewerTest extends QpidRestTestCase // 1 file appender is configured in QPID default log4j xml: assertTrue("Unexpected number of log files", logFiles.size() > 0); + Map logFileDetails = null; + for (Map appenderDetails: logFiles) + { + if (_appenderName.equals(appenderDetails.get("appenderName"))) + { + logFileDetails = appenderDetails; + break; + } + } - Map logFileDetails = logFiles.get(0); assertEquals("Unexpected log file name", _expectedLogFileName, logFileDetails.get("name")); assertEquals("Unexpected log file mime type", "text/plain", logFileDetails.get("mimeType")); - assertEquals("Unexpected log file appender",DEFAULT_FILE_APPENDER_NAME, logFileDetails.get("appenderName")); + assertEquals("Unexpected log file appender",_appenderName, logFileDetails.get("appenderName")); assertTrue("Unexpected log file size", ((Number)logFileDetails.get("size")).longValue()>0); assertTrue("Unexpected log file modification time", ((Number)logFileDetails.get("lastModified")).longValue()>0); } public void testDownloadExistingLogFiles() throws Exception { - byte[] bytes = getRestTestHelper().getBytes("/service/logfile?l=" + DEFAULT_FILE_APPENDER_NAME + "%2F" + _expectedLogFileName); + byte[] bytes = getRestTestHelper().getBytes("/service/logfile?l=" + _appenderName + "%2F" + _expectedLogFileName); ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bytes)); try { ZipEntry entry = zis.getNextEntry(); - assertEquals("Unexpected broker log file name", DEFAULT_FILE_APPENDER_NAME + "/" + _expectedLogFileName, entry.getName()); + assertEquals("Unexpected broker log file name", _appenderName + "/" + _expectedLogFileName, entry.getName()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; @@ -91,7 +114,7 @@ public class LogViewerTest extends QpidRestTestCase public void testDownloadNonExistingLogFiles() throws Exception { - int responseCode = getRestTestHelper().submitRequest("/service/logfile?l=" + DEFAULT_FILE_APPENDER_NAME + "%2F" + int responseCode = getRestTestHelper().submitRequest("/service/logfile?l=" + _appenderName + "%2F" + _expectedLogFileName + "_" + System.currentTimeMillis(), "GET"); assertEquals("Unexpected response code", 404, responseCode); diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java index 5d2e9de3fa..1aac22d0aa 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java @@ -56,7 +56,7 @@ public class TrustStoreRestTest extends QpidRestTestCase Map truststore = trustStores.get(0); assertTrustStoreAttributes(truststore, TestBrokerConfiguration.ENTRY_NAME_SSL_TRUSTSTORE, - System.getProperty(QPID_HOME) + "/../" + TestSSLConstants.BROKER_TRUSTSTORE, false); + QPID_HOME + "/../" + TestSSLConstants.BROKER_TRUSTSTORE, false); } public void testCreate() throws Exception @@ -96,7 +96,7 @@ public class TrustStoreRestTest extends QpidRestTestCase List> trustStores = assertNumberOfTrustStores(1); Map truststore = trustStores.get(0); assertTrustStoreAttributes(truststore, TestBrokerConfiguration.ENTRY_NAME_SSL_TRUSTSTORE, - System.getProperty(QPID_HOME) + "/../" + TestSSLConstants.BROKER_TRUSTSTORE, false); + QPID_HOME + "/../" + TestSSLConstants.BROKER_TRUSTSTORE, false); } public void testDeleteFailsWhenTrustStoreInUse() throws Exception -- cgit v1.2.1 From 96f9c3e225682940e18bd5fa6a9a270a80de034c Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Mon, 15 Dec 2014 14:28:17 +0000 Subject: QPID-6125: [Java Broker] Fix test broken by my previous commit git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1645667 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java index 3fe45143d5..dfec1a8517 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/close/JavaServerCloseRaceConditionTest.java @@ -106,7 +106,7 @@ public class JavaServerCloseRaceConditionTest extends QpidBrokerTestCase } catch (Exception e) { - assertTrue("Exception should say the exchange is not known.", e.getMessage().contains("Unknown exchange: " + EXCHANGE_NAME)); + assertTrue("Exception should say the exchange is not known.", e.getMessage().contains("Unknown exchange: '" + EXCHANGE_NAME + "'")); } try @@ -119,7 +119,7 @@ public class JavaServerCloseRaceConditionTest extends QpidBrokerTestCase } catch (Exception e) { - assertTrue("Exception should say the exchange is not known.", e.getMessage().contains("Unknown exchange: " + EXCHANGE_NAME)); + assertTrue("Exception should say the exchange is not known.", e.getMessage().contains("Unknown exchange: '" + EXCHANGE_NAME + "'")); } } -- cgit v1.2.1 From 5e0175cee706d931b12968004e61e5ed0aac071a Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Mon, 22 Dec 2014 14:21:22 +0000 Subject: QPID-5099: Add system test to ensure that client does indeed release the messages on consumer close git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1647319 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/unit/close/MessageConsumerCloseTest.java | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/close/MessageConsumerCloseTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/close/MessageConsumerCloseTest.java index df32bd7858..de30a98a7d 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/close/MessageConsumerCloseTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/close/MessageConsumerCloseTest.java @@ -35,7 +35,7 @@ import org.apache.qpid.test.utils.QpidBrokerTestCase; public class MessageConsumerCloseTest extends QpidBrokerTestCase { - Exception _exception; + private volatile Exception _exception; public void testConsumerCloseAndSessionRollback() throws Exception { @@ -65,7 +65,7 @@ public class MessageConsumerCloseTest extends QpidBrokerTestCase boolean messageReceived = receiveLatch.await(1l, TimeUnit.SECONDS); consumer.close(); - assertNull("Exception occured on rollback:" + _exception, _exception); + assertNull("Exception occurred on rollback:" + _exception, _exception); assertTrue("Message is not received", messageReceived); consumer = session.createConsumer(destination); @@ -74,4 +74,38 @@ public class MessageConsumerCloseTest extends QpidBrokerTestCase Message message2 = consumer.receive(1000l); assertNotNull("message2 is not received", message2); } + + public void testPrefetchedMessagesReleasedOnConsumerClose() throws Exception + { + Connection connection = getConnection(); + final Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + + Destination destination = getTestQueue(); + MessageConsumer consumer = session.createConsumer(destination); + + sendMessage(session, destination, 3); + + connection.start(); + + Message msg1 = consumer.receive(1000); + assertNotNull("Message one was null", msg1); + assertEquals("Message one has unexpected content", 0, msg1.getIntProperty(INDEX)); + session.commit(); + + // Messages two and three will have been prefetched by the consumer. + // Closing the consumer must make the available for delivery elsewhere + + consumer.close(); + + MessageConsumer consumer2 = session.createConsumer(destination); + + Message msg2 = consumer2.receive(1000); + Message msg3 = consumer2.receive(1000); + assertNotNull("Message two was null", msg2); + assertEquals("Message two has unexpected content", 1, msg2.getIntProperty(INDEX)); + + assertNotNull("Message three was null", msg3); + assertEquals("Message three has unexpected content", 2, msg3.getIntProperty(INDEX)); + session.commit(); + } } -- cgit v1.2.1 From b0175c7154a5025c0e98c7fff7d3a59f5fb4a405 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Sun, 28 Dec 2014 19:26:55 +0000 Subject: QPID-6290: [Java Broker] Management UI - refactor add VHN/VH to remove type based conditional logic * Also removed now defunct Broker attributes #supportedVirtualHostNodeTypes and #supportedVirtualHostTypes git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1648245 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java | 3 --- 1 file changed, 3 deletions(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java index ba95eecc6d..4023830a8d 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java @@ -235,9 +235,6 @@ public class BrokerRestTest extends QpidRestTestCase assertNotNull("Unexpected value of attribute ports", brokerDetails.get(BROKER_PORTS_ATTRIBUTE)); assertNotNull("Unexpected value of attribute authenticationproviders", brokerDetails.get(BROKER_AUTHENTICATIONPROVIDERS_ATTRIBUTE)); - assertNotNull("Unexpected value of attribute supportedVirtualHostTypes", brokerDetails.get(Broker.SUPPORTED_VIRTUALHOST_TYPES)); - assertNotNull("Unexpected value of attribute supportedVirtualHostNodeTypes", brokerDetails.get(Broker.SUPPORTED_VIRTUALHOSTNODE_TYPES)); - } } -- cgit v1.2.1 From fcaa5ff88e5ad15469c54e29d8f0d87821ccf8e1 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Tue, 30 Dec 2014 07:48:12 +0000 Subject: NO-JIRA: [Java Tests] Prevent sporadic spurious failure of testUnidirectionalHeartbeating git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1648488 13f79535-47bb-0310-9956-ffa450edef68 --- .../systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java index 881a37a970..6612fedd35 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java @@ -120,12 +120,15 @@ public class HeartbeatTest extends QpidBrokerTestCase sendConn.setHeartbeatListener(sendListener); receiveConn.start(); + // Start the flow of messages to the consumer + consumer.receiveNoWait(); + for(int i = 0; i < 5; i++) { producer.send(senderSession.createTextMessage("Msg " + i)); Thread.sleep(500); assertNotNull("Expected to received message", consumer.receive(500)); - // Consumer does not ack the message in order to generate no bytes from consumer back to Broker + // Consumer does not ack the message in order that no bytes flow from consumer connection back to Broker } assertTrue("Too few heartbeats sent "+ receiveListener.getHeartbeatsSent() +" (expected at least 2)", receiveListener.getHeartbeatsSent()>=2); -- cgit v1.2.1 From 6631e8e980107ad609105d4ef1bb2ee5c4275e8b Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Fri, 2 Jan 2015 09:47:21 +0000 Subject: QPID-6294 : [Java Client] Allow use of 0 prefetch in AMQP 0-8/9/9-1 git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1648987 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/systest/prefetch/ZeroPrefetchTest.java | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 qpid/java/systests/src/test/java/org/apache/qpid/systest/prefetch/ZeroPrefetchTest.java (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/prefetch/ZeroPrefetchTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/prefetch/ZeroPrefetchTest.java new file mode 100644 index 0000000000..6a9fa0175a --- /dev/null +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/prefetch/ZeroPrefetchTest.java @@ -0,0 +1,83 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.systest.prefetch; + +import java.util.UUID; + +import javax.jms.Connection; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; + +import org.apache.qpid.configuration.ClientProperties; +import org.apache.qpid.test.utils.QpidBrokerTestCase; + +public class ZeroPrefetchTest extends QpidBrokerTestCase +{ + + private static final String TEST_PROPERTY_NAME = "testProp"; + + // send two messages to the queue, consume and acknowledge one message on connection 1 + // create a second connection and attempt to consume the second message - this will only be possible + // if the first connection has no prefetch + public void testZeroPrefetch() throws Exception + { + setTestClientSystemProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, "0"); + Connection prefetch1Connection = getConnection(); + + prefetch1Connection.start(); + + final Session prefetch1session = prefetch1Connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Queue queue = prefetch1session.createQueue(getTestQueueName()); + MessageConsumer prefetch1consumer = prefetch1session.createConsumer(queue); + + + Session producerSession = prefetch1Connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageProducer producer = producerSession.createProducer(queue); + Message firstMessage = producerSession.createMessage(); + String firstPropertyValue = UUID.randomUUID().toString(); + firstMessage.setStringProperty(TEST_PROPERTY_NAME, firstPropertyValue); + producer.send(firstMessage); + + Message secondMessage = producerSession.createMessage(); + String secondPropertyValue = UUID.randomUUID().toString(); + secondMessage.setStringProperty(TEST_PROPERTY_NAME, secondPropertyValue); + producer.send(secondMessage); + + + Message receivedMessage = prefetch1consumer.receive(2000l); + assertNotNull("First message was not received", receivedMessage); + assertEquals("Message property was not as expected", firstPropertyValue, receivedMessage.getStringProperty(TEST_PROPERTY_NAME)); + + Connection prefetch2Connection = getConnection(); + + prefetch2Connection.start(); + final Session prefetch2session = prefetch2Connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer prefetch2consumer = prefetch2session.createConsumer(queue); + + receivedMessage = prefetch2consumer.receive(2000l); + assertNotNull("Second message was not received", receivedMessage); + assertEquals("Message property was not as expected", secondPropertyValue, receivedMessage.getStringProperty(TEST_PROPERTY_NAME)); + + } +} -- cgit v1.2.1 From 87d3ca113acad85afe0143069484f0640427928a Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Mon, 5 Jan 2015 16:45:58 +0000 Subject: QPID-6295 : [Java Broker] reload ACL config when the file value is changed git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1649587 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java index 8c4effd685..e40add449e 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java @@ -795,10 +795,11 @@ public class BrokerACLTest extends QpidRestTestCase assertAccessControlProviderExistence(accessControlProviderName, true); + File aclFile = TestFileUtils.createTempFile(this, ".acl", "ACL ALLOW all all"); + Map attributes = new HashMap(); - attributes.put(GroupProvider.NAME, accessControlProviderName); - attributes.put(GroupProvider.TYPE, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE); - attributes.put(FileBasedGroupProvider.PATH, "/path/to/file"); + attributes.put(AccessControlProvider.NAME, accessControlProviderName); + attributes.put(FileBasedGroupProvider.PATH, aclFile.getAbsolutePath()); responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "PUT", attributes); assertEquals("Setting of access control provider attributes should be allowed", 200, responseCode); } -- cgit v1.2.1 From a1b5b082b083bc574866bb53712a68269fc793e0 Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Sat, 10 Jan 2015 01:20:02 +0000 Subject: QPID-6306 : [Java Broker] Restrict broker to single ACL Provider at any given time git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1650708 13f79535-47bb-0310-9956-ffa450edef68 --- .../rest/AccessControlProviderRestTest.java | 78 ++-------------------- .../qpid/systest/rest/acl/BrokerACLTest.java | 48 +++---------- 2 files changed, 14 insertions(+), 112 deletions(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java index 4140c9c12c..0dda8e077b 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java @@ -125,34 +125,28 @@ public class AccessControlProviderRestTest extends QpidRestTestCase public void testReplaceAccessControlProvider() throws Exception { - String accessControlProviderName1 = getTestName() + "1"; - //verify that the access control provider doesn't exist, and - //in doing so implicitly verify that the 'denied' user can - //actually currently connect because no ACL is in effect yet - getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER); - assertAccessControlProviderExistence(accessControlProviderName1, false); //create the access control provider using the 'allowed' user getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - int responseCode = createAccessControlProvider(accessControlProviderName1, _aclFileContent1); + int responseCode = createAccessControlProvider(getTestName(), _aclFileContent1); assertEquals("Access control provider creation should be allowed", 201, responseCode); //verify it exists with the 'allowed' user - assertAccessControlProviderExistence(accessControlProviderName1, true); + assertAccessControlProviderExistence(getTestName(), true); //verify the 'denied' and 'other' user can no longer access the management //interface due to the just-created ACL file now preventing them getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER); - assertCanAccessManagementInterface(accessControlProviderName1, false); + assertCanAccessManagementInterface(getTestName(), false); getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER); - assertCanAccessManagementInterface(accessControlProviderName1, false); + assertCanAccessManagementInterface(getTestName(), false); //create the replacement access control provider using the 'allowed' user. String accessControlProviderName2 = getTestName() + "2"; getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - responseCode = createAccessControlProvider(accessControlProviderName2, _aclFileContent2); - assertEquals("Access control provider creation should be allowed", 201, responseCode); + responseCode = createAccessControlProvider(getTestName(), _aclFileContent2); + assertEquals("Access control provider creation should be allowed", 200, responseCode); //Verify that it took effect immediately, replacing the first access control provider @@ -162,11 +156,6 @@ public class AccessControlProviderRestTest extends QpidRestTestCase getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER); assertCanAccessManagementInterface(accessControlProviderName2, true); - //remove the original access control provider using the 'allowed' user - getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName1, "DELETE"); - assertEquals("Access control provider deletion should be allowed", 200, responseCode); - assertAccessControlProviderExistence(accessControlProviderName1, false); //verify the 'denied' user still can't access the management interface, the 'other' user still can, thus //confirming that the second access control provider is still in effect @@ -177,61 +166,6 @@ public class AccessControlProviderRestTest extends QpidRestTestCase } - public void testAddAndRemoveSecondAccessControlProviderReinstatesOriginal() throws Exception - { - String accessControlProviderName1 = getTestName() + "1"; - - //verify that the access control provider doesn't exist, and - //in doing so implicitly verify that the 'denied' user can - //actually currently connect because no ACL is in effect yet - getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER); - assertAccessControlProviderExistence(accessControlProviderName1, false); - - //create the access control provider using the 'allowed' user - getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - int responseCode = createAccessControlProvider(accessControlProviderName1, _aclFileContent1); - assertEquals("Access control provider creation should be allowed", 201, responseCode); - - //verify it exists with the 'allowed' user - assertAccessControlProviderExistence(accessControlProviderName1, true); - - //verify the 'denied' and 'other' user can no longer access the management - //interface due to the just-created ACL file now preventing them - getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER); - assertCanAccessManagementInterface(accessControlProviderName1, false); - getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER); - assertCanAccessManagementInterface(accessControlProviderName1, false); - - //create the replacement access control provider using the 'allowed' user. - String accessControlProviderName2 = getTestName() + "2"; - getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - responseCode = createAccessControlProvider(accessControlProviderName2, _aclFileContent2); - assertEquals("Access control provider creation should be allowed", 201, responseCode); - - //Verify that it took effect immediately, replacing the first access control provider - - //verify the 'denied' user still can't access the management interface, but the 'other' user now CAN. - getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER); - assertCanAccessManagementInterface(accessControlProviderName2, false); - getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER); - assertCanAccessManagementInterface(accessControlProviderName2, true); - - //remove the second access control provider using the 'allowed' user - getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName2, "DELETE"); - assertEquals("Access control provider deletion should be allowed", 200, responseCode); - assertAccessControlProviderExistence(accessControlProviderName2, false); - - //verify the 'denied' user still can't access the management interface, the - //'other' now CANT again, the 'allowed' still can, thus confirming that the - //first access control provider is now in effect once again - getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER); - assertCanAccessManagementInterface(accessControlProviderName2, false); - getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER); - assertCanAccessManagementInterface(accessControlProviderName2, false); - getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - assertCanAccessManagementInterface(accessControlProviderName2, true); - } public void testRemovalOfAccessControlProviderInErrorStateUsingManagementMode() throws Exception { diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java index e40add449e..86ebf11575 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java @@ -714,19 +714,6 @@ public class BrokerACLTest extends QpidRestTestCase /* === AccessControlProvider === */ - public void testCreateAccessControlProviderAllowed() throws Exception - { - getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - - String accessControlProviderName = getTestName(); - - assertAccessControlProviderExistence(accessControlProviderName, false); - - int responseCode = createAccessControlProvider(accessControlProviderName); - assertEquals("Access control provider creation should be allowed", 201, responseCode); - - assertAccessControlProviderExistence(accessControlProviderName, true); - } public void testCreateAccessControlProviderDenied() throws Exception { @@ -746,18 +733,13 @@ public class BrokerACLTest extends QpidRestTestCase { getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - String accessControlProviderName = getTestName(); - - assertAccessControlProviderExistence(accessControlProviderName, false); - - int responseCode = createAccessControlProvider(accessControlProviderName); - assertEquals("Access control provider creation should be allowed", 201, responseCode); + String accessControlProviderName = TestBrokerConfiguration.ENTRY_NAME_ACL_FILE; assertAccessControlProviderExistence(accessControlProviderName, true); getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER); - responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "DELETE"); + int responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "DELETE"); assertEquals("Access control provider deletion should be denied", 403, responseCode); assertAccessControlProviderExistence(accessControlProviderName, true); @@ -767,16 +749,12 @@ public class BrokerACLTest extends QpidRestTestCase { getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - String accessControlProviderName = getTestName(); - - assertAccessControlProviderExistence(accessControlProviderName, false); + String accessControlProviderName = TestBrokerConfiguration.ENTRY_NAME_ACL_FILE; - int responseCode = createAccessControlProvider(accessControlProviderName); - assertEquals("Access control provider creation should be allowed", 201, responseCode); assertAccessControlProviderExistence(accessControlProviderName, true); - responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "DELETE"); + int responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "DELETE"); assertEquals("Access control provider deletion should be allowed", 200, responseCode); assertAccessControlProviderExistence(accessControlProviderName, false); @@ -786,12 +764,7 @@ public class BrokerACLTest extends QpidRestTestCase { getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - String accessControlProviderName = getTestName(); - - assertAccessControlProviderExistence(accessControlProviderName, false); - - int responseCode = createAccessControlProvider(accessControlProviderName); - assertEquals("Access control provider creation should be allowed", 201, responseCode); + String accessControlProviderName = TestBrokerConfiguration.ENTRY_NAME_ACL_FILE; assertAccessControlProviderExistence(accessControlProviderName, true); @@ -800,7 +773,7 @@ public class BrokerACLTest extends QpidRestTestCase Map attributes = new HashMap(); attributes.put(AccessControlProvider.NAME, accessControlProviderName); attributes.put(FileBasedGroupProvider.PATH, aclFile.getAbsolutePath()); - responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "PUT", attributes); + int responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "PUT", attributes); assertEquals("Setting of access control provider attributes should be allowed", 200, responseCode); } @@ -808,12 +781,7 @@ public class BrokerACLTest extends QpidRestTestCase { getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER); - String accessControlProviderName = getTestName(); - - assertAccessControlProviderExistence(accessControlProviderName, false); - - int responseCode = createAccessControlProvider(accessControlProviderName); - assertEquals("Access control provider creation should be allowed", 201, responseCode); + String accessControlProviderName = TestBrokerConfiguration.ENTRY_NAME_ACL_FILE; assertAccessControlProviderExistence(accessControlProviderName, true); @@ -823,7 +791,7 @@ public class BrokerACLTest extends QpidRestTestCase attributes.put(GroupProvider.NAME, accessControlProviderName); attributes.put(GroupProvider.TYPE, FileBasedGroupProviderImpl.GROUP_FILE_PROVIDER_TYPE); attributes.put(FileBasedGroupProvider.PATH, "/path/to/file"); - responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "PUT", attributes); + int responseCode = getRestTestHelper().submitRequest("accesscontrolprovider/" + accessControlProviderName, "PUT", attributes); assertEquals("Setting of access control provider attributes should be denied", 403, responseCode); } -- cgit v1.2.1 From 9b1d37a0cbef71478b58c6acee4f72a2474a9f7d Mon Sep 17 00:00:00 2001 From: Andrew MacBean Date: Wed, 14 Jan 2015 10:38:04 +0000 Subject: QPID-6304: [Java Broker] Allow truststore and keystore (JKS) files to be stored as a data:// URL inside the config * Added truststore/keystore unit tests too to cover both new and (most of) the existing functionality, retiring the equivilent slower REST system tests. * Added single REST test exercising the creation of a keystore/teststore from data:// URL. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1651615 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/systest/rest/KeyStoreRestTest.java | 172 ++++++--------------- .../qpid/systest/rest/TrustStoreRestTest.java | 147 ++++-------------- 2 files changed, 72 insertions(+), 247 deletions(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java index 169ece986e..03b0a7a304 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java @@ -20,23 +20,20 @@ */ package org.apache.qpid.systest.rest; -import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; +import javax.servlet.http.HttpServletResponse; + import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.security.FileKeyStore; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.test.utils.TestSSLConstants; +import org.apache.qpid.util.DataUrlUtils; +import org.apache.qpid.util.FileUtils; public class KeyStoreRestTest extends QpidRestTestCase { @@ -67,7 +64,7 @@ public class KeyStoreRestTest extends QpidRestTestCase String certAlias = "app2"; assertNumberOfKeyStores(1); - createKeyStore(name, certAlias); + createKeyStore(name, certAlias, TestSSLConstants.KEYSTORE, TestSSLConstants.KEYSTORE_PASSWORD); assertNumberOfKeyStores(2); List> keyStores = getRestTestHelper().getJsonAsList("keystore/" + name); @@ -76,161 +73,72 @@ public class KeyStoreRestTest extends QpidRestTestCase assertKeyStoreAttributes(keyStores.get(0), name, TestSSLConstants.KEYSTORE, certAlias); } - public void testDelete() throws Exception + public void testCreateWithDataUrl() throws Exception { super.setUp(); String name = getTestName(); - String certAlias = "app2"; + byte[] keystoreAsBytes = FileUtils.readFileAsBytes(TestSSLConstants.KEYSTORE); + String dataUrlForKeyStore = DataUrlUtils.getDataUrlForBytes(keystoreAsBytes); assertNumberOfKeyStores(1); - createKeyStore(name, certAlias); - assertNumberOfKeyStores(2); - - int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "DELETE"); - assertEquals("Unexpected response code for provider deletion", 200, responseCode); - - List> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name); - assertNotNull("details should not be null", keyStore); - assertTrue("details should be empty as the keystore no longer exists", keyStore.isEmpty()); - - //check only the default systests key store remains - List> keyStores = assertNumberOfKeyStores(1); - Map keystore = keyStores.get(0); - assertKeyStoreAttributes(keystore, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE, - QPID_HOME + "/../" + TestSSLConstants.BROKER_KEYSTORE, null); - } - - public void testDeleteFailsWhenKeyStoreInUse() throws Exception - { - String name = "testDeleteFailsWhenKeyStoreInUse"; - - //add a new key store config to use - Map sslKeyStoreAttributes = new HashMap(); - sslKeyStoreAttributes.put(KeyStore.NAME, name); - sslKeyStoreAttributes.put(FileKeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE); - sslKeyStoreAttributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); - getBrokerConfiguration().addObjectConfiguration(KeyStore.class,sslKeyStoreAttributes); - - //add the SSL port using it - Map sslPortAttributes = new HashMap(); - sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); - sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); - sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); - sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); - sslPortAttributes.put(Port.KEY_STORE, name); - getBrokerConfiguration().addObjectConfiguration(Port.class,sslPortAttributes); - - super.setUp(); - - //verify the keystore is there + createKeyStore(name, null, dataUrlForKeyStore, TestSSLConstants.KEYSTORE_PASSWORD); assertNumberOfKeyStores(2); - List> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name); - assertNotNull("details should not be null", keyStore); - assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.BROKER_KEYSTORE, null); - - //try to delete it, which should fail as it is in use - int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "DELETE"); - assertEquals("Unexpected response code for provider deletion", 409, responseCode); + List> keyStores = getRestTestHelper().getJsonAsList("keystore/" + name); + assertNotNull("details cannot be null", keyStores); - //check its still there - assertNumberOfKeyStores(2); - keyStore = getRestTestHelper().getJsonAsList("keystore/" + name); - assertNotNull("details should not be null", keyStore); - assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.BROKER_KEYSTORE, null); + assertKeyStoreAttributes(keyStores.get(0), name, dataUrlForKeyStore, null); } - public void testUpdateWithGoodPathSucceeds() throws Exception + public void testDelete() throws Exception { super.setUp(); String name = getTestName(); + String certAlias = "app2"; assertNumberOfKeyStores(1); - createKeyStore(name, null); + createKeyStore(name, certAlias, TestSSLConstants.KEYSTORE, TestSSLConstants.KEYSTORE_PASSWORD); assertNumberOfKeyStores(2); - Map attributes = new HashMap(); - attributes.put(KeyStore.NAME, name); - attributes.put(FileKeyStore.PATH, TestSSLConstants.UNTRUSTED_KEYSTORE); - - int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "PUT", attributes); - assertEquals("Unexpected response code for keystore update", 200, responseCode); + getRestTestHelper().submitRequest("keystore/" + name, "DELETE", HttpServletResponse.SC_OK); List> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name); assertNotNull("details should not be null", keyStore); + assertTrue("details should be empty as the keystore no longer exists", keyStore.isEmpty()); - assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.UNTRUSTED_KEYSTORE, null); + //check only the default systests key store remains + List> keyStores = assertNumberOfKeyStores(1); + Map keystore = keyStores.get(0); + assertKeyStoreAttributes(keystore, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE, + QPID_HOME + "/../" + TestSSLConstants.BROKER_KEYSTORE, null); } - public void testUpdateWithNonExistentPathFails() throws Exception + public void testUpdate() throws Exception { super.setUp(); String name = getTestName(); assertNumberOfKeyStores(1); - createKeyStore(name, null); + createKeyStore(name, null, TestSSLConstants.KEYSTORE, TestSSLConstants.KEYSTORE_PASSWORD); assertNumberOfKeyStores(2); Map attributes = new HashMap(); attributes.put(KeyStore.NAME, name); - attributes.put(FileKeyStore.PATH, "does.not.exist"); + attributes.put(FileKeyStore.PATH, TestSSLConstants.UNTRUSTED_KEYSTORE); - int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "PUT", attributes); - assertEquals("Unexpected response code for keystore update", 409, responseCode); + getRestTestHelper().submitRequest("keystore/" + name, "PUT", attributes, HttpServletResponse.SC_OK); List> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name); assertNotNull("details should not be null", keyStore); - //verify the details remain unchanged - assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.KEYSTORE, null); + assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.UNTRUSTED_KEYSTORE, null); } - public void testUpdateCertificateAlias() throws Exception - { - super.setUp(); - - String name = getTestName(); - - assertNumberOfKeyStores(1); - createKeyStore(name, "app1"); - assertNumberOfKeyStores(2); - - List> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name); - assertNotNull("details should not be null", keyStore); - assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.KEYSTORE, "app1"); - - //Update the certAlias from app1 to app2 - Map attributes = new HashMap(); - attributes.put(KeyStore.NAME, name); - attributes.put(FileKeyStore.CERTIFICATE_ALIAS, "app2"); - - int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "PUT", attributes); - assertEquals("Unexpected response code for keystore update", 200, responseCode); - - keyStore = getRestTestHelper().getJsonAsList("keystore/" + name); - assertNotNull("details should not be null", keyStore); - - assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.KEYSTORE, "app2"); - - //Update the certAlias to clear it (i.e go from from app1 to null) - attributes = new HashMap(); - attributes.put(KeyStore.NAME, name); - attributes.put(FileKeyStore.CERTIFICATE_ALIAS, null); - - responseCode = getRestTestHelper().submitRequest("keystore/" + name , "PUT", attributes); - assertEquals("Unexpected response code for keystore update", 200, responseCode); - keyStore = getRestTestHelper().getJsonAsList("keystore/" + name); - assertNotNull("details should not be null", keyStore); - - assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.KEYSTORE, null); - } - - private List> assertNumberOfKeyStores(int numberOfKeystores) throws IOException, - JsonParseException, JsonMappingException + private List> assertNumberOfKeyStores(int numberOfKeystores) throws Exception { List> keyStores = getRestTestHelper().getJsonAsList("keystore"); assertNotNull("keystores should not be null", keyStores); @@ -239,16 +147,18 @@ public class KeyStoreRestTest extends QpidRestTestCase return keyStores; } - private void createKeyStore(String name, String certAlias) throws IOException, JsonGenerationException, JsonMappingException + private void createKeyStore(String name, String certAlias, final String keyStorePath, final String keystorePassword) throws Exception { - Map keyStoreAttributes = new HashMap(); + Map keyStoreAttributes = new HashMap<>(); keyStoreAttributes.put(KeyStore.NAME, name); - keyStoreAttributes.put(FileKeyStore.PATH, TestSSLConstants.KEYSTORE); - keyStoreAttributes.put(FileKeyStore.PASSWORD, TestSSLConstants.KEYSTORE_PASSWORD); - keyStoreAttributes.put(FileKeyStore.CERTIFICATE_ALIAS, certAlias); + keyStoreAttributes.put(FileKeyStore.PATH, keyStorePath); + keyStoreAttributes.put(FileKeyStore.PASSWORD, keystorePassword); + if (certAlias != null) + { + keyStoreAttributes.put(FileKeyStore.CERTIFICATE_ALIAS, certAlias); + } - int responseCode = getRestTestHelper().submitRequest("keystore/" + name, "PUT", keyStoreAttributes); - assertEquals("Unexpected response code", 201, responseCode); + getRestTestHelper().submitRequest("keystore/" + name, "PUT", keyStoreAttributes, HttpServletResponse.SC_CREATED); } private void assertKeyStoreAttributes(Map keystore, String name, String path, String certAlias) @@ -261,12 +171,16 @@ public class KeyStoreRestTest extends QpidRestTestCase AbstractConfiguredObject.SECURED_STRING_VALUE, keystore.get(FileKeyStore.PASSWORD)); assertEquals("unexpected type of default systests key store", java.security.KeyStore.getDefaultType(), keystore.get(FileKeyStore.KEY_STORE_TYPE)); - assertEquals("unexpected certificateAlias value", - certAlias, keystore.get(FileKeyStore.CERTIFICATE_ALIAS)); if(certAlias == null) { assertFalse("should not be a certificateAlias attribute", keystore.containsKey(FileKeyStore.CERTIFICATE_ALIAS)); } + else + { + assertEquals("unexpected certificateAlias value", + certAlias, keystore.get(FileKeyStore.CERTIFICATE_ALIAS)); + + } } } diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java index 1aac22d0aa..6cca3fc12c 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java @@ -20,23 +20,19 @@ */ package org.apache.qpid.systest.rest; -import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; +import javax.servlet.http.HttpServletResponse; import org.apache.qpid.server.model.AbstractConfiguredObject; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.model.TrustStore; import org.apache.qpid.server.security.FileTrustStore; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.test.utils.TestSSLConstants; +import org.apache.qpid.util.DataUrlUtils; +import org.apache.qpid.util.FileUtils; public class TrustStoreRestTest extends QpidRestTestCase { @@ -66,7 +62,7 @@ public class TrustStoreRestTest extends QpidRestTestCase String name = getTestName(); assertNumberOfTrustStores(1); - createTrustStore(name, true); + createTrustStore(name, true, TestSSLConstants.TRUSTSTORE, TestSSLConstants.TRUSTSTORE_PASSWORD); assertNumberOfTrustStores(2); List> trustStores = getRestTestHelper().getJsonAsList("truststore/" + name); @@ -75,157 +71,73 @@ public class TrustStoreRestTest extends QpidRestTestCase assertTrustStoreAttributes(trustStores.get(0), name, TestSSLConstants.TRUSTSTORE, true); } - public void testDelete() throws Exception + public void testCreateUsingDataUrl() throws Exception { super.setUp(); String name = getTestName(); + byte[] trustStoreAsBytes = FileUtils.readFileAsBytes(TestSSLConstants.TRUSTSTORE); + String dataUrlForTruststore = DataUrlUtils.getDataUrlForBytes(trustStoreAsBytes); assertNumberOfTrustStores(1); - createTrustStore(name, false); - assertNumberOfTrustStores(2); - - int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "DELETE"); - assertEquals("Unexpected response code for provider deletion", 200, responseCode); - - List> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name); - assertNotNull("details should not be null", trustStore); - assertTrue("details should be empty as the truststore no longer exists", trustStore.isEmpty()); - - //check only the default systests trust store remains - List> trustStores = assertNumberOfTrustStores(1); - Map truststore = trustStores.get(0); - assertTrustStoreAttributes(truststore, TestBrokerConfiguration.ENTRY_NAME_SSL_TRUSTSTORE, - QPID_HOME + "/../" + TestSSLConstants.BROKER_TRUSTSTORE, false); - } - public void testDeleteFailsWhenTrustStoreInUse() throws Exception - { - String name = "testDeleteFailsWhenTrustStoreInUse"; - - //add a new trust store config to use - Map sslTrustStoreAttributes = new HashMap(); - sslTrustStoreAttributes.put(TrustStore.NAME, name); - sslTrustStoreAttributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); - sslTrustStoreAttributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); - getBrokerConfiguration().addObjectConfiguration(TrustStore.class,sslTrustStoreAttributes); - - //add the SSL port using it - Map sslPortAttributes = new HashMap(); - sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); - sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); - sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); - sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); - sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); - sslPortAttributes.put(Port.TRUST_STORES, Collections.singleton(name)); - getBrokerConfiguration().addObjectConfiguration(Port.class, sslPortAttributes); + createTrustStore(name, false, dataUrlForTruststore, TestSSLConstants.TRUSTSTORE_PASSWORD); - super.setUp(); - - //verify the truststore is there assertNumberOfTrustStores(2); - List> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name); - assertNotNull("details should not be null", trustStore); - assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false); - - //try to delete it, which should fail as it is in use - int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "DELETE"); - assertEquals("Unexpected response code for provider deletion", 409, responseCode); + List> trustStores = getRestTestHelper().getJsonAsList("truststore/" + name); + assertNotNull("details cannot be null", trustStores); - //check its still there - assertNumberOfTrustStores(2); - trustStore = getRestTestHelper().getJsonAsList("truststore/" + name); - assertNotNull("details should not be null", trustStore); - assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false); + assertTrustStoreAttributes(trustStores.get(0), name, dataUrlForTruststore, false); } - public void testUpdateWithGoodPathSucceeds() throws Exception + public void testDelete() throws Exception { super.setUp(); String name = getTestName(); assertNumberOfTrustStores(1); - createTrustStore(name, false); + createTrustStore(name, false, TestSSLConstants.TRUSTSTORE, TestSSLConstants.TRUSTSTORE_PASSWORD); assertNumberOfTrustStores(2); - Map attributes = new HashMap(); - attributes.put(TrustStore.NAME, name); - attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); - - int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes); - assertEquals("Unexpected response code for truststore update", 200, responseCode); + getRestTestHelper().submitRequest("truststore/" + name , "DELETE", HttpServletResponse.SC_OK); List> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name); assertNotNull("details should not be null", trustStore); + assertTrue("details should be empty as the truststore no longer exists", trustStore.isEmpty()); - assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false); + //check only the default systests trust store remains + List> trustStores = assertNumberOfTrustStores(1); + Map truststore = trustStores.get(0); + assertTrustStoreAttributes(truststore, TestBrokerConfiguration.ENTRY_NAME_SSL_TRUSTSTORE, + QPID_HOME + "/../" + TestSSLConstants.BROKER_TRUSTSTORE, false); } - public void testUpdateWithNonExistentPathFails() throws Exception - { - super.setUp(); - - String name = getTestName(); - - assertNumberOfTrustStores(1); - createTrustStore(name, false); - assertNumberOfTrustStores(2); - Map attributes = new HashMap(); - attributes.put(TrustStore.NAME, name); - attributes.put(FileTrustStore.PATH, "does.not.exist"); - - int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes); - assertEquals("Unexpected response code for trust store update", 409, responseCode); - - List> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name); - assertNotNull("details should not be null", trustStore); - - //verify the details remain unchanged - assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false); - } - - public void testUpdatePeersOnly() throws Exception + public void testUpdate() throws Exception { super.setUp(); String name = getTestName(); assertNumberOfTrustStores(1); - createTrustStore(name, false); + createTrustStore(name, false, TestSSLConstants.TRUSTSTORE, TestSSLConstants.TRUSTSTORE_PASSWORD); assertNumberOfTrustStores(2); - //update the peersOnly attribute from false to true Map attributes = new HashMap(); attributes.put(TrustStore.NAME, name); - attributes.put(FileTrustStore.PEERS_ONLY, true); + attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); - int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes); - assertEquals("Unexpected response code for trust store update", 200, responseCode); + getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes, HttpServletResponse.SC_OK); List> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name); assertNotNull("details should not be null", trustStore); - assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, true); - - //Update peersOnly to clear it (i.e go from from true to null, which will default to false) - attributes = new HashMap(); - attributes.put(TrustStore.NAME, name); - attributes.put(FileTrustStore.PEERS_ONLY, null); - - responseCode = getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes); - assertEquals("Unexpected response code for trust store update", 200, responseCode); - - trustStore = getRestTestHelper().getJsonAsList("truststore/" + name); - assertNotNull("details should not be null", trustStore); - assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false); } - private List> assertNumberOfTrustStores(int numberOfTrustStores) throws IOException, - JsonParseException, JsonMappingException + private List> assertNumberOfTrustStores(int numberOfTrustStores) throws Exception { List> trustStores = getRestTestHelper().getJsonAsList("truststore"); assertNotNull("trust stores should not be null", trustStores); @@ -234,17 +146,16 @@ public class TrustStoreRestTest extends QpidRestTestCase return trustStores; } - private void createTrustStore(String name, boolean peersOnly) throws IOException, JsonGenerationException, JsonMappingException + private void createTrustStore(String name, boolean peersOnly, final String truststorePath, final String truststorePassword) throws Exception { Map trustStoreAttributes = new HashMap(); trustStoreAttributes.put(TrustStore.NAME, name); //deliberately using the client trust store to differentiate from the one we are already for broker - trustStoreAttributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); - trustStoreAttributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); + trustStoreAttributes.put(FileTrustStore.PATH, truststorePath); + trustStoreAttributes.put(FileTrustStore.PASSWORD, truststorePassword); trustStoreAttributes.put(FileTrustStore.PEERS_ONLY, peersOnly); - int responseCode = getRestTestHelper().submitRequest("truststore/" + name, "PUT", trustStoreAttributes); - assertEquals("Unexpected response code", 201, responseCode); + getRestTestHelper().submitRequest("truststore/" + name, "PUT", trustStoreAttributes, HttpServletResponse.SC_CREATED); } private void assertTrustStoreAttributes(Map truststore, String name, String path, boolean peersOnly) -- cgit v1.2.1 From d6ad905aa5da8b0c4be507c87cdae735d778154f Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Tue, 27 Jan 2015 13:27:05 +0000 Subject: QPID-6336: [Java Broker] Change 0-8..0-91 path to await the receiver being closed before continuing with the next connection attempt Based on work by Oleksandr Rudyy git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1655034 13f79535-47bb-0310-9956-ffa450edef68 --- .../failover/MultipleBrokersFailoverTest.java | 28 ++++++++-------------- .../java/org/apache/qpid/client/ssl/SSLTest.java | 24 +++++++++++++++++++ .../unit/client/connection/ConnectionTest.java | 1 - 3 files changed, 34 insertions(+), 19 deletions(-) (limited to 'qpid/java/systests/src/test') diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java index 15ec0f9a4d..c59b0ecf34 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java @@ -38,7 +38,6 @@ import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQConnectionURL; import org.apache.qpid.jms.ConnectionListener; import org.apache.qpid.test.utils.QpidBrokerTestCase; -import org.apache.qpid.test.utils.TestUtils; import org.apache.qpid.util.FileUtils; public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements ConnectionListener @@ -48,9 +47,10 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C private static final String FAILOVER_VIRTUAL_HOST = "failover"; private static final String NON_FAILOVER_VIRTUAL_HOST = "nonfailover"; private static final String BROKER_PORTION_FORMAT = "tcp://localhost:%d?connectdelay='%d',retries='%d'"; - private static final int FAILOVER_RETRIES = 1; - private static final int FAILOVER_CONNECTDELAY = 1000; - private static final int FAILOVER_FACTOR = 4; + private static final int FAILOVER_RETRIES = 0; + private static final int FAILOVER_CONNECTDELAY = 0; + private static final int FAILOVER_AWAIT_TIME = 10000; + private int[] _brokerPorts; private AMQConnectionURL _connectionURL; @@ -169,7 +169,7 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C killBroker(_brokerPorts[1]); - awaitForFailoverCompletion(FAILOVER_CONNECTDELAY * _brokerPorts.length * FAILOVER_FACTOR); + awaitForFailoverCompletion(FAILOVER_AWAIT_TIME); assertEquals("Failover is not started as expected", 0, _failoverStarted.getCount()); assertSendReceive(2); @@ -185,7 +185,7 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C stopBroker(_brokerPorts[1]); - awaitForFailoverCompletion(FAILOVER_CONNECTDELAY * _brokerPorts.length * FAILOVER_FACTOR); + awaitForFailoverCompletion(FAILOVER_AWAIT_TIME); assertEquals("Failover is not started as expected", 0, _failoverStarted.getCount()); assertSendReceive(1); @@ -214,20 +214,12 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C } } - private void awaitForFailoverCompletion(long delay) + private void awaitForFailoverCompletion(long delay) throws Exception { _logger.info("Awaiting Failover completion.."); - try - { - if (!_failoverComplete.await(delay, TimeUnit.MILLISECONDS)) - { - _logger.warn("Test thread stack:\n\n" + TestUtils.dumpThreads()); - fail("Failover did not complete"); - } - } - catch (InterruptedException e) + if (!_failoverComplete.await(delay, TimeUnit.MILLISECONDS)) { - fail("Test was interrupted:" + e.getMessage()); + fail("Failover did not complete within " + delay + "ms."); } } @@ -239,7 +231,7 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C receivedMessage instanceof TextMessage); } - private void init(int acknowledgeMode, boolean startConnection) throws JMSException + private void init(int acknowledgeMode, boolean startConnection) throws Exception { boolean isTransacted = acknowledgeMode == Session.SESSION_TRANSACTED ? true : false; diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/client/ssl/SSLTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/client/ssl/SSLTest.java index 1dba5ced9d..7c82ea8e55 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/client/ssl/SSLTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/client/ssl/SSLTest.java @@ -94,6 +94,29 @@ public class SSLTest extends QpidBrokerTestCase } } + public void testSSLConnectionToPlainPortRejected() throws Exception + { + if (shouldPerformTest()) + { + super.setUp(); + + String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" + + "?ssl='true''"; + + url = String.format(url,QpidBrokerTestCase.DEFAULT_PORT); + + try + { + getConnection(new AMQConnectionURL(url)); + fail("Exception not thrown"); + } + catch (JMSException e) + { + assertTrue("Unexpected exception message", e.getMessage().contains("Unrecognized SSL message, plaintext connection?")); + } + } + } + public void testHostVerificationIsOnByDefault() throws Exception { if (shouldPerformTest()) @@ -116,6 +139,7 @@ public class SSLTest extends QpidBrokerTestCase try { getConnection(new AMQConnectionURL(url)); + fail("Exception not thrown"); } catch(JMSException e) { diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java index ed03e83292..191f9d72cf 100644 --- a/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java +++ b/qpid/java/systests/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java @@ -81,7 +81,6 @@ public class ConnectionTest extends QpidBrokerTestCase + "&temporaryQueueExchange='tmp.direct'" + "&temporaryTopicExchange='tmp.topic'"); - System.err.println(url.toString()); conn = new AMQConnection(url); -- cgit v1.2.1