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 km...@apache.org on 2008/06/23 18:39:46 UTC
svn commit: r670669 - in /db/derby/code/branches/10.4/java:
drda/org/apache/derby/impl/drda/
testing/org/apache/derbyTesting/functionTests/tests/derbynet/
testing/org/apache/derbyTesting/functionTests/util/
Author: kmarsden
Date: Mon Jun 23 09:39:46 2008
New Revision: 670669
URL: http://svn.apache.org/viewvc?rev=670669&view=rev
Log:
DERBY-3708 setting tracedirectory from the command line does not work
Added:
db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java (with props)
Modified:
db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
Modified: db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=670669&r1=670668&r2=670669&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java (original)
+++ db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java Mon Jun 23 09:39:46 2008
@@ -2155,8 +2155,9 @@
break;
}
case COMMAND_TRACEDIRECTORY:
- setTraceDirectory((String) commandArgs.elementAt(0));
- consolePropertyMessage("DRDA_TraceDirectoryChange.I", traceDirectory);
+ String directory = (String) commandArgs.elementAt(0);
+ sendSetTraceDirectory(directory);
+ consolePropertyMessage("DRDA_TraceDirectoryChange.I", directory);
break;
case COMMAND_TESTCONNECTION:
ping();
Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java?rev=670669&r1=670668&r2=670669&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java (original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SecureServerTest.java Mon Jun 23 09:39:46 2008
@@ -21,6 +21,7 @@
package org.apache.derbyTesting.functionTests.tests.derbynet;
+import java.io.File;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -45,6 +46,7 @@
import org.apache.derbyTesting.junit.SupportFilesSetup;
import org.apache.derbyTesting.junit.SystemPropertyTestSetup;
import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
import org.apache.derby.drda.NetworkServerControl;
@@ -353,6 +355,35 @@
//
runsysinfo();
enableTracing();
+ setTraceDirectory();
+ disableTracing();
+
+ }
+
+ private void disableTracing() throws Exception {
+
+ String traceOffOutput = runServerCommand( "trace off" );
+
+ println( "Output for trace off command:\n\n" + traceOffOutput );
+
+ if ( traceOffOutput.indexOf( "Trace turned off for all sessions." ) < 0 )
+ { fail( "Failed to turn trace off:\n\n:" + traceOffOutput ); }
+ }
+
+ private void setTraceDirectory() throws Exception {
+ PrivilegedFileOpsForTests.mkdirs(new File("trace"));
+ String traceDirectoryOutput = runServerCommand( "tracedirectory trace" );
+ println( "Output for tracedirectory trace command:\n\n" + traceDirectoryOutput );
+
+ if ( traceDirectoryOutput.indexOf( "Trace directory changed to trace." ) < 0 )
+ { fail( "Unexpected output in setting trace directory:" + traceDirectoryOutput ); }
+
+ String pingOutput = runServerCommand( "ping" );
+
+ if (pingOutput.indexOf("Connection obtained for host:") < 0)
+ { fail ("Failed ping after changing trace directory: " + pingOutput);}
+ assertTrue("Trace file does not exist",
+ PrivilegedFileOpsForTests.exists(new File("trace/Server6.trace")));
}
private void connectToServer()
Added: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java?rev=670669&view=auto
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java (added)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java Mon Jun 23 09:39:46 2008
@@ -0,0 +1,132 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsorTests
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.derbyTesting.functionTests.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * A set of operations on {$@link java.io.File} that wraps the
+ * operations in privileged block of code. This class is intended to provide
+ * these methods for testcases to reduce the hassle of having to wrap file
+ * operations in privileged code blocks.
+ * <p>
+ * Derby needs to use privileged blocks in some places to avoid
+ * {@link SecurityException}s being thrown, as the required privileges are
+ * often granted to Derby itself, but not the higher level application code.
+ * <p>
+ */
+public class PrivilegedFileOpsForTests {
+
+ /**
+ * Get the file length.
+ *
+ * @return byte length of the file.
+ * @throws SecurityException if the required permissions to read the file,
+ * or the path it is in, are missing
+ * @see File#length
+ */
+ public static long length(final File file)
+ throws SecurityException {
+ if (file == null) {
+ throw new IllegalArgumentException("file cannot be <null>");
+ }
+ try {
+ return ((Long)AccessController.doPrivileged(
+ new PrivilegedExceptionAction() {
+ public Object run() throws SecurityException {
+ return new Long(file.length());
+ }
+ })).longValue();
+ } catch (PrivilegedActionException pae) {
+ throw (SecurityException)pae.getException();
+ }
+ }
+
+ public static FileInputStream getFileInputStream(final File file)
+ throws SecurityException, FileNotFoundException {
+ if (file == null) {
+ throw new IllegalArgumentException("file cannot be <null>");
+ }
+ try {
+ return ((FileInputStream)AccessController.doPrivileged(
+ new PrivilegedExceptionAction() {
+ public Object run() throws SecurityException, FileNotFoundException {
+ return new FileInputStream(file);
+ }
+ }));
+ } catch (PrivilegedActionException pae) {
+ throw (SecurityException)pae.getException();
+ }
+ }
+
+ /**
+ * Check if the file exists.
+ *
+ * @return <code>true</code> if file exists, <code>false</code> otherwise
+ * @throws SecurityException if the required permissions to read the file,
+ * or the path it is in, are missing
+ * @see File#exists
+ */
+ public static boolean exists(final File file)
+ throws SecurityException {
+ if (file == null) {
+ throw new IllegalArgumentException("file cannot be <null>");
+ }
+ try {
+ return ((Boolean)AccessController.doPrivileged(
+ new PrivilegedExceptionAction() {
+ public Object run() throws SecurityException {
+ return new Boolean(file.exists());
+ }
+ })).booleanValue();
+ } catch (PrivilegedActionException pae) {
+ throw (SecurityException)pae.getException();
+ }
+ }
+ /**
+ * Creates the directory named by this abstract pathname and
+ * parent directories
+ *
+ * @param file directory to create
+ * @return {@code true} if directory was created.
+ */
+ public static boolean mkdirs(final File file) {
+
+ if (file == null) {
+ throw new IllegalArgumentException("file cannot be <null>");
+ }
+ try {
+ return ((Boolean) AccessController.doPrivileged(
+ new PrivilegedExceptionAction() {
+ public Object run() throws SecurityException {
+ return new Boolean(file.mkdirs());
+ }
+ })).booleanValue();
+ } catch (PrivilegedActionException pae) {
+ throw (SecurityException)pae.getException();
+ }
+ }
+}
Propchange: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
------------------------------------------------------------------------------
svn:eol-style = native