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:59:12 UTC

[tomcat] branch 7.0.x updated (0dda9b9 -> 233cb63)

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

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


    from 0dda9b9  Expand Java search path for Windows installer to JDK and JAVA_HOME
     new bf074ae  PR #227 Unit test FileStore utility methods
     new 233cb63  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] 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 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit bf074ae239b15594ace6671668c9d797536cffe8
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 9263bdf..87760c2 100644
--- a/java/org/apache/catalina/session/FileStore.java
+++ b/java/org/apache/catalina/session/FileStore.java
@@ -138,17 +138,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++;
                 }
             }
@@ -183,12 +183,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)) {
@@ -198,9 +198,9 @@ public final class FileStore extends StoreBase {
         // Build and return the list of session identifiers
         List<String> list = new ArrayList<String>();
         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()]);
@@ -221,11 +221,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


[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 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 233cb6326bc732dc530ed26381cdce4fdae369ce
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 | 16 ++++++++--------
 webapps/docs/changelog.xml                          |  5 +++++
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/java/org/apache/catalina/session/FileStore.java b/java/org/apache/catalina/session/FileStore.java
index 87760c2..5dde3fd 100644
--- a/java/org/apache/catalina/session/FileStore.java
+++ b/java/org/apache/catalina/session/FileStore.java
@@ -187,11 +187,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..e46a308 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,10 +41,10 @@ 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);
+        manager.setContainer(testerContext);
         fileStore = new FileStore();
         fileStore.setManager(manager);
     }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index d22839b..16c50a6 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -85,6 +85,11 @@
         <code>TestAsyncContextStateChanges</code> test that caused it
         to hang indefinitely. (markt)
       </fix>
+      <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