protected function handleProxy(\Closure $callback) { $toxiproxy = new Toxiproxy(self::httpClientFactory()); $proxy = $toxiproxy->create(self::TEST_NAME, self::TEST_UPSTREAM, self::TEST_LISTEN); $this->assertTrue($proxy instanceof Proxy, "Create proxy was not an instance of Proxy"); $callback($proxy); }
public function testCreate($callback = null) { $toxiproxy = new Toxiproxy(self::httpClientFactory()); $proxy = $toxiproxy->create(self::TEST_NAME, self::TEST_UPSTREAM, self::TEST_LISTEN); $this->assertTrue($proxy instanceof Proxy, "Create proxy was not an instance of Proxy"); if (!is_null($callback)) { $callback($toxiproxy, $proxy); } }
/** * overriding for explicit http mocking */ protected function handleProxy($responses, \Closure $callback) { $responses = array_merge([self::createProxyResponse(self::TEST_NAME, self::TEST_LISTEN, self::TEST_UPSTREAM)], $responses); $httpClient = self::mockHttpClientFactory($responses); $toxiproxy = new Toxiproxy($httpClient); $proxy = $toxiproxy->create(self::TEST_NAME, self::TEST_UPSTREAM, self::TEST_LISTEN); $this->assertTrue($proxy instanceof Proxy, "Create proxy was not an instance of Proxy"); $callback($proxy); }
public function testCreate(array $responses = [], $callback = null) { $responses = array_merge([self::createProxyResponse(self::TEST_NAME, self::TEST_LISTEN, self::TEST_UPSTREAM)], $responses); $toxiproxy = new Toxiproxy(self::mockHttpClientFactory($responses)); $proxy = $toxiproxy->create(self::TEST_NAME, self::TEST_UPSTREAM, self::TEST_LISTEN); $this->assertTrue($proxy instanceof Proxy, "Create proxy was not an instance of Proxy"); if (!is_null($callback)) { $callback($toxiproxy, $proxy); } }
<?php require "./vendor/autoload.php"; use GuzzleHttp\Client as HttpClient; use Ihsw\Toxiproxy\Toxiproxy; $toxiproxy = new Toxiproxy(new HttpClient(["base_url" => "http://127.0.0.1:8474"])); $proxy = $toxiproxy->create("ihsw_example_redis_master", "127.0.0.1:6379"); $proxy->updateDownstream("latency", ["enabled" => true, "latency" => 100, "jitter" => 100]); $listen = $proxy->getListen(); $ip = implode(":", explode(":", $proxy->getListen(), -1)); $port = substr($listen, 1 + strlen($ip)); printf("Listening on IP %s and port %s on behalf of 6379, with latency between 100ms and 200ms, randomly distributed\n", $ip, $port);