wuchong commented on a change in pull request #9074: [FLINK-13198][core] Introduce TimeLength in configuration package URL: https://github.com/apache/flink/pull/9074#discussion_r302340591
########## File path: flink-core/src/test/java/org/apache/flink/configuration/TimeLengthTest.java ########## @@ -0,0 +1,200 @@ +/* + * 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. + */ + +package org.apache.flink.configuration; + +import org.apache.flink.core.testutils.CommonTestUtils; + +import org.junit.Test; + +import java.io.IOException; + +import static org.apache.flink.configuration.TimeLength.TimeUnit.MINUTES; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; + +/** + * Tests for the {@link MemorySize} class. + */ +public class TimeLengthTest { + + @Test + public void testUnitConversion() { + final TimeLength zero = new TimeLength(0); + assertEquals(0, zero.getMilliseconds()); + assertEquals(0, zero.getSeconds()); + assertEquals(0, zero.getMinutes()); + assertEquals(0, zero.getHours()); + + final TimeLength ms = new TimeLength(955); + assertEquals(955, ms.getMilliseconds()); + assertEquals(0, ms.getSeconds()); + assertEquals(0, ms.getMinutes()); + assertEquals(0, ms.getHours()); + + final TimeLength secs = new TimeLength(18500); + assertEquals(18500, secs.getMilliseconds()); + assertEquals(18, secs.getSeconds()); + assertEquals(0, secs.getMinutes()); + assertEquals(0, secs.getHours()); + + final TimeLength mins = new TimeLength(60000 + 18500); + assertEquals(60000 + 18500, mins.getMilliseconds()); + assertEquals(60 + 18, mins.getSeconds()); + assertEquals(1, mins.getMinutes()); + assertEquals(0, mins.getHours()); + + final TimeLength hrs = new TimeLength(3600 * 1000 + 999); + assertEquals(3600 * 1000 + 999, hrs.getMilliseconds()); + assertEquals(3600, hrs.getSeconds()); + assertEquals(60, hrs.getMinutes()); + assertEquals(1, hrs.getHours()); + } + + @Test(expected = IllegalArgumentException.class) + public void testInvalid() { + new TimeLength(-1); + } + + @Test + public void testStandardUtils() throws IOException { + final TimeLength ms = new TimeLength(1234567890L); + final TimeLength cloned = CommonTestUtils.createCopySerializable(ms); + + assertEquals(ms, cloned); + assertEquals(ms.hashCode(), cloned.hashCode()); + assertEquals(ms.toString(), cloned.toString()); + } + + @Test + public void testParseMilliseconds() { + assertEquals(1234, TimeLength.parse("1234").getMilliseconds()); + assertEquals(1234, TimeLength.parse("1234ms").getMilliseconds()); + assertEquals(1234, TimeLength.parse("1234 ms").getMilliseconds()); + } + + @Test + public void testParseSeconds() { + assertEquals(667766, TimeLength.parse("667766s").getSeconds()); + assertEquals(667766, TimeLength.parse("667766 s").getSeconds()); + assertEquals(667766, TimeLength.parse("667766s").getSeconds()); Review comment: The same with L94? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
