You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2021/04/14 20:28:46 UTC

[tika] branch branch_1x updated: TIKA-3355 -- integrate fakeload library into MockParser

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

tallison pushed a commit to branch branch_1x
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/branch_1x by this push:
     new d3ed76f  TIKA-3355 -- integrate fakeload library into MockParser
d3ed76f is described below

commit d3ed76f42437130f8b498b994c2ab00b0918e42c
Author: tallison <ta...@apache.org>
AuthorDate: Wed Apr 14 16:22:12 2021 -0400

    TIKA-3355 -- integrate fakeload library into MockParser
    
    # Conflicts:
    #	tika-core/pom.xml
    #	tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
---
 NOTICE.txt                                         |  24 ++
 tika-core/pom.xml                                  | 357 ++++++++++++---------
 .../org/apache/tika/parser/mock/MockParser.java    | 163 +++++++---
 .../apache/tika/parser/mock/MockParserTest.java    |  30 ++
 .../resources/test-documents/mock_fakeload.xml     |  29 ++
 5 files changed, 406 insertions(+), 197 deletions(-)

diff --git a/NOTICE.txt b/NOTICE.txt
index eace5b3..1e1412f 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1542,3 +1542,27 @@ based on this library.  If you modify this library, you may extend this
 exception to your version of the library, but you are not obligated to
 do so.  If you do not wish to do so, delete this exception statement
 from your version.
