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.datacollection.connector;
20  
21  
22  import java.io.File;
23  import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
24  import org.apache.hadoop.chukwa.datacollection.agent.ChukwaAgent;
25  import org.apache.hadoop.chukwa.datacollection.connector.http.HttpConnector;
26  import org.apache.hadoop.chukwa.datacollection.controller.ChukwaAgentController;
27  import org.apache.hadoop.chukwa.util.TempFileUtil;
28  import junit.framework.TestCase;
29  
30  public class TestFailedCollector extends TestCase {
31  
32    public void testFailedCollector() {
33      try {
34        ChukwaAgent agent = new ChukwaAgent();
35        boolean failed = false;
36        HttpConnector connector = new HttpConnector(agent,
37            "http://localhost:1234/chukwa");
38        connector.start();
39  
40        ChukwaConfiguration cc = new ChukwaConfiguration();
41        int portno = cc.getInt("chukwaAgent.control.port", 9093);
42        ChukwaAgentController cli = new ChukwaAgentController("localhost", portno);
43  
44        File tmpOutput = TempFileUtil.makeBinary(2000);
45  
46        cli.addFile("unknown", tmpOutput.getAbsolutePath());
47        System.out.println("have " + agent.adaptorCount() + " running adaptors");
48        cli.removeFile("unknown", tmpOutput.getAbsolutePath());
49  
50        tmpOutput.delete();
51        assertFalse(failed);
52        System.out.println("done");
53        agent.shutdown();
54        connector.shutdown();
55        Thread.sleep(2000);
56      } catch (Exception e) {
57        e.printStackTrace();
58      }
59    }
60  
61  }