Skip to content
Permalink
Browse files

migrated scala tests to use java

  • Loading branch information
ceki committed Apr 3, 2013
1 parent 1edd4e4 commit cc50828820dce57ecb3217f4000997b51a0fb6c5
@@ -18,7 +18,7 @@
<url>http://logback.qos.ch</url>

<properties>
<scala.version>2.9.1</scala.version>
<!--<scala.version>2.9.1</scala.version>-->
</properties>

<licenses>
@@ -75,12 +75,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<scope>test</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>org.scala-lang</groupId>-->
<!--<artifactId>scala-library</artifactId>-->
<!--<version>${scala.version}</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->

</dependencies>

@@ -96,24 +96,6 @@
</configuration>
</plugin>

<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<testSourceDir>src/test/scala</testSourceDir>
</configuration>
<executions>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -0,0 +1,55 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2013, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.core.rolling;


import ch.qos.logback.core.util.Compare;
import ch.qos.logback.core.util.CoreTestConstants;

import java.io.IOException;
import java.util.List;

import static org.junit.Assert.assertTrue;

public class DefaultRolloverChecker implements RolloverChecker {

final String testId;
final boolean withCompression;
final String compressionSuffix;

public DefaultRolloverChecker(String testId, boolean withCompression, String compressionSuffix) {
this.testId = testId;
this.withCompression = withCompression;
this.compressionSuffix = compressionSuffix;
}

public void check(List<String> expectedFilenameList) throws IOException {

int i = 0;
for (String fn : expectedFilenameList) {
String suffix = withCompression ? addGZIfNotLast(expectedFilenameList, i, compressionSuffix) : "";

String witnessFileName = CoreTestConstants.TEST_SRC_PREFIX + "witness/rolling/tbr-" + testId + "." + i + suffix;
assertTrue(Compare.compare(fn, witnessFileName));
i++;
}
}

String addGZIfNotLast(List<String> expectedFilenameList, int i, String suff) {
int lastIndex = expectedFilenameList.size() - 1;
return (i != lastIndex) ? suff : "";
}
}


@@ -0,0 +1,15 @@
package ch.qos.logback.core.rolling;

import java.io.File;

