public function testGetHealthCountsExpiringSnapshot() { $now = \Odesk\Phystrix\microtime() * 1000; // current time in milliseconds // a snapshot created two seconds ago is no longer valid and we expect a new one $snapshot = new HealthCountsSnapshot($now - 2000, 11, 22); // setting it as the last snapshot into metrics $reflection = new \ReflectionClass('Odesk\\Phystrix\\CommandMetrics'); $property = $reflection->getProperty('lastSnapshot'); $property->setAccessible(true); $property->setValue($this->metrics, $snapshot); $this->counter->expects($this->exactly(2))->method('get')->will($this->returnValueMap(array(array(MetricsCounter::FAILURE, 22), array(MetricsCounter::SUCCESS, 33)))); $newSnapshot = $this->metrics->getHealthCounts(); $this->assertNotEquals($snapshot, $newSnapshot); $this->assertEquals(33, $newSnapshot->getSuccessful()); }
protected function getExpectedBucketIndex($bucketNumber) { $timeInMilliseconds = \Odesk\Phystrix\microtime() * 1000; return floor(($timeInMilliseconds - $bucketNumber * 1000) / 1000); }