[
https://issues.apache.org/jira/browse/DERBY-3211?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12545642
]
Myrna van Lunteren commented on DERBY-3211:
-------------------------------------------
Coincidentally, I wrote a silly getAlternatePort() method for the
TestConfiguration class.
Maybe some review of the method will be useful here - it'll take a bit longer
before I have the test I'm working on (testProperties.java) converted. This is
what I have so far:
public int getAlternativePort() throws SQLException {
Exception failException = null;
// start with the default port + 1
// there may be a smarter way to get the starting point...
int possiblePort = getPort();
if (!(possiblePort > 0))
possiblePort = 1528;
else
possiblePort = getPort() + 1;
try {
boolean portOK = false;
while (!portOK) {
// check for first one in use
NetworkServerControl networkServer =
new
NetworkServerControl(InetAddress.getByName("localhost"), possiblePort);
// Ping and wait for the network server to reply
boolean started = false;
try {
networkServer.ping();
// If ping throws no exception the server is running
started = true;
} catch(Exception e) {
failException = e;
}
// Check if we got a reply on ping
if (!started) {
// we'll assume we can use this port.
// If there was some other problem with the pinging, it'll
// become clear when someone attempts to use the port
portOK = true;
}
else { // this port's in use.
possiblePort = possiblePort + 1;
}
}
} catch (Exception e) {
SQLException se = new SQLException("Error pinging network server");
se.initCause(failException);
throw se;
}
return possiblePort;
}
> Convert derbynet/NSinSameJVM.java to junit
> ------------------------------------------
>
> Key: DERBY-3211
> URL: https://issues.apache.org/jira/browse/DERBY-3211
> Project: Derby
> Issue Type: Test
> Reporter: Manjula Kutty
> Assignee: Manjula Kutty
> Priority: Minor
> Fix For: 10.3.1.5, 10.4.0.0
>
> Attachments: DERBY-3211_diff_11_16.txt, DERBY-3211_diff_11_19.txt,
> DERBY-3211_diff_11_19_ver2.txt, DERBY-3211_stat_11_16.txt,
> DERBY-3211_stat_11_19.txt, DERBY-3211_stat_11_19_ver2.txt
>
>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.