public final class NetworkServerTestSetup extends BaseTestSetup
Modifier and Type | Field and Description |
---|---|
private boolean |
asCommand |
private static long |
DEFAULT_WAIT_TIME
Setting maximum wait time to 4 minutes by default.
|
static java.lang.String |
HOST_OPTION |
private org.apache.derby.drda.NetworkServerControl |
networkServerController |
private java.io.FileOutputStream |
serverOutput |
private boolean |
serverShouldComeUp |
private static int |
SLEEP_TIME
Sleep for 100 ms before pinging the network server (again)
|
private SpawnedProcess |
spawnedServer
The server as a process if started in a different vm.
|
private boolean |
startServerAtSetup |
private java.lang.String[] |
startupArgs
Startup arguments for the command line
only when starting the server in a separate virtual machine.
|
private java.lang.String[] |
systemProperties
System properties to set on the command line (using -D)
only when starting the server in a separate virtual machine.
|
private boolean |
useSeparateProcess |
private static long |
WAIT_TIME |
private static long |
waitTime |
Constructor and Description |
---|
NetworkServerTestSetup(junit.framework.Test test,
boolean asCommand)
Decorates a test with the NetworkServerTestSetup.
|
NetworkServerTestSetup(junit.framework.Test test,
boolean asCommand,
boolean startServerAtSetup)
Decorates a test with the NetworkServerTestSetup.
|
NetworkServerTestSetup(junit.framework.Test test,
java.lang.String[] systemProperties,
java.lang.String[] startupArgs,
boolean serverShouldComeUp)
Decorator for starting up with specific command args
and system properties.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
getDefaultStartupArgs(boolean skipHostName)
Get the default command arguments for booting the network server.
|
static org.apache.derby.drda.NetworkServerControl |
getNetworkServerControl()
Return a new NetworkServerControl for the current configuration.
|
static org.apache.derby.drda.NetworkServerControl |
getNetworkServerControl(int port)
Return a new NetworkServerControl for the current configuration.
|
static org.apache.derby.drda.NetworkServerControl |
getNetworkServerControlDefault()
Return a new NetworkServerControl for the current configuration.
|
SpawnedProcess |
getServerProcess()
Returns the
Process object for the server process or null if the
network server does not run in a separate process |
private static java.lang.String |
getTimeoutErrorMsg(java.lang.String failedAction) |
private static java.lang.String |
getTimeoutErrorMsg(java.lang.String failedAction,
int port)
Returns an error message for timeouts including the port and host.
|
static long |
getWaitTime()
Set the period before network server times out on start up based on the
value passed in with property derby.tests.networkServerStartTimeout
in seconds, or use the default.
|
private static boolean |
isDRDAerror(java.lang.Throwable t) |
static boolean |
pingForServerStart(org.apache.derby.drda.NetworkServerControl control) |
static boolean |
pingForServerUp(org.apache.derby.drda.NetworkServerControl networkServerController,
java.lang.Process serverProcess,
boolean expectServerUp)
Ping server for upto sixty seconds.
|
private static void |
probeServerPort(int port,
java.net.InetAddress addr)
Check if a server socket can be opened on the specified port.
|
static void |
setDefaultWaitTime()
Set the number of milliseconds to wait before declaring server startup
a failure back to the default value specified in this class.
|
protected void |
setUp()
Start the network server.
|
static void |
setWaitTime(long newWaitTime)
Set the number of milliseconds to wait before declaring server startup
a failure.
|
private SpawnedProcess |
startSeparateProcess() |
private void |
startWithAPI() |
private void |
startWithCommand() |
protected void |
tearDown()
Stop the network server if it still
appears to be running.
|
private static boolean |
vetPing(java.lang.Throwable t) |
static void |
waitForAvailablePort()
Wait until the server port has been released by server instances used
by earlier test cases, or until the timeout specified by
getWaitTime() has elapsed. |
static void |
waitForAvailablePort(int port)
Wait until the specified port has been released by
by earlier test cases, or until the timeout specified by
getWaitTime() has elapsed. |
static void |
waitForServerStart(org.apache.derby.drda.NetworkServerControl networkServerController)
Ping the server until it has started.
|
run
basicRun, countTestCases, getTest, toString
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
private static final long DEFAULT_WAIT_TIME
Setting maximum wait time to 4 minutes by default. On some platforms it may take this long to start the server. See for example this JVM bug that sometimes makes server startup take more than 3 minutes.
Increasing the wait time should not adversely affect those systems with fast port turnaround as the actual code loops for SLEEP_TIME intervals, so should never see WAIT_TIME. For even slower systems (or for faster systems) the default value can be overwritten using the property derby.tests.networkServerStartTimeout (which is in seconds, rather than milliseconds)
private static final long WAIT_TIME
private static final int SLEEP_TIME
public static final java.lang.String HOST_OPTION
private static long waitTime
private java.io.FileOutputStream serverOutput
private final boolean asCommand
private final boolean startServerAtSetup
private final boolean useSeparateProcess
private final boolean serverShouldComeUp
private final java.lang.String[] systemProperties
private java.lang.String[] startupArgs
private SpawnedProcess spawnedServer
private org.apache.derby.drda.NetworkServerControl networkServerController
public NetworkServerTestSetup(junit.framework.Test test, boolean asCommand)
asCommand
- True to start using NetworkServerControl.main()
within the same virtual machine, false to use NetworkServerControl.start
(also within the same JVM).NetworkServerControl.main(String[])
,
NetworkServerControl.start(PrintWriter)
public NetworkServerTestSetup(junit.framework.Test test, boolean asCommand, boolean startServerAtSetup)
test
- the Test for which this setup is usedasCommand
- True to start using NetworkServerControl.main()
within the same virtual machine, false to use NetworkServerControl.start()
(also within the same virtual machine).startServerAtSetup
- True to start the Network Server at setup time,
False otherwise.NetworkServerControl.main(String[])
,
NetworkServerControl.start(PrintWriter)
public NetworkServerTestSetup(junit.framework.Test test, java.lang.String[] systemProperties, java.lang.String[] startupArgs, boolean serverShouldComeUp)
If the classes are being loaded from the classes folder instead of jar files then this will start the server up with no security manager using -noSecurityManager, unless the systemProperties or startupArgs set up any security manager. This is because the default policy installed by the network server only works from jar files. If this not desired then the test should skip the fixtures when loading from classes or install its own security manager.
protected void setUp() throws java.lang.Exception
setUp
in class junit.extensions.TestSetup
java.lang.Exception
public static void waitForAvailablePort() throws java.lang.InterruptedException, java.net.UnknownHostException
getWaitTime()
has elapsed.junit.framework.AssertionFailedError
- if the port didn't become available before
the timeoutjava.lang.InterruptedException
- if the thread was interrupted while waiting
for the port to become availablejava.net.UnknownHostException
- if the host name couldn't be resolvedpublic static void waitForAvailablePort(int port) throws java.lang.InterruptedException, java.net.UnknownHostException
getWaitTime()
has elapsed.port
- value.junit.framework.AssertionFailedError
- if the port didn't become available before
the timeoutjava.lang.InterruptedException
- if the thread was interrupted while waiting
for the port to become availablejava.net.UnknownHostException
- if the host name couldn't be resolvedprivate static void probeServerPort(int port, java.net.InetAddress addr) throws java.io.IOException
port
- the port to checkaddr
- the address of the network interfacejava.io.IOException
- if a server socket couldn't be openedprivate void startWithAPI() throws java.lang.Exception
java.lang.Exception
private void startWithCommand() throws java.lang.Exception
java.lang.Exception
private SpawnedProcess startSeparateProcess() throws java.lang.Exception
java.lang.Exception
public SpawnedProcess getServerProcess()
Process
object for the server process or null
if the
network server does not run in a separate processprotected void tearDown() throws java.lang.Exception
tearDown
in class junit.extensions.TestSetup
java.lang.Exception
public static java.lang.String[] getDefaultStartupArgs(boolean skipHostName)
public static org.apache.derby.drda.NetworkServerControl getNetworkServerControl() throws java.lang.Exception
java.lang.Exception
public static org.apache.derby.drda.NetworkServerControl getNetworkServerControl(int port) throws java.lang.Exception
java.lang.Exception
public static org.apache.derby.drda.NetworkServerControl getNetworkServerControlDefault() throws java.lang.Exception
java.lang.Exception
public static void waitForServerStart(org.apache.derby.drda.NetworkServerControl networkServerController) throws java.lang.InterruptedException
java.lang.InterruptedException
public static void setWaitTime(long newWaitTime)
public static void setDefaultWaitTime()
public static boolean pingForServerUp(org.apache.derby.drda.NetworkServerControl networkServerController, java.lang.Process serverProcess, boolean expectServerUp) throws java.lang.InterruptedException
networkServerController
- controller object for network serverserverProcess
- the external process in which the server runs
(could be null
)java.lang.InterruptedException
private static boolean vetPing(java.lang.Throwable t)
private static boolean isDRDAerror(java.lang.Throwable t)
public static boolean pingForServerStart(org.apache.derby.drda.NetworkServerControl control) throws java.lang.InterruptedException
java.lang.InterruptedException
public static long getWaitTime()
-Dderby.tests.networkServerStartTimeout=600would extend the timeout to 10 minutes. If an invalid value is passed in (eg. 'abc') the calling test will fail
private static java.lang.String getTimeoutErrorMsg(java.lang.String failedAction, int port)
private static java.lang.String getTimeoutErrorMsg(java.lang.String failedAction)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.