KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > derbynet > maxthreads


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.maxthreads
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21 package org.apache.derbyTesting.functionTests.tests.derbynet;
22
23 import java.sql.*;
24 import java.util.Vector JavaDoc;
25 import java.util.Properties JavaDoc;
26 import java.io.File JavaDoc;
27 import java.io.FileOutputStream JavaDoc;
28 import java.io.BufferedOutputStream JavaDoc;
29
30 import org.apache.derby.iapi.reference.Property;
31 import org.apache.derby.drda.NetworkServerControl;
32 import org.apache.derbyTesting.functionTests.harness.jvm;
33 import org.apache.derbyTesting.functionTests.util.TestUtil;
34 import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
35 import org.apache.derby.tools.ij;
36
37 /**
38     This tests the maxthreads command
39 */

40
41 public class maxthreads
42 {
43     private static Properties JavaDoc properties = new java.util.Properties JavaDoc();
44     private static jvm jvm;
45     private static Vector JavaDoc vCmd;
46     private static String JavaDoc[] maxthreadsCmd1 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
47         "maxthreads", "0"};
48     private static String JavaDoc[] maxthreadsCmd2 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
49         "maxthreads","-1", "-h", "localhost", "-p", "1527"};
50     private static String JavaDoc[] maxthreadsCmd3 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
51         "maxthreads", "-12"};
52     private static String JavaDoc[] maxthreadsCmd4 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
53         "maxthreads", "2147483647"};
54     private static String JavaDoc[] maxthreadsCmd5 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
55         "maxthreads", "9000"};
56     private static String JavaDoc[] maxthreadsCmd6 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
57             "maxthreads", "a"};
58     private static BufferedOutputStream JavaDoc bos = null;
59     private static NetworkServerControl server;
60     private static String JavaDoc host;
61     private static int port = 1527;
62    
63     private static void checkMaxThreads( int value)
64         throws Exception JavaDoc
65     {
66         int maxValue = server.getMaxThreads();
67         if (maxValue == value)
68             System.out.println("PASS - max threads value, "+ value +" is correct");
69         else
70             System.out.println("FAIL - max threads value is " + maxValue + " should be "
71                 + value);
72     }
73
74
75     public static void main (String JavaDoc args[]) throws Exception JavaDoc
76     {
77         host = TestUtil.getHostName();
78         maxthreadsCmd2[4] = host;
79         
80         if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9"))
81             jvm = jvm.getJvm("j9_13");
82         else
83             jvm = jvm.getJvm("currentjvm"); // ensure compatibility
84
vCmd = jvm.getCommandLine();
85         try
86         {
87             ij.getPropertyArg(args);
88             Connection conn1 = ij.startJBMS();
89
90             bos = new BufferedOutputStream JavaDoc(System.out, 1024);
91
92             server = new NetworkServerControl();
93             /************************************************************
94              * Test max threads
95              ************************************************************/

96             System.out.println("Testing maxthreads");
97             //test maxthreads 0
98
ExecProcUtil.execCmdDumpResults(maxthreadsCmd1,vCmd,bos);
99             checkMaxThreads(0);
100             //test maxthreads -1
101
ExecProcUtil.execCmdDumpResults(maxthreadsCmd2,vCmd,bos);
102             checkMaxThreads(0); //default is currently 0
103
//test maxthreads -12 - should error
104
ExecProcUtil.execCmdDumpResults(maxthreadsCmd3,vCmd,bos);
105             checkMaxThreads(0);
106             //test maxthreads 2147483647 - should work
107
ExecProcUtil.execCmdDumpResults(maxthreadsCmd4,vCmd,bos);
108             checkMaxThreads(2147483647);
109             //test maxthreads 9000 - should work
110
ExecProcUtil.execCmdDumpResults(maxthreadsCmd5,vCmd,bos);
111             checkMaxThreads(9000);
112             //test maxthreads with invalid value (NumberFormatException)
113
ExecProcUtil.execCmdDumpResults(maxthreadsCmd6,vCmd,bos);
114             // try the same values using the callable interface
115
//test maxthreads 0
116
server.setMaxThreads(0);
117             checkMaxThreads(0);
118             //test maxthreads -1
119
server.setMaxThreads(-1);
120             checkMaxThreads(0);
121             //test maxthreads -2 - should error
122
try {
123                 server.setMaxThreads(-2);
124             } catch (Exception JavaDoc e) {
125                 System.out.println (e.getMessage());
126             }
127             //test maxthreads 2147483647 - should work
128
server.setMaxThreads(2147483647);
129             checkMaxThreads(2147483647);
130             //test maxthreads 9000 - should work
131
server.setMaxThreads(9000);
132             checkMaxThreads(9000);
133             System.out.println("End test");
134             bos.close();
135         }
136         catch (Exception JavaDoc e)
137         {
138             e.printStackTrace();
139         }
140     }
141 }
142
Popular Tags