mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r733158 - in /mina/ftpserver/trunk/core/src: main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java main/java/org/apache/ftpserver/impl/DefaultFtpStatistics.java test/java/org/apache/ftpserver/clienttests/SiteTest.java
Date Fri, 09 Jan 2009 21:37:49 GMT
Author: ngn
Date: Fri Jan  9 13:37:49 2009
New Revision: 733158

URL: http://svn.apache.org/viewvc?rev=733158&view=rev
Log:
Fix for statistics being wrong for the number of connections (FTPSERVER-259) and removed directories
(FTPSERVER-261). Also added test for all stats

Modified:
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpStatistics.java
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/SiteTest.java

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java?rev=733158&r1=733157&r2=733158&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java
(original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpHandler.java
Fri Jan  9 13:37:49 2009
@@ -58,6 +58,13 @@
 
     public void sessionCreated(final FtpIoSession session) throws Exception {
         session.setListener(listener);
+        
+        ServerFtpStatistics stats = ((ServerFtpStatistics) context
+                .getFtpStatistics());
+
+        if (stats != null) {
+            stats.setOpenConnection(session);
+        }
     }
 
     public void sessionOpened(final FtpIoSession session) throws Exception {
@@ -83,6 +90,7 @@
 
         if (stats != null) {
             stats.setLogout(session);
+            stats.setCloseConnection(session);
         }
     }
 

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpStatistics.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpStatistics.java?rev=733158&r1=733157&r2=733158&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpStatistics.java
(original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/impl/DefaultFtpStatistics.java
Fri Jan  9 13:37:49 2009
@@ -178,7 +178,7 @@
      * Get total directory removed.
      */
     public int getTotalDirectoryRemoved() {
-        return mkdirCount.get();
+        return rmdirCount.get();
     }
 
     /**

Modified: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/SiteTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/SiteTest.java?rev=733158&r1=733157&r2=733158&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/SiteTest.java
(original)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/SiteTest.java
Fri Jan  9 13:37:49 2009
@@ -19,9 +19,11 @@
 
 package org.apache.ftpserver.clienttests;
 
-import java.util.regex.Matcher;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.util.regex.Pattern;
 
+import org.apache.commons.net.ftp.FTPClient;
 import org.apache.commons.net.ftp.FTPReply;
 
 /**
@@ -32,6 +34,11 @@
 */
 public class SiteTest extends ClientTestTemplate {
 
+    private static final String TEST_FILENAME = "test.txt";
+    private static final byte[] TESTDATA = "TESTDATA".getBytes();
+    
+    private static final String TIMESTAMP_PATTERN = "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}";
+
     public void testSiteDescUser() throws Exception {
         client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
 
@@ -62,15 +69,63 @@
         String[] siteReplies = client.getReplyString().split("\r\n");
 
         assertEquals("200-", siteReplies[0]);
+        String pattern = "200 admin           127.0.0.1       " + TIMESTAMP_PATTERN + " "
+ TIMESTAMP_PATTERN + " "; 
         
-        String timestampPattern = "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}";
-        System.out.println(">>" + siteReplies[1] + "<<");
+        assertTrue(Pattern.matches(pattern, siteReplies[1]));
+    }
+
+    public void testSiteStat() throws Exception {
+        // reboot server to clear stats
+        server.stop();
+        initServer();
         
-        String pattern = "200 admin           127.0.0.1       " + timestampPattern + " "
+ timestampPattern + " "; 
+        // let's generate some stats
+        FTPClient client1 = new FTPClient();
+        client1.connect("localhost", port);
+        
+        assertTrue(client1.login(ADMIN_USERNAME, ADMIN_PASSWORD));
+        assertTrue(client1.makeDirectory("foo"));
+        assertTrue(client1.makeDirectory("foo2"));
+        assertTrue(client1.removeDirectory("foo2"));
+        assertTrue(client1.storeFile(TEST_FILENAME, new ByteArrayInputStream(TESTDATA)));
+        assertTrue(client1.storeFile(TEST_FILENAME, new ByteArrayInputStream(TESTDATA)));
+        assertTrue(client1.retrieveFile(TEST_FILENAME, new ByteArrayOutputStream()));
+        assertTrue(client1.deleteFile(TEST_FILENAME));
+        
+        assertTrue(client1.logout());
+        client1.disconnect();
+
+        FTPClient client2 = new FTPClient();
+        client2.connect("localhost", port);
+
+        assertTrue(client2.login(ANONYMOUS_USERNAME, ANONYMOUS_PASSWORD));
+        // done setting up stats
         
+        client.connect("localhost", port);
+        client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+
+        client.sendCommand("SITE STAT");
+        String[] siteReplies = client.getReplyString().split("\r\n");
+
+        assertEquals("200-", siteReplies[0]);
+        
+        String pattern = "Start Time               : " + TIMESTAMP_PATTERN; 
         assertTrue(Pattern.matches(pattern, siteReplies[1]));
-    }
 
+        assertTrue(Pattern.matches("File Upload Number       : 2", siteReplies[2]));
+        assertTrue(Pattern.matches("File Download Number     : 1", siteReplies[3]));
+        assertTrue(Pattern.matches("File Delete Number       : 1", siteReplies[4]));
+        assertTrue(Pattern.matches("File Upload Bytes        : 16", siteReplies[5]));
+        assertTrue(Pattern.matches("File Download Bytes      : 8", siteReplies[6]));
+        assertTrue(Pattern.matches("Directory Create Number  : 2", siteReplies[7]));
+        assertTrue(Pattern.matches("Directory Remove Number  : 1", siteReplies[8]));
+        assertTrue(Pattern.matches("Current Logins           : 2", siteReplies[9]));
+        assertTrue(Pattern.matches("Total Logins             : 3", siteReplies[10]));
+        assertTrue(Pattern.matches("Current Anonymous Logins : 1", siteReplies[11]));
+        assertTrue(Pattern.matches("Total Anonymous Logins   : 1", siteReplies[12]));
+        assertTrue(Pattern.matches("Current Connections      : 2", siteReplies[13]));
+        assertTrue(Pattern.matches("200 Total Connections        : 3", siteReplies[14]));
+    }
 
     
 }



Mime
View raw message