/**
* Created with IntelliJ IDEA.
* User: ceki
* Date: 4/3/13
* Time: 7:42 PM
* To change this template use File | Settings | File Templates.
*/
public interface FileMatchFunction {

boolean match(File f, String pattern);
}
@@ -17,10 +17,10 @@
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({RenameUtilTest.class, SizeBasedRolling_STest.class,
TimeBasedRolling_STest.class, TimeBasedRollingWithArchiveRemoval_STest.class,
@Suite.SuiteClasses({RenameUtilTest.class, SizeBasedRollingTest.class,
TimeBasedRollingTest.class, TimeBasedRollingWithArchiveRemoval_Test.class,
MultiThreadedRollingTest.class,
SizeAndTimeBasedFNATP_STest.class,
SizeAndTimeBasedFNATP_Test.class,
RollingFileAppenderTest.class,
ch.qos.logback.core.rolling.helper.PackageTest.class})
public class PackageTest {
@@ -0,0 +1,23 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2013, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/

package ch.qos.logback.core.rolling;

import java.io.IOException;
import java.util.List;


public interface RolloverChecker {
public void check(List<String> expectedFilenameList) throws IOException;
}
@@ -13,27 +13,29 @@
*/
package ch.qos.logback.core.rolling;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.encoder.EchoEncoder;
import ch.qos.logback.core.rolling.helper.FileFilterUtil;
import ch.qos.logback.core.rolling.helper.FileNamePattern;
import ch.qos.logback.core.testUtil.FileToBufferUtil;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.util.CoreTestConstants;

import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.encoder.EchoEncoder;
import ch.qos.logback.core.rolling.helper.FileFilterUtil;
import ch.qos.logback.core.testUtil.FileToBufferUtil;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.util.CoreTestConstants;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Scaffolding for various rolling tests. Some assumptions are made: - rollover
@@ -150,10 +152,32 @@ protected Date getDateOfPreviousPeriodsStart() {
return new Date(currentTime - delta - 1000);
}

static void waitForCompression(TimeBasedRollingPolicy<Object> tbrp)
throws InterruptedException, ExecutionException, TimeoutException {
protected long getMillisOfCurrentPeriodsStart() {
long delta = currentTime % 1000;
return (currentTime - delta);
}


void waitForCompression(TimeBasedRollingPolicy<Object> tbrp) {
if (tbrp.future != null && !tbrp.future.isDone()) {
tbrp.future.get(200, TimeUnit.MILLISECONDS);
try {
tbrp.future.get(400, TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

protected void addExpectedFileName_ByDate(String patternStr, long millis) {
FileNamePattern fileNamePattern = new FileNamePattern(patternStr, context);
String fn = fileNamePattern.convert(new Date(millis));
expectedFilenameList.add(fn);
}

void addExpectedFileNamedIfItsTime_ByDate(String fileNamePatternStr) {
if (passThresholdTime(nextRolloverThreshold)) {
addExpectedFileName_ByDate(fileNamePatternStr, getMillisOfCurrentPeriodsStart());
recomputeRolloverThreshold(currentTime);
}
}

@@ -167,6 +191,22 @@ protected void addExpectedFileName_ByDate(String outputDir, String testId, Date
expectedFilenameList.add(fn);
}

protected void addExpectedFileName_ByFileIndexCounter(String randomOutputDir, String testId, long millis,
int fileIndexCounter, String compressionSuffix) {
String fn = randomOutputDir + testId + "-" + SDF.format(millis) + "-" + fileIndexCounter + ".txt" + compressionSuffix;
expectedFilenameList.add(fn);
}


protected List<String> filterElementsInListBySuffix(String suffix) {
List<String> zipFiles = new ArrayList<String>();
for (String filename : expectedFilenameList) {
if (filename.endsWith(suffix))
zipFiles.add(filename);
}
return zipFiles;
}

protected void addExpectedFileNamedIfItsTime_ByDate(String outputDir, String testId,
boolean gzExtension) {
if (passThresholdTime(nextRolloverThreshold)) {
@@ -176,6 +216,20 @@ protected void addExpectedFileNamedIfItsTime_ByDate(String outputDir, String tes
}
}

void massageExpectedFilesToCorresponToCurrentTarget(String fileName, boolean fileOptionIsSet) {
int lastIndex = expectedFilenameList.size() - 1;
String last = expectedFilenameList.remove(lastIndex);

if (fileOptionIsSet) {
expectedFilenameList.add(fileName);
} else if (last.endsWith(".gz")) {
int lastLen = last.length();
String stem = last.substring(0, lastLen - 3);
expectedFilenameList.add(stem);
}
}


String addGZIfNotLast(int i) {
int lastIndex = expectedFilenameList.size() - 1;
if (i != lastIndex) {
@@ -184,4 +238,37 @@ String addGZIfNotLast(int i) {
return "";
}
}

void zipEntryNameCheck(List<String> expectedFilenameList, String pattern) throws IOException {
for (String filepath : expectedFilenameList) {
checkZipEntryName(filepath, pattern);
}
}

void checkZipEntryMatchesZipFilename(List<String> expectedFilenameList) throws IOException {
for (String filepath : expectedFilenameList) {
String stripped = stripStemFromZipFilename(filepath);
checkZipEntryName(filepath, stripped);
}
}

String stripStemFromZipFilename(String filepath) {
File filepathAsFile = new File(filepath);
String stem = filepathAsFile.getName();
int stemLen = stem.length();
return stem.substring(0, stemLen - ".zip".length());

}

void checkZipEntryName(String filepath, String pattern) throws IOException {
System.out.println("Checking [" + filepath + "]");
ZipFile zf = new ZipFile(filepath);
Enumeration<? extends ZipEntry> entries = zf.entries();
assert ((entries.hasMoreElements()));
ZipEntry firstZipEntry = entries.nextElement();
assert ((!entries.hasMoreElements()));
System.out.println("Testing zip entry [" + firstZipEntry.getName() + "]");
assertTrue(firstZipEntry.getName().matches(pattern));
}

}

0 comments on commit cc50828

Please sign in to comment.
You can’t perform that action at this time.