+
+--------------------
+The Fakeload library
+
+MIT License
+
+Copyright (c) 2017 Marten Sigwart
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation files
+(the "Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to permit
+persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/tika-core/pom.xml b/tika-core/pom.xml
index e686bd1..7604c5e 100644
--- a/tika-core/pom.xml
+++ b/tika-core/pom.xml
@@ -19,8 +19,9 @@
   under the License.
 -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
 
   <parent>
     <groupId>org.apache.tika</groupId>
@@ -29,165 +30,203 @@
     <relativePath>../tika-parent/pom.xml</relativePath>
   </parent>
 
-  <artifactId>tika-core</artifactId>
-  <packaging>bundle</packaging>
-  <name>Apache Tika core</name>
-  <url>http://tika.apache.org/</url>
+    <artifactId>tika-core</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Tika core</name>
+    <url>http://tika.apache.org/</url>
 
-  <dependencies>
-    <!-- Optional OSGi dependencies, used only when running within OSGi -->
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <version>${osgi.core.version}</version>
-      <scope>provided</scope>
-      <optional>true</optional>
-    </dependency>
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.compendium</artifactId>
-      <version>5.0.0</version>
-      <scope>provided</scope>
-      <optional>true</optional>
-    </dependency>
-    <dependency>
-      <groupId>biz.aQute</groupId>
-      <artifactId>bndlib</artifactId>
-      <scope>provided</scope>
-    </dependency>
+    <dependencies>
+        <!-- See https://issues.apache.org/jira/browse/TIKA-2566 for more info -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>${commons.io.version}</version>
+        </dependency>
 
-    <!-- Test dependencies -->
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
+        <!-- Optional OSGi dependencies, used only when running within OSGi -->
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>${osgi.core.version}</version>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.0.0</version>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>biz.aQute</groupId>
+            <artifactId>bndlib</artifactId>
+            <scope>provided</scope>
+        </dependency>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <version>${maven.bundle.version}</version>
-        <extensions>true</extensions>
-        <configuration>
-          <instructions>
-            <Bundle-DocURL>${project.url}</Bundle-DocURL>
-            <Bundle-Activator>
-              org.apache.tika.config.TikaActivator
-            </Bundle-Activator>
-            <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
-            <!-- modern versions of the bundle plugin figure out that we
-                 test for a class in org.apache.xerces.util even though
-                 we don't include it in core -->
-            <Import-Package>!org.apache.xerces.util,!sun.misc,*</Import-Package>
-          </instructions>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.rat</groupId>
-        <artifactId>apache-rat-plugin</artifactId>
-        <version>${rat.version}</version>
-        <configuration>
-          <excludes>
-            <exclude>src/test/resources/org/apache/tika/**</exclude>
-            <exclude>src/main/resources/org/apache/tika/language/*.ngp</exclude>
-            <exclude>src/main/resources/org/apache/tika/detect/*.nnmodel</exclude>
-            <exclude>src/test/resources/test-documents/ang20150420t182050_corr_v1e_img.hdr</exclude>
-          </excludes>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-jar-plugin</artifactId>
-        <configuration>
-          <archive>
-            <manifestEntries>
-              <Automatic-Module-Name>org.apache.tika.core</Automatic-Module-Name>
-            </manifestEntries>
-          </archive>
-        </configuration>
-        <executions>
-          <execution>
-            <goals>
-              <goal>test-jar</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>clirr-maven-plugin</artifactId>
-        <version>2.8</version>
-        <executions>
-          <execution>
-            <phase>verify</phase>
-            <goals>
-              <goal>check</goal>
-            </goals>
-            <configuration>
-              <excludes>
-                <exlude>org/apache/tika/config/TikaActivator</exlude>
-                <exlude>org/apache/tika/language/LanguageIdentifier</exlude>
-                <exlude>org/apache/tika/language/LanguageProfile</exlude>
-                <exlude>org/apache/tika/language/LanguageProfilerBuilder</exlude>
-                <exlude>org/apache/tika/language/ProfilingHandler</exlude>
-                <exlude>org/apache/tika/language/ProfilingWriter</exlude>
-                <exlude>org/apache/tika/metadata/Property$PropertyType</exlude>
-                <exlude>org/apache/tika/metadata/Property$ValueType</exlude>
-                <exlude>org/apache/tika/metadata/DublinCore</exlude>
-                <exlude>org/apache/tika/metadata/Metadata</exlude>
-                <exlude>org/apache/tika/metadata/MSOffice</exlude>
-                <exlude>org/apache/tika/parser/EmptyParser</exlude>
-              </excludes>
-              <comparisonArtifacts>
-                <comparisonArtifact>
-                  <groupId>org.apache.tika</groupId>
-                  <artifactId>tika-core</artifactId>
-                  <version>1.0</version>
-                  <type>jar</type>
-                </comparisonArtifact>
-              </comparisonArtifacts>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
-        <artifactId>maven-failsafe-plugin</artifactId>
-        <version>2.22.1</version>
-        <configuration>
-          <additionalClasspathElements>
-            <additionalClasspathElement>
-              ${project.build.directory}/${project.build.finalName}.jar
-            </additionalClasspathElement>
-          </additionalClasspathElements>
-        </configuration>
-        <executions>
-          <execution>
-            <goals>
-              <goal>integration-test</goal>
-              <goal>verify</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
+        <!-- Test dependencies -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>${guava.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <!-- versions &gt; 0.4.0 require java > 8 -->
+        <dependency>
+            <groupId>com.martensigwart</groupId>
+            <artifactId>fakeload</artifactId>
+            <version>0.4.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.google.code.findbugs</groupId>
+                    <artifactId>jsr305</artifactId>
+                </exclusion>
+            </exclusions>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 
-  <description>This is the core Apache Tika™ toolkit library from which all other modules inherit functionality. It also
-    includes the core facades for the Tika API.
-  </description>
-  <organization>
-    <name>The Apache Software Foundation</name>
-    <url>http://www.apache.org</url>
-  </organization>
-  <issueManagement>
-    <system>JIRA</system>
-    <url>https://issues.apache.org/jira/browse/TIKA</url>
-  </issueManagement>
-  <ciManagement>
-    <system>Jenkins</system>
-    <url>https://builds.apache.org/job/Tika-trunk/</url>
-  </ciManagement>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>${maven.bundle.version}</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-DocURL>${project.url}</Bundle-DocURL>
+                        <Bundle-Activator>
+                            org.apache.tika.config.TikaActivator
+                        </Bundle-Activator>
+                        <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
+                        <Import-Package>!sun.misc,org.apache.xerces.util;resolution:=optional,*</Import-Package>
+                        <Export-Package>
+                            org.apache.tika.*
+                        </Export-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <version>${rat.version}</version>
+                <configuration>
+                    <excludes>
+                        <exclude>src/test/resources/org/apache/tika/**</exclude>
+                        <exclude>src/main/resources/org/apache/tika/language/*.ngp</exclude>
+                        <exclude>src/main/resources/org/apache/tika/detect/*.nnmodel</exclude>
+                        <exclude>src/test/resources/test-documents/ang20150420t182050_corr_v1e_img.hdr</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifestEntries>
+                            <Automatic-Module-Name>org.apache.tika.core</Automatic-Module-Name>
+                        </manifestEntries>
+                    </archive>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- no harm, no foul for 2.0.0 :D TODO: turn this back on after the 2.0.0 release
+            <plugin>
+              <groupId>org.codehaus.mojo</groupId>
+              <artifactId>clirr-maven-plugin</artifactId>
+              <version>2.8</version>
+              <executions>
+                <execution>
+                  <phase>verify</phase>
+                  <goals>
+                    <goal>check</goal>
+                  </goals>
+                  <configuration>
+                    <excludes>
+                      <exlude>org/apache/tika/config/TikaActivator</exlude>
+                      <exlude>org/apache/tika/language/LanguageIdentifier</exlude>
+                      <exlude>org/apache/tika/language/LanguageProfile</exlude>
+                      <exlude>org/apache/tika/language/LanguageProfilerBuilder</exlude>
+                      <exlude>org/apache/tika/language/ProfilingHandler</exlude>
+                      <exlude>org/apache/tika/language/ProfilingWriter</exlude>
+                      <exlude>org/apache/tika/metadata/Property$PropertyType</exlude>
+                      <exlude>org/apache/tika/metadata/Property$ValueType</exlude>
+                      <exlude>org/apache/tika/metadata/DublinCore</exlude>
+                      <exlude>org/apache/tika/metadata/Metadata</exlude>
+                      <exlude>org/apache/tika/metadata/MSOffice</exlude>
+                      <exlude>org/apache/tika/parser/EmptyParser</exlude>
+                      <exclude>org/apache/tika/metadata/TikaMetadataKeys</exclude>
+                    </excludes>
+                    <comparisonArtifacts>
+                      <comparisonArtifact>
+                        <groupId>org.apache.tika</groupId>
+                        <artifactId>tika-core</artifactId>
+                        <version>2.0.0-SNAPSHOT</version>
+                        <type>jar</type>
+                      </comparisonArtifact>
+                    </comparisonArtifacts>
+                  </configuration>
+                </execution>
+              </executions>
+            </plugin> -->
+            <plugin>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <version>2.22.1</version>
+                <configuration>
+                    <additionalClasspathElements>
+                        <additionalClasspathElement>
+                            ${project.build.directory}/${project.build.finalName}.jar
+                        </additionalClasspathElement>
+                    </additionalClasspathElements>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <description>This is the core Apache Tika™ toolkit library from which all other modules inherit functionality. It
+        also
+        includes the core facades for the Tika API.
+    </description>
+    <organization>
+        <name>The Apache Software Foundation</name>
+        <url>http://www.apache.org</url>
+    </organization>
+    <issueManagement>
+        <system>JIRA</system>
+        <url>https://issues.apache.org/jira/browse/TIKA</url>
+    </issueManagement>
+    <ciManagement>
+        <system>Jenkins</system>
+        <url>https://builds.apache.org/job/Tika-trunk/</url>
+    </ciManagement>
 </project>
diff --git a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
index 6ce7502..5eea587 100644
--- a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
+++ b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
@@ -1,5 +1,3 @@
-package org.apache.tika.parser.mock;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -16,11 +14,11 @@ package org.apache.tika.parser.mock;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.tika.parser.mock;
 
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
-import javax.xml.parsers.DocumentBuilder;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -33,12 +31,32 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Random;
 import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.xml.parsers.DocumentBuilder;
+
+import com.martensigwart.fakeload.FakeLoad;
+import com.martensigwart.fakeload.FakeLoadBuilder;
+import com.martensigwart.fakeload.FakeLoadExecutor;
+import com.martensigwart.fakeload.FakeLoadExecutors;
+import com.martensigwart.fakeload.MemoryUnit;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
 
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.extractor.EmbeddedDocumentExtractor;
 import org.apache.tika.extractor.ParsingEmbeddedDocumentExtractor;
-import org.apache.tika.io.IOExceptionWithCause;
 import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.TikaCoreProperties;
 import org.apache.tika.metadata.TikaMetadataKeys;
 import org.apache.tika.mime.MediaType;
 import org.apache.tika.parser.AbstractParser;
@@ -46,12 +64,6 @@ import org.apache.tika.parser.ParseContext;
 import org.apache.tika.parser.Parser;
 import org.apache.tika.sax.EmbeddedContentHandler;
 import org.apache.tika.sax.XHTMLContentHandler;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
 
 /**
  * This class enables mocking of parser behavior for use in testing
@@ -69,13 +81,29 @@ public class MockParser extends AbstractParser {
 
 
     private static final long serialVersionUID = 1L;
-    private static PrintStream ORIG_STDERR;
-    private static PrintStream ORIG_STDOUT;
+    private static final PrintStream ORIG_STDERR;
+    private static final PrintStream ORIG_STDOUT;
+    private static final AtomicInteger TIMES_INITIATED = new AtomicInteger(0);
+
     static {
         ORIG_STDERR = System.err;
         ORIG_STDOUT = System.out;
     }
+
     private final Random random = new Random();
+
+    public MockParser() {
+        TIMES_INITIATED.incrementAndGet();
+    }
+
+    public static void resetTimesInitiated() {
+        TIMES_INITIATED.set(0);
+    }
+
+    public static int getTimesInitiated() {
+        return TIMES_INITIATED.get();
+    }
+
     @Override
     public Set<MediaType> getSupportedTypes(ParseContext context) {
         Set<MediaType> types = new HashSet<>();
@@ -85,9 +113,8 @@ public class MockParser extends AbstractParser {
     }
 
     @Override
-    public void parse(InputStream stream, ContentHandler handler,
-                      Metadata metadata, ParseContext context) throws IOException,
-            SAXException, TikaException {
+    public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
+                      ParseContext context) throws IOException, SAXException, TikaException {
         if (Thread.currentThread().isInterrupted()) {
             throw new TikaException("interrupted", new InterruptedException());
         }
@@ -97,7 +124,7 @@ public class MockParser extends AbstractParser {
             doc = docBuilder.parse(stream);
         } catch (SAXException e) {
             //to distinguish between SAX on read vs SAX while writing
-            throw new IOExceptionWithCause(e);
+            throw new IOException(e);
         }
         Node root = doc.getDocumentElement();
         NodeList actions = root.getChildNodes();
@@ -110,8 +137,8 @@ public class MockParser extends AbstractParser {
     }
 
     private void executeAction(Node action, Metadata metadata, ParseContext context,
-                               XHTMLContentHandler xhtml) throws SAXException,
-            IOException, TikaException {
+                               XHTMLContentHandler xhtml)
+            throws SAXException, IOException, TikaException {
 
         if (action.getNodeType() != 1) {
             return;
@@ -120,15 +147,17 @@ public class MockParser extends AbstractParser {
         String name = action.getNodeName();
         if ("metadata".equals(name)) {
             metadata(action, metadata);
-        } else if("write".equals(name)) {
+        } else if ("write".equals(name)) {
             write(action, xhtml);
         } else if ("throw".equals(name)) {
             throwIt(action);
         } else if ("hang".equals(name)) {
             hang(action);
+        } else if ("fakeload".equals(name)) {
+            fakeload(action);
         } else if ("oom".equals(name)) {
             kabOOM();
-        } else if ("print_out".equals(name) || "print_err".equals(name)){
+        } else if ("print_out".equals(name) || "print_err".equals(name)) {
             print(action, name);
         } else if ("embedded".equals(name)) {
             handleEmbedded(action, xhtml, context);
@@ -139,8 +168,70 @@ public class MockParser extends AbstractParser {
         } else if ("thread_interrupt".equals(name)) {
             Thread.currentThread().interrupt();
         } else {
-            throw new IllegalArgumentException("Didn't recognize mock action: "+name);
+            throw new IllegalArgumentException("Didn't recognize mock action: " + name);
+        }
+    }
+
+    private void fakeload(Node action) {
+        //https://github.com/msigwart/fakeload
+        //with this version of fakeload, you should only need one thread to hit
+        //the cpu targets; on Linux with Java 8 at least, two or more threads did
+        //not increase the overall CPU over a single thread
+        int numThreads = 1;
+        NamedNodeMap attrs = action.getAttributes();
+        if (attrs == null) {
+            throw new IllegalArgumentException("Must specify details...no attributes for " +
+                    "fakeload?!");
+        }
+        if (attrs.getNamedItem("millis") == null || attrs.getNamedItem("cpu") == null ||
+                attrs.getNamedItem("mb") == null) {
+            throw new IllegalArgumentException("must specify 'millis' (time to process), " +
+                    "'cpu' (% cpu as an integer, e.g. 50% would be '50'), " +
+                    "and 'mb' (megabytes as an integer)");
+        }
+        Node n = attrs.getNamedItem("numThreads");
+        if (n != null) {
+            numThreads = Integer.parseInt(n.getNodeValue());
         }
+        final long millis = Long.parseLong(attrs.getNamedItem("millis").getNodeValue());
+        final int cpu = Integer.parseInt(attrs.getNamedItem("cpu").getNodeValue());
+        final int mb = Integer.parseInt(attrs.getNamedItem("mb").getNodeValue());
+
+        ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
+        ExecutorCompletionService<Integer> executorCompletionService =
+                new ExecutorCompletionService<>(executorService);
+
+        for (int i = 0; i < numThreads; i++) {
+            executorCompletionService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    FakeLoad fakeload =
+                            new FakeLoadBuilder().lasting(millis, TimeUnit.MILLISECONDS)
+                                    .withCpu(cpu).withMemory(mb, MemoryUnit.MB).build();
+                    FakeLoadExecutor executor = FakeLoadExecutors.newDefaultExecutor();
+                    executor.execute(fakeload);
+                }
+            }, 1);
+
+            int finished = 0;
+            try {
+                while (finished < numThreads) {
+                    Future<Integer> future = executorCompletionService.take();
+                    if (future != null) {
+                        future.get();
+                        finished++;
+                    }
+                }
+            } catch (ExecutionException e) {
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            } finally {
+                executorService.shutdownNow();
+            }
+
+        }
+
     }
 
     private void throwIllegalChars() throws IOException {
@@ -172,17 +263,13 @@ public class MockParser extends AbstractParser {
         }
         InputStream is = new ByteArrayInputStream(embeddedText.getBytes(UTF_8));
 
-        extractor.parseEmbedded(
-                is,
-                new EmbeddedContentHandler(handler),
-                m, true);
+        extractor.parseEmbedded(is, new EmbeddedContentHandler(handler), m, true);
 
 
     }
 
     protected EmbeddedDocumentExtractor getEmbeddedDocumentExtractor(ParseContext context) {
-        EmbeddedDocumentExtractor extractor =
-                context.get(EmbeddedDocumentExtractor.class);
+        EmbeddedDocumentExtractor extractor = context.get(EmbeddedDocumentExtractor.class);
         if (extractor == null) {
             Parser p = context.get(Parser.class);
             if (p == null) {
@@ -195,7 +282,7 @@ public class MockParser extends AbstractParser {
 
     private void print(Node action, String name) throws IOException {
         String content = action.getTextContent();
-        boolean isStatic = (action.getAttributes().getNamedItem("static") == null) ? false : true;
+        boolean isStatic = (action.getAttributes().getNamedItem("static") != null);
         Node rand = action.getAttributes().getNamedItem("random");
         int randLength = -1;
         if (rand != null) {
@@ -259,7 +346,8 @@ public class MockParser extends AbstractParser {
         if (heavy) {
             Node pNode = attrs.getNamedItem("pulse_millis");
             if (pNode == null) {
-                throw new RuntimeException("Must specify attribute \"pulse_millis\" if the hang is \"heavy\"");
+                throw new RuntimeException(
+                        "Must specify attribute \"pulse_millis\" if the hang is \"heavy\"");
             }
             String pulseMillisString = mNode.getNodeValue();
             try {
@@ -275,8 +363,7 @@ public class MockParser extends AbstractParser {
         }
     }
 
-    private void throwIt(Node action) throws IOException,
-            SAXException, TikaException {
+    private void throwIt(Node action) throws IOException, SAXException, TikaException {
         NamedNodeMap attrs = action.getAttributes();
         String className = attrs.getNamedItem("class").getNodeValue();
         String msg = action.getTextContent();
@@ -314,14 +401,14 @@ public class MockParser extends AbstractParser {
     }
 
 
-    private void throwIt(String className, String msg) throws IOException,
-            SAXException, TikaException {
+    private void throwIt(String className, String msg)
+            throws IOException, SAXException, TikaException {
         Throwable t = null;
         if (msg == null || msg.equals("")) {
             try {
                 t = (Throwable) Class.forName(className).newInstance();
             } catch (Exception e) {
-                throw new RuntimeException("couldn't create throwable class:"+className, e);
+                throw new RuntimeException("couldn't create throwable class:" + className, e);
             }
         } else {
             try {
@@ -333,7 +420,7 @@ public class MockParser extends AbstractParser {
             }
         }
         if (t instanceof SAXException) {
-            throw (SAXException)t;
+            throw (SAXException) t;
         } else if (t instanceof IOException) {
             throw (IOException) t;
         } else if (t instanceof TikaException) {
@@ -370,13 +457,13 @@ public class MockParser extends AbstractParser {
                 for (int j = 1; j < Integer.MAX_VALUE; j++) {
                     double div = (double) i / (double) j;
 
-                    long elapsedSinceLastCheck = new Date().getTime()-lastChecked;
+                    long elapsedSinceLastCheck = new Date().getTime() - lastChecked;
                     if (elapsedSinceLastCheck > pulseCheckMillis) {
                         lastChecked = new Date().getTime();
                         if (interruptible && Thread.currentThread().isInterrupted()) {
                             return;
                         }
-                        long elapsed = new Date().getTime()-start;
+                        long elapsed = new Date().getTime() - start;
                         if (elapsed > maxMillis) {
                             return;
                         }
@@ -397,7 +484,7 @@ public class MockParser extends AbstractParser {
                     return;
                 }
             }
-            long elapsed = System.currentTimeMillis()-start;
+            long elapsed = System.currentTimeMillis() - start;
             millisRemaining = maxMillis - elapsed;
             if (millisRemaining <= 0) {
                 break;
diff --git a/tika-core/src/test/java/org/apache/tika/parser/mock/MockParserTest.java b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParserTest.java
new file mode 100644
index 0000000..843d737
--- /dev/null
+++ b/tika-core/src/test/java/org/apache/tika/parser/mock/MockParserTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.tika.parser.mock;
+
+import org.junit.Test;
+
+import org.apache.tika.TikaTest;
+
+public class MockParserTest extends TikaTest {
+
+    @Test
+    public void testFakeload() throws Exception {
+        //just make sure there aren't any exceptions
+        getRecursiveMetadata("mock_fakeload.xml");
+    }
+}
diff --git a/tika-core/src/test/resources/test-documents/mock_fakeload.xml b/tika-core/src/test/resources/test-documents/mock_fakeload.xml
new file mode 100644
index 0000000..f926b91
--- /dev/null
+++ b/tika-core/src/test/resources/test-documents/mock_fakeload.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!--
+  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.
+-->
+
+<mock>
+
+    <metadata action="add" name="dc:creator">Nikolai Lobachevsky</metadata>
+    <write element="p">main_content</write>
+    <!-- millis = milliseconds to run, cpu is % of the cpu to peg and mb is the
+         amount of memory to consume in megabytes -->
+    <fakeload millis="100" cpu="10" mb="10"/>
+</mock>
\ No newline at end of file