KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.timeslice
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 timeslice command
39 */

40
41 public class timeslice
42 {
43
44     private static jvm jvm;
45     private static Vector JavaDoc vCmd;
46     private static String JavaDoc[] timesliceCmd1 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
47         "timeslice", "0"};
48     private static String JavaDoc[] timesliceCmd2 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
49         "timeslice","-1", "-h", "localhost", "-p", "1527"};
50     private static String JavaDoc[] timesliceCmd3 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
51         "timeslice", "-12"};
52     private static String JavaDoc[] timesliceCmd4 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
53         "timeslice", "2147483647"};
54     private static String JavaDoc[] timesliceCmd5 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
55         "timeslice", "9000"};
56     private static String JavaDoc[] timesliceCmd6 = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
57             "timeslice", "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 checkTimeSlice( int value)
64         throws Exception JavaDoc
65     {
66         int timeSliceValue = server.getTimeSlice();
67         if (timeSliceValue == value)
68             System.out.println("PASS - time slice value, "+value+" is correct");
69         else
70             System.out.println("FAIL - time slice value is " + timeSliceValue + " should be "
71                 + value);
72     }
73
74     public static void main (String JavaDoc args[]) throws Exception JavaDoc
75     {
76         host = TestUtil.getHostName();
77         timesliceCmd2[4] = host;
78         if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9"))
79             jvm = jvm.getJvm("j9_13");
80         else
81             jvm = jvm.getJvm("currentjvm"); // ensure compatibility
82
vCmd = jvm.getCommandLine();
83         try
84         {
85             Connection conn1 = ij.startJBMS();
86             bos = new BufferedOutputStream JavaDoc(System.out, 1024);
87
88             server = new NetworkServerControl();
89             /************************************************************
90              * Test timeslice
91              ************************************************************/

92             System.out.println("Testing timeslice");
93             //test timeslice 0
94
ExecProcUtil.execCmdDumpResults(timesliceCmd1,vCmd,bos);
95             checkTimeSlice(0);
96             //test timeslice -1
97
ExecProcUtil.execCmdDumpResults(timesliceCmd2,vCmd,bos);
98             checkTimeSlice(0); //default is currently 0
99
//test timeslice -12 - should error
100
ExecProcUtil.execCmdDumpResults(timesliceCmd3,vCmd,bos);
101             checkTimeSlice(0);
102             //test timeslice 2147483647 - should work
103
ExecProcUtil.execCmdDumpResults(timesliceCmd4,vCmd,bos);
104             checkTimeSlice(2147483647);
105             //test timeslice 9000 - should work
106
ExecProcUtil.execCmdDumpResults(timesliceCmd5,vCmd,bos);
107             checkTimeSlice(9000);
108             //test timeslice with invlaid value - NumberFormatException
109
ExecProcUtil.execCmdDumpResults(timesliceCmd6,vCmd,bos);
110             //test callable interface
111
//test timeslice 0
112
server.setTimeSlice(0);
113             checkTimeSlice(0);
114             //test timeslice -1
115
server.setTimeSlice(-1);
116             checkTimeSlice(0); //default is currently 0
117
//test timeslice -2 - should error
118
try {
119                 server.setTimeSlice(-2);
120             } catch (Exception JavaDoc e) {
121                 System.out.println ("Expecting exception:" + e.getMessage());
122             }
123             checkTimeSlice(0);
124             //test timeslice 2147483647 - should work
125
server.setTimeSlice(2147483647);
126             checkTimeSlice(2147483647);
127             //test timeslice 9000 - should work
128
server.setTimeSlice(9000);
129             checkTimeSlice(9000);
130             System.out.println("End test");
131             bos.close();
132         }
133         catch (Exception JavaDoc e)
134         {
135             e.printStackTrace();
136         }
137     }
138 }
139
Popular Tags