private static RollingFileAppender createFileAppender(String name, String logFile, String maxSizeKey, Map<String, Exception> errors) { RollingFileAppender.Builder builder = RollingFileAppender.newBuilder(); builder.setConfiguration(new NullConfiguration()); builder.withName(name); builder.withLayout(getDetailedLayout()); builder.withFileName(logFile); builder.withFilePattern(logFile); builder.withAppend(true); builder.withImmediateFlush(true); int limit = getLimit(maxSizeKey, errors); if (limit == 0) limit = 900 * 1024 * 1024; // Default in Logging.DEFAULT_MAX_FILE_SIZE builder.withPolicy(SizeBasedTriggeringPolicy.createPolicy(Integer.toString(limit))); return builder.build(); }
@Setup public void setUp() { System.setProperty("log4j2.enable.direct.encoders", "true"); appender = new DemoAppender(GelfLayout.newBuilder() .setConfiguration(new NullConfiguration()) .setHost("host") .setAdditionalFields(ADDITIONAL_FIELDS) .setCompressionType(GelfLayout.CompressionType.OFF) .setCompressionThreshold(0) .setIncludeStacktrace(true) .setIncludeThreadContext(true) .build()); j = 0; }
@Test public void testNanoPatternShortChangesConfigurationNanoClock() { final Configuration config = new NullConfiguration(); assertTrue(config.getNanoClock() instanceof DummyNanoClock); final PatternParser pp = new PatternParser(config, KEY, null); assertTrue(config.getNanoClock() instanceof DummyNanoClock); pp.parse("%m"); assertTrue(config.getNanoClock() instanceof DummyNanoClock); pp.parse("%nano"); // this changes the config clock assertTrue(config.getNanoClock() instanceof SystemNanoClock); }
@Test public void testNanoPatternLongChangesNanoClockFactoryMode() { final Configuration config = new NullConfiguration(); assertTrue(config.getNanoClock() instanceof DummyNanoClock); final PatternParser pp = new PatternParser(config, KEY, null); assertTrue(config.getNanoClock() instanceof DummyNanoClock); pp.parse("%m"); assertTrue(config.getNanoClock() instanceof DummyNanoClock); pp.parse("%N"); assertTrue(config.getNanoClock() instanceof SystemNanoClock); }
@Test public void testNullDefaultValue() throws Exception { final ValidatingPlugin validatingPlugin = (ValidatingPlugin) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNull(validatingPlugin); }
@Test public void testNonNullValue() throws Exception { node.getAttributes().put("name", "foo"); final ValidatingPlugin validatingPlugin = (ValidatingPlugin) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNotNull(validatingPlugin); assertEquals("foo", validatingPlugin.getName()); }
@Test public void testNullDefaultValue() throws Exception { final ValidatingPluginWithGenericBuilder validatingPlugin = (ValidatingPluginWithGenericBuilder) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNull(validatingPlugin); }
@Test public void testNonNullValue() throws Exception { node.getAttributes().put("name", "foo"); final ValidatingPluginWithGenericBuilder validatingPlugin = (ValidatingPluginWithGenericBuilder) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNotNull(validatingPlugin); assertEquals("foo", validatingPlugin.getName()); }
@Test public void testNullDefaultValue() throws Exception { // @formatter:off final ValidatingPluginWithTypedBuilder validatingPlugin = (ValidatingPluginWithTypedBuilder) new PluginBuilder(plugin). withConfiguration(new NullConfiguration()). withConfigurationNode(node).build(); // @formatter:on assertNull(validatingPlugin); }
@Test public void testNonNullValue() throws Exception { node.getAttributes().put("name", "foo"); // @formatter:off final ValidatingPluginWithTypedBuilder validatingPlugin = (ValidatingPluginWithTypedBuilder) new PluginBuilder(plugin). withConfiguration(new NullConfiguration()). withConfigurationNode(node).build(); // @formatter:on assertNotNull(validatingPlugin); assertEquals("foo", validatingPlugin.getName()); }
@Test public void testNullDefaultValue() throws Exception { final PluginWithGenericSubclassFoo1Builder validatingPlugin = (PluginWithGenericSubclassFoo1Builder) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNull(validatingPlugin); }
@Test public void testNonNullValue() throws Exception { node.getAttributes().put("thing", "thing1"); node.getAttributes().put("foo1", "foo1"); final PluginWithGenericSubclassFoo1Builder validatingPlugin = (PluginWithGenericSubclassFoo1Builder) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); assertNotNull(validatingPlugin); assertEquals("thing1", validatingPlugin.getThing()); assertEquals("foo1", validatingPlugin.getFoo1()); }
private HostAndPort buildPlugin() { return (HostAndPort) new PluginBuilder(plugin) .withConfiguration(new NullConfiguration()) .withConfigurationNode(node) .build(); }
@Before public void before() { configuration = new NullConfiguration(); }