Merged 5.2.N (5.2.1) to HEAD (5.2)

125859 adragoi: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
      125817 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
         125673 abalmus: MNT-15421 : Intermittent failure SubsystemsTest.testAbstractPropertyBackedBean_performEarlyPropertyChecks_PortEarlyPropertyChecker
            - Fixed intermittently failing test


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127820 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-06-04 11:01:10 +00:00
parent 68302b2140
commit 1a5bba295d
2 changed files with 275 additions and 275 deletions

View File

@@ -115,72 +115,10 @@ public class SubsystemsTest extends BaseSpringTest
assertEquals("Global Instance Default", testBeans[2].getAnotherStringProperty());
}
private void blockPort(final String host, final int portNumber)
{
shouldBlockPort = true;
new Thread()
{
public void run()
{
ServerSocket serverSocket = null;
try
{
if (host != null && !host.equals("0.0.0.0"))
{
serverSocket = new ServerSocket(portNumber, 0, InetAddress.getByName(host));
}
else
{
serverSocket = new ServerSocket(portNumber);
}
serverSocket.setSoTimeout(200);
do
{
try
{
serverSocket.accept();
}
catch (SocketTimeoutException ste)
{
//We're expecting this.
}
}
while (shouldBlockPort);
}
catch (IOException ex)
{
LogFactory.getLog(SubsystemsTest.class).error(ex.getMessage());
}
finally
{
if (serverSocket != null)
{
try
{
serverSocket.close();
}
catch (Exception ex)
{
LogFactory.getLog(SubsystemsTest.class).error(ex.getMessage());
}
}
}
}
}.start();
}
private void unblockPort()
{
shouldBlockPort = false;
}
public void testAbstractPropertyBackedBean_performEarlyPropertyChecks_PortEarlyPropertyChecker()
{
int testPortNumber = (Integer) getApplicationContext().getBean("testPortNumber");
String testHost = (String) getApplicationContext().getBean("testHost");
ChildApplicationContextFactory testBean = (ChildApplicationContextFactory) getApplicationContext().getBean("testsubsystem");
@@ -201,33 +139,23 @@ public class SubsystemsTest extends BaseSpringTest
// Check for "port in use" error:
testProperties.put("test5.port", "" + testPortNumber);
try
{
blockPort(null, testPortNumber);
String errorMessage = testBean.performEarlyPropertyChecks(testProperties);
String errorMessage = testBean.performEarlyPropertyChecks(testProperties);
assertTrue(errorMessage.contains("The value for TestSubsystem port property cannot be empty."));
assertTrue(errorMessage.contains("Unable to parse value for TestSubsystem port property: 123xy."));
assertTrue(errorMessage.contains("The port chosen for TestSubsystem is outside the required range (1, 65535): 0."));
assertTrue(errorMessage.contains("The port chosen for TestSubsystem is outside the required range (1, 65535): 65536."));
assertTrue(errorMessage.contains("The value for TestSubsystem port property cannot be empty."));
assertTrue(errorMessage.contains("Unable to parse value for TestSubsystem port property: 123xy."));
assertTrue(errorMessage.contains("The port chosen for TestSubsystem is outside the required range (1, 65535): 0."));
assertTrue(errorMessage.contains("The port chosen for TestSubsystem is outside the required range (1, 65535): 65536."));
assertTrue(errorMessage.contains(
"The port chosen for TestSubsystem is already in use or you don't have permission to use it: " + testPortNumber + "."));
}
finally
{
unblockPort();
}
assertTrue(errorMessage.contains(
"The port chosen for TestSubsystem is already in use or you don't have permission to use it: " + testPortNumber + "."));
testProperties.clear();
testProperties.put("test_with_host.port", "" + testPortNumber);
// Check for unknown host:
testProperties.put("test.subsystem.host", "The quick brown fox jumps over the lazy dog.");
testProperties.put("test.subsystem.host", testHost);
String errorMessage = testBean.performEarlyPropertyChecks(testProperties);
errorMessage = testBean.performEarlyPropertyChecks(testProperties);
assertTrue(errorMessage.contains(
"The hostname chosen for TestSubsystem is unknown or misspelled: " + testProperties.get("test.subsystem.host") + "."));

View File

@@ -0,0 +1,72 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.management.subsystems.test;
import java.io.IOException;
import org.alfresco.repo.management.subsystems.PortEarlyPropertyChecker;
public class TestPortEarlyPropertyChecker extends PortEarlyPropertyChecker
{
private int blockedPort = -1;
private String wrongHost = "";
public TestPortEarlyPropertyChecker(String subsystemName, boolean hasMultiplePorts,
boolean shouldCheckForBlockedPort)
{
super(subsystemName, hasMultiplePorts, shouldCheckForBlockedPort);
}
public TestPortEarlyPropertyChecker(String subsystemName, String requiredPairedPropertyName,
boolean hasMultiplePorts, boolean shouldCheckForBlockedPort)
{
super(subsystemName, requiredPairedPropertyName, hasMultiplePorts,
shouldCheckForBlockedPort);
}
public void setBlockedPort(int blockedPort)
{
this.blockedPort = blockedPort;
}
public void setWrongHost(String wrongHost)
{
this.wrongHost = wrongHost;
}
@Override
public void checkPort(int portNumber, String host) throws IOException
{
if (portNumber == blockedPort)
{
throw new java.net.BindException();
}
if (wrongHost.equals(host))
{
throw new java.net.UnknownHostException();
}
}
}