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.hbase;
20  
21  import org.apache.hadoop.hbase.util.ChaosMonkey;
22  import org.apache.hadoop.hbase.util.ChaosMonkey.BatchRestartRs;
23  import org.apache.hadoop.hbase.util.ChaosMonkey.RestartActiveMaster;
24  import org.apache.hadoop.hbase.util.ChaosMonkey.RestartRandomRs;
25  import org.apache.hadoop.hbase.util.ChaosMonkey.RestartRsHoldingMeta;
26  import org.apache.hadoop.hbase.util.ChaosMonkey.RestartRsHoldingRoot;
27  import org.apache.hadoop.hbase.util.ChaosMonkey.RollingBatchRestartRs;
28  import org.junit.After;
29  import org.junit.Before;
30  import org.junit.Test;
31  import org.junit.experimental.categories.Category;
32  
33  /**
34   * A system test which does large data ingestion and verify using {@link LoadTestTool}.
35   * It performs a set of actions deterministically using ChaosMonkey, then starts killing
36   * things randomly. You can configure how long should the load test run by using 
37   * "hbase.IntegrationTestDataIngestSlowDeterministic.runtime" configuration parameter.
38   */
39  @Category(IntegrationTests.class)
40  public class IntegrationTestDataIngestSlowDeterministic extends IngestIntegrationTestBase {
41    private static final int SERVER_COUNT = 3; // number of slaves for the smallest cluster
42    private static final long DEFAULT_RUN_TIME = 30 * 60 * 1000;
43    private static final long CHAOS_EVERY_MS = 150 * 1000; // Chaos every 2.5 minutes.
44  
45    private ChaosMonkey monkey;
46  
47    @Before
48    public void setUp() throws Exception {
49      super.setUp(SERVER_COUNT);
50      ChaosMonkey.Action[] actions = new ChaosMonkey.Action[] {
51          new RestartRandomRs(60000),
52          new BatchRestartRs(5000, 0.5f),
53          new RestartActiveMaster(5000),
54          new RollingBatchRestartRs(5000, 1.0f),
55          new RestartRsHoldingMeta(35000),
56          new RestartRsHoldingRoot(35000)
57      };
58      monkey = new ChaosMonkey(util, new ChaosMonkey.CompositeSequentialPolicy(
59              new ChaosMonkey.DoActionsOncePolicy(CHAOS_EVERY_MS, actions),
60              new ChaosMonkey.PeriodicRandomActionPolicy(CHAOS_EVERY_MS, actions)));
61      monkey.start();
62    }
63  
64    @After
65    public void tearDown() throws Exception {
66      if (monkey != null) {
67        monkey.stop("tearDown");
68        monkey.waitForStop();
69      }
70      super.tearDown();
71    }
72  
73    @Test
74    public void testDataIngest() throws Exception {
75      runIngestTest(DEFAULT_RUN_TIME, 2500, 10, 100, 5);
76    }
77  }