Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 100 lines (91 sloc) 2.235 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<?php
include "ChaosMonkey/Chaos.php";
include "ChaosMonkey/Exception.php";

/**
* Implementation of ChaosMonkey_Chaos that will create the most
* possible havoc to the request
*
* This plugin will NOT decide when in the request to be run, that
* is the work of ChaosMonkey/Monkeys/* classes
*/
class ChaosMonkey_AbsoluteChaos implements ChaosMonkey_Chaos {
    
    /**
* Should the chaos plugin be run?
* Randomly selects every other request to be subject to chaos
*
* @return bool
*/
    public function shouldRun() {
return rand(0, 1);
    }
    
    /**
* Interfere with the current request
*
* Randomly selects a interfereWith* function
*
* @return void
*/
    public function interfere() {
$interfere = array(
"GeneralException",
"ChaosMonkeyException",
"TimeDelay",
"OutputGarbage",
"Die",
"Exit"
);
$key = rand(0, count($interfere) - 1);
$function = "interfereWith" . $interfere[$key];
if(is_callable(array( $this, $function) ) ) {
$this->$function();
}
    }
    
    /**
* Throw a general PHP Exception
*
* @throws Exception
*/
    private function interfereWithGeneralException() {
throw new Exception("Chaos" );
    }
    
    /**
* Throw a ChaosMonkey Exception to see how the rest of the
* application will handle this
*
* @throws ChaosMonkey_Exception
*/
    public function interfereWithChaosMonkeyException() {
throw new ChaosMonkey_Exception( "Chaos" );
    }
    
    /**
* Sleep between 5 and 60 seconds before resuming the request
*
* @return void
*/
    private function interfereWithTimeDelay() {
sleep(rand(5, 60));
    }
    
    /**
* interfere with random output garbage and then
* die()
*
* @return void
*/
    private function interfereWithOutputGarbage() {
$str = str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ',3));
echo $str;
die();
    }
    
    /**
* Interfere with die()
*/
    private function interfereWithDie() {
die();
    }
    
    /**
* Interfere with exit()
*/
    private function interfereWithExit() {
exit();
    }
}
Something went wrong with that request. Please try again.