WIP
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/aec5d155 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/aec5d155 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/aec5d155 Branch: refs/heads/feature/GEODE-2267 Commit: aec5d15591e9c629f4378b39e3ae75711802470c Parents: ff6ced2 Author: Jared Stewart <[email protected]> Authored: Tue Feb 7 10:47:48 2017 -0800 Committer: Jinmei Liao <[email protected]> Committed: Tue Feb 7 11:02:52 2017 -0800 ---------------------------------------------------------------------- .../cli/functions/ExportLogsFunction.java | 122 ++++++++++++++++++ .../internal/cli/util/ExactLogLevelFilter.java | 42 +++++++ .../internal/cli/util/FileDateFilter.java | 61 +++++++++ .../internal/cli/util/LogExporter.java | 124 +++++++++++++++++++ .../internal/cli/util/LogLevelFilter.java | 21 ++++ .../cli/util/ThresholdLogLevelFilter.java | 57 +++++++++ .../cli/util/ExactLogLevelFilterTest.java | 31 +++++ .../internal/cli/util/FileDateFilterTest.java | 24 ++++ .../internal/cli/util/LogExporterTest.java | 77 ++++++++++++ .../cli/util/ThresholdLogLevelFilterTest.java | 31 +++++ 10 files changed, 590 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java new file mode 100644 index 0000000..6a2a9b7 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportLogsFunction.java @@ -0,0 +1,122 @@ +/* + * 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.geode.management.internal.cli.functions; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.cache.execute.Function; +import org.apache.geode.cache.execute.FunctionContext; +import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.internal.InternalEntity; +import org.apache.geode.internal.lang.StringUtils; +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.management.internal.cli.commands.MiscellaneousCommands; +import org.apache.geode.management.internal.cli.util.ExactLogLevelFilter; +import org.apache.geode.management.internal.cli.util.FileDateFilter; +import org.apache.geode.management.internal.cli.util.LogExporter; +import org.apache.geode.management.internal.cli.util.LogLevelFilter; +import org.apache.geode.management.internal.cli.util.ThresholdLogLevelFilter; +import org.apache.logging.log4j.Logger; +import org.joda.time.Interval; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +public class ExportLogsFunction implements Function, InternalEntity { + private static final Logger LOGGER = LogService.getLogger(); + private static final long serialVersionUID = 1L; + + @Override + public void execute(final FunctionContext context) { + try { + // TODO: change this to get cache from FunctionContext when it becomes available + Cache cache = CacheFactory.getAnyInstance(); + String memberId = ((InternalDistributedSystem) cache.getDistributedSystem()).getMemberId(); + LOGGER.debug("ExportLogsFunction started for member {}", memberId); + + Object[] args = (Object[]) context.getArguments(); + + LogLevelFilter logLevelFilter = getLogLevelFilter(args); + FileDateFilter fileDateFilter = getFileDateFilter(args); + + new LogExporter(logLevelFilter, fileDateFilter).export(); + } catch (Exception e) { + context.getResultSender().sendException(e); + } + } + + protected FileDateFilter getFileDateFilter(Object[] args) { + Long startTime = getStartTime(args); + Long endTime = getEndTime(args); + + if (startTime == null && endTime == null) { + return null; + } + + startTime = (startTime == null) ? 0L : startTime; + endTime = (endTime == null) ? System.currentTimeMillis() : endTime; + + Interval logInterval = new Interval(startTime, endTime); + return new FileDateFilter(logInterval); + } + + protected LogLevelFilter getLogLevelFilter(Object[] args) { + String logLevel = getLogLevel(args); + if (StringUtils.isEmpty(logLevel)) { + return null; + } + + boolean logLevelOnly = getLogLevelOnly(args); + + return logLevelOnly ? new ExactLogLevelFilter(logLevel) : new ThresholdLogLevelFilter(logLevel); + } + + private static Long parseTime(String dateString) { + try { + SimpleDateFormat df = new SimpleDateFormat(MiscellaneousCommands.FORMAT); + return df.parse(dateString).toInstant().toEpochMilli(); + } catch (ParseException e) { + try { + SimpleDateFormat df = new SimpleDateFormat(MiscellaneousCommands.ONLY_DATE_FORMAT); + return df.parse(dateString).toInstant().toEpochMilli(); + } catch (ParseException e1) { + return null; + } + } + } + + private String getLogLevel(Object[] args) { + return (String) args[0]; + } + + private boolean getLogLevelOnly(Object[] args) { + return (boolean) args[1]; + } + + private Long getStartTime(Object[] args) { + return parseTime((String) args[2]); + } + + private Long getEndTime(Object[] args) { + return parseTime((String) args[3]); + } + + @Override + public boolean isHA() { + return false; + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ExactLogLevelFilter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ExactLogLevelFilter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ExactLogLevelFilter.java new file mode 100644 index 0000000..159b7e6 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ExactLogLevelFilter.java @@ -0,0 +1,42 @@ +/* + * 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.geode.management.internal.cli.util; + +import org.apache.geode.internal.logging.InternalLogWriter; + +import java.util.Arrays; + +public class ExactLogLevelFilter implements LogLevelFilter { + private final String logLevel; + + public ExactLogLevelFilter(String logLevel) { + if (!Arrays.asList(InternalLogWriter.levelNames).contains(logLevel)) { + throw new IllegalArgumentException("Unknown log level: " + logLevel); + } + + this.logLevel = logLevel; + } + + @Override + public boolean acceptsLine(String givenLogLevel) { + return givenLogLevel.equalsIgnoreCase(logLevel); + } + + protected String getLogLevel() { + return logLevel; + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/FileDateFilter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/FileDateFilter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/FileDateFilter.java new file mode 100644 index 0000000..b15aec1 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/FileDateFilter.java @@ -0,0 +1,61 @@ +/* + * 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.geode.management.internal.cli.util; + +import org.apache.geode.management.internal.cli.commands.MiscellaneousCommands; +import org.joda.time.Interval; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.sql.Time; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; + +public class FileDateFilter { + private Interval specifiedInterval; + + public FileDateFilter(Interval specifiedInterval) { + this.specifiedInterval = specifiedInterval; + } + + public boolean acceptsFile(Path file) { + try { + long fileStartTime = getStartTimeOf(file); + long fileEndTime = getEndTimeOf(file); + Interval fileInterval = new Interval(fileStartTime, fileEndTime); + return fileInterval.overlaps(specifiedInterval); + } catch (IOException e) { + throw new RuntimeException("Error accessing file", e); + } + } + + private static long getStartTimeOf(Path file) throws IOException { + return Files.readAttributes(file, BasicFileAttributes.class).creationTime().toInstant() + .toEpochMilli(); + } + + private static long getEndTimeOf(Path file) throws IOException { + return file.toFile().lastModified(); + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java new file mode 100644 index 0000000..d241499 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogExporter.java @@ -0,0 +1,124 @@ +/* + * 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.geode.management.internal.cli.util; + +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.geode.cache.execute.FunctionContext; +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.management.internal.configuration.utils.ZipUtils; +import org.apache.logging.log4j.Logger; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.ParseException; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class LogExporter { + private static final Logger LOGGER = LogService.getLogger(); + + private final LogLevelFilter logLevelFilter; + private final FileDateFilter fileDateFilter; + + public LogExporter(LogLevelFilter logLevelFilter, FileDateFilter fileDateFilter) + throws ParseException { + this.fileDateFilter = fileDateFilter; + this.logLevelFilter = logLevelFilter; + } + + public Path export() throws IOException { + Path workingDir = Paths.get(System.getProperty("user.dir")); + LOGGER.debug("Working directory is {}", workingDir); + + Path tempDirectory = Files.createTempDirectory("exportLogs"); + + for (Path logFile : findLogFiles(workingDir)) { + Path filteredLogFile = tempDirectory.resolve(logFile.getFileName()); + + if (logLevelFilter == null) { + Files.copy(logFile, filteredLogFile); + } else { + copyFilteringLogLevel(logFile, filteredLogFile); + } + } + + for (Path statFile : findStatFiles(workingDir)) { + Files.copy(statFile, tempDirectory); + } + + Path zipFile = Files.createTempFile("logExport", "zip"); + ZipUtils.zipDirectory(tempDirectory, zipFile); + + FileUtils.deleteDirectory(tempDirectory.toFile()); + + return zipFile; + } + + protected void copyFilteringLogLevel(Path originalLogFile, Path filteredLogFile) + throws IOException { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(filteredLogFile.toFile()))) { + Stream<String> lines = Files.lines(originalLogFile); + + lines.filter(this.logLevelFilter::acceptsLine) + .forEach((String line) -> writeLine(line, writer)); + } + } + + private void writeLine(String line, BufferedWriter writer) { + try { + writer.write(line); + writer.newLine(); + } catch (IOException e) { + throw new RuntimeException("Unable to write to log file", e); + } + } + + protected List<Path> findLogFiles(Path workingDir) throws IOException { + Predicate<Path> logFileSelector = (Path file) -> file.toString().toLowerCase().endsWith(".log"); + return findFiles(workingDir, logFileSelector); + } + + + protected List<Path> findStatFiles(Path workingDir) throws IOException { + Predicate<Path> statFileSelector = + (Path file) -> file.toString().toLowerCase().endsWith(".gfs"); + return findFiles(workingDir, statFileSelector); + } + + private List<Path> findFiles(Path workingDir, Predicate<Path> fileSelector) throws IOException { + Stream<Path> selectedFiles = Files.list(workingDir).filter(fileSelector); + + if (fileDateFilter != null) { + selectedFiles = selectedFiles.filter(fileDateFilter::acceptsFile); + } + + return selectedFiles.collect(toList()); + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogLevelFilter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogLevelFilter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogLevelFilter.java new file mode 100644 index 0000000..ff96907 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/LogLevelFilter.java @@ -0,0 +1,21 @@ +/* + * 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.geode.management.internal.cli.util; + +public interface LogLevelFilter { + public boolean acceptsLine(String logLevel); +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ThresholdLogLevelFilter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ThresholdLogLevelFilter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ThresholdLogLevelFilter.java new file mode 100644 index 0000000..2f78dc8 --- /dev/null +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/util/ThresholdLogLevelFilter.java @@ -0,0 +1,57 @@ +/* + * 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.geode.management.internal.cli.util; + +import static java.util.stream.Collectors.toSet; + +import org.apache.geode.internal.logging.InternalLogWriter; +import org.apache.geode.internal.logging.LogWriterImpl; + +import java.util.Arrays; +import java.util.Set; + +public class ThresholdLogLevelFilter implements LogLevelFilter { + private final String logLevelThreshold; + private final Set<String> permittedLogLevels; + + public ThresholdLogLevelFilter(String logLevelThreshold) { + if (!Arrays.asList(InternalLogWriter.levelNames).contains(logLevelThreshold)) { + throw new IllegalArgumentException("Unknown log level: " + logLevelThreshold); + } + + this.logLevelThreshold = logLevelThreshold; + this.permittedLogLevels = findPermittedLogLevels(); + } + + @Override + public boolean acceptsLine(String givenLogLevel) { + return permittedLogLevels.contains(givenLogLevel); + } + + private Set<String> findPermittedLogLevels() { + return Arrays.stream(InternalLogWriter.levelNames).filter((String logLevel) -> { + int logLevelCode = LogWriterImpl.levelNameToCode(logLevel); + int logLevelCodeThreshold = LogWriterImpl.levelNameToCode(this.logLevelThreshold); + + return logLevelCode <= logLevelCodeThreshold; + }).collect(toSet()); + } + + public String getLogLevelThreshold() { + return logLevelThreshold; + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExactLogLevelFilterTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExactLogLevelFilterTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExactLogLevelFilterTest.java new file mode 100644 index 0000000..140da20 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ExactLogLevelFilterTest.java @@ -0,0 +1,31 @@ +/* + * 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.geode.management.internal.cli.util; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ExactLogLevelFilterTest { + + // TODO: Jared + @Test + public void isLoggable() throws Exception { + + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/FileDateFilterTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/FileDateFilterTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/FileDateFilterTest.java new file mode 100644 index 0000000..4fc3f8d --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/FileDateFilterTest.java @@ -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. + * + */ + +package org.apache.geode.management.internal.cli.util; + +import static org.junit.Assert.*; + +public class FileDateFilterTest { + // TODO: Jared - add test + +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java new file mode 100644 index 0000000..7d62b4e --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/LogExporterTest.java @@ -0,0 +1,77 @@ +/* + * 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.geode.management.internal.cli.util; + + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.commons.logging.Log; +import org.apache.geode.internal.cache.execute.FunctionContextImpl; +import org.apache.geode.internal.logging.InternalLogWriter; +import org.junit.Test; + +public class LogExporterTest { + + @Test + public void testArgumentBindingWithExact() { + String dir = "someDir"; + String logLevel = InternalLogWriter.levelNames[3]; + + Object[] args = new Object[] {dir, logLevel, true}; + + LogExporter logExporter = new LogExporter(new FunctionContextImpl(null, args, null)); + + assertThat(logExporter.getTargetDirName()).isEqualTo(dir); + assertThat(logExporter.getLogLevelFilter()).isExactlyInstanceOf(ExactLogLevelFilter.class); + assertThat(((ExactLogLevelFilter) logExporter.getLogLevelFilter()).getLogLevel()) + .isEqualTo(logLevel); + } + + @Test + public void testArgumentBindingWithNonExact() { + String dir = "someDir"; + String logLevel = InternalLogWriter.levelNames[3]; + + Object[] args = new Object[] {dir, logLevel, false}; + + LogExporter logExporter = new LogExporter(new FunctionContextImpl(null, args, null)); + + assertThat(logExporter.getTargetDirName()).isEqualTo(dir); + assertThat(logExporter.getLogLevelFilter()).isExactlyInstanceOf(ThresholdLogLevelFilter.class); + assertThat(((ThresholdLogLevelFilter) logExporter.getLogLevelFilter()).getLogLevelThreshold()) + .isEqualTo(logLevel); + } + + @Test + public void testFindLogFiles() {} + + @Test + public void testFindStatFiles() { + + } + + @Test + public void testCopyFilteringLogLevel() { + + } + + @Test + public void testFilterLine() { + + } + +} http://git-wip-us.apache.org/repos/asf/geode/blob/aec5d155/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ThresholdLogLevelFilterTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ThresholdLogLevelFilterTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ThresholdLogLevelFilterTest.java new file mode 100644 index 0000000..2d84b95 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/util/ThresholdLogLevelFilterTest.java @@ -0,0 +1,31 @@ +/* + * 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.geode.management.internal.cli.util; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ThresholdLogLevelFilterTest { + + // TODO: Jared + @Test + public void isLoggable() throws Exception { + + } + +}
