changeset 397:827d48b75dd5

TimeValue.fromString() should accept HOURS.
author shade
date Fri, 14 Feb 2014 15:49:52 +0400
parents ea56528a6677
children 0801825c8b52
files jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/TimeValue.java jmh-core/src/test/java/org/openjdk/jmh/runner/parameters/TimeValueTest.java
diffstat 2 files changed, 86 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/TimeValue.java	Thu Feb 13 00:52:34 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/parameters/TimeValue.java	Fri Feb 14 15:49:52 2014 +0400
@@ -171,6 +171,9 @@
         if (timeString.contains("m")) {
             return new TimeValue(Integer.parseInt(timeString.substring(0, timeString.indexOf("m"))), TimeUnit.MINUTES);
         }
+        if (timeString.contains("hr")) {
+            return new TimeValue(Integer.parseInt(timeString.substring(0, timeString.indexOf("hr"))), TimeUnit.HOURS);
+        }
         if (timeString.contains("day")) {
             return new TimeValue(Integer.parseInt(timeString.substring(0, timeString.indexOf("day"))), TimeUnit.DAYS);
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/test/java/org/openjdk/jmh/runner/parameters/TimeValueTest.java	Fri Feb 14 15:49:52 2014 +0400
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.runner.parameters;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+import java.util.concurrent.TimeUnit;
+
+public class TimeValueTest {
+
+    @Test
+    public void testNano() {
+        TimeValue v = TimeValue.fromString(TimeValue.nanoseconds(10).toString());
+        Assert.assertEquals(TimeUnit.NANOSECONDS, v.getTimeUnit());
+        Assert.assertEquals(10, v.getTime());
+    }
+
+    @Test
+    public void testMicro() {
+        TimeValue v = TimeValue.fromString(TimeValue.microseconds(10).toString());
+        Assert.assertEquals(TimeUnit.MICROSECONDS, v.getTimeUnit());
+        Assert.assertEquals(10, v.getTime());
+    }
+
+    @Test
+    public void testMilli() {
+        TimeValue v = TimeValue.fromString(TimeValue.milliseconds(10).toString());
+        Assert.assertEquals(TimeUnit.MILLISECONDS, v.getTimeUnit());
+        Assert.assertEquals(10, v.getTime());
+    }
+
+    @Test
+    public void testSeconds() {
+        TimeValue v = TimeValue.fromString(TimeValue.seconds(10).toString());
+        Assert.assertEquals(TimeUnit.SECONDS, v.getTimeUnit());
+        Assert.assertEquals(10, v.getTime());
+    }
+
+    @Test
+    public void testMinutes() {
+        TimeValue v = TimeValue.fromString(TimeValue.minutes(10).toString());
+        Assert.assertEquals(TimeUnit.MINUTES, v.getTimeUnit());
+        Assert.assertEquals(10, v.getTime());
+    }
+
+    @Test
+    public void testHours() {
+        TimeValue v = TimeValue.fromString(TimeValue.hours(10).toString());
+        Assert.assertEquals(TimeUnit.HOURS, v.getTimeUnit());
+        Assert.assertEquals(10, v.getTime());
+    }
+
+    @Test
+    public void testDays() {
+        TimeValue v = TimeValue.fromString(TimeValue.days(10).toString());
+        Assert.assertEquals(TimeUnit.DAYS, v.getTimeUnit());
+        Assert.assertEquals(10, v.getTime());
+    }
+
+}