db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1409100 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: tests/engine/ReadMeFilesTest.java util/PrivilegedFileOpsForTests.java
Date Wed, 14 Nov 2012 06:55:59 GMT
Author: mamta
Date: Wed Nov 14 06:55:59 2012
New Revision: 1409100

URL: http://svn.apache.org/viewvc?rev=1409100&view=rev
Log:
DERBY-5232 (Put a stern README file in log and seg0 directories to warn users of corrpution
they will cause if they touch files there)

Adding a test case for default database creation with the checks for the existence of the
3 readme files. These readmes warn users against editing/deleting any of the files in the
database directories. The location of the readme files are  
 1)at the db level directory, 
 2)in seg0 directory and 
 3)in the log directocy.
All the three readme files are named README_DONT_TOUCH_FILES.txt


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ReadMeFilesTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ReadMeFilesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ReadMeFilesTest.java?rev=1409100&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ReadMeFilesTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ReadMeFilesTest.java
Wed Nov 14 06:55:59 2012
@@ -0,0 +1,77 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.engine.ReadMeFilesTest
+
+
+   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.tests.engine;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.SQLException;
+
+import junit.framework.Test;
+
+import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+
+/**
+ * Tests related to the 3 Derby readme files. These readmes warn users against 
+ *   editing/deleting any of the files in the database directories. The 
+ *   location of the readme files are  
+ *   1)at the db level directory, 
+ *   2)in seg0 directory and 
+ *   3)in the log directocy.
+ * All the three readme files are named README_DONT_TOUCH_FILES.txt
+ */
+public class ReadMeFilesTest extends BaseJDBCTestCase {
+    /**
+    The readme file cautioning users against touching the files in
+    the database directory 
+    */
+    private static final String DB_README_FILE_NAME = "README_DONT_TOUCH_FILES.txt";
+
+    public ReadMeFilesTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        Test suite = TestConfiguration.embeddedSuite(ReadMeFilesTest.class);
+        return TestConfiguration.singleUseDatabaseDecorator(suite);
+    }
+
+    public void testReadMeFilesExist() throws IOException, SQLException {
+        getConnection();
+        TestConfiguration currentConfig = TestConfiguration.getCurrent();
+        String dbPath = currentConfig.getDatabasePath(currentConfig.getDefaultDatabaseName());
+        lookForReadmeFile(dbPath);
+        lookForReadmeFile(dbPath+File.separator+"seg0");
+        lookForReadmeFile(dbPath+File.separator+"log");
+    }
+
+    private void lookForReadmeFile(String path) throws IOException {
+        File readmeFile = new File(path,
+            DB_README_FILE_NAME);
+        PrivilegedFileOpsForTests.exists(readmeFile);
+        PrivilegedFileOpsForTests.isFileEmpty(readmeFile);
+    }
+}
+ 

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/engine/ReadMeFilesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java?rev=1409100&r1=1409099&r2=1409100&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
Wed Nov 14 06:55:59 2012
@@ -440,6 +440,34 @@ public class PrivilegedFileOpsForTests {
     }
 
     /**
+     * Checks if the specified file is empty.
+     *
+     * @param f the file
+     * @return true if the file is empty
+     */
+    public static boolean isFileEmpty(final File f) 
+            throws FileNotFoundException {
+        if (f == null) {
+            throw new IllegalArgumentException("file cannot be <null>");
+        }
+        try {
+            return((Boolean)AccessController.doPrivileged (new PrivilegedExceptionAction()
{
+                public Object run() throws IOException {
+                    FileInputStream fis = new FileInputStream(f);
+                    int result = fis.read();
+                    fis.close();
+                    if(result == -1)
+                        return Boolean.valueOf(true);
+                    else
+                        return Boolean.valueOf(false);
+                }
+            })).booleanValue();
+        } catch (PrivilegedActionException pae) {
+            throw (FileNotFoundException)pae.getCause();
+        }
+    }
+
+    /**
      * Obtains information about the specified file.
      *
      * @param f the file



Mime
View raw message