lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r926654 - in /lucene/dev/trunk/solr/src: common/org/apache/solr/common/SolrException.java test/org/apache/solr/BasicFunctionalityTest.java test/org/apache/solr/ConvertedLegacyTest.java test/org/apache/solr/SolrTestCaseJ4.java
Date Tue, 23 Mar 2010 16:41:25 GMT
Author: yonik
Date: Tue Mar 23 16:41:25 2010
New Revision: 926654

URL: http://svn.apache.org/viewvc?rev=926654&view=rev
Log:
SOLR-1835: add ability to not log exceptions matching a certain pattern

Modified:
    lucene/dev/trunk/solr/src/common/org/apache/solr/common/SolrException.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/BasicFunctionalityTest.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/ConvertedLegacyTest.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java

Modified: lucene/dev/trunk/solr/src/common/org/apache/solr/common/SolrException.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/common/org/apache/solr/common/SolrException.java?rev=926654&r1=926653&r2=926654&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/common/org/apache/solr/common/SolrException.java (original)
+++ lucene/dev/trunk/solr/src/common/org/apache/solr/common/SolrException.java Tue Mar 23
16:41:25 2010
@@ -18,15 +18,18 @@
 package org.apache.solr.common;
 
 import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
 import java.io.CharArrayWriter;
 import java.io.PrintWriter;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @version $Id$
  */
 public class SolrException extends RuntimeException {
-  
+
   /**
    * @since solr 1.2
    */
@@ -136,17 +139,30 @@ public class SolrException extends Runti
 
   public void log(Logger log) { log(log,this); }
   public static void log(Logger log, Throwable e) {
-    log.error(toStr(e));
     if (e instanceof SolrException) {
       ((SolrException)e).logged = true;
     }
+    String stackTrace = toStr(e);
+    String ignore = doIgnore(stackTrace);
+    if (ignore != null) {
+      log.info(ignore);
+      return;
+    }
+    log.error(stackTrace);
+
   }
 
   public static void log(Logger log, String msg, Throwable e) {
-    log.error(msg + ':' + toStr(e));
     if (e instanceof SolrException) {
       ((SolrException)e).logged = true;
     }
+    String stackTrace = msg + ':' + toStr(e);
+    String ignore = doIgnore(stackTrace);
+    if (ignore != null) {
+      log.info(ignore);
+      return;
+    }
+    log.error(stackTrace);
   }
 
   public static void logOnce(Logger log, String msg, Throwable e) {
@@ -179,4 +195,22 @@ public class SolrException extends Runti
 **/
   }
 
+
+  /** For test code - do not log exceptions that match any of the regular expressions in
ignorePatterns */
+  public static Set<String> ignorePatterns;
+
+  /** Returns null if this exception does not match any ignore patterns, or a message string
to use if it does. */
+  public static String doIgnore(String m) {
+    if (ignorePatterns == null || m == null) return null;
+
+    for (String regex : ignorePatterns) {
+      Pattern pattern = Pattern.compile(regex);
+      Matcher matcher = pattern.matcher(m);
+      if (matcher.find()) return "Ignoring exception matching " + regex;
+    }
+
+    return null;
+  }
+
+
 }

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/BasicFunctionalityTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/BasicFunctionalityTest.java?rev=926654&r1=926653&r2=926654&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/BasicFunctionalityTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/BasicFunctionalityTest.java Tue Mar 23
16:41:25 2010
@@ -65,7 +65,7 @@ public class BasicFunctionalityTest exte
   public String getCoreName() { return "basic"; }
 
   @BeforeClass
