Package hudson.util.io

Source Code of hudson.util.io.ReopenableRotatingFileOutputStreamTest

package hudson.util.io;

import hudson.FilePath;
import junit.framework.TestCase;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

/**
* @author Kohsuke Kawaguchi
*/
public class ReopenableRotatingFileOutputStreamTest extends TestCase {
    public void testRotation() throws IOException {
        File base = File.createTempFile("test", "log");
        ReopenableRotatingFileOutputStream os = new ReopenableRotatingFileOutputStream(base,3);
        PrintWriter w = new PrintWriter(os,true);
        for (int i=0; i<=4; i++) {
            w.println("Content"+i);
            os.rewind();
        }
        w.println("Content5");

        assertEquals("Content5", new FilePath(base).readToString().trim());
        assertEquals("Content4", new FilePath(new File(base.getPath() + ".1")).readToString().trim());
        assertEquals("Content3", new FilePath(new File(base.getPath() + ".2")).readToString().trim());
        assertEquals("Content2", new FilePath(new File(base.getPath() + ".3")).readToString().trim());
        assertFalse(new File(base.getPath() + ".4").exists());

        os.deleteAll();
    }
}
TOP

Related Classes of hudson.util.io.ReopenableRotatingFileOutputStreamTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.