Zend_Service_Amazon_Ec2_CloudWatch = new Zend_Service_Amazon_Ec2_CloudWatch('access_key', 'secret_access_key');
$adapter = new Zend_Http_Client_Adapter_Test();
$client = new Zend_Http_Client(null, array(
'adapter' => $adapter
));
$this->adapter = $adapter;
Zend_Service_Amazon_Ec2_CloudWatch::setHttpClient($client);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
unset($this->adapter);
$this->Zend_Service_Amazon_Ec2_CloudWatch = null;
parent::tearDown();
}
/**
* Tests Zend_Service_Amazon_Ec2_CloudWatch->getMetricStatistics()
*/
public function testGetMetricStatistics()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
."\r\n"
." \r\n"
." \r\n"
." \r\n"
." 2009-06-16T23:57:00Z\r\n"
." Bytes\r\n"
." 1.0\r\n"
." 14838.0\r\n"
." \r\n"
." \r\n"
." 2009-06-17T00:16:00Z\r\n"
." Bytes\r\n"
." 1.0\r\n"
." 18251.0\r\n"
." \r\n"
." \r\n"
." "
." \r\n"
."\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_CloudWatch->getMetricStatistics(array('MeasureName' => 'NetworkIn', 'Statistics' => array('Average')));
$arrReturn = array(
'label' => 'NetworkIn',
'datapoints' => array(
array(
'Timestamp' => '2009-06-16T23:57:00Z',
'Unit' => 'Bytes',
'Samples' => '1.0',
'Average' => '14838.0',
),
array(
'Timestamp' => '2009-06-17T00:16:00Z',
'Unit' => 'Bytes',
'Samples' => '1.0',
'Average' => '18251.0',
)
)
);
$this->assertSame($arrReturn, $return);
}
/**
* Tests Zend_Service_Amazon_Ec2_CloudWatch->listMetrics()
*/
public function testListMetrics()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
."\r\n"
." \r\n"
." \r\n"
." \r\n"
." \r\n"
." \r\n"
." InstanceId\r\n"
." i-bec576d7\r\n"
." \r\n"
." \r\n"
." NetworkIn\r\n"
." AWS/EC2\r\n"
." \r\n"
." \r\n"
." \r\n"
." \r\n"
." InstanceId\r\n"
." i-bec576d7\r\n"
." \r\n"
." \r\n"
." CPUUtilization\r\n"
." AWS/EC2\r\n"
." \r\n"
." \r\n"
." \r\n"
." NetworkIn\r\n"
." AWS/EC2\r\n"
." \r\n"
." \r\n"
." \r\n"
."\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_CloudWatch->listMetrics();
$arrReturn = array(
array(
'MeasureName' => 'NetworkIn',
'Namespace' => 'AWS/EC2',
'Deminsions' => array(
'name' => 'InstanceId',
'value' => 'i-bec576d7'
)
),
array(
'MeasureName' => 'CPUUtilization',
'Namespace' => 'AWS/EC2',
'Deminsions' => array(
'name' => 'InstanceId',
'value' => 'i-bec576d7'
)
),
array(
'MeasureName' => 'NetworkIn',
'Namespace' => 'AWS/EC2',
'Deminsions' => array()
)
);
$this->assertSame($arrReturn, $return);
}
}