-  public static void beforeClass() throws Exception {
+  public static void beforeTests() throws Exception {
     initCore("solrconfig.xml","schema.xml");
   }
   // tests the performance of dynamic field creation and
@@ -224,7 +224,7 @@ public class BasicFunctionalityTest exte
 
   @Test
   public void testRequestHandlerBaseException() {
-    final String tmp = "BOO!";
+    final String tmp = "BOO! ignore_exception";
     SolrRequestHandler handler = new RequestHandlerBase() {
         public String getDescription() { return tmp; }
         public String getSourceId() { return tmp; }

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/ConvertedLegacyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/ConvertedLegacyTest.java?rev=926654&r1=926653&r2=926654&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/ConvertedLegacyTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/ConvertedLegacyTest.java Tue Mar 23 16:41:25
2010
@@ -19,6 +19,8 @@ package org.apache.solr;
 
 import org.apache.solr.request.*;
 import org.apache.solr.util.*;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
 import java.util.*;
 
@@ -29,11 +31,14 @@ import java.util.*;
  * it does not represent the best practices that should be used when
  * writing Solr JUnit tests
  */
-public class ConvertedLegacyTest extends AbstractSolrTestCase {
+public class ConvertedLegacyTest extends SolrTestCaseJ4 {
 
-  public String getSchemaFile() { return "schema.xml"; } 
-  public String getSolrConfigFile() { return "solrconfig.xml"; } 
+  @BeforeClass
+  public static void beforeTests() throws Exception {
+    initCore("solrconfig.xml","schema.xml");
+  }
 
+  @Test
   public void testABunchOfConvertedStuff() {
     // these may be reused by things that need a special query
     SolrQueryRequest req = null;
@@ -780,7 +785,12 @@ public class ConvertedLegacyTest extends
             ,"//doc[2]/int[.='1000']  "
             ,"//doc[3]/int[.='1001']"
             );
-    
+
+    ignoreException("shouldbeunindexed");
+    ignoreException("nullfirst");
+    ignoreException("abcde12345");
+    ignoreException("aaa");
+
     // Sort parsing exception tests.  (SOLR-6, SOLR-99)
     assertQEx( "can not sort unindexed fields",
         req( "id_i:1000; shouldbeunindexed asc" ), 400 );
@@ -792,7 +802,10 @@ public class ConvertedLegacyTest extends
         req( "id_i:1000; abcde12345 asc" ), 400 ); 
 
     assertQEx( "unknown sort order",
-        req( "id_i:1000; nullfirst aaa" ), 400 ); 
+        req( "id_i:1000; nullfirst aaa" ), 400 );
+
+    resetExceptionIgnores();
+
         
     // test prefix query
 

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java?rev=926654&r1=926653&r2=926654&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java Tue Mar 23 16:41:25
2010
@@ -38,6 +38,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -51,12 +52,14 @@ import static org.junit.Assert.fail;
 public class SolrTestCaseJ4 extends LuceneTestCaseJ4 {
 
   @BeforeClass
-  public static void beforeClass() throws Exception {
+  public static void beforeClassSolrTestCase() throws Exception {
+    ignoreException("ignore_exception");
   }
 
   @AfterClass
-  public static void afterClass() throws Exception {
+  public static void afterClassSolrTestCase() throws Exception {
     deleteCore();
+    resetExceptionIgnores();
   }
 
   @Override
@@ -74,11 +77,25 @@ public class SolrTestCaseJ4 extends Luce
   /** Call initCore in @BeforeClass to instantiate a solr core in your test class.
    * deleteCore will be called for you via SolrTestCaseJ4 @AfterClass */
   public static void initCore(String config, String schema) throws Exception {
+    //ignoreException("ignore_exception");
     configString = config;
     schemaString = schema;
     initCore();
   }
 
+  /** Causes an exception matching the regex pattern to not be logged. */
+  public static void ignoreException(String pattern) {
+    if (SolrException.ignorePatterns == null)
+      SolrException.ignorePatterns = new HashSet<String>();
+    SolrException.ignorePatterns.add(pattern);
+  }
+
+  public static void resetExceptionIgnores() {
+    SolrException.ignorePatterns = null;
+    ignoreException("ignore_exception");  // always ignore "ignore_exception"    
+  }
+
+
 
   protected static String configString;
   protected static String schemaString;



Mime
View raw message