/*
 * 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 static org.junit.Assert.assertTrue;

import java.io.File;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.status.StatusLogger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 *
 */
public class RollingAppenderTimeAndSizeTest {

    private static final String CONFIG = "log4j-rolling3.xml";
    private static final String DIR = "target/rolling3/test";

    org.apache.logging.log4j.Logger logger = LogManager.getLogger(RollingAppenderTimeAndSizeTest.class.getName());

    @BeforeClass
    public static void setupClass() {
        deleteDir();
        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        final Configuration config = ctx.getConfiguration();
    }

    @AfterClass
    public static void cleanupClass() {
        //deleteDir();
        System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
        final LoggerContext ctx = (LoggerContext) LogManager.getContext();
        ctx.reconfigure();
        StatusLogger.getLogger().reset();
    }

    @Test
    public void testAppender() throws Exception {
        for (int i=0; i < 100; ++i) {
            if (i % 11 == 0) {
                Thread.sleep(1000);
            }
            logger.debug("This is test message number " + i);
        }
        final File dir = new File(DIR);
        assertTrue("Directory not created", dir.exists() && dir.listFiles().length > 0);
        final File[] files = dir.listFiles();
        assertTrue("No files created", files.length > 0);
        boolean found = false;
        for (final File file : files) {
            if (file.getName().endsWith(".gz")) {
                found = true;
                break;
            }
        }
        assertTrue("No compressed files found", found);
    }

    private static void deleteDir() {
        final File dir = new File(DIR);
        if (dir.exists()) {
            final File[] files = dir.listFiles();
            for (final File file : files) {
                file.delete();
            }
            dir.delete();
        }
    }
}

@@ -952,20 +952,16 @@
 og4j.Log
-Mana
 ger;%0Aimp
@@ -993,263 +993,34 @@
 g4j.
-core.LoggerContext;%0Aimport org.apache.logging.log4j.core.config.Configuration;%0Aimport org.apache.logging.log4j.core.config.ConfigurationFactory;%0Aimport org.apache.logging.log4j.status.StatusLogger;%0Aimport org.junit.AfterClass;%0Aimport org.junit.BeforeClass
+junit.InitialLoggerContext
 ;%0Aim
@@ -1034,20 +1034,17 @@
 g.junit.
-Test
+*
 ;%0A%0A/**%0A 
@@ -1132,215 +1132,162 @@
 ing 
-CONFIG = %22log4j-rolling3.xml%22;%0A    private static final String DIR = %22target/rolling3/test%22;%0A%0A    org.apache.logging.log4j.Logger logger = LogManager.getLogger(RollingAppenderTimeAndSizeTest.class.getName())
+DIR = %22target/rolling3/test%22;%0A%0A    @Rule%0A    public InitialLoggerContext init = new InitialLoggerContext(%22log4j-rolling3.xml%22);%0A%0A    private Logger logger
 ;%0A%0A 
@@ -1296,21 +1296,16 @@
  @Before
-Class
 %0A    pub
@@ -1312,23 +1312,16 @@
 lic 
-static 
 void set
 upCl
@@ -1320,259 +1320,140 @@
  set
-upClass() %7B%0A        deleteDir();%0A        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);%0A        final LoggerContext ctx = (LoggerContext) LogManager.getContext();%0A        final Configuration config = ctx.getConfiguration
+Up() throws Exception %7B%0A        this.logger = this.init.getLogger(RollingAppenderTimeAndSizeTest.class.getName());%0A        deleteDir
 ();%0A
@@ -1469,21 +1469,16 @@
   @After
-Class
 %0A    pub
@@ -1485,280 +1485,60 @@
 lic 
-static void cleanupClass() %7B%0A        //deleteDir();%0A        System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);%0A        final LoggerContext ctx = (LoggerContext) LogManager.getContext();%0A        ctx.reconfigure();%0A        StatusLogger.getLogger().reset
+void tearDown() throws Exception %7B%0A        deleteDir
 ();%0A

Update to use InitialLoggerContext rule.