Ejemplo n.º 1
0
 public function testRun()
 {
     /* @var CommandRunner $fakeCmdRunner1 */
     $fakeCmdRunner1 = Stub::make('\\AWSCustomMetric\\CommandRunner', ['execute' => function () {
     }, 'getReturnValue' => '56']);
     /* @var CommandRunner $fakeCmdRunner2 */
     $fakeCmdRunner2 = Stub::make('\\AWSCustomMetric\\CommandRunner', ['execute' => function () {
     }, 'getReturnCode' => 0, 'getOutput' => ['MemTotal:        10000 kB', 'MemFree:          2000 kB', 'MemAvailable:     419980 kB', 'Buffers:          1000 kB', 'Cached:           1000 kB', 'SwapCached:            0 kB', 'Active:           526652 kB', 'Inactive:         164928 kB', 'SwapTotal:        10000 kB', 'SwapFree:          9000 kB']]);
     $diObj1 = new DI();
     $diObj1->setCommandRunner($fakeCmdRunner1);
     $diObj2 = new DI();
     $diObj2->setCommandRunner($fakeCmdRunner2);
     $plugin1 = new DiskUsage($diObj1);
     $plugin2 = new MemoryUsage($diObj2);
     $testObj = new Sender('fakekey', 'fakesecret', 'fakeregion', $fakeCmdRunner1, 'testInstance', 'testns');
     $testObj->addPlugin([$plugin1, $plugin2]);
     $testObj->run();
     $actualStr = file_get_contents(rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'cloud_watch_client.txt');
     $exceptedStr = '';
     $exceptedStr .= json_encode($this->tester->getMetricDataArray($plugin1->getMetrics(), 'testInstance', 'testns')) . "\n";
     $exceptedStr .= json_encode($this->tester->getMetricDataArray($plugin2->getMetrics(), 'testInstance', 'testns')) . "\n";
     $this->assertEquals($exceptedStr, $actualStr, 'Sender::run default test failed!');
     $plugin3 = new DiskUsage($diObj1, 'Test/System', '* * * * *');
     $plugin4 = new MemoryUsage($diObj2, 'Test/System', '*/' . (date('i') + 1) . ' * * * *');
     $testObj2 = new Sender('fakekey', 'fakesecret', 'fakeregion', $fakeCmdRunner1, 'testInstance', 'testns');
     $testObj2->addPlugin([$plugin3, $plugin4]);
     $testObj2->run();
     $actualStr = file_get_contents(rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'cloud_watch_client.txt');
     $exceptedStr = '';
     $exceptedStr .= json_encode($this->tester->getMetricDataArray($plugin3->getMetrics(), 'testInstance', 'Test/System')) . "\n";
     $this->assertEquals($exceptedStr, $actualStr, 'Sender::run cron test failed!');
 }
 public function testIsSwapCheckOn()
 {
     $memUsage = new MemoryUsage(new DI());
     $this->assertTrue($memUsage->isSwapCheckOn(), 'MemoryUsage::isSwapCheckOn default true value test failed!');
     $memUsage = new MemoryUsage(new DI());
     $memUsage->setSwapCheckOn(false);
     $this->assertFalse($memUsage->isSwapCheckOn(), 'MemoryUsage::isSwapCheckOn test failed!');
 }