tika-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1225451 - /tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java
Date Thu, 29 Dec 2011 06:59:08 GMT
Author: nick
Date: Thu Dec 29 06:59:08 2011
New Revision: 1225451

URL: http://svn.apache.org/viewvc?rev=1225451&view=rev
Log:
TIKA-831 Start on a test for the ForkParser with a parser exception that isn't serializable
(currently not working so disabled)

Modified:
    tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java

Modified: tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java?rev=1225451&r1=1225450&r2=1225451&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java
(original)
+++ tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/fork/ForkParserIntegrationTest.java
Thu Dec 29 06:59:08 2011
@@ -26,7 +26,6 @@ import java.util.Set;
 import junit.framework.TestCase;
 
 import org.apache.tika.Tika;
-import org.apache.tika.config.TikaConfig;
 import org.apache.tika.detect.Detector;
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.fork.ForkParser;
@@ -99,16 +98,43 @@ public class ForkParserIntegrationTest e
         }
     }
     
+    /**
+     * This error isn't serializable on the server, so can't be sent back
+     *  to the Fork Client once it has occured
+     */
+    static class WontBeSerializedError extends RuntimeException {
+       private static final long serialVersionUID = 1L;
+
+       WontBeSerializedError(String message) {
+          super(message);
+       }
+
+       private void writeObject(java.io.ObjectOutputStream out) {
+          RuntimeException e = new RuntimeException("Bang!");
+          boolean found = false;
+          for (StackTraceElement ste : e.getStackTrace()) {
+             if (ste.getClassName().equals(ForkParser.class.getName())) {
+                found = true;
+             }
+          }
+          if (!found) {
+             throw e;
+          }
+       }
+    }
+    
     static class BrokenParser implements Parser {
         private static final long serialVersionUID = 995871497930817839L;
-        public Error e = new AnError("Simulated fail"); 
+        public Error err = new AnError("Simulated fail");
+        public RuntimeException re = null;
         
         public Set<MediaType> getSupportedTypes(ParseContext context) {
             return new HashSet<MediaType>(Arrays.asList(MediaType.TEXT_PLAIN));
         }
 
         public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
ParseContext context) throws IOException, SAXException, TikaException {
-            throw e;
+            if (re != null) throw re;
+            throw err;
         }
     }
     
@@ -120,14 +146,31 @@ public class ForkParserIntegrationTest e
         BrokenParser brokenParser = new BrokenParser();
         Parser parser = new ForkParser(ForkParser.class.getClassLoader(), brokenParser);
         InputStream stream = getClass().getResourceAsStream("/test-documents/testTXT.txt");
+        
+        // With a serializable error, we'll get that back
         try {
             ContentHandler output = new BodyContentHandler();
             ParseContext context = new ParseContext();
             parser.parse(stream, output, new Metadata(), context);
             fail("Expected TikaException caused by Error");
         } catch (TikaException e) {
-            assertEquals(brokenParser.e, e.getCause());
+            assertEquals(brokenParser.err, e.getCause());
         }
+        
+        // With a non serializable one, we'll get something else
+        // TODO Fix this test
+        brokenParser = new BrokenParser();
+        brokenParser.re= new WontBeSerializedError("Can't Serialize");
+        parser = new ForkParser(ForkParser.class.getClassLoader(), brokenParser);
+//        try {
+//           ContentHandler output = new BodyContentHandler();
+//           ParseContext context = new ParseContext();
+//           parser.parse(stream, output, new Metadata(), context);
+//           fail("Expected TikaException caused by Error");
+//       } catch (TikaException e) {
+//           assertEquals(TikaException.class, e.getCause().getClass());
+//           assertEquals("Bang!", e.getCause().getMessage());
+//       }
     }
     
     /**



Mime
View raw message