001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.timeslice
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 timeslice command
039: */
040:
041: public class timeslice {
042:
043: private static jvm jvm;
044: private static Vector vCmd;
045: private static String[] timesliceCmd1 = new String[] {
046: "org.apache.derby.drda.NetworkServerControl", "timeslice",
047: "0" };
048: private static String[] timesliceCmd2 = new String[] {
049: "org.apache.derby.drda.NetworkServerControl", "timeslice",
050: "-1", "-h", "localhost", "-p", "1527" };
051: private static String[] timesliceCmd3 = new String[] {
052: "org.apache.derby.drda.NetworkServerControl", "timeslice",
053: "-12" };
054: private static String[] timesliceCmd4 = new String[] {
055: "org.apache.derby.drda.NetworkServerControl", "timeslice",
056: "2147483647" };
057: private static String[] timesliceCmd5 = new String[] {
058: "org.apache.derby.drda.NetworkServerControl", "timeslice",
059: "9000" };
060: private static String[] timesliceCmd6 = new String[] {
061: "org.apache.derby.drda.NetworkServerControl", "timeslice",
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 checkTimeSlice(int value) throws Exception {
069: int timeSliceValue = server.getTimeSlice();
070: if (timeSliceValue == value)
071: System.out.println("PASS - time slice value, " + value
072: + " is correct");
073: else
074: System.out.println("FAIL - time slice value is "
075: + timeSliceValue + " should be " + value);
076: }
077:
078: public static void main(String args[]) throws Exception {
079: host = TestUtil.getHostName();
080: timesliceCmd2[4] = host;
081: if ((System.getProperty("java.vm.name") != null)
082: && System.getProperty("java.vm.name").equals("J9"))
083: jvm = jvm.getJvm("j9_13");
084: else
085: jvm = jvm.getJvm("currentjvm"); // ensure compatibility
086: vCmd = jvm.getCommandLine();
087: try {
088: Connection conn1 = ij.startJBMS();
089: bos = new BufferedOutputStream(System.out, 1024);
090:
091: server = new NetworkServerControl();
092: /************************************************************
093: * Test timeslice
094: ************************************************************/
095: System.out.println("Testing timeslice");
096: //test timeslice 0
097: ExecProcUtil.execCmdDumpResults(timesliceCmd1, vCmd, bos);
098: checkTimeSlice(0);
099: //test timeslice -1
100: ExecProcUtil.execCmdDumpResults(timesliceCmd2, vCmd, bos);
101: checkTimeSlice(0); //default is currently 0
102: //test timeslice -12 - should error
103: ExecProcUtil.execCmdDumpResults(timesliceCmd3, vCmd, bos);
104: checkTimeSlice(0);
105: //test timeslice 2147483647 - should work
106: ExecProcUtil.execCmdDumpResults(timesliceCmd4, vCmd, bos);
107: checkTimeSlice(2147483647);
108: //test timeslice 9000 - should work
109: ExecProcUtil.execCmdDumpResults(timesliceCmd5, vCmd, bos);
110: checkTimeSlice(9000);
111: //test timeslice with invlaid value - NumberFormatException
112: ExecProcUtil.execCmdDumpResults(timesliceCmd6, vCmd, bos);
113: //test callable interface
114: //test timeslice 0
115: server.setTimeSlice(0);
116: checkTimeSlice(0);
117: //test timeslice -1
118: server.setTimeSlice(-1);
119: checkTimeSlice(0); //default is currently 0
120: //test timeslice -2 - should error
121: try {
122: server.setTimeSlice(-2);
123: } catch (Exception e) {
124: System.out.println("Expecting exception:"
125: + e.getMessage());
126: }
127: checkTimeSlice(0);
128: //test timeslice 2147483647 - should work
129: server.setTimeSlice(2147483647);
130: checkTimeSlice(2147483647);
131: //test timeslice 9000 - should work
132: server.setTimeSlice(9000);
133: checkTimeSlice(9000);
134: System.out.println("End test");
135: bos.close();
136: } catch (Exception e) {
137: e.printStackTrace();
138: }
139: }
140: }
|