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 4aae925 TIKA-2785 -- clean up logging in tika-server; redirect child stdout to parent stderr to avoid maven complaining about corrupting stdout in forked process; convert oom to fake oom 4aae925 is described below commit 4aae9251b26180377bfa44c3720aa4bfac29b81b Author: TALLISON <talli...@apache.org> AuthorDate: Tue Nov 20 15:08:47 2018 -0500 TIKA-2785 -- clean up logging in tika-server; redirect child stdout to parent stderr to avoid maven complaining about corrupting stdout in forked process; convert oom to fake oom --- .../org/apache/tika/server/TikaServerWatchDog.java | 31 ++++++++++++++- .../apache/tika/server/NullWebClientLogger.java | 45 ++++++++++++++++++++++ .../tika/server/TikaServerIntegrationTest.java | 17 ++++++-- tika-server/src/test/resources/log4j.properties | 24 ++++++++++++ tika-server/src/test/resources/mock/fake_oom.xml | 24 ++++++++++++ 5 files changed, 136 insertions(+), 5 deletions(-) diff --git a/tika-server/src/main/java/org/apache/tika/server/TikaServerWatchDog.java b/tika-server/src/main/java/org/apache/tika/server/TikaServerWatchDog.java index 4c4028e..6a57bbe 100644 --- a/tika-server/src/main/java/org/apache/tika/server/TikaServerWatchDog.java +++ b/tika-server/src/main/java/org/apache/tika/server/TikaServerWatchDog.java @@ -22,10 +22,15 @@ import org.apache.tika.utils.ProcessUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -356,7 +361,7 @@ public class TikaServerWatchDog { ProcessBuilder builder = new ProcessBuilder(); builder.redirectError(ProcessBuilder.Redirect.INHERIT); - builder.redirectOutput(ProcessBuilder.Redirect.INHERIT); + List<String> argList = new ArrayList<>(); String javaPath = extractJavaPath(args); List<String> jvmArgs = extractJVMArgs(args); @@ -378,7 +383,9 @@ public class TikaServerWatchDog { LOG.debug("child process commandline: " +argList.toString()); builder.command(argList); Process process = builder.start(); - + //redirect stdout to parent stderr to avoid error msgs + //from maven during build: Corrupted STDOUT by directly writing to native stream in forked + redirectIO(process.getInputStream(), System.err); if (SHUTDOWN_HOOK != null) { Runtime.getRuntime().removeShutdownHook(SHUTDOWN_HOOK); } @@ -389,6 +396,26 @@ public class TikaServerWatchDog { } } + private static void redirectIO(final InputStream src, final PrintStream targ) { + Thread gobbler = new Thread(new Runnable() { + public void run() { + BufferedReader reader = new BufferedReader(new InputStreamReader(src, StandardCharsets.UTF_8)); + String line = null; + try { + line = reader.readLine(); + while (line != null) { + targ.println(line); + line = reader.readLine(); + } + } catch (IOException e) { + //swallow + } + } + }); + gobbler.setDaemon(true); + gobbler.start(); + } + private static synchronized void destroyChildForcibly(Process process) { process = process.destroyForcibly(); try { diff --git a/tika-server/src/test/java/org/apache/tika/server/NullWebClientLogger.java b/tika-server/src/test/java/org/apache/tika/server/NullWebClientLogger.java new file mode 100644 index 0000000..d41a4e7 --- /dev/null +++ b/tika-server/src/test/java/org/apache/tika/server/NullWebClientLogger.java @@ -0,0 +1,45 @@ +/* + * 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.server; + +import org.apache.cxf.common.logging.AbstractDelegatingLogger; + +import java.util.logging.Level; +import java.util.logging.LogRecord; + +/** + * null logger to swallow client messages + * in {@link TikaServerIntegrationTest} + */ +public class NullWebClientLogger extends AbstractDelegatingLogger { + + + public NullWebClientLogger(String name, String resourceBundleName) { + super(name, resourceBundleName); + } + + @Override + public Level getLevel() { + return Level.OFF; + } + + @Override + protected void internalLogFormatted(String s, LogRecord logRecord) { + + } + +} diff --git a/tika-server/src/test/java/org/apache/tika/server/TikaServerIntegrationTest.java b/tika-server/src/test/java/org/apache/tika/server/TikaServerIntegrationTest.java index 2f8cd84..7b08ca4 100644 --- a/tika-server/src/test/java/org/apache/tika/server/TikaServerIntegrationTest.java +++ b/tika-server/src/test/java/org/apache/tika/server/TikaServerIntegrationTest.java @@ -16,6 +16,7 @@ */ package org.apache.tika.server; +import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.jaxrs.client.WebClient; import org.apache.tika.TikaTest; import org.apache.tika.metadata.Metadata; @@ -27,6 +28,8 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.ws.rs.core.Response; import java.io.InputStream; @@ -47,8 +50,10 @@ import static org.junit.Assert.assertEquals; public class TikaServerIntegrationTest extends TikaTest { + private static final Logger LOG = LoggerFactory.getLogger(TikaServerIntegrationTest.class); + private static final String TEST_RECURSIVE_DOC = "test_recursive_embedded.docx"; - private static final String TEST_OOM = "mock/real_oom.xml"; + private static final String TEST_OOM = "mock/fake_oom.xml"; private static final String TEST_SYSTEM_EXIT = "mock/system_exit.xml"; private static final String TEST_HEAVY_HANG = "mock/heavy_hang_30000.xml"; private static final String TEST_HEAVY_HANG_SHORT = "mock/heavy_hang_100.xml"; @@ -78,6 +83,7 @@ public class TikaServerIntegrationTest extends TikaTest { } @BeforeClass public static void staticSetup() throws Exception { + LogUtils.setLoggerClass(NullWebClientLogger.class); LOG_FILE = Files.createTempFile("tika-server-integration", ".xml"); Files.copy(TikaServerIntegrationTest.class.getResourceAsStream("/logging/log4j_child.xml"), LOG_FILE, StandardCopyOption.REPLACE_EXISTING); } @@ -290,8 +296,8 @@ public class TikaServerIntegrationTest extends TikaTest { TikaServerCli.main( new String[]{ "-spawnChild", "-p", INTEGRATION_TEST_PORT, - "-taskTimeoutMillis", "10000", "-taskPulseMillis", "500", - "-pingPulseMillis", "500", + "-taskTimeoutMillis", "5000", "-taskPulseMillis", "100", + "-pingPulseMillis", "100", "-tmpFilePrefix", "tika-server-timeout" }); @@ -465,8 +471,13 @@ public class TikaServerIntegrationTest extends TikaTest { if (response.getStatus() == 200) { return; } + LOG.info("tika test client failed to connect to server with status: {}", response.getStatus()); + } catch (javax.ws.rs.ProcessingException e) { + LOG.info("tika test client failed to connect to server: {}", e.getMessage()); + LOG.debug("tika test client failed to connect to server", e); } + Thread.sleep(100); elapsed = Duration.between(started, Instant.now()).toMillis(); } diff --git a/tika-server/src/test/resources/log4j.properties b/tika-server/src/test/resources/log4j.properties new file mode 100644 index 0000000..6aa860a --- /dev/null +++ b/tika-server/src/test/resources/log4j.properties @@ -0,0 +1,24 @@ +# 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. + +#info,debug, error,fatal ... +log4j.rootLogger=info,stderr + +#console +log4j.appender.stderr=org.apache.log4j.ConsoleAppender +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.Target=System.err + +log4j.appender.stderr.layout.ConversionPattern= %-5p %d [%t] (%F:%L) - %m%n diff --git a/tika-server/src/test/resources/mock/fake_oom.xml b/tika-server/src/test/resources/mock/fake_oom.xml new file mode 100644 index 0000000..42aa9a7 --- /dev/null +++ b/tika-server/src/test/resources/mock/fake_oom.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> + <throw class="java.lang.OutOfMemoryError">oom message</throw> +</mock> \ No newline at end of file