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 2018/06/01 13:48:57 UTC
[tika] branch master updated: TIKA-2657 -- add system exit,
thread interrupt and gc-triggering new Date() in MockParser
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/master by this push:
new 7707dea TIKA-2657 -- add system exit, thread interrupt and gc-triggering new Date() in MockParser
7707dea is described below
commit 7707dea4e0445b0e22e06c9d4cbd069bc72212e2
Author: tballison <ta...@mitre.org>
AuthorDate: Fri Jun 1 09:48:30 2018 -0400
TIKA-2657 -- add system exit, thread interrupt and gc-triggering new Date()
in MockParser
---
.../org/apache/tika/batch/fs/BatchDriverTest.java | 41 ++++++++++++++++++++++
.../org/apache/tika/batch/fs/FSBatchTestBase.java | 37 +++++--------------
.../test-input/system_exit/test0_system_exit.xml | 25 +++++++++++++
.../test-input/system_exit/test1_system_exit.xml | 25 +++++++++++++
.../test-input/system_exit/test2_system_exit.xml | 25 +++++++++++++
.../resources/test-input/system_exit/test3_ok.xml | 23 ++++++++++++
.../resources/test-input/system_exit/test4_ok.xml | 23 ++++++++++++
.../resources/test-input/system_exit/test5_ok.xml | 23 ++++++++++++
.../thread_interrupt/test0_thread_interrupt.xml | 24 +++++++++++++
.../thread_interrupt/test1_thread_interrupt.xml | 24 +++++++++++++
.../thread_interrupt/test2_thread_interrupt.xml | 24 +++++++++++++
.../test-input/thread_interrupt/test3_ok.xml | 23 ++++++++++++
.../test-input/thread_interrupt/test4_ok.xml | 23 ++++++++++++
.../test-input/thread_interrupt/test5_ok.xml | 23 ++++++++++++
.../org/apache/tika/parser/mock/MockParser.java | 24 +++++++++----
15 files changed, 351 insertions(+), 36 deletions(-)
diff --git a/tika-batch/src/test/java/org/apache/tika/batch/fs/BatchDriverTest.java b/tika-batch/src/test/java/org/apache/tika/batch/fs/BatchDriverTest.java
index 8c85fb9..654eea7 100644
--- a/tika-batch/src/test/java/org/apache/tika/batch/fs/BatchDriverTest.java
+++ b/tika-batch/src/test/java/org/apache/tika/batch/fs/BatchDriverTest.java
@@ -206,5 +206,46 @@ public class BatchDriverTest extends FSBatchTestBase {
assertEquals(0, driver.getNumRestarts());
}
+ @Test(timeout = 60000)
+ public void testSystemExit() throws Exception {
+ Path outputDir = getNewOutputDir("system-exit");
+ Map<String, String> args = new HashMap<>();
+ args.put("-numConsumers", "1");
+
+ String[] commandLine = getDefaultCommandLineArgsArr("system_exit", outputDir, args);
+ BatchProcessDriverCLI driver = getNewDriver("/tika-batch-config-test.xml", commandLine);
+ driver.execute();
+ assertEquals(6, countChildren(outputDir));
+ assertTrue(driver.getNumRestarts() > 1);
+ for (int i = 0; i < 3; i++) {
+ assertEquals("problem with "+i, 0, Files.size(outputDir.resolve("test"+i+"_system_exit.xml.xml")));
+ }
+ //sys exit may prevent test3 from running successfully
+ for (int i = 5; i < 6; i++) {
+ assertContains("first test file",
+ readFileToString(outputDir.resolve("test"+i+"_ok.xml.xml"), UTF_8));
+ }
+ }
+
+ @Test(timeout = 60000)
+ public void testThreadInterrupt() throws Exception {
+ Path outputDir = getNewOutputDir("thread-interrupt");
+ Map<String, String> args = new HashMap<>();
+ args.put("-numConsumers", "1");
+
+ String[] commandLine = getDefaultCommandLineArgsArr("thread_interrupt", outputDir, args);
+ BatchProcessDriverCLI driver = getNewDriver("/tika-batch-config-test.xml", commandLine);
+ driver.execute();
+ assertEquals(6, countChildren(outputDir));
+
+ for (int i = 0; i < 3; i++) {
+ assertEquals("problem with "+i, 0, Files.size(outputDir.resolve("test"+i+"_thread_interrupt.xml.xml")));
+ }
+ //sys exit may prevent test3 from running successfully
+ for (int i = 5; i < 6; i++) {
+ assertContains("first test file",
+ readFileToString(outputDir.resolve("test"+i+"_ok.xml.xml"), UTF_8));
+ }
+ }
}
diff --git a/tika-batch/src/test/java/org/apache/tika/batch/fs/FSBatchTestBase.java b/tika-batch/src/test/java/org/apache/tika/batch/fs/FSBatchTestBase.java
index 4354009..3ce7198 100644
--- a/tika-batch/src/test/java/org/apache/tika/batch/fs/FSBatchTestBase.java
+++ b/tika-batch/src/test/java/org/apache/tika/batch/fs/FSBatchTestBase.java
@@ -39,12 +39,14 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.tika.TikaTest;
import org.apache.tika.batch.BatchProcess;
import org.apache.tika.batch.BatchProcessDriverCLI;
import org.apache.tika.batch.ParallelFileProcessingResult;
import org.apache.tika.batch.builders.BatchProcessBuilder;
+import org.apache.tika.utils.ProcessUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -80,7 +82,8 @@ public abstract class FSBatchTestBase extends TikaTest {
//see caveat in TikaCLITest's textExtract
try {
- deleteDirectory(outputRoot);
+
+ FileUtils.deleteDirectory(outputRoot.toFile());
} catch (IOException e) {
e.printStackTrace();
}
@@ -172,11 +175,8 @@ public abstract class FSBatchTestBase extends TikaTest {
commandLine.add("-Xmx128m");
commandLine.add("-cp");
String cp = System.getProperty("java.class.path");
- //need to test for " " on *nix, can't just add double quotes
- //across platforms.
- if (cp.contains(" ")){
- cp = "\""+cp+"\"";
- }
+ cp = ProcessUtils.escapeCommandLine(cp);
+
commandLine.add(cp);
commandLine.add("org.apache.tika.batch.fs.FSBatchProcessCLI");
@@ -205,9 +205,8 @@ public abstract class FSBatchTestBase extends TikaTest {
String cp = System.getProperty("java.class.path");
//need to test for " " on *nix, can't just add double quotes
//across platforms.
- if (cp.contains(" ")){
- cp = "\""+cp+"\"";
- }
+ cp = ProcessUtils.escapeCommandLine(cp);
+
commandLine.add(cp);
commandLine.add("org.apache.tika.batch.fs.FSBatchProcessCLI");
@@ -264,26 +263,6 @@ public abstract class FSBatchTestBase extends TikaTest {
return sb.toString();
}
- //TODO: move this into FileUtils
- public static void deleteDirectory(Path dir) throws IOException {
- Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
- @Override
- public FileVisitResult visitFile(Path file,
- BasicFileAttributes attrs) throws IOException {
- Files.delete(file);
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult postVisitDirectory(Path dir,
- IOException exc) throws IOException {
- Files.delete(dir);
- return FileVisitResult.CONTINUE;
- }
-
- });
- }
-
/**
* helper method equivalent to File#listFiles()
* grabs children only, does not walk recursively
diff --git a/tika-batch/src/test/resources/test-input/system_exit/test0_system_exit.xml b/tika-batch/src/test/resources/test-input/system_exit/test0_system_exit.xml
new file mode 100644
index 0000000..6bc2672
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/system_exit/test0_system_exit.xml
@@ -0,0 +1,25 @@
+<?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>
+ <system_exit />
+ <metadata action="add" name="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/system_exit/test1_system_exit.xml b/tika-batch/src/test/resources/test-input/system_exit/test1_system_exit.xml
new file mode 100644
index 0000000..6bc2672
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/system_exit/test1_system_exit.xml
@@ -0,0 +1,25 @@
+<?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>
+ <system_exit />
+ <metadata action="add" name="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/system_exit/test2_system_exit.xml b/tika-batch/src/test/resources/test-input/system_exit/test2_system_exit.xml
new file mode 100644
index 0000000..6bc2672
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/system_exit/test2_system_exit.xml
@@ -0,0 +1,25 @@
+<?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>
+ <system_exit />
+ <metadata action="add" name="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/system_exit/test3_ok.xml b/tika-batch/src/test/resources/test-input/system_exit/test3_ok.xml
new file mode 100644
index 0000000..555ab7a
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/system_exit/test3_ok.xml
@@ -0,0 +1,23 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/system_exit/test4_ok.xml b/tika-batch/src/test/resources/test-input/system_exit/test4_ok.xml
new file mode 100644
index 0000000..555ab7a
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/system_exit/test4_ok.xml
@@ -0,0 +1,23 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/system_exit/test5_ok.xml b/tika-batch/src/test/resources/test-input/system_exit/test5_ok.xml
new file mode 100644
index 0000000..555ab7a
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/system_exit/test5_ok.xml
@@ -0,0 +1,23 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/thread_interrupt/test0_thread_interrupt.xml b/tika-batch/src/test/resources/test-input/thread_interrupt/test0_thread_interrupt.xml
new file mode 100644
index 0000000..4910906
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/thread_interrupt/test0_thread_interrupt.xml
@@ -0,0 +1,24 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">some content</write>
+ <thread_interrupt />
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/thread_interrupt/test1_thread_interrupt.xml b/tika-batch/src/test/resources/test-input/thread_interrupt/test1_thread_interrupt.xml
new file mode 100644
index 0000000..4910906
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/thread_interrupt/test1_thread_interrupt.xml
@@ -0,0 +1,24 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">some content</write>
+ <thread_interrupt />
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/thread_interrupt/test2_thread_interrupt.xml b/tika-batch/src/test/resources/test-input/thread_interrupt/test2_thread_interrupt.xml
new file mode 100644
index 0000000..3032b5f
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/thread_interrupt/test2_thread_interrupt.xml
@@ -0,0 +1,24 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+ <thread_interrupt />
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/thread_interrupt/test3_ok.xml b/tika-batch/src/test/resources/test-input/thread_interrupt/test3_ok.xml
new file mode 100644
index 0000000..555ab7a
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/thread_interrupt/test3_ok.xml
@@ -0,0 +1,23 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/thread_interrupt/test4_ok.xml b/tika-batch/src/test/resources/test-input/thread_interrupt/test4_ok.xml
new file mode 100644
index 0000000..555ab7a
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/thread_interrupt/test4_ok.xml
@@ -0,0 +1,23 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+</mock>
\ No newline at end of file
diff --git a/tika-batch/src/test/resources/test-input/thread_interrupt/test5_ok.xml b/tika-batch/src/test/resources/test-input/thread_interrupt/test5_ok.xml
new file mode 100644
index 0000000..555ab7a
--- /dev/null
+++ b/tika-batch/src/test/resources/test-input/thread_interrupt/test5_ok.xml
@@ -0,0 +1,23 @@
+<?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="author">Nikolai Lobachevsky</metadata>
+ <write element="p">This is tika-batch's first test file.</write>
+</mock>
\ No newline at end of file
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 66ef719..87f8d89 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
@@ -68,7 +68,7 @@ public class MockParser extends AbstractParser {
@Override
public Set<MediaType> getSupportedTypes(ParseContext context) {
- Set<MediaType> types = new HashSet<MediaType>();
+ Set<MediaType> types = new HashSet<>();
MediaType type = MediaType.application("mock+xml");
types.add(type);
return types;
@@ -78,6 +78,9 @@ public class MockParser extends AbstractParser {
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());
+ }
Document doc = null;
try {
DocumentBuilder docBuilder = context.getDocumentBuilder();
@@ -121,6 +124,10 @@ public class MockParser extends AbstractParser {
handleEmbedded(action, xhtml, context);
} else if ("throwIllegalChars".equals(name)) {
throwIllegalChars();
+ } else if ("system_exit".equals(name)) {
+ System.exit(1);
+ } else if ("thread_interrupt".equals(name)) {
+ Thread.currentThread().interrupt();
} else {
throw new IllegalArgumentException("Didn't recognize mock action: "+name);
}
@@ -305,7 +312,7 @@ public class MockParser extends AbstractParser {
}
private void kabOOM() {
- List<int[]> ints = new ArrayList<int[]>();
+ List<int[]> ints = new ArrayList<>();
while (true) {
int[] intArr = new int[32000];
@@ -316,16 +323,19 @@ public class MockParser extends AbstractParser {
private void hangHeavy(long maxMillis, long pulseCheckMillis, boolean interruptible) {
//do some heavy computation and occasionally check for
//whether time has exceeded maxMillis (see TIKA-1132 for inspiration)
- //or whether the thread was interrupted
+ //or whether the thread was interrupted.
+ //By creating a new Date in the inner loop, we're also intentionally
+ //triggering the gc most likely.
long start = new Date().getTime();
- int lastChecked = 0;
+ long lastChecked = start;
while (true) {
for (int i = 1; i < Integer.MAX_VALUE; i++) {
for (int j = 1; j < Integer.MAX_VALUE; j++) {
double div = (double) i / (double) j;
- lastChecked++;
- if (lastChecked > pulseCheckMillis) {
- lastChecked = 0;
+
+ long elapsedSinceLastCheck = new Date().getTime()-lastChecked;
+ if (elapsedSinceLastCheck > pulseCheckMillis) {
+ lastChecked = new Date().getTime();
if (interruptible && Thread.currentThread().isInterrupted()) {
return;
}
--
To stop receiving notification emails like this one, please contact
tallison@apache.org.