001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.maxthreads
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021: package org.apache.derbyTesting.functionTests.tests.derbynet;
022:
023: import java.sql.*;
024: import java.util.Vector;
025: import java.util.Properties;
026: import java.io.File;
027: import java.io.FileOutputStream;
028: import java.io.BufferedOutputStream;
029:
030: import org.apache.derby.iapi.reference.Property;
031: import org.apache.derby.drda.NetworkServerControl;
032: import org.apache.derbyTesting.functionTests.harness.jvm;
033: import org.apache.derbyTesting.functionTests.util.TestUtil;
034: import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
035: import org.apache.derby.tools.ij;
036:
037: /**
038: This tests the maxthreads command
039: */
040:
041: public class maxthreads {
042: private static Properties properties = new java.util.Properties();
043: private static jvm jvm;
044: private static Vector vCmd;
045: private static String[] maxthreadsCmd1 = new String[] {
046: "org.apache.derby.drda.NetworkServerControl", "maxthreads",
047: "0" };
048: private static String[] maxthreadsCmd2 = new String[] {
049: "org.apache.derby.drda.NetworkServerControl", "maxthreads",
050: "-1", "-h", "localhost", "-p", "1527" };
051: private static String[] maxthreadsCmd3 = new String[] {
052: "org.apache.derby.drda.NetworkServerControl", "maxthreads",
053: "-12" };
054: private static String[] maxthreadsCmd4 = new String[] {
055: "org.apache.derby.drda.NetworkServerControl", "maxthreads",
056: "2147483647" };
057: private static String[] maxthreadsCmd5 = new String[] {
058: "org.apache.derby.drda.NetworkServerControl", "maxthreads",
059: "9000" };
060: private static String[] maxthreadsCmd6 = new String[] {
061: "org.apache.derby.drda.NetworkServerControl", "maxthreads",
062: "a" };
063: private static BufferedOutputStream bos = null;
064: private static NetworkServerControl server;
065: private static String host;
066: private static int port = 1527;
067:
068: private static void checkMaxThreads(int value) throws Exception {
069: int maxValue = server.getMaxThreads();
070: if (maxValue == value)
071: System.out.println("PASS - max threads value, " + value
072: + " is correct");
073: else
074: System.out.println("FAIL - max threads value is "
075: + maxValue + " should be " + value);
076: }
077:
078: public static void main(String args[]) throws Exception {
079: host = TestUtil.getHostName();
080: maxthreadsCmd2[4] = host;
081:
082: if ((System.getProperty("java.vm.name") != null)
083: && System.getProperty("java.vm.name").equals("J9"))
084: jvm = jvm.getJvm("j9_13");
085: else
086: jvm = jvm.getJvm("currentjvm"); // ensure compatibility
087: vCmd = jvm.getCommandLine();
088: try {
089: ij.getPropertyArg(args);
090: Connection conn1 = ij.startJBMS();
091:
092: bos = new BufferedOutputStream(System.out, 1024);
093:
094: server = new NetworkServerControl();
095: /************************************************************
096: * Test max threads
097: ************************************************************/
098: System.out.println("Testing maxthreads");
099: //test maxthreads 0
100: ExecProcUtil.execCmdDumpResults(maxthreadsCmd1, vCmd, bos);
101: checkMaxThreads(0);
102: //test maxthreads -1
103: ExecProcUtil.execCmdDumpResults(maxthreadsCmd2, vCmd, bos);
104: checkMaxThreads(0); //default is currently 0
105: //test maxthreads -12 - should error
106: ExecProcUtil.execCmdDumpResults(maxthreadsCmd3, vCmd, bos);
107: checkMaxThreads(0);
108: //test maxthreads 2147483647 - should work
109: ExecProcUtil.execCmdDumpResults(maxthreadsCmd4, vCmd, bos);
110: checkMaxThreads(2147483647);
111: //test maxthreads 9000 - should work
112: ExecProcUtil.execCmdDumpResults(maxthreadsCmd5, vCmd, bos);
113: checkMaxThreads(9000);
114: //test maxthreads with invalid value (NumberFormatException)
115: ExecProcUtil.execCmdDumpResults(maxthreadsCmd6, vCmd, bos);
116: // try the same values using the callable interface
117: //test maxthreads 0
118: server.setMaxThreads(0);
119: checkMaxThreads(0);
120: //test maxthreads -1
121: server.setMaxThreads(-1);
122: checkMaxThreads(0);
123: //test maxthreads -2 - should error
124: try {
125: server.setMaxThreads(-2);
126: } catch (Exception e) {
127: System.out.println(e.getMessage());
128: }
129: //test maxthreads 2147483647 - should work
130: server.setMaxThreads(2147483647);
131: checkMaxThreads(2147483647);
132: //test maxthreads 9000 - should work
133: server.setMaxThreads(9000);
134: checkMaxThreads(9000);
135: System.out.println("End test");
136: bos.close();
137: } catch (Exception e) {
138: e.printStackTrace();
139: }
140: }
141: }
|