You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2009/03/09 23:09:59 UTC

svn commit: r751868 - in /hadoop/core/branches/branch-0.20: CHANGES.txt src/test/org/apache/hadoop/http/TestGlobalFilter.java

Author: szetszwo
Date: Mon Mar  9 22:09:58 2009
New Revision: 751868

URL: http://svn.apache.org/viewvc?rev=751868&view=rev
Log:
HADOOP-4695. Change TestGlobalFilter so that it allows a web page to be filtered more than once for a single access.  (Kan Zhang via szetszwo) 

Modified:
    hadoop/core/branches/branch-0.20/CHANGES.txt
    hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/http/TestGlobalFilter.java

Modified: hadoop/core/branches/branch-0.20/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.20/CHANGES.txt?rev=751868&r1=751867&r2=751868&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.20/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.20/CHANGES.txt Mon Mar  9 22:09:58 2009
@@ -678,6 +678,9 @@
     tasktrackers forcing them to fetch all events afresh, thus avoiding missed
     task completion events on the tasktrackers. (Amar Kamat via yhemanth)
 
+    HADOOP-4695. Change TestGlobalFilter so that it allows a web page to be
+    filtered more than once for a single access.  (Kan Zhang via szetszwo) 
+
 Release 0.19.2 - Unreleased
 
   BUG FIXES

Modified: hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/http/TestGlobalFilter.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/http/TestGlobalFilter.java?rev=751868&r1=751867&r2=751868&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/http/TestGlobalFilter.java (original)
+++ hadoop/core/branches/branch-0.20/src/test/org/apache/hadoop/http/TestGlobalFilter.java Mon Mar  9 22:09:58 2009
@@ -22,9 +22,8 @@
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.net.URLConnection;
-import java.util.Map;
-import java.util.Random;
-import java.util.TreeMap;
+import java.util.Set;
+import java.util.TreeSet;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -40,10 +39,10 @@
 
 public class TestGlobalFilter extends junit.framework.TestCase {
   static final Log LOG = LogFactory.getLog(HttpServer.class);
-  static final Map<String, Integer> COUNTS = new TreeMap<String, Integer>(); 
+  static final Set<String> RECORDS = new TreeSet<String>(); 
 
-  /** A very simple filter which counts number of accesses for each uri */
-  static public class CountingFilter implements Filter {
+  /** A very simple filter that records accessed uri's */
+  static public class RecordingFilter implements Filter {
     private FilterConfig filterConfig = null;
 
     public void init(FilterConfig filterConfig) {
@@ -61,18 +60,16 @@
 
       String uri = ((HttpServletRequest)request).getRequestURI();
       LOG.info("filtering " + uri);
-      Integer value = COUNTS.get(uri);
-      value = value == null? 1: value + 1;
-      COUNTS.put(uri, value);
+      RECORDS.add(uri);
       chain.doFilter(request, response);
     }
 
-    /** Configuration for CountingFilter */
+    /** Configuration for RecordingFilter */
     static public class Initializer extends FilterInitializer {
       public Initializer() {}
 
       void initFilter(FilterContainer container) {
-        container.addGlobalFilter("counting", CountingFilter.class.getName(), null);
+        container.addGlobalFilter("recording", RecordingFilter.class.getName(), null);
       }
     }
   }
@@ -103,7 +100,7 @@
     
     //start a http server with CountingFilter
     conf.set(HttpServer.FILTER_INITIALIZER_PROPERTY,
-        CountingFilter.Initializer.class.getName());
+        RecordingFilter.Initializer.class.getName());
     HttpServer http = new HttpServer("datanode", "localhost", 0, true, conf);
     http.start();
 
@@ -120,37 +117,23 @@
 
     final String[] urls = {fsckURL, stacksURL, ajspURL, listPathsURL, 
         dataURL, streamFile, rootURL, allURL, outURL, logURL};
-    final Random ran = new Random();
-    final int[] sequence = new int[100];
-    final int[] counts = new int[urls.length]; 
 
-    //generate a random sequence and update counts 
-    for(int i = 0; i < sequence.length; i++) {
-      sequence[i] = ran.nextInt(urls.length);
-      counts[sequence[i]]++;
-    }
-
-    //access the urls as the sequence
+    //access the urls
     final String prefix = "http://localhost:" + http.getPort();
     try {
-      for(int i = 0; i < sequence.length; i++) {
-        access(prefix + urls[sequence[i]]);
+      for(int i = 0; i < urls.length; i++) {
+        access(prefix + urls[i]);
       }
     } finally {
       http.stop();
     }
 
-    LOG.info("COUNTS = " + COUNTS);
+    LOG.info("RECORDS = " + RECORDS);
     
-    //verify counts
+    //verify records
     for(int i = 0; i < urls.length; i++) {
-      if (counts[i] == 0) {
-        assertFalse(COUNTS.containsKey(urls[i]));
-      } else {
-        assertEquals("url[" + i + "]=" + urls[i],
-            Integer.valueOf(counts[i]), COUNTS.remove(urls[i]));
-      }
+      assertTrue(RECORDS.remove(urls[i]));
     }
-    assertTrue(COUNTS.isEmpty());
+    assertTrue(RECORDS.isEmpty());
   }
 }