View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.chukwa.database;
19  
20  import junit.framework.TestCase;
21  import java.util.TreeMap;
22  import java.util.ArrayList;
23  import java.util.Date;
24  import java.text.ParseException;
25  import java.text.ParsePosition;
26  import java.text.SimpleDateFormat;
27  
28  public class TestMacro extends TestCase {
29  
30    public void testPastXIntervals() {
31      Macro m = new Macro(1234567890000L, "select '[past_5_minutes]';");
32      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
33      long time = 0;
34      Date result = null;
35      result = format.parse(m.toString(), new ParsePosition(8));
36      time = result.getTime()+300000L;
37      assertTrue(time<=1234567890000L);
38      m = new Macro(1234567890000L, "select '[past_hour]';");
39      result = format.parse(m.toString(), new ParsePosition(8));
40      time = result.getTime()+3600000L;
41      assertTrue(time<=1234567890000L);
42      m = new Macro(1234567890000L, "select '[start]';");
43      result = format.parse(m.toString(), new ParsePosition(8));
44      time = result.getTime();
45      assertTrue(time==1234567890000L);
46    }
47  
48    public void testPartitions() {
49      Macro m = new Macro(1234567890000L, "select from [system_metrics_week];");
50      System.out.println(m.toString());
51      assertTrue(m.toString().intern()=="select from system_metrics_2041_week;".intern());
52      m = new Macro(1234567890000L, "select from [system_metrics_month];");
53      System.out.println(m.toString());
54      assertTrue(m.toString().intern()=="select from system_metrics_476_month;".intern());
55      m = new Macro(1234567890000L, "select from [system_metrics_quarter];");
56      System.out.println(m.toString());
57      assertTrue(m.toString().intern()=="select from system_metrics_156_quarter;".intern());
58      m = new Macro(1234567890000L, "select from [system_metrics_year];");
59      System.out.println(m.toString());
60      assertTrue(m.toString().intern()=="select from system_metrics_39_year;".intern());
61      m = new Macro(1234567890000L, "select from [system_metrics_decade];");
62      System.out.println(m.toString());
63      assertTrue(m.toString().intern()=="select from system_metrics_3_decade;".intern());
64    }
65  
66  }