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); }
/** * 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); }
<?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"])); $proxies = array_filter($toxiproxy->all(), function ($proxy) { return strlen($proxy->getName()) > 0; }); foreach ($proxies as $proxy) { $toxiproxy->delete($proxy); }
<?php require "./vendor/autoload.php"; use GuzzleHttp\Client as HttpClient; use Ihsw\Toxiproxy\Toxiproxy; // hooking up to toxiproxy and starting a bandwidth proxy $toxiproxy = new Toxiproxy(new HttpClient(["base_url" => "http://127.0.0.1:8474"])); $proxies = $toxiproxy->all(); if (count($proxies) === 0) { printf("no proxies found\n"); return; } foreach ($proxies as $proxy) { printf("%s\n", $proxy->getName()); }
public function testGetNonexist() { $toxiproxy = new Toxiproxy(self::httpClientFactory()); $proxy = $toxiproxy->get(self::NONEXISTENT_TEST_NAME); $this->assertNull($proxy, sprintf("Non-existent proxy was not null", self::NONEXISTENT_TEST_NAME)); }
<?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);
public function testGetNonexist() { $toxiproxy = new Toxiproxy(self::mockHttpClientFactory([self::getNonexistentProxyResponse(self::NONEXISTENT_TEST_NAME)])); $proxy = $toxiproxy->get(self::NONEXISTENT_TEST_NAME); $this->assertNull($proxy, "Non-existent proxy was expected to be null, was not null"); }