001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.test; 019 020import org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.hbase.HBaseConfiguration; 022import org.apache.hadoop.hbase.IntegrationTestingUtility; 023import org.apache.hadoop.hbase.chaos.util.ChaosMonkeyRunner; 024import org.apache.hadoop.hbase.chaos.util.Monkeys; 025import org.apache.hadoop.hbase.testclassification.IntegrationTests; 026import org.apache.hadoop.util.ToolRunner; 027import org.junit.Test; 028import org.junit.experimental.categories.Category; 029 030/** 031 * This is an integration test for showing a simple usage of how to use {@link Monkeys} to control 032 * {@link ChaosMonkeyRunner}. 033 */ 034@Category(IntegrationTests.class) 035public class IntegrationTestMonkeys extends ChaosMonkeyRunner { 036 private static final int RUN_SECS = 15 * 1000; 037 private static final int WAIT_SECS = 10 * 1000; 038 039 @Override 040 protected int doWork() throws Exception { 041 super.setUpCluster(); 042 runMonkeys(); 043 return 0; 044 } 045 046 @Test 047 public void runMonkeys() throws Exception { 048 try (Monkeys monkeys = new Monkeys()) { 049 for (int i = 0; i < 2; i++) { 050 monkeys.startChaos(); 051 Thread.sleep(RUN_SECS); 052 monkeys.stopChaos(); 053 Thread.sleep(WAIT_SECS); 054 } 055 } 056 } 057 058 public static void main(String[] args) throws Exception { 059 // Run chaos monkeys 15 seconds, then stop them. 060 // After 10 seconds, run chaos monkeys again. 061 Configuration conf = HBaseConfiguration.create(); 062 IntegrationTestingUtility.setUseDistributedCluster(conf); 063 int exitCode = ToolRunner.run(conf, new IntegrationTestMonkeys(), args); 064 System.exit(exitCode); 065 } 066}