Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when processing job summaries that are marked as error. #38

Merged
merged 2 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions classes/DataWarehouse/Query/SUPREMM/JobMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ private function arrayMergeRecursiveWildcard(array $array1, array $array2)
if (is_array($value) && array_key_exists('*', $value)) {
if (isset($merged[$key]) && is_array($merged[$key])) {
foreach ($merged[$key] as $mkey => $mvalue) {
if ($mkey === "error") {
break;
}
$merged[$key][$mkey] = $this->arrayMergeRecursiveWildcard($mvalue, $value['*']);
}
}
Expand Down
18 changes: 3 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,8 @@
}
},
{
"type": "package",
"package": {
"name": "ubccr/xdmod-test-artifacts",
"version": "master",
"dist": {
"url": "https://github.com/ubccr/xdmod-test-artifacts/archive/master.zip",
"type": "zip",
"reference": "master"
},
"autoload": {
"classmap": ["."]
}
}

"type": "vcs",
"url": "https://github.com/ubccr/xdmod-test-artifacts.git"
}
],
"extra": {
Expand All @@ -54,7 +42,7 @@
}
},
"require-dev": {
"ubccr/xdmod-test-artifacts": "dev-master",
"ubccr/xdmod-test-artifacts": "@dev",
"squizlabs/php_codesniffer": "2.8.0"
}
}
26 changes: 16 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion tests/unit_tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function ($className) use ($dir) {
$classPath
= $dir
. '/lib/'
. str_replace('_', '/', $className)
. str_replace('\\', '/', $className)
. '.php';

if (is_readable($classPath)) {
Expand Down Expand Up @@ -36,5 +36,22 @@ function ($className) use ($dir) {
}
);

// Autoloader for XDMoD test classes
spl_autoload_register(
function ($className) use ($dir) {
$classPath
= __DIR__ . '/../../../xdmod/open_xdmod/modules/xdmod/tests/lib/'
. str_replace('\\', '/', $className)
. '.php';

if (is_readable($classPath)) {
return require_once $classPath;
} else {
return false;
}
}
);


// Autoloader for XDMoD classes.
require_once __DIR__ . '/../../../xdmod/configuration/linker.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace DataWarehouse\Query\SUPREMM;

class JobMetadataTest extends \PHPUnit_Framework_TestCase
{
const TEST_ARTIFACT_PATH = "../../vendor/ubccr/xdmod-test-artifacts/xdmod-supremm/summaries/";

/**
* @dataProvider arrayMergeTestdata
*/
public function testArrayMerge($left, $right, $expected)
{
$jobmd = new \TestHelpers\mock\JobMetadataWorkaround();

$arrayMergeFn = \TestHelpers\TestHelper::unlockMethod($jobmd, 'arrayMergeRecursiveWildcard');
$result = $arrayMergeFn->invoke($jobmd, $left, $right);

$this->assertEquals($expected, $result);
}

public function arrayMergeTestdata()
{
$output = array();

$left = array(
"one" => array("data" => 1),
"two" => array("data" => 2),
"three" => array("data" => 3)
);

$right = array(
"one" => array("doc" => 1),
"two" => array("doc" => 2),
"three" => array("doc" => 3)
);

$expected = array(
"one" => array("data" => 1, "doc" => 1),
"two" => array("data" => 2, "doc" => 2),
"three" => array("data" => 3, "doc" => 3)
);

$output[] = array($left, $right, $expected);

$left = array(
"metric" => array(
"device1" => array("data" => 1),
"device2" => array("data" => 2)
)
);

$right = array(
"metric" => array(
"*" => array("doc" => 1)
)
);

$expected = array(
"metric" => array(
"device1" => array("data" => 1, "doc" => 1),
"device2" => array("data" => 2, "doc" => 1)
)
);

$output[] = array($left, $right, $expected);

$left = json_decode(file_get_contents(self::TEST_ARTIFACT_PATH . '4824787-1451650405-gpu.json'), true);

$schema = json_decode(file_get_contents(self::TEST_ARTIFACT_PATH . 'summary-1.0.7-gpu.json'), true);
$right = $schema['definitions'];
$expected = $left;

$output[] = array($left, $right, $expected);

return $output;

}
}
12 changes: 12 additions & 0 deletions tests/unit_tests/lib/TestHelpers/mock/JobMetadataWorkaround.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace TestHelpers\mock;

/* Unfortunately, the JobMetadata class was not designed to be testable
* so this workaround is a necessary evil.
*/
class JobMetadataWorkaround extends \DataWarehouse\Query\SUPREMM\JobMetadata
{
public function __construct() {
}
}