You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/12/05 12:56:35 UTC

[tomcat] branch master updated (709a331 -> b9ad09a)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from 709a331  Expand Java search path for Windows installer to JDK and JAVA_HOME
     new d2c22d7  PR #227 Unit test FileStore utility methods
     new b9ad09a  Review PR #227. Add changelog entry

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/org/apache/catalina/session/FileStore.java    | 31 +++----
 .../org/apache/catalina/session/FileStoreTest.java | 95 ++++++++++++++++++++++
 webapps/docs/changelog.xml                         |  5 ++
 3 files changed, 113 insertions(+), 18 deletions(-)
 create mode 100644 test/org/apache/catalina/session/FileStoreTest.java


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 02/02: Review PR #227. Add changelog entry

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit b9ad09a1d1369e5e046f619f2d2a2d651a6077f3
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Dec 5 12:53:50 2019 +0000

    Review PR #227. Add changelog entry
---
 java/org/apache/catalina/session/FileStore.java     |  3 +--
 test/org/apache/catalina/session/FileStoreTest.java | 14 +++++++-------
 webapps/docs/changelog.xml                          |  5 +++++
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/java/org/apache/catalina/session/FileStore.java b/java/org/apache/catalina/session/FileStore.java
index 48d464e..73016ff 100644
--- a/java/org/apache/catalina/session/FileStore.java
+++ b/java/org/apache/catalina/session/FileStore.java
@@ -176,11 +176,10 @@ public final class FileStore extends StoreBase {
         if (dir == null) {
             return new String[0];
         }
-
         String files[] = dir.list();
 
         // Bugzilla 32130
-        if((files == null) || (files.length < 1)) {
+        if (files == null || files.length < 1) {
             return new String[0];
         }
 
diff --git a/test/org/apache/catalina/session/FileStoreTest.java b/test/org/apache/catalina/session/FileStoreTest.java
index 330c4a0..f2555de 100644
--- a/test/org/apache/catalina/session/FileStoreTest.java
+++ b/test/org/apache/catalina/session/FileStoreTest.java
@@ -19,17 +19,17 @@ package org.apache.catalina.session;
 import java.io.File;
 import java.io.IOException;
 
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
 import org.apache.catalina.Manager;
 import org.apache.tomcat.unittest.TesterContext;
 import org.apache.tomcat.unittest.TesterServletContext;
 import org.apache.tomcat.util.http.fileupload.FileUtils;
-import org.junit.*;
 
-/**
- * Test utility methods of FileStore class
- *
- * @author Govinda Sakhare
- */
 public class FileStoreTest {
 
     private static final String SESS_TEMPPATH = "SESS_TEMP";
@@ -41,7 +41,7 @@ public class FileStoreTest {
 
 
     @BeforeClass
-    public static void setup() throws IOException {
+    public static void setup() {
         TesterContext testerContext = new TesterContext();
         testerContext.setServletContext(new TesterServletContext());
         manager.setContext(testerContext);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 250edef..53a5f78 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -90,6 +90,11 @@
       <update>
         <bug>63987</bug>: Deprecate <code>Realm.getRoles(Principal)</code>. (michaelo)
       </update>
+      <scode>
+        Add a unit test for the session <code>FileStore</code> implementation
+        and refactor loops in <code>FileStore</code> to use the ForEach style.
+        Pull request provided by Govinda Sakhare. (markt)
+      </scode>
     </changelog>
   </subsection>
   <subsection name="Coyote">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 01/02: PR #227 Unit test FileStore utility methods

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit d2c22d7d1c49928a97e2caec695fb9357726d391
Author: govi20 <go...@gmail.com>
AuthorDate: Sun Dec 1 17:45:24 2019 +0530

    PR #227 Unit test FileStore utility methods
---
 java/org/apache/catalina/session/FileStore.java    | 28 +++----
 .../org/apache/catalina/session/FileStoreTest.java | 95 ++++++++++++++++++++++
 2 files changed, 107 insertions(+), 16 deletions(-)

diff --git a/java/org/apache/catalina/session/FileStore.java b/java/org/apache/catalina/session/FileStore.java
index a1916dc..48d464e 100644
--- a/java/org/apache/catalina/session/FileStore.java
+++ b/java/org/apache/catalina/session/FileStore.java
@@ -127,17 +127,17 @@ public final class FileStore extends StoreBase {
     @Override
     public int getSize() throws IOException {
         // Acquire the list of files in our storage directory
-        File file = directory();
-        if (file == null) {
+        File dir = directory();
+        if (dir == null) {
             return 0;
         }
-        String files[] = file.list();
+        String files[] = dir.list();
 
         // Figure out which files are sessions
         int keycount = 0;
         if (files != null) {
-            for (int i = 0; i < files.length; i++) {
-                if (files[i].endsWith(FILE_EXT)) {
+            for (String file : files) {
+                if (file.endsWith(FILE_EXT)) {
                     keycount++;
                 }
             }
@@ -172,12 +172,12 @@ public final class FileStore extends StoreBase {
     @Override
     public String[] keys() throws IOException {
         // Acquire the list of files in our storage directory
-        File file = directory();
-        if (file == null) {
+        File dir = directory();
+        if (dir == null) {
             return new String[0];
         }
 
-        String files[] = file.list();
+        String files[] = dir.list();
 
         // Bugzilla 32130
         if((files == null) || (files.length < 1)) {
@@ -187,9 +187,9 @@ public final class FileStore extends StoreBase {
         // Build and return the list of session identifiers
         List<String> list = new ArrayList<>();
         int n = FILE_EXT.length();
-        for (int i = 0; i < files.length; i++) {
-            if (files[i].endsWith(FILE_EXT)) {
-                list.add(files[i].substring(0, files[i].length() - n));
+        for (String file : files) {
+            if (file.endsWith(FILE_EXT)) {
+                list.add (file.substring(0, file.length() - n));
             }
         }
         return list.toArray(new String[list.size()]);
@@ -210,11 +210,7 @@ public final class FileStore extends StoreBase {
     public Session load(String id) throws ClassNotFoundException, IOException {
         // Open an input stream to the specified pathname, if any
         File file = file(id);
-        if (file == null) {
-            return null;
-        }
-
-        if (!file.exists()) {
+        if (file == null || !file.exists()) {
             return null;
         }
 
diff --git a/test/org/apache/catalina/session/FileStoreTest.java b/test/org/apache/catalina/session/FileStoreTest.java
new file mode 100644
index 0000000..330c4a0
--- /dev/null
+++ b/test/org/apache/catalina/session/FileStoreTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.catalina.session;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.catalina.Manager;
+import org.apache.tomcat.unittest.TesterContext;
+import org.apache.tomcat.unittest.TesterServletContext;
+import org.apache.tomcat.util.http.fileupload.FileUtils;
+import org.junit.*;
+
+/**
+ * Test utility methods of FileStore class
+ *
+ * @author Govinda Sakhare
+ */
+public class FileStoreTest {
+
+    private static final String SESS_TEMPPATH = "SESS_TEMP";
+    private static final File dir = new File(SESS_TEMPPATH);
+    private static FileStore fileStore;
+    private static File file1 = new File(SESS_TEMPPATH + "/tmp1.session");
+    private static File file2 = new File(SESS_TEMPPATH + "/tmp2.session");
+    private static Manager manager = new StandardManager();
+
+
+    @BeforeClass
+    public static void setup() throws IOException {
+        TesterContext testerContext = new TesterContext();
+        testerContext.setServletContext(new TesterServletContext());
+        manager.setContext(testerContext);
+        fileStore = new FileStore();
+        fileStore.setManager(manager);
+    }
+
+
+    @AfterClass
+    public static void cleanup() throws IOException {
+        FileUtils.cleanDirectory(dir);
+        FileUtils.deleteDirectory(dir);
+    }
+
+
+    @Before
+    public void beforeEachTest() throws IOException {
+        fileStore.setDirectory(SESS_TEMPPATH);
+        dir.mkdir();
+        file1.createNewFile();
+        file2.createNewFile();
+    }
+
+
+    @Test
+    public void getSize() throws Exception {
+        Assert.assertEquals(2, fileStore.getSize());
+    }
+
+
+    @Test
+    public void clear() throws Exception {
+        fileStore.clear();
+        Assert.assertEquals(0, fileStore.getSize());
+    }
+
+
+    @Test
+    public void keys() throws Exception {
+        Assert.assertArrayEquals(new String[]{"tmp1", "tmp2"}, fileStore.keys());
+        fileStore.clear();
+        Assert.assertArrayEquals(new String[]{}, fileStore.keys());
+    }
+
+
+    @Test
+    public void removeTest() throws Exception {
+        fileStore.remove("tmp1");
+        Assert.assertEquals(1, fileStore.getSize());
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org