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  
19  package org.apache.hadoop.chukwa.inputtools.hdfsusage;
20  
21  import java.util.Map.Entry;
22  
23  import org.apache.hadoop.chukwa.inputtools.hdfsusage.HDFSUsageMetrics;
24  import org.apache.hadoop.chukwa.inputtools.hdfsusage.HDFSUsagePlugin;
25  import org.apache.hadoop.chukwa.inputtools.jplugin.ChukwaMetrics;
26  import org.apache.hadoop.chukwa.inputtools.jplugin.ChukwaMetricsList;
27  import org.apache.hadoop.chukwa.inputtools.jplugin.GenericChukwaMetricsList;
28  
29  import junit.framework.TestCase;
30  
31  public class HDFSUsagePluginTest extends TestCase {
32  
33    public void testGetMetrics() throws Throwable {
34      HDFSUsagePlugin plugin = new HDFSUsagePlugin();
35      plugin.init(new String[0]);
36      ChukwaMetricsList<HDFSUsageMetrics> list = plugin.getMetrics();
37      System.out.println(list.getTimestamp());
38      for (ChukwaMetrics metrics : list.getMetricsList()) {
39        HDFSUsageMetrics usage = (HDFSUsageMetrics) metrics;
40        System.out.print(usage.getName());
41        System.out.println("size: " + usage.getSize());
42      }
43      System.out.println();
44  
45      String xml = list.toXml();
46      System.out.println(xml);
47  
48      GenericChukwaMetricsList gene = new GenericChukwaMetricsList(xml);
49      System.out.println(list.getTimestamp());
50      for (ChukwaMetrics metrics : gene.getMetricsList()) {
51        System.out.print(metrics.getKey());
52        for (Entry<String, String> entry : metrics.getAttributes().entrySet()) {
53          System.out.println(entry.getKey() + ": " + entry.getValue());
54        }
55      }
56      System.out.println();
57    }
58  
59  }