/**
* 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.flume.tools;
import java.util.Calendar;
import junit.framework.Assert;
import org.junit.Test;
public class TestTimestampRoundDownUtil {
@Test
public void testRoundDownTimeStampSeconds() {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2012, 5, 15, 15, 12, 54);
cal.set(Calendar.MILLISECOND, 20);
Calendar cal2 = Calendar.getInstance();
cal2.clear();
cal2.set(2012, 5, 15, 15, 12, 0);
cal2.set(Calendar.MILLISECOND, 0);
long timeToVerify = cal2.getTimeInMillis();
long ret = TimestampRoundDownUtil.
roundDownTimeStampSeconds(cal.getTimeInMillis(), 60);
System.out.println("Cal 1: " + cal.toString());
System.out.println("Cal 2: " + cal2.toString());
Assert.assertEquals(timeToVerify, ret);
}
@Test
public void testRoundDownTimeStampMinutes() {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2012, 5, 15, 15, 12, 54);
cal.set(Calendar.MILLISECOND, 20);
Calendar cal2 = Calendar.getInstance();
cal2.clear();
cal2.set(2012, 5, 15, 15, 10, 0);
cal2.set(Calendar.MILLISECOND, 0);
long timeToVerify = cal2.getTimeInMillis();
long ret = TimestampRoundDownUtil.
roundDownTimeStampMinutes(cal.getTimeInMillis(), 5);
System.out.println("Cal 1: " + cal.toString());
System.out.println("Cal 2: " + cal2.toString());
Assert.assertEquals(timeToVerify, ret);
}
@Test
public void testRoundDownTimeStampHours() {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2012, 5, 15, 15, 12, 54);
cal.set(Calendar.MILLISECOND, 20);
Calendar cal2 = Calendar.getInstance();
cal2.clear();
cal2.set(2012, 5, 15, 14, 0, 0);
cal2.set(Calendar.MILLISECOND, 0);
long timeToVerify = cal2.getTimeInMillis();
long ret = TimestampRoundDownUtil.
roundDownTimeStampHours(cal.getTimeInMillis(), 2);
System.out.println("Cal 1: " + ret);
System.out.println("Cal 2: " + cal2.toString());
Assert.assertEquals(timeToVerify, ret);
}
}