Thanks for the update Ralph. Gary
On Sun, Dec 9, 2018 at 5:32 PM Ralph Goers <ralph.go...@dslextreme.com> wrote: > No, they are not. They are related to the commit I did for LOG4J2-1906 a > week ago. I am trying to add more diagnostics so I can figure out why it > occasionally fails. Note that this is a new test that would have failed > every time it ran prior to that fix. > > Ralph > > > On Dec 9, 2018, at 3:05 PM, Gary Gregory <garydgreg...@gmail.com> wrote: > > > > Hi, > > > > I think the Jenkins build failures are related to this commit :-( > > > > Gary > > > > ---------- Forwarded message --------- > > From: <rgo...@apache.org> > > Date: Sun, Dec 9, 2018 at 10:23 AM > > Subject: [logging-log4j2] branch release-2.x updated: Enhance direct > write > > test. Add new OnStartup test > > To: comm...@logging.apache.org <comm...@logging.apache.org> > > > > > > This is an automated email from the ASF dual-hosted git repository. > > > > rgoers pushed a commit to branch release-2.x > > in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git > > > > > > The following commit(s) were added to refs/heads/release-2.x by this > push: > > new 3a6f602 Enhance direct write test. Add new OnStartup test > > 3a6f602 is described below > > > > commit 3a6f6022130b1eee6100c633b988cd8cb091580c > > Author: Ralph Goers <rgo...@apache.org> > > AuthorDate: Sun Dec 9 10:22:19 2018 -0700 > > > > Enhance direct write test. Add new OnStartup test > > --- > > .../core/appender/rolling/RollingFileManager.java | 1 + > > .../RollingAppenderDirectWrite1906Test.java | 11 +- > > .../rolling/RollingAppenderOnStartup2Test.java | 120 > > +++++++++++++++++++++ > > .../src/test/resources/log4j-rollOnStartup.json | 41 +++++++ > > 4 files changed, 169 insertions(+), 4 deletions(-) > > > > diff --git > > > a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java > > > b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java > > index 8a9e980..4060a90 100644 > > --- > > > a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java > > +++ > > > b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java > > @@ -669,6 +669,7 @@ public class RollingFileManager extends FileManager { > > final BasicFileAttributes attrs = > > Files.readAttributes(path, BasicFileAttributes.class); > > final FileTime fileTime = attrs.creationTime(); > > if (fileTime.compareTo(EPOCH) > 0) { > > + LOGGER.debug("Returning file creation time for {}", > > file.getAbsolutePath()); > > return fileTime.toMillis(); > > } > > LOGGER.info("Unable to obtain file creation time for " + > > file.getAbsolutePath()); > > diff --git > > > a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.java > > > b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.java > > index c58c0ad..9417c40 100644 > > --- > > > a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.java > > +++ > > > b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDirectWrite1906Test.java > > @@ -92,11 +92,14 @@ public class RollingAppenderDirectWrite1906Test { > > > > } > > > > - private String logFileNameError(final String expected, final String > > actual) { > > + private String logFileNameError(String expected, String actual) { > > final List<StatusData> statusData = > > StatusLogger.getLogger().getStatusData(); > > - for (final StatusData statusItem : statusData) { > > - System.err.println(statusItem.getFormattedStatus()); > > + final StringBuilder sb = new StringBuilder(); > > + for (StatusData statusItem : statusData) { > > + sb.append(statusItem.getFormattedStatus()); > > + sb.append("\n"); > > } > > - return "Incorrect file name. Expected: " + expected + " Actual: > " > > + actual; > > + sb.append("Incorrect file name. Expected: > > ").append(expected).append(" Actual: ").append(actual); > > + return sb.toString(); > > } > > } > > diff --git > > > a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartup2Test.java > > > b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartup2Test.java > > new file mode 100644 > > index 0000000..681a81b > > --- /dev/null > > +++ > > > b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderOnStartup2Test.java > > @@ -0,0 +1,120 @@ > > +/* > > + * 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.logging.log4j.core.appender.rolling; > > + > > +import java.io.ByteArrayInputStream; > > +import java.io.InputStream; > > +import java.nio.file.DirectoryStream; > > +import java.nio.file.Files; > > +import java.nio.file.Path; > > +import java.nio.file.Paths; > > +import java.nio.file.StandardCopyOption; > > +import java.nio.file.attribute.BasicFileAttributeView; > > +import java.nio.file.attribute.FileTime; > > +import java.util.Arrays; > > +import java.util.Collection; > > + > > +import org.apache.logging.log4j.LogManager; > > +import org.apache.logging.log4j.Logger; > > +import org.apache.logging.log4j.core.config.Configuration; > > +import org.apache.logging.log4j.core.config.DefaultConfiguration; > > +import org.apache.logging.log4j.core.util.datetime.FastDateFormat; > > +import org.apache.logging.log4j.junit.LoggerContextRule; > > +import org.junit.AfterClass; > > +import org.junit.Assert; > > +import org.junit.Before; > > +import org.junit.BeforeClass; > > +import org.junit.Rule; > > +import org.junit.Test; > > +import org.junit.runner.RunWith; > > +import org.junit.runners.Parameterized; > > + > > +import static org.junit.Assert.assertEquals; > > +import static org.junit.Assert.assertTrue; > > + > > +/** > > + * > > + */ > > +public class RollingAppenderOnStartup2Test { > > + > > + private static final String DIR = "target/rollOnStartup"; > > + private static final String TARGET_FILE = DIR + "/orchestrator.log"; > > + private static final FastDateFormat formatter = > > FastDateFormat.getInstance("MM-dd-yy-HH-mm-ss"); > > + private static final String ROLLED_FILE_PREFIX = DIR + > > "/orchestrator-"; > > + private static final String ROLLED_FILE_SUFFIX = "-1.log.gz"; > > + private static final String TEST_DATA = "Hello world!"; > > + > > + @BeforeClass > > + public static void beforeClass() throws Exception { > > + if (Files.exists(Paths.get("target/rollOnStartup"))) { > > + try (DirectoryStream<Path> directoryStream = > > Files.newDirectoryStream(Paths.get(DIR))) { > > + for (final Path path : directoryStream) { > > + Files.delete(path); > > + } > > + Files.delete(Paths.get(DIR)); > > + } > > + } > > + //System.setProperty("log4j2.debug", "true"); > > + //System.setProperty("log4j2.StatusLogger.level", "trace"); > > + final Configuration configuration = new DefaultConfiguration(); > > + final Path target = Paths.get(TARGET_FILE); > > + Assert.assertFalse(Files.exists(target)); > > + target.toFile().getParentFile().mkdirs(); > > + final long timeStamp = System.currentTimeMillis() - (1000 * 60 * > > 60 * 24); > > + final String expectedDate = formatter.format(timeStamp); > > + final String rolledFileName = ROLLED_FILE_PREFIX + expectedDate > + > > ROLLED_FILE_SUFFIX; > > + final Path rolled = Paths.get(rolledFileName); > > + final long copied; > > + try (final InputStream is = new > > ByteArrayInputStream(TEST_DATA.getBytes("UTF-8"))) { > > + copied = Files.copy(is, target, > > StandardCopyOption.REPLACE_EXISTING); > > + } > > + final long size = Files.size(target); > > + assertTrue(size > 0); > > + assertEquals(copied, size); > > + final FileTime fileTime = FileTime.fromMillis(timeStamp); > > + final BasicFileAttributeView attrs = > > Files.getFileAttributeView(target, BasicFileAttributeView.class); > > + attrs.setTimes(fileTime, fileTime, fileTime); > > + System.setProperty("log4j.configurationFile", > > "log4j-rollOnStartup.json"); > > + } > > + > > + @AfterClass > > + public static void afterClass() throws Exception { > > + long size = 0; > > + /* try (DirectoryStream<Path> directoryStream = > > Files.newDirectoryStream(Paths.get(DIR))) { > > + for (final Path path : directoryStream) { > > + if (size == 0) { > > + size = Files.size(path); > > + } else { > > + final long fileSize = Files.size(path); > > + assertTrue("Expected size: " + size + " Size of " + > > path.getFileName() + ": " + fileSize, > > + size == fileSize); > > + } > > + Files.delete(path); > > + } > > + Files.delete(Paths.get("target/rollOnStartup")); > > + } */ > > + } > > + > > + @Test > > + public void testAppender() throws Exception { > > + Logger logger = > > LogManager.getLogger(RollingAppenderOnStartup2Test.class); > > + for (int i = 0; i < 10; ++i) { > > + logger.debug("This is test message number " + i); > > + } > > + > > + } > > +} > > diff --git a/log4j-core/src/test/resources/log4j-rollOnStartup.json > > b/log4j-core/src/test/resources/log4j-rollOnStartup.json > > new file mode 100644 > > index 0000000..85e9203 > > --- /dev/null > > +++ b/log4j-core/src/test/resources/log4j-rollOnStartup.json > > @@ -0,0 +1,41 @@ > > +{ > > + "configuration": { "status": "debug", > > + "appenders": { > > + "Console": { > > + "name": "Console", > > + "PatternLayout": { > > + "pattern": "%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%c{2}] [%t]%n[%p] : > > %m%n" > > + } > > + }, > > + "RollingFile": { > > + "name": "RollingFile", > > + "fileName": "target/rollOnStartup/orchestrator.log", > > + "filePattern": > > "target/RollOnStartup/orchestrator-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz", > > + "append": false, > > + "PatternLayout": { > > + "pattern": "%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%c{2}] [%t]%n[%p] : > > %m%n" > > + }, > > + "Policies": { > > + "OnStartupTriggeringPolicy": { > > + "minSize" : 0 > > + }, > > + "SizeBasedTriggeringPolicy": { > > + "size": "50 MB" > > + } > > + }, > > + "DefaultRolloverStrategy": { > > + "max": "10" > > + } > > + } > > + }, > > + "loggers": { > > + "root": { > > + "level": "info", > > + "AppenderRef": [ > > + {"ref": "RollingFile", "level": "INFO"}, > > + {"ref": "Console", "level": "ERROR"} > > + ] > > + } > > + } > > + } > > +} > > \ No newline at end of file > > >