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.extraction.demux.processor.mapper;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.util.ArrayList;
24  import java.util.HashMap;
25  import java.util.Map.Entry;
26  
27  import org.apache.hadoop.chukwa.extraction.demux.processor.mapper.Ps.InvalidPsRecord;
28  import org.apache.hadoop.chukwa.extraction.demux.processor.mapper.Ps.PsOutput;
29  
30  import junit.framework.TestCase;
31  
32  public class TestPsOutput extends TestCase {
33  
34    public void testGetRecordList() throws IOException, InvalidPsRecord {
35      // below is from command
36      // "ps axo pid,user,vsize,size,pcpu,pmem,time,start_time,start,cmd"
37      String output = "  PID USER        VSZ    SZ %CPU %MEM     TIME START  STARTED CMD\n"
38          + "    1 root       2064   284  0.0  0.0 00:00:02  2008   Dec 29 init [5]\n"
39          + "    2 root          0     0  0.0  0.0 00:00:01  2008   Dec 29 [migration/0]\n"
40          + "20270 chzhang    4248   588  0.0  0.0 00:00:00 15:32 15:32:36 ps axo pid,user,vsize,size,pcpu,pmem,time,start_time,start,cmd\n"
41          + "28371 angelac2   7100  1716  0.0  0.0 00:00:00 Feb27   Feb 27 /usr/libexec/gconfd-2 5\n";
42  
43      PsOutput pso = new PsOutput(output);
44      ArrayList<HashMap<String, String>> processes = pso.getProcessList();
45      assertEquals(4, processes.size());
46      assertEquals("Dec29", processes.get(0).get("STARTED"));
47      assertEquals("15:32:36", processes.get(2).get("STARTED"));
48      assertEquals(
49          "ps axo pid,user,vsize,size,pcpu,pmem,time,start_time,start,cmd",
50          processes.get(2).get("CMD"));
51    }
52  
53  }