Beispiel #1
0
 public function testBasics()
 {
     $this->assertSame(\histou\Debug::isEnable(), false);
     \histou\Debug::enable();
     $this->assertSame(\histou\Debug::isEnable(), true);
     $this->assertSame(\histou\Debug::printBoolean(true), "true");
     $this->assertSame(\histou\Debug::printBoolean(false), "false");
     \histou\Debug::add("foo");
     $this->assertSame("#### foo\n", \histou\Debug::getLogAsMarkdown());
     \histou\Debug::add("bar");
     $this->assertSame("#### foo\n#### bar\n", \histou\Debug::getLogAsMarkdown());
 }
Beispiel #2
0
    public function testForecastLoad()
    {
        $files = array(join(DIRECTORY_SEPARATOR, array(FORECAST_TEMPLATE_FOLDER, 'template1.php')) => '<?php
                            $rule = new \\histou\\template\\Rule(
                                $host = ".*",
                                $service = ".*",
                                $command = "NONE",
                                $perfLabel = array("rta", "pl")
                            );
                            $forecast = <<<EOF
[
   {
      "label":"size",
      "method":"SimpleLinearRegression",
      "methodSpecificOptions":{

      },
      "lookback_range":"30m",
      "forecast_range":"10m",
      "forecast_interval":"1m",
      "update_rate":"1m"
   },
   {
      "label":"time",
      "method":"SimpleLinearRegression",
      "methodSpecificOptions":{

      },
      "lookback_range":"30m",
      "forecast_range":"10m",
      "forecast_interval":"1m",
      "update_rate":"1m"
   }
]
EOF;
', join(DIRECTORY_SEPARATOR, array(FORECAST_TEMPLATE_FOLDER, 'template2.php')) => '<?php
                            $rule = new \\histou\\template\\Rule(
                                $host = ".*",
                                $service = ".*",        adsfasdfasdf
                                $command = ".*",
                                $perfLabel = array("rta", "pl")
                            );
                            $forecast = <<<EOF
[
   {
      "label":"size",
      "method":"SimpleLinearRegression",
      "methodSpecificOptions":{

      },
      "lookback_range":"30m",
      "forecast_range":"10m",
      "forecast_interval":"1m",
      "update_rate":"1m"
   },
   {
      "label":"time",
      "method":"SimpleLinearRegression",
      "methodSpecificOptions":{

      },
      "lookback_range":"30m",
      "forecast_range":"10m",
      "forecast_interval":"1m",
      "update_rate":"1m"
   }
]
EOF;
', join(DIRECTORY_SEPARATOR, array(FORECAST_TEMPLATE_FOLDER, 'template3.php')) => '<?php
                            $rule = new \\histou\\template\\Rule(
                                $host = ".*",
                                $service = ".*",
                                $command = ".*",
                                $perfLabel = array("rta", "pl")
                            );
                            $forecast = <<<EOF
[
   {
      "label":"size",
      "method":"SimpleLinearRegression",
      "methodSpecificOptions":{

      },
      "lookback_range":"30m",
      "forecast_range":"20m",
      "forecast_interval":"1m",
      "update_rate":"1m"
   },
   {
      "label":"time",
      "method":"SimpleLinearRegression",
      "methodSpecificOptions":{

      },
      "lookback_range":"30m",
      "forecast_range":"30m",
      "forecast_interval":"1m",
      "update_rate":"1m"
   }
]
EOF;
');
        foreach ($files as $file => $content) {
            file_put_contents($file, $content);
        }
        $templateFiles = \histou\Folder::loadFolders(array(FORECAST_TEMPLATE_FOLDER));
        $expected = array(join(DIRECTORY_SEPARATOR, array(FORECAST_TEMPLATE_FOLDER, 'template1.php')), join(DIRECTORY_SEPARATOR, array(FORECAST_TEMPLATE_FOLDER, 'template2.php')), join(DIRECTORY_SEPARATOR, array(FORECAST_TEMPLATE_FOLDER, 'template3.php')));
        $this->assertEquals(sort($expected), sort($templateFiles));
        $templates = array();
        foreach ($files as $file => $content) {
            array_push($templates, \histou\template\Loader::loadForecastTemplate($file));
        }
        $this->assertInstanceOf('\\histou\\template\\ForecastTemplate', $templates[0]);
        $this->assertInstanceOf('\\histou\\template\\ForecastTemplate', $templates[2]);
        $this->assertSame(null, $templates[1]);
        //Syntaxcheck failed
        $this->assertContains('Parse error: syntax error', \histou\Debug::getLogAsMarkdown());
        $this->assertSame(FORECAST_TEMPLATE_FOLDER, $templates[0]->getPath());
        $this->assertSame('template1.php', $templates[0]->getBaseName());
        $this->assertSame('template1', $templates[0]->getSimpleFileName());
        $this->assertSame("File:\t{$expected['0']}:\nRule:\n\tFile:\t{$expected['0']}:\n\t\tHost: ;.*;\n\t\tService: ;.*;\n\t\tCommand: ;^\$;\n\t\tPerflabel: ;pl;, ;rta;", $templates[0]->__toString());
        $rule = $templates[0]->getRule();
        $this->assertSame('template1.php', $rule->getBaseName());
        $this->assertSame(join(DIRECTORY_SEPARATOR, array(FORECAST_TEMPLATE_FOLDER, 'template1.php')), $rule->getFileName());
        $expected = '[
   {
      "label":"size",
      "method":"SimpleLinearRegression",
      "methodSpecificOptions":{

      },
      "lookback_range":"30m",
      "forecast_range":"10m",
      "forecast_interval":"1m",
      "update_rate":"1m"
   },
   {
      "label":"time",
      "method":"SimpleLinearRegression",
      "methodSpecificOptions":{

      },
      "lookback_range":"30m",
      "forecast_range":"10m",
      "forecast_interval":"1m",
      "update_rate":"1m"
   }
]';
        $this->assertSame($expected, $templates[0]->getJSON());
        $this->assertSame(null, \histou\template\ForecastTemplate::$config);
        $templates[0]->setForecastDurations();
        $this->assertSame(array('size' => array('method' => 'SimpleLinearRegression', 'forecast' => '10m'), 'time' => array('method' => 'SimpleLinearRegression', 'forecast' => '10m')), \histou\template\ForecastTemplate::$config);
        $templates[2]->setForecastDurations();
        $this->assertSame(array('size' => array('method' => 'SimpleLinearRegression', 'forecast' => '20m'), 'time' => array('method' => 'SimpleLinearRegression', 'forecast' => '30m')), \histou\template\ForecastTemplate::$config);
        $default = \histou\template\template::findDefaultTemplate($templates, "template1.php");
        $this->assertSame($templates[0], $default);
        $default2 = \histou\template\template::findDefaultTemplate($templates, "foo.php");
        $this->assertSame(null, $default2);
    }