You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2007/12/19 23:06:56 UTC
svn commit: r605719 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/derbynet/NSinSameJVMTest.java
junit/TestConfiguration.java
Author: kahatlen
Date: Wed Dec 19 14:06:56 2007
New Revision: 605719
URL: http://svn.apache.org/viewvc?rev=605719&view=rev
Log:
Followup to DERBY-3211, addressing some review comments.
Patch contributed by Manjula Kutty.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java?rev=605719&r1=605718&r2=605719&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/NSinSameJVMTest.java Wed Dec 19 14:06:56 2007
@@ -1,6 +1,6 @@
/*
- Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.DRDAProtocolTest
+ Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.NSinSameJVMTest
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -20,7 +20,6 @@
*/
package org.apache.derbyTesting.functionTests.tests.derbynet;
-import java.net.InetAddress;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
@@ -29,44 +28,40 @@
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.NetworkServerTestSetup;
public class NSinSameJVMTest extends BaseJDBCTestCase {
- public NSinSameJVMTest(String name) {
- super(name);
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
- /** Test NetworkServer start and shutdown on a different port
- * other than 1527 in the same jvm
- * @throws Exception
- **/
- public void testShutdown() throws Exception {
- final int NETWORKSERVER_PORT = 20000; //port to start the server
- NetworkServerControl serverControl = null;
- try {
- serverControl = new NetworkServerControl(InetAddress
- .getByName("localhost"), NETWORKSERVER_PORT);//initialized for the shutdown.
- Connection connection = null;
- // Just connect, do something and close the connection
- connection = getConnection();
- Statement stmt = connection.createStatement();
- ResultSet rs = stmt.executeQuery("Select tablename from sys.systables");
- JDBC.assertDrainResults(rs);
- serverControl.shutdown();
- Thread.sleep(5000);
- } catch (Exception e) {
- System.out.print("FAIL: Unexpected exception" + e.getMessage());
- e.printStackTrace();
- }
- }
- /**
- * Construct the name of the server policy file.
+ public NSinSameJVMTest(String name) {
+ super(name);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test NetworkServer start and shutdown on a different port other than 1527
+ * in the same jvm
+ *
+ * @throws Exception
*/
- public static Test suite() {
+ public void testShutdown() throws Exception {
+ NetworkServerControl serverControl= NetworkServerTestSetup.getNetworkServerControl();
+ Connection connection = null;
+ // Just connect, do something
+ connection = getConnection();
+ Statement stmt = connection.createStatement();
+ ResultSet rs = stmt
+ .executeQuery("Select tablename from sys.systables");
+ JDBC.assertDrainResults(rs);
+ // Leave the connection open before shutdown
+ serverControl.shutdown();
+ }
+
+ public static Test suite() {
Test test;
- test = TestConfiguration.clientServerSuite(NSinSameJVMTest.class,20000);
+ test = TestConfiguration
+ .clientServerSuiteWithAlternativePort(NSinSameJVMTest.class);
return test;
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?rev=605719&r1=605718&r2=605719&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java Wed Dec 19 14:06:56 2007
@@ -330,14 +330,14 @@
/**
* Create a suite for the passed test class that includes
* all the default fixtures from the class, wrapped in
- * a derbyClientServerDecorator with a given port.
+ * a derbyClientServerDecorator with alternative port.
*
*/
- public static Test clientServerSuite(Class testClass, int port)
- {
- TestSuite suite = new TestSuite(testClass,
- suiteName(testClass)+":client");
- return clientServerDecorator(suite,port);
+
+ public static Test clientServerSuiteWithAlternativePort(Class testClass) {
+ TestSuite suite = new TestSuite(testClass, suiteName(testClass)
+ + ":client");
+ return clientServerDecoratorWithAlternativePort(suite);
}
/**
@@ -371,13 +371,12 @@
return defaultServerDecorator(test);
}
/**
- * Wrapper ot use the given port number.
+ * Wrapper to use the alternative port number.
*/
- public static Test clientServerDecorator(Test suite,int port)
- {
+ public static Test clientServerDecoratorWithAlternativePort(Test suite) {
Test test = new NetworkServerTestSetup(suite, false);
-
- return defaultServerDecorator(test,port);
+
+ return defaultServerDecoratorWithAlternativePort(test);
}
/**
* Decorate a test to use suite's default host and port,
@@ -421,15 +420,15 @@
return new ServerSetup(test, DEFAULT_HOSTNAME, DEFAULT_PORT);
}
/**
- * Decorate a test to use suite's default host and given port.
+ * Decorate a test to use suite's default host and Alternative port.
*/
- public static Test defaultServerDecorator(Test test, int port)
- {
+ public static Test defaultServerDecoratorWithAlternativePort(Test test) {
// Need to have network server and client and not
// running in J2ME (JSR169).
if (!(Derby.hasClient() && Derby.hasServer())
|| JDBC.vmSupportsJSR169())
return new TestSuite("empty: no network server support");
+ int port = getCurrent().getAlternativePort();
//
// This looks bogus to me. Shouldn't this get the hostname and port
@@ -1128,6 +1127,20 @@
*/
public int getPort() {
return port;
+ }
+ /**
+ * Get an alternative port number for network server.
+ *
+ * @return port number.
+ */
+
+ public int getAlternativePort() {
+ int possiblePort = getPort();
+ if (!(possiblePort > 0))
+ possiblePort = 1528;
+ else
+ possiblePort = getPort() + 1;
+ return possiblePort;
}
/**