Composite request logger doesn't invoke @LifeCycleStart and @LifeCycleStop methods on its dependencies (#6173)

This commit is contained in:
Samarth Jain 2018-08-17 09:34:25 -07:00 committed by Gian Merlino
parent 0c3bb47558
commit 1c8032f9f3
4 changed files with 28 additions and 3 deletions

View File

@ -23,6 +23,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import io.druid.java.util.common.lifecycle.LifecycleStart;
import io.druid.java.util.common.lifecycle.LifecycleStop;
import io.druid.java.util.common.logger.Logger;
import io.druid.server.RequestLogLine;
@ -63,6 +65,24 @@ public class ComposingRequestLoggerProvider implements RequestLoggerProvider
this.loggers = loggers;
}
@LifecycleStart
@Override
public void start() throws Exception
{
for (RequestLogger logger : loggers) {
logger.start();
}
}
@LifecycleStop
@Override
public void stop()
{
for (RequestLogger logger : loggers) {
logger.stop();
}
}
@Override
public void log(RequestLogLine requestLogLine) throws IOException
{

View File

@ -63,7 +63,8 @@ public class FileRequestLogger implements RequestLogger
}
@LifecycleStart
public void start()
@Override
public void start() throws Exception
{
try {
baseDir.mkdirs();
@ -117,6 +118,7 @@ public class FileRequestLogger implements RequestLogger
}
@LifecycleStop
@Override
public void stop()
{
synchronized (lock) {

View File

@ -28,4 +28,8 @@ import java.io.IOException;
public interface RequestLogger
{
void log(RequestLogLine requestLogLine) throws IOException;
default void start() throws Exception {}
default void stop() {}
}

View File

@ -31,7 +31,6 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.concurrent.Executors;
@ -45,7 +44,7 @@ public class FileRequestLoggerTest
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test public void testLog() throws IOException
@Test public void testLog() throws Exception
{
ObjectMapper objectMapper = new ObjectMapper();
DateTime dateTime = DateTimes.nowUtc();