mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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:
@@ -115,72 +115,10 @@ public class SubsystemsTest extends BaseSpringTest
|
|||||||
assertEquals("Global Instance Default", testBeans[2].getAnotherStringProperty());
|
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()
|
public void testAbstractPropertyBackedBean_performEarlyPropertyChecks_PortEarlyPropertyChecker()
|
||||||
{
|
{
|
||||||
int testPortNumber = (Integer) getApplicationContext().getBean("testPortNumber");
|
int testPortNumber = (Integer) getApplicationContext().getBean("testPortNumber");
|
||||||
|
String testHost = (String) getApplicationContext().getBean("testHost");
|
||||||
|
|
||||||
ChildApplicationContextFactory testBean = (ChildApplicationContextFactory) getApplicationContext().getBean("testsubsystem");
|
ChildApplicationContextFactory testBean = (ChildApplicationContextFactory) getApplicationContext().getBean("testsubsystem");
|
||||||
|
|
||||||
@@ -201,10 +139,6 @@ public class SubsystemsTest extends BaseSpringTest
|
|||||||
// Check for "port in use" error:
|
// Check for "port in use" error:
|
||||||
testProperties.put("test5.port", "" + testPortNumber);
|
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("The value for TestSubsystem port property cannot be empty."));
|
||||||
@@ -215,19 +149,13 @@ public class SubsystemsTest extends BaseSpringTest
|
|||||||
assertTrue(errorMessage.contains(
|
assertTrue(errorMessage.contains(
|
||||||
"The port chosen for TestSubsystem is already in use or you don't have permission to use it: " + testPortNumber + "."));
|
"The port chosen for TestSubsystem is already in use or you don't have permission to use it: " + testPortNumber + "."));
|
||||||
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
unblockPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
testProperties.clear();
|
testProperties.clear();
|
||||||
|
|
||||||
testProperties.put("test_with_host.port", "" + testPortNumber);
|
testProperties.put("test_with_host.port", "" + testPortNumber);
|
||||||
// Check for unknown host:
|
// 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(
|
assertTrue(errorMessage.contains(
|
||||||
"The hostname chosen for TestSubsystem is unknown or misspelled: " + testProperties.get("test.subsystem.host") + "."));
|
"The hostname chosen for TestSubsystem is unknown or misspelled: " + testProperties.get("test.subsystem.host") + "."));
|
||||||
|
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user