[Git][java-team/jboss-logmanager][upstream] New upstream version 2.1.14
Markus Koschany
gitlab at salsa.debian.org
Sun Aug 11 23:42:55 BST 2019
Markus Koschany pushed to branch upstream at Debian Java Maintainers / jboss-logmanager
Commits:
626b699c by Markus Koschany at 2019-08-11T22:37:41Z
New upstream version 2.1.14
- - - - -
24 changed files:
- pom.xml
- src/main/java/org/jboss/logmanager/CallerClassLoaderLogContextSelector.java
- src/main/java/org/jboss/logmanager/ClassLoaderLogContextSelector.java
- src/main/java/org/jboss/logmanager/ContextClassLoaderLogContextSelector.java
- src/main/java/org/jboss/logmanager/config/LogContextConfigurationImpl.java
- src/main/java/org/jboss/logmanager/formatters/Formatters.java
- src/main/java/org/jboss/logmanager/handlers/PeriodicSizeRotatingFileHandler.java
- src/main/java/org/jboss/logmanager/handlers/SizeRotatingFileHandler.java
- + src/test/java/org/jboss/logmanager/AssertingErrorManager.java
- src/test/java/org/jboss/logmanager/FileHandlerPerformanceTests.java
- src/test/java/org/jboss/logmanager/HandlerTests.java
- src/test/java/org/jboss/logmanager/TestFileHandler.java
- src/test/java/org/jboss/logmanager/config/LogContextConfigurationTests.java
- src/test/java/org/jboss/logmanager/handlers/AbstractHandlerTest.java
- src/test/java/org/jboss/logmanager/handlers/AsyncHandlerTests.java
- src/test/java/org/jboss/logmanager/handlers/DelayedHandlerTests.java
- src/test/java/org/jboss/logmanager/handlers/ExtHandlerTests.java
- src/test/java/org/jboss/logmanager/handlers/OutputStreamHandlerTest.java
- src/test/java/org/jboss/logmanager/handlers/PeriodicRotatingFileHandlerTests.java
- src/test/java/org/jboss/logmanager/handlers/PeriodicSizeRotatingFileHandlerTests.java
- src/test/java/org/jboss/logmanager/handlers/QueueHandlerTests.java
- src/test/java/org/jboss/logmanager/handlers/SizeRotatingFileHandlerTests.java
- src/test/java/org/jboss/logmanager/handlers/SocketHandlerTests.java
- src/test/java/org/jboss/logmanager/handlers/SyslogHandlerTests.java
Changes:
=====================================
pom.xml
=====================================
@@ -28,7 +28,7 @@
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
<packaging>jar</packaging>
- <version>2.1.13.Final</version>
+ <version>2.1.14.Final</version>
<parent>
<groupId>org.jboss</groupId>
=====================================
src/main/java/org/jboss/logmanager/CallerClassLoaderLogContextSelector.java
=====================================
@@ -118,7 +118,8 @@ public final class CallerClassLoaderLogContextSelector implements LogContextSele
*/
@Override
public LogContext getLogContext() {
- return AccessController.doPrivileged(logContextAction);
+ return System.getSecurityManager() == null? logContextAction.run() :
+ AccessController.doPrivileged(logContextAction);
}
/**
=====================================
src/main/java/org/jboss/logmanager/ClassLoaderLogContextSelector.java
=====================================
@@ -118,7 +118,8 @@ public final class ClassLoaderLogContextSelector implements LogContextSelector {
* with any log context.
*/
public LogContext getLogContext() {
- return AccessController.doPrivileged(logContextAction);
+ return System.getSecurityManager() == null? logContextAction.run() :
+ AccessController.doPrivileged(logContextAction);
}
/**
=====================================
src/main/java/org/jboss/logmanager/ContextClassLoaderLogContextSelector.java
=====================================
@@ -69,7 +69,8 @@ public final class ContextClassLoaderLogContextSelector implements LogContextSel
};
public LogContext getLogContext() {
- return doPrivileged(logContextAction);
+ return System.getSecurityManager() == null? logContextAction.run() :
+ doPrivileged(logContextAction);
}
/**
=====================================
src/main/java/org/jboss/logmanager/config/LogContextConfigurationImpl.java
=====================================
@@ -664,14 +664,13 @@ final class LogContextConfigurationImpl implements LogContextConfiguration {
expect(")", iterator);
return new SimpleObjectProducer(new SubstituteFilter(pattern, replacement, true));
} else {
- final String name = expectName(iterator);
- if (! filters.containsKey(name) || immediate && ! filterRefs.containsKey(name)) {
- throw new IllegalArgumentException(String.format("No filter named \"%s\" is defined", name));
+ if (! filters.containsKey(token) || immediate && ! filterRefs.containsKey(token)) {
+ throw new IllegalArgumentException(String.format("No filter named \"%s\" is defined", token));
}
if (immediate) {
- return new SimpleObjectProducer(filterRefs.get(name));
+ return new SimpleObjectProducer(filterRefs.get(token));
} else {
- return new RefProducer(name, filterRefs);
+ return new RefProducer(token, filterRefs);
}
}
}
=====================================
src/main/java/org/jboss/logmanager/formatters/Formatters.java
=====================================
@@ -765,26 +765,33 @@ public final class Formatters {
public static FormatStep exceptionFormatStep(final boolean leftJustify, final int minimumWidth, final boolean truncateBeginning, final int maximumWidth, final String argument, final boolean extended) {
return new JustifyingFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth) {
public void renderRaw(final StringBuilder builder, final ExtLogRecord record) {
- doPrivileged(new PrivilegedAction<Void>() {
- public Void run() {
- final Throwable t = record.getThrown();
- if (t != null) {
- int depth = -1;
- if (argument != null) {
- try {
- depth = Integer.parseInt(argument);
- } catch (NumberFormatException ignore) {
- }
- }
- StackTraceFormatter.renderStackTrace(builder, t, extended, depth);
+ if (System.getSecurityManager() != null)
+ doPrivileged(new PrivilegedAction<Void>() {
+ public Void run() {
+ doExceptionFormatStep(builder, record, argument, extended);
+ return null;
}
- return null;
- }
- });
+ });
+ else
+ doExceptionFormatStep(builder, record, argument, extended);
}
};
}
+ private static void doExceptionFormatStep(final StringBuilder builder, final ExtLogRecord record, final String argument, final boolean extended) {
+ final Throwable t = record.getThrown();
+ if (t != null) {
+ int depth = -1;
+ if (argument != null) {
+ try {
+ depth = Integer.parseInt(argument);
+ } catch (NumberFormatException ignore) {
+ }
+ }
+ StackTraceFormatter.renderStackTrace(builder, t, extended, depth);
+ }
+ }
+
/**
* Create a format step which emits the log message resource key (if any) with the given justification rules.
*
=====================================
src/main/java/org/jboss/logmanager/handlers/PeriodicSizeRotatingFileHandler.java
=====================================
@@ -154,6 +154,8 @@ public class PeriodicSizeRotatingFileHandler extends PeriodicRotatingFileHandler
final String suffix = getNextSuffix();
final SuffixRotator suffixRotator = getSuffixRotator();
if (suffixRotator != SuffixRotator.EMPTY && suffix != null) {
+ // Make sure any previous files are closed before we attempt to rotate
+ setFileInternal(null);
suffixRotator.rotate(getErrorManager(), file.toPath(), suffix, maxBackupIndex);
}
}
=====================================
src/main/java/org/jboss/logmanager/handlers/SizeRotatingFileHandler.java
=====================================
@@ -139,6 +139,8 @@ public class SizeRotatingFileHandler extends FileHandler {
synchronized (outputLock) {
// Check for a rotate
if (rotateOnBoot && maxBackupIndex > 0 && file != null && file.exists() && file.length() > 0L) {
+ // Make sure any previous files are closed before we attempt to rotate
+ setFileInternal(null);
suffixRotator.rotate(getErrorManager(), file.toPath(), maxBackupIndex);
}
setFileInternal(file);
=====================================
src/test/java/org/jboss/logmanager/AssertingErrorManager.java
=====================================
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2019 Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags.
+ *
+ * Licensed 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.jboss.logmanager;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.logging.ErrorManager;
+
+import org.junit.Assert;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class AssertingErrorManager extends ErrorManager {
+
+ private final int[] allowedCodes;
+
+ private AssertingErrorManager() {
+ this.allowedCodes = null;
+ }
+
+ private AssertingErrorManager(final int... allowedCodes) {
+ this.allowedCodes = allowedCodes;
+ }
+
+ public static AssertingErrorManager of() {
+ return new AssertingErrorManager();
+ }
+
+ public static AssertingErrorManager of(final int... allowedCodes) {
+ return new AssertingErrorManager(allowedCodes);
+ }
+
+ @Override
+ public void error(final String msg, final Exception ex, final int code) {
+ if (notAllowed(code)) {
+ final String codeStr;
+ switch (code) {
+ case CLOSE_FAILURE:
+ codeStr = "CLOSE_FAILURE";
+ break;
+ case FLUSH_FAILURE:
+ codeStr = "FLUSH_FAILURE";
+ break;
+ case FORMAT_FAILURE:
+ codeStr = "FORMAT_FAILURE";
+ break;
+ case GENERIC_FAILURE:
+ codeStr = "GENERIC_FAILURE";
+ break;
+ case OPEN_FAILURE:
+ codeStr = "OPEN_FAILURE";
+ break;
+ case WRITE_FAILURE:
+ codeStr = "WRITE_FAILURE";
+ break;
+ default:
+ codeStr = "INVALID (" + code + ")";
+ break;
+ }
+ try (
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw)
+ ) {
+ pw.printf("LogManager error of type %s: %s%n", codeStr, msg);
+ ex.printStackTrace(pw);
+ Assert.fail(sw.toString());
+ } catch (IOException e) {
+ // This shouldn't happen, but just fail if it does
+ e.printStackTrace();
+ Assert.fail(String.format("Failed to print error message: %s", e.getMessage()));
+ }
+ }
+ }
+
+ private boolean notAllowed(final int code) {
+ if (allowedCodes != null) {
+ for (int allowedCode : allowedCodes) {
+ if (code == allowedCode) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}
=====================================
src/test/java/org/jboss/logmanager/FileHandlerPerformanceTests.java
=====================================
@@ -38,6 +38,7 @@ public class FileHandlerPerformanceTests {
handler.setLevel(Level.ALL);
handler.setAutoFlush(true);
handler.setEncoding("utf-8");
+ handler.setErrorManager(AssertingErrorManager.of());
}
private static void publish(final ExtHandler handler, final String msg) {
=====================================
src/test/java/org/jboss/logmanager/HandlerTests.java
=====================================
@@ -172,6 +172,7 @@ public final class HandlerTests {
static class MultiHandler extends ExtHandler {
protected MultiHandler() {
+ setErrorManager(AssertingErrorManager.of());
}
public void publish(final LogRecord record) {
=====================================
src/test/java/org/jboss/logmanager/TestFileHandler.java
=====================================
@@ -36,10 +36,12 @@ public class TestFileHandler extends FileHandler {
public TestFileHandler() {
super();
+ setErrorManager(AssertingErrorManager.of());
}
public TestFileHandler(final String fileName, final boolean append) throws FileNotFoundException {
super(fileName, append);
+ setErrorManager(AssertingErrorManager.of());
}
@Override
=====================================
src/test/java/org/jboss/logmanager/config/LogContextConfigurationTests.java
=====================================
@@ -22,6 +22,7 @@ package org.jboss.logmanager.config;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Filter;
+import java.util.logging.LogRecord;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
@@ -74,6 +75,51 @@ public class LogContextConfigurationTests {
}
}
+ @Test
+ public void testNamedFilter() {
+ final LogContext context = LogContext.create();
+ final LogContextConfiguration configuration = LogContextConfiguration.Factory.create(context);
+ final LoggerConfiguration loggerConfiguration = configuration.addLoggerConfiguration(LOGGER_NAME);
+ final Logger logger = context.getLogger(LOGGER_NAME);
+
+ final FilterDescription description = new FilterDescription("test", "test named filter",
+ "test named filter | filtered", true);
+
+ configuration.addFilterConfiguration(null, TestFilter.class.getName(), "test");
+ loggerConfiguration.setFilter(description.filterExpression);
+ configuration.commit();
+
+ final ExtLogRecord record = create(description.logMessage);
+
+ final Filter filter = logger.getFilter();
+ Assert.assertNotNull("Expected a filter on the logger, but one was not found: " + description, filter);
+ Assert.assertEquals("Filter.isLoggable() test failed: " + description, description.isLoggable, filter.isLoggable(record));
+ final String msg = record.getFormattedMessage();
+ Assert.assertEquals(String.format("Expected %s found %s: %n%s", description.expectedMessage, msg, description), description.expectedMessage, msg);
+ }
+
+ @Test
+ public void testEmbeddedNamedFilter() {
+ final LogContext context = LogContext.create();
+ final LogContextConfiguration configuration = LogContextConfiguration.Factory.create(context);
+ final LoggerConfiguration loggerConfiguration = configuration.addLoggerConfiguration(LOGGER_NAME);
+ final Logger logger = context.getLogger(LOGGER_NAME);
+
+ final FilterDescription description = new FilterDescription("all(test)", "test named filter",
+ "test named filter | filtered", true);
+ configuration.addFilterConfiguration(null, TestFilter.class.getName(), "test");
+ loggerConfiguration.setFilter(description.filterExpression);
+ configuration.commit();
+
+ final ExtLogRecord record = create(description.logMessage);
+
+ final Filter filter = logger.getFilter();
+ Assert.assertNotNull("Expected a filter on the logger, but one was not found: " + description, filter);
+ Assert.assertEquals("Filter.isLoggable() test failed: " + description, description.isLoggable, filter.isLoggable(record));
+ final String msg = record.getFormattedMessage();
+ Assert.assertEquals(String.format("Expected %s found %s: %n%s", description.expectedMessage, msg, description), description.expectedMessage, msg);
+ }
+
private static ExtLogRecord create(final String message) {
final ExtLogRecord record = new ExtLogRecord(Level.INFO, message, Logger.class.getName());
record.setLoggerName(LOGGER_NAME);
@@ -105,4 +151,13 @@ public class LogContextConfigurationTests {
", isLoggable=" + isLoggable + ")";
}
}
+
+ public static class TestFilter implements Filter {
+
+ @Override
+ public boolean isLoggable(final LogRecord record) {
+ record.setMessage(record.getMessage() + " | filtered");
+ return true;
+ }
+ }
}
=====================================
src/test/java/org/jboss/logmanager/handlers/AbstractHandlerTest.java
=====================================
@@ -37,6 +37,7 @@ import java.util.zip.GZIPInputStream;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.formatters.PatternFormatter;
import org.junit.After;
import org.junit.Assert;
@@ -105,6 +106,7 @@ public class AbstractHandlerTest {
protected static void configureHandlerDefaults(final ExtHandler handler) {
handler.setAutoFlush(true);
handler.setFormatter(FORMATTER);
+ handler.setErrorManager(AssertingErrorManager.of());
}
protected ExtLogRecord createLogRecord(final String msg) {
=====================================
src/test/java/org/jboss/logmanager/handlers/AsyncHandlerTests.java
=====================================
@@ -23,6 +23,7 @@ import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
@@ -108,6 +109,7 @@ public class AsyncHandlerTests {
BlockingQueueHandler() {
queue = new LinkedBlockingDeque<String>();
+ setErrorManager(AssertingErrorManager.of());
}
@Override
=====================================
src/test/java/org/jboss/logmanager/handlers/DelayedHandlerTests.java
=====================================
@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import java.util.stream.Collectors;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.LogContext;
@@ -101,6 +102,7 @@ public class DelayedHandlerTests {
final LogContext logContext = LogContext.create();
final DelayedHandler handler = new DelayedHandler();
+ handler.setErrorManager(AssertingErrorManager.of());
final Logger rootLogger = logContext.getLogger("");
rootLogger.addHandler(handler);
@@ -141,6 +143,7 @@ public class DelayedHandlerTests {
final LogContext logContext = LogContext.create();
final DelayedHandler handler = new DelayedHandler();
+ handler.setErrorManager(AssertingErrorManager.of());
final Logger rootLogger = logContext.getLogger("");
rootLogger.addHandler(handler);
final Random r = new Random();
@@ -186,6 +189,7 @@ public class DelayedHandlerTests {
final LogContext logContext = LogContext.create();
final DelayedHandler handler = new DelayedHandler();
+ handler.setErrorManager(AssertingErrorManager.of());
final Logger rootLogger = logContext.getLogger("");
rootLogger.addHandler(handler);
final Random r = new Random();
@@ -241,6 +245,11 @@ public class DelayedHandlerTests {
public static class TestHandler extends ExtHandler {
static final List<ExtLogRecord> MESSAGES = new ArrayList<>();
+ @SuppressWarnings("WeakerAccess")
+ public TestHandler() {
+ setErrorManager(AssertingErrorManager.of());
+ }
+
@Override
protected synchronized void doPublish(final ExtLogRecord record) {
MESSAGES.add(record);
=====================================
src/test/java/org/jboss/logmanager/handlers/ExtHandlerTests.java
=====================================
@@ -21,6 +21,7 @@ package org.jboss.logmanager.handlers;
import java.util.logging.SimpleFormatter;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.formatters.PatternFormatter;
import org.junit.Assert;
@@ -140,6 +141,10 @@ public class ExtHandlerTests {
static class CloseHandler extends ExtHandler {
private boolean closed = false;
+ CloseHandler() {
+ setErrorManager(AssertingErrorManager.of());
+ }
+
@Override
public void close() {
closed = true;
=====================================
src/test/java/org/jboss/logmanager/handlers/OutputStreamHandlerTest.java
=====================================
@@ -18,75 +18,79 @@
*/
package org.jboss.logmanager.handlers;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
import java.io.IOException;
import java.io.StringWriter;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
-import static org.hamcrest.core.Is.is;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
import org.jboss.logmanager.handlers.ConsoleHandler.Target;
import org.junit.After;
-import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
/**
- *
* @author <a href="mailto:ehugonne at redhat.com">Emmanuel Hugonnet</a> (c) 2013 Red Hat, inc.
*/
public class OutputStreamHandlerTest {
private StringWriter out;
private OutputStreamHandler handler;
-
+
private static final Formatter NO_FORMATTER = new Formatter() {
public String format(final LogRecord record) {
return record.getMessage();
}
};
-
+
public OutputStreamHandlerTest() {
}
-
+
@Before
public void prepareBuffer() {
out = new StringWriter();
}
-
+
@After
public void cleanAll() throws IOException {
- handler.flush();
- handler.close();
- out.close();
+ handler.flush();
+ handler.close();
+ out.close();
}
-
+
@Test
public void testSetEncoding() throws Exception {
handler = new OutputStreamHandler();
+ handler.setErrorManager(AssertingErrorManager.of());
handler.setEncoding("UTF-8");
assertThat(handler.getEncoding(), is("UTF-8"));
}
-
- @Test
- public void testSetEncodingOnOutputStream() throws Exception {
- handler = new ConsoleHandler(Target.CONSOLE, NO_FORMATTER);
+
+ @Test
+ public void testSetEncodingOnOutputStream() throws Exception {
+ handler = new ConsoleHandler(Target.CONSOLE, NO_FORMATTER);
+ handler.setErrorManager(AssertingErrorManager.of());
handler.setWriter(out);
handler.setEncoding("UTF-8");
assertThat(handler.getEncoding(), is("UTF-8"));
- handler.publish(new ExtLogRecord(Level.INFO, "Hello World", getClass().getName()));
+ handler.publish(new ExtLogRecord(Level.INFO, "Hello World", getClass().getName()));
assertThat(out.toString(), is("Hello World"));
}
-
+
@Test
public void testSetNullEncodingOnOutputStream() throws Exception {
handler = new OutputStreamHandler(NO_FORMATTER);
+ handler.setErrorManager(AssertingErrorManager.of());
handler.setWriter(out);
handler.setEncoding(null);
handler.publish(new ExtLogRecord(Level.INFO, "Hello World", getClass().getName()));
- assertThat(out.toString(), is("Hello World"));
+ assertThat(out.toString(), is("Hello World"));
}
-
-
+
+
}
=====================================
src/test/java/org/jboss/logmanager/handlers/PeriodicRotatingFileHandlerTests.java
=====================================
@@ -29,9 +29,11 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.List;
+import java.util.logging.ErrorManager;
import org.jboss.byteman.contrib.bmunit.BMRule;
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
import org.junit.After;
@@ -59,6 +61,7 @@ public class PeriodicRotatingFileHandlerTests extends AbstractHandlerTest {
handler.setFormatter(FORMATTER);
// Set append to true to ensure the rotated file is overwritten
handler.setAppend(true);
+ handler.setErrorManager(AssertingErrorManager.of());
}
@After
@@ -112,6 +115,7 @@ public class PeriodicRotatingFileHandlerTests extends AbstractHandlerTest {
final int nextDay = currentDay + 1;
// Set to false for this specific test
handler.setAppend(false);
+ handler.setErrorManager(AssertingErrorManager.of(ErrorManager.GENERIC_FAILURE));
final String currentDate = sdf.format(cal.getTime());
=====================================
src/test/java/org/jboss/logmanager/handlers/PeriodicSizeRotatingFileHandlerTests.java
=====================================
@@ -31,9 +31,11 @@ import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.ErrorManager;
import org.jboss.byteman.contrib.bmunit.BMRule;
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtLogRecord;
import org.junit.Assert;
import org.junit.Ignore;
@@ -217,6 +219,7 @@ public class PeriodicSizeRotatingFileHandlerTests extends AbstractHandlerTest {
public void testFailedRotate() throws Exception {
final PeriodicSizeRotatingFileHandler handler = new PeriodicSizeRotatingFileHandler();
configureHandlerDefaults(handler);
+ handler.setErrorManager(AssertingErrorManager.of(ErrorManager.GENERIC_FAILURE));
handler.setRotateSize(1024L);
handler.setMaxBackupIndex(5);
handler.setFile(logFile);
=====================================
src/test/java/org/jboss/logmanager/handlers/QueueHandlerTests.java
=====================================
@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
@@ -38,6 +39,7 @@ public class QueueHandlerTests extends AbstractHandlerTest {
@Test
public void testQueueSize() throws Exception {
final QueueHandler handler = new QueueHandler(5);
+ handler.setErrorManager(AssertingErrorManager.of());
// Log 6 records and ensure only 5 are available
for (int i = 0; i < 6; i++) {
@@ -62,6 +64,7 @@ public class QueueHandlerTests extends AbstractHandlerTest {
nestedHandler.setLevel(Level.INFO);
final QueueHandler handler = new QueueHandler(10);
+ handler.setErrorManager(AssertingErrorManager.of());
handler.setLevel(Level.ERROR);
handler.addHandler(nestedHandler);
@@ -84,6 +87,10 @@ public class QueueHandlerTests extends AbstractHandlerTest {
static class NestedHandler extends ExtHandler {
private final List<ExtLogRecord> records = new ArrayList<ExtLogRecord>();
+ NestedHandler() {
+ setErrorManager(AssertingErrorManager.of());
+ }
+
@Override
protected void doPublish(final ExtLogRecord record) {
records.add(record);
=====================================
src/test/java/org/jboss/logmanager/handlers/SizeRotatingFileHandlerTests.java
=====================================
@@ -26,9 +26,11 @@ import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
+import java.util.logging.ErrorManager;
import org.jboss.byteman.contrib.bmunit.BMRule;
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
+import org.jboss.logmanager.AssertingErrorManager;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -155,6 +157,44 @@ public class SizeRotatingFileHandlerTests extends AbstractHandlerTest {
rotatedFile.delete();
}
+ @Test
+ public void testBootRotateChange() throws Exception {
+ SizeRotatingFileHandler handler = new SizeRotatingFileHandler();
+ configureHandlerDefaults(handler);
+ // Enough to not rotate
+ handler.setRotateSize(5000L);
+ handler.setMaxBackupIndex(1);
+ handler.setFile(logFile);
+ final Path rotatedFile = BASE_LOG_DIR.toPath().resolve(FILENAME + ".1");
+
+ // The rotated file should not exist
+ Assert.assertTrue("Rotated file should not exist", Files.notExists(rotatedFile));
+
+ // Log a few records
+ for (int i = 0; i < 5; i++) {
+ handler.publish(createLogRecord("Test message: %d", i));
+ }
+
+ // Configure the handler to rotate on boot and reset the file
+ handler.setRotateOnBoot(true);
+ handler.setFile(logFile);
+
+ // Log a few records
+ for (int i = 0; i < 10; i++) {
+ handler.publish(createLogRecord("Test message: %d", i));
+ }
+
+ handler.close();
+
+ // File should have been rotated
+ Assert.assertTrue(logFile.exists());
+ Assert.assertTrue(Files.exists(rotatedFile));
+
+ // Neither file should be empty
+ Assert.assertTrue(logFile.length() > 0L);
+ Assert.assertTrue(Files.size(rotatedFile) > 0L);
+ }
+
@Test
public void testArchiveRotateGzip() throws Exception {
testArchiveRotate(".gz", false);
@@ -181,6 +221,7 @@ public class SizeRotatingFileHandlerTests extends AbstractHandlerTest {
public void testFailedRotate() throws Exception {
final SizeRotatingFileHandler handler = new SizeRotatingFileHandler();
configureHandlerDefaults(handler);
+ handler.setErrorManager(AssertingErrorManager.of(ErrorManager.GENERIC_FAILURE));
handler.setRotateSize(1024L);
handler.setMaxBackupIndex(5);
handler.setFile(logFile);
=====================================
src/test/java/org/jboss/logmanager/handlers/SocketHandlerTests.java
=====================================
@@ -5,10 +5,12 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
+import java.util.logging.ErrorManager;
import java.util.logging.Handler;
import javax.net.ssl.SSLContext;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.LogContext;
import org.jboss.logmanager.Logger;
@@ -131,6 +133,7 @@ public class SocketHandlerTests extends AbstractHandlerTest {
@Test
public void testTcpReconnect() throws Exception {
try (SocketHandler handler = createHandler(Protocol.TCP)) {
+ handler.setErrorManager(AssertingErrorManager.of(ErrorManager.FLUSH_FAILURE));
// Publish a record to a running server
try (
@@ -208,6 +211,7 @@ public class SocketHandlerTests extends AbstractHandlerTest {
handler.setAutoFlush(true);
handler.setEncoding("utf-8");
handler.setFormatter(new PatternFormatter("%s\n"));
+ handler.setErrorManager(AssertingErrorManager.of());
return handler;
}
=====================================
src/test/java/org/jboss/logmanager/handlers/SyslogHandlerTests.java
=====================================
@@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.logging.Level;
+import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.formatters.PatternFormatter;
import org.jboss.logmanager.handlers.SyslogHandler.SyslogType;
@@ -49,6 +50,7 @@ public class SyslogHandlerTests {
public void setupHandler() throws Exception {
handler = new SyslogHandler(HOSTNAME, PORT);
handler.setFormatter(new PatternFormatter("%s"));
+ handler.setErrorManager(AssertingErrorManager.of());
}
@After
View it on GitLab: https://salsa.debian.org/java-team/jboss-logmanager/commit/626b699c6fc2c344c073199268d09de2887143d5
--
View it on GitLab: https://salsa.debian.org/java-team/jboss-logmanager/commit/626b699c6fc2c344c073199268d09de2887143d5
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20190811/06daa617/attachment.html>
More information about the pkg-java-commits
mailing list