Updated Branches: refs/heads/trunk 1c7e66dad -> 12609b27d
AMBARI-4150. Provide ability to batch requests based on schedule. Unit tests. (swagle) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/12609b27 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/12609b27 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/12609b27 Branch: refs/heads/trunk Commit: 12609b27d87aca2223f702b5a4abd0541003cdcf Parents: 1c7e66d Author: Siddharth Wagle <[email protected]> Authored: Tue Jan 7 13:17:07 2014 -0800 Committer: Siddharth Wagle <[email protected]> Committed: Tue Jan 7 13:17:07 2014 -0800 ---------------------------------------------------------------------- .../apache/ambari/server/utils/DateUtils.java | 2 +- .../ambari/server/utils/TestDateUtils.java | 68 ++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/12609b27/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java b/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java index 11875ed..add74f9 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java @@ -26,7 +26,7 @@ import java.util.Date; */ public class DateUtils { - public static final String ALLOWED_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + public static final String ALLOWED_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssz"; /** * Milliseconds to readable format in current server timezone http://git-wip-us.apache.org/repos/asf/ambari/blob/12609b27/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java b/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java new file mode 100644 index 0000000..44d7989 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/TestDateUtils.java @@ -0,0 +1,68 @@ +/** + * 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.ambari.server.utils; + +import junit.framework.Assert; +import org.junit.Test; + +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +public class TestDateUtils { + + @Test + public void testConvertToReadableTime() throws Exception { + Long timestamp = 1389125737000L; + String readableTime = DateUtils.convertToReadableTime(timestamp); + Assert.assertEquals("2014-01-07 12:15:37", readableTime); + } + + @Test + public void testConvertToDate() throws Exception { + String time = "2013-11-18T14:29:29-0800"; + Date date = DateUtils.convertToDate(time); + Assert.assertNotNull(date); + Calendar calendar = Calendar.getInstance(); + calendar.setTimeZone(TimeZone.getTimeZone("PST")); + calendar.set(Calendar.YEAR, 2013); + calendar.set(Calendar.MONTH, Calendar.NOVEMBER); + calendar.set(Calendar.DAY_OF_MONTH, 18); + calendar.set(Calendar.HOUR_OF_DAY, 14); + calendar.set(Calendar.MINUTE, 29); + calendar.set(Calendar.SECOND, 29); + calendar.set(Calendar.MILLISECOND, 0); + Assert.assertEquals(0, date.compareTo(calendar.getTime())); + } + + @Test + public void testGetDateDifferenceInMinutes() throws Exception { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, 2013); + calendar.set(Calendar.MONTH, Calendar.NOVEMBER); + calendar.set(Calendar.DAY_OF_MONTH, 18); + calendar.set(Calendar.HOUR_OF_DAY, 14); + calendar.set(Calendar.MINUTE, 49); + calendar.set(Calendar.SECOND, 29); + calendar.set(Calendar.MILLISECOND, 0); + String time = "2013-11-18T14:29:29-0800"; + Date date = DateUtils.convertToDate(time); + Long diff = (Math.abs(date.getTime() - calendar.getTimeInMillis())) / (60 * 1000) % 60; + Assert.assertEquals(Long.valueOf(20L).longValue(), diff.longValue()); + } +}
