-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #720 from smgallo/catch-unknown-resource-code
Improve verification of resource codes
- Loading branch information
Showing
7 changed files
with
312 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
open_xdmod/modules/xdmod/component_tests/lib/ETL/EtlOverseerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<?php | ||
/** | ||
* Test various aspects of the EtlOverseer class. We use an EtlConfiguration with the DummyIngestor | ||
* and DummyAggregator to allow us to pipeline infrastructure outside of the actions themselves. | ||
*/ | ||
|
||
namespace ComponentTests\ETL; | ||
|
||
use Exception; | ||
use CCR\DB; | ||
use ETL\EtlOverseer; | ||
use ETL\Configuration\EtlConfiguration; | ||
use ETL\EtlOverseerOptions; | ||
|
||
/** | ||
* Various tests for the EtlOverseer class. | ||
*/ | ||
|
||
class EtlOverseerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private static $etlConfig = null; | ||
private static $testArtifactInputPath = null; | ||
private static $overseerOptions = null; | ||
|
||
/** | ||
* Set up machinery that we will need for these tests. | ||
* | ||
* @return Nothing | ||
*/ | ||
|
||
public static function setupBeforeClass() | ||
{ | ||
self::$testArtifactInputPath = realpath(BASE_DIR . '/tests/artifacts/xdmod-test-artifacts/xdmod/etlv2/configuration/input/'); | ||
|
||
// Use a pipeline with DummyIngestor and/or DummyAggregator so we can test infrastructure | ||
$configFile = self::$testArtifactInputPath . "/xdmod_etl_config_dummy_actions.json"; | ||
self::$etlConfig = new EtlConfiguration( | ||
$configFile, | ||
self::$testArtifactInputPath, | ||
null, | ||
array('default_module_name' => 'xdmod') | ||
); | ||
self::$etlConfig->initialize(); | ||
|
||
// Explicitly set the resource code map so we don't need to query the database | ||
self::$overseerOptions = new EtlOverseerOptions( | ||
array( | ||
'default-module-name' => 'xdmod', | ||
'process-sections' => array('dummy-actions'), | ||
'resource-code-map' => array( | ||
'resource1' => 1, | ||
'resource2' => 2 | ||
) | ||
) | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Reset values in shared classes. | ||
*/ | ||
|
||
public function setUp() | ||
{ | ||
self::$overseerOptions->setIncludeOnlyResourceCodes(null); | ||
self::$overseerOptions->setIncludeOnlyResourceCodes(null); | ||
} | ||
|
||
|
||
/** | ||
* Test various cases of valid include and exclude resource codes | ||
*/ | ||
|
||
public function testValidResourceCodes() { | ||
|
||
// Single valid resource codes to include | ||
|
||
try { | ||
self::$overseerOptions->setIncludeOnlyResourceCodes('resource1'); | ||
$overseer = new EtlOverseer(self::$overseerOptions); | ||
$overseer->execute(self::$etlConfig); | ||
} catch ( Exception $e ) { | ||
$this->assertTrue(false, $e->getMessage()); | ||
} | ||
|
||
// Array of valid resource codes to include | ||
|
||
try { | ||
self::$overseerOptions->setIncludeOnlyResourceCodes(array('resource1', 'resource2')); | ||
$overseer = new EtlOverseer(self::$overseerOptions); | ||
$overseer->execute(self::$etlConfig); | ||
} catch ( Exception $e ) { | ||
$this->assertTrue(false, $e->getMessage()); | ||
} | ||
|
||
// Single valid resource code to exclude | ||
|
||
try { | ||
self::$overseerOptions->setExcludeResourceCodes('resource1'); | ||
$overseer = new EtlOverseer(self::$overseerOptions); | ||
$overseer->execute(self::$etlConfig); | ||
} catch ( Exception $e ) { | ||
$this->assertTrue(false, $e->getMessage()); | ||
} | ||
|
||
// Array of valid resource codes to exclude | ||
|
||
try { | ||
self::$overseerOptions->setExcludeResourceCodes(array('resource1', 'resource2')); | ||
$overseer = new EtlOverseer(self::$overseerOptions); | ||
$overseer->execute(self::$etlConfig); | ||
} catch ( Exception $e ) { | ||
$this->assertTrue(false, $e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Test various cases of invali include and exclude resource codes | ||
*/ | ||
|
||
public function testInvalidResourceCodes() { | ||
|
||
// Single invalid resource code to include | ||
|
||
$unknownCode = 'unknown101'; | ||
$exceptionThrown = true; | ||
try { | ||
self::$overseerOptions->setIncludeOnlyResourceCodes($unknownCode); | ||
$overseer = new EtlOverseer(self::$overseerOptions); | ||
$overseer->execute(self::$etlConfig); | ||
$exceptionThrown = false; | ||
} catch ( Exception $e ) { | ||
$this->assertContains($unknownCode, $e->getMessage(), "Unknown resource code but did not find expected code '$unknownCode'"); | ||
} | ||
$this->assertTrue($exceptionThrown, "Expected exception to be thrown for unknown resource code '$unknownCode'"); | ||
|
||
|
||
// Array with one invalid resource code to include | ||
|
||
$unknownCode = 'unknown102'; | ||
$exceptionThrown = true; | ||
try { | ||
self::$overseerOptions->setIncludeOnlyResourceCodes(array('resource1',$unknownCode)); | ||
$overseer = new EtlOverseer(self::$overseerOptions); | ||
$overseer->execute(self::$etlConfig); | ||
$exceptionThrown = false; | ||
} catch ( Exception $e ) { | ||
$this->assertContains($unknownCode, $e->getMessage(), "Unknown resource code but did not find expected code '$unknownCode'"); | ||
} | ||
$this->assertTrue($exceptionThrown, "Expected exception to be thrown for unknown resource code '$unknownCode'"); | ||
|
||
// Single invalid resource code to exclude | ||
|
||
$unknownCode = 'unknown101'; | ||
$exceptionThrown = true; | ||
try { | ||
self::$overseerOptions->setExcludeResourceCodes($unknownCode); | ||
$overseer = new EtlOverseer(self::$overseerOptions); | ||
$overseer->execute(self::$etlConfig); | ||
$exceptionThrown = false; | ||
} catch ( Exception $e ) { | ||
$this->assertContains($unknownCode, $e->getMessage(), "Unknown resource code but did not find expected code '$unknownCode'"); | ||
} | ||
$this->assertTrue($exceptionThrown, "Expected exception to be thrown for unknown resource code '$unknownCode'"); | ||
|
||
// Array with one invalid resource code to exclude | ||
|
||
$unknownCode = 'unknown102'; | ||
$exceptionThrown = true; | ||
try { | ||
self::$overseerOptions->setExcludeResourceCodes(array('resource1',$unknownCode)); | ||
$overseer = new EtlOverseer(self::$overseerOptions); | ||
$overseer->execute(self::$etlConfig); | ||
$exceptionThrown = false; | ||
} catch ( Exception $e ) { | ||
$this->assertContains($unknownCode, $e->getMessage(), "Unknown resource code but did not find expected code '$unknownCode'"); | ||
} | ||
$this->assertTrue($exceptionThrown, "Expected exception to be thrown for unknown resource code '$unknownCode'"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...-test-artifacts/xdmod/etlv2/configuration/input/etl_action_defs_8.0.0.d/dummy_action.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"table_definition": [ | ||
{ | ||
"$ref": "${table_definition_dir}/dummy_table.json#/table_definition" | ||
} | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
.../xdmod-test-artifacts/xdmod/etlv2/configuration/input/etl_tables_8.0.0.d/dummy_table.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"table_definition": { | ||
"name": "dummy_table", | ||
"engine": "MyISAM", | ||
"comment": "Use with dummy actions", | ||
"columns": [ | ||
{ | ||
"name": "my_int", | ||
"type": "int", | ||
"nullable": false | ||
}, | ||
{ | ||
"name": "my_varchar8", | ||
"type": "varchar(8)", | ||
"nullable": false | ||
} | ||
] | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
.../xdmod-test-artifacts/xdmod/etlv2/configuration/input/xdmod_etl_config_dummy_actions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"#": "Paths for the various configuraiton and data subdirectories. This is added to the global", | ||
"#": "defaults and actions.", | ||
|
||
"paths": { | ||
"table_definition_dir": "etl_tables_8.0.0.d", | ||
"action_definition_dir": "etl_action_defs_8.0.0.d", | ||
"specs_dir": "etl_specs.d", | ||
"macro_dir": "etl_macros.d", | ||
"sql_dir": "etl_sql.d", | ||
"data_dir": "etl_data.d" | ||
}, | ||
|
||
"defaults": { | ||
|
||
"#": "Global options are lowest priority and applied to all actions", | ||
|
||
"global" : { | ||
"#": "The utility endpoint is used by the etl_overseer script to query resource codes.", | ||
"endpoints": { | ||
"utility": { | ||
"type": "mysql", | ||
"name": "Utility DB", | ||
"config": "datawarehouse", | ||
"schema": "modw" | ||
}, | ||
"source": { | ||
"type": "mysql", | ||
"name": "Utility DB", | ||
"config": "datawarehouse", | ||
"schema": "modw" | ||
}, | ||
"destination": { | ||
"type": "mysql", | ||
"name": "Utility DB", | ||
"config": "datawarehouse", | ||
"schema": "modw" | ||
} | ||
} | ||
}, | ||
|
||
"#": "Options specific to the 'dummy-actions' pipeline", | ||
|
||
"dummy-actions": { | ||
"namespace": "ETL\\Ingestor", | ||
"options_class": "IngestorOptions" | ||
} | ||
|
||
}, | ||
|
||
"dummy-actions": [ | ||
{ | ||
"name": "dummy-ingestor", | ||
"description": "Dummy ingestor for testing general ETL machinery", | ||
"class": "DummyIngestor", | ||
"definition_file": "dummy_action.json" | ||
} | ||
] | ||
|
||
} |