This is an automated email from the ASF dual-hosted git repository. gk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/turbine-fulcrum-parser.git
commit 9da401b867a9bc113dc4ffa3182e89db330251a9 Author: Georg Kallidis <[email protected]> AuthorDate: Wed Aug 2 16:54:02 2023 +0200 Use maxWait Duration on pool2, use non deprecated valueOf methods in Numbers, add warning and adjust test settings, if borrowObject is false and maxWaitInMillis is set, add log4j2 test logger configuration. --- pom.xml | 9 ++++ .../org/apache/fulcrum/parser/BaseValueParser.java | 8 ++-- .../fulcrum/parser/DefaultParserService.java | 11 ++++- src/test/TestComponentConfig.xml | 5 ++- src/test/log4j2-test.xml | 50 ++++++++++++++++++++++ .../apache/fulcrum/parser/BaseValueParserTest.java | 38 ++++++++-------- 6 files changed, 94 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index bc339b1..aa4a2e7 100644 --- a/pom.xml +++ b/pom.xml @@ -149,6 +149,15 @@ <build> <sourceDirectory>${basedir}/src/java</sourceDirectory> <testSourceDirectory>${basedir}/src/test</testSourceDirectory> + <testResources> + <testResource> + <directory>${basedir}/src/test</directory> + <includes> + <include>*.java</include> + <include>log4j2*.xml</include> + </includes> + </testResource> + </testResources> </build> <properties> diff --git a/src/java/org/apache/fulcrum/parser/BaseValueParser.java b/src/java/org/apache/fulcrum/parser/BaseValueParser.java index 9107cf8..d8b1aa3 100644 --- a/src/java/org/apache/fulcrum/parser/BaseValueParser.java +++ b/src/java/org/apache/fulcrum/parser/BaseValueParser.java @@ -722,7 +722,7 @@ public class BaseValueParser public Double getDoubleObject(String name, Double defaultValue) { Number result = getNumber(name); - return (result == null ? defaultValue : new Double(result.doubleValue())); + return (result == null ? defaultValue : Double.valueOf(result.doubleValue())); } /** @@ -756,7 +756,7 @@ public class BaseValueParser for (int i = 0; i < value.length; i++) { Number number = parseNumber(value[i]); - result[i] = (number == null ? null : new Double(number.doubleValue())); + result[i] = (number == null ? null : Double.valueOf(number.doubleValue())); } } return result; @@ -826,7 +826,7 @@ public class BaseValueParser public Float getFloatObject(String name, Float defaultValue) { Number result = getNumber(name); - return (result == null ? defaultValue : new Float(result.floatValue())); + return (result == null ? defaultValue : Float.valueOf(result.floatValue())); } /** @@ -860,7 +860,7 @@ public class BaseValueParser for (int i = 0; i < value.length; i++) { Number number = parseNumber(value[i]); - result[i] = (number == null ? null : new Float(number.floatValue())); + result[i] = (number == null ? null : Float.valueOf(number.floatValue())); } } return result; diff --git a/src/java/org/apache/fulcrum/parser/DefaultParserService.java b/src/java/org/apache/fulcrum/parser/DefaultParserService.java index 17a7ebc..4ed7932 100644 --- a/src/java/org/apache/fulcrum/parser/DefaultParserService.java +++ b/src/java/org/apache/fulcrum/parser/DefaultParserService.java @@ -20,6 +20,7 @@ package org.apache.fulcrum.parser; */ import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -471,7 +472,8 @@ public class DefaultParserService break; case "maxWaitMillis": int maxWaitMillis = poolConf.getValueAsInteger(); - genObjPoolConfig.setMaxWaitMillis(maxWaitMillis); + Duration maxWaitMillisDuration = Duration.ofMillis( maxWaitMillis ); + genObjPoolConfig.setMaxWait(maxWaitMillisDuration); break; case "blockWhenExhausted": boolean blockWhenExhausted = poolConf.getValueAsBoolean(); @@ -501,7 +503,12 @@ public class DefaultParserService break; } - } + } + + if (!genObjPoolConfig.getBlockWhenExhausted() && !genObjPoolConfig.getMaxWaitDuration().isZero()) { + getLogger().warn( "maxWaitMillis will only be applied, if blockWhenExhausted is set. maxWait: " + + genObjPoolConfig.getMaxWaitDuration() ); + } // reinit the pools valueParserPool.setConfig(genObjPoolConfig); parameterParserPool.setConfig(genObjPoolConfig); diff --git a/src/test/TestComponentConfig.xml b/src/test/TestComponentConfig.xml index 83ee8a4..b4a3ef0 100644 --- a/src/test/TestComponentConfig.xml +++ b/src/test/TestComponentConfig.xml @@ -24,8 +24,9 @@ <pool2> <!-- cft. defaults in org.apache.commons.pool2.impl.BaseObjectPoolConfig and GenericKeyedObjectPoolConfig --> <maxTotal>2048</maxTotal> - <blockWhenExhausted>false</blockWhenExhausted> - <maxWaitMillis>100</maxWaitMillis> + <!-- if set to false, set maxWaitMillis to (0) zero --> + <blockWhenExhausted>true</blockWhenExhausted> + <maxWaitMillis>500</maxWaitMillis> </pool2> </parser> </componentConfig> diff --git a/src/test/log4j2-test.xml b/src/test/log4j2-test.xml new file mode 100644 index 0000000..897e0eb --- /dev/null +++ b/src/test/log4j2-test.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<Configuration status="trace" verbose="true"> + <Appenders> + <Console name="console" target="SYSTEM_OUT"> + <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/> + </Console> + <File name="logfile" fileName="target/fulcrum-parser-test.log"> + <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/> + </File> + <File name="avalon" fileName="target/avalon-test.log"> + <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/> + </File> + </Appenders> + <Loggers> + <Logger name="org.apache.fulcrum" level="debug" additivity="false"> + <AppenderRef ref="console"/> + <AppenderRef ref="logfile"/> + </Logger> + <Logger name="org.apache.fulcrum.parser" level="debug" additivity="false"> + <AppenderRef ref="avalon"/> + </Logger> + <Logger name="avalon" level="debug" additivity="info"> + <AppenderRef ref="avalon"/> + </Logger> + <Logger name="org.apache.logging.log4j" level="info" additivity="false"> + <AppenderRef ref="logfile"/> + </Logger> + <Root level="error"> + <AppenderRef ref="console"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/src/test/org/apache/fulcrum/parser/BaseValueParserTest.java b/src/test/org/apache/fulcrum/parser/BaseValueParserTest.java index e320cf7..5e5aa6b 100644 --- a/src/test/org/apache/fulcrum/parser/BaseValueParserTest.java +++ b/src/test/org/apache/fulcrum/parser/BaseValueParserTest.java @@ -132,13 +132,13 @@ public class BaseValueParserTest extends BaseUnit5Test assertNull(result); // default - result = parser.getByteObject("default", new Byte((byte)3)); - assertEquals(result, new Byte((byte)3)); + result = parser.getByteObject("default", Byte.valueOf((byte)3)); + assertEquals(result, Byte.valueOf((byte)3)); // param exists parser.add("exists", "1"); result = parser.getByteObject("exists"); - assertEquals(result, new Byte((byte)1)); + assertEquals(result, Byte.valueOf((byte)1)); // unparsable value parser.add("unparsable", "a"); @@ -289,13 +289,13 @@ public class BaseValueParserTest extends BaseUnit5Test assertNull(result); // default - result = parser.getFloatObject("default", new Float(3)); - assertEquals(new Float(3), result); + result = parser.getFloatObject("default", Float.valueOf(3)); + assertEquals(Float.valueOf(3), result); // param exists parser.add("exists", "1"); result = parser.getFloatObject("exists"); - assertEquals(new Float(1), result); + assertEquals(Float.valueOf(1), result); // unparsable value parser.add("unparsable", "a"); @@ -307,7 +307,7 @@ public class BaseValueParserTest extends BaseUnit5Test parser.add("array", "2"); parser.add("array", "3"); Float arrayResult[] = parser.getFloatObjects("array"); - Float compare[] = {new Float(1), new Float(2), new Float(3)}; + Float compare[] = {Float.valueOf(1), Float.valueOf(2), Float.valueOf(3)}; assertEquals(compare.length, arrayResult.length); for( int i=0; i<compare.length; i++) { @@ -319,7 +319,7 @@ public class BaseValueParserTest extends BaseUnit5Test parser.add("array2", "a"); parser.add("array2", "3"); Float arrayResult2[] = parser.getFloatObjects("array2"); - Float compare2[] = {new Float(1), null, new Float(3)}; + Float compare2[] = { Float.valueOf(1), null, Float.valueOf(3)}; assertEquals(compare2.length, arrayResult2.length); for( int i=0; i<compare2.length; i++) { @@ -379,13 +379,13 @@ public class BaseValueParserTest extends BaseUnit5Test assertNull(result); // default - result = parser.getDoubleObject("default", new Double(3)); - assertEquals( new Double(3), result); + result = parser.getDoubleObject("default", Double.valueOf(3)); + assertEquals( Double.valueOf(3), result); // param exists parser.add("exists", "1"); result = parser.getDoubleObject("exists"); - assertEquals( new Double(1), result); + assertEquals( Double.valueOf(1), result); // unparsable value parser.add("unparsable", "a"); @@ -397,7 +397,7 @@ public class BaseValueParserTest extends BaseUnit5Test parser.add("array", "2"); parser.add("array", "3"); Double arrayResult[] = parser.getDoubleObjects("array"); - Double compare[] = {new Double(1), new Double(2), new Double(3)}; + Double compare[] = { Double.valueOf(1), Double.valueOf(2), Double.valueOf(3)}; assertEquals(arrayResult.length, compare.length); for( int i=0; i<compare.length; i++) { @@ -409,7 +409,7 @@ public class BaseValueParserTest extends BaseUnit5Test parser.add("array2", "a"); parser.add("array2", "3"); Double arrayResult2[] = parser.getDoubleObjects("array2"); - Double compare2[] = {new Double(1), null, new Double(3)}; + Double compare2[] = { Double.valueOf(1), null, Double.valueOf(3)}; assertEquals(arrayResult2.length, compare2.length); for( int i=0; i<compare2.length; i++) { @@ -1622,12 +1622,12 @@ public class BaseValueParserTest extends BaseUnit5Test assertEquals( (byte) -127, parser.getByte("foo4"),"Wrong value"); assertEquals( (byte) 100, parser.getByte("foo5"),"Wrong value"); - assertEquals( new Byte((byte) 0), parser.getByteObject("foo0"),"Wrong value"); - assertEquals( new Byte((byte) 127), parser.getByteObject("foo1"),"Wrong value"); - assertEquals( new Byte((byte) -1), parser.getByteObject("foo2"),"Wrong value"); - assertEquals( new Byte((byte) 0), parser.getByteObject("foo3"),"Wrong value"); - assertEquals( new Byte((byte) -127), parser.getByteObject("foo4"),"Wrong value"); - assertEquals( new Byte((byte) 100), parser.getByteObject("foo5"),"Wrong value"); + assertEquals( Byte.valueOf((byte) 0), parser.getByteObject("foo0"),"Wrong value"); + assertEquals( Byte.valueOf((byte) 127), parser.getByteObject("foo1"),"Wrong value"); + assertEquals( Byte.valueOf((byte) -1), parser.getByteObject("foo2"),"Wrong value"); + assertEquals( Byte.valueOf((byte) 0), parser.getByteObject("foo3"),"Wrong value"); + assertEquals( Byte.valueOf((byte) -127), parser.getByteObject("foo4"),"Wrong value"); + assertEquals( Byte.valueOf((byte) 100), parser.getByteObject("foo5"),"Wrong value"); } @Test
