From 0238d7ac079b405bcce4546880d662a9906f2be8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 14 Mar 2011 20:39:55 +0000 Subject: [PATCH] Generator/helper class for generating test units introduced: - There is currently a loop in the cruncher class which is not recommended but maybe fine here --- .gitattributes | 7 +++ application/hub/config.php | 10 +++- .../hub/interfaces/work_units/.htaccess | 1 + .../work_units/class_UnitHelper.php | 34 +++++++++++ .../main/cruncher/class_BaseHubCruncher.php | 2 +- .../mcrypt/class_HubMcryptCruncher.php | 18 +++++- .../hub/main/helper/work_units/.htaccess | 1 + application/hub/main/helper/work_units/class_ | 60 +++++++++++++++++++ .../work_units/class_BaseWorkUnitHelper.php | 38 ++++++++++++ .../main/helper/work_units/cruncher/.htaccess | 1 + .../cruncher/class_CruncherTestUnitHelper.php | 60 +++++++++++++++++++ docs/TODOs.txt | 7 ++- 12 files changed, 232 insertions(+), 7 deletions(-) create mode 100644 application/hub/interfaces/work_units/.htaccess create mode 100644 application/hub/interfaces/work_units/class_UnitHelper.php create mode 100644 application/hub/main/helper/work_units/.htaccess create mode 100644 application/hub/main/helper/work_units/class_ create mode 100644 application/hub/main/helper/work_units/class_BaseWorkUnitHelper.php create mode 100644 application/hub/main/helper/work_units/cruncher/.htaccess create mode 100644 application/hub/main/helper/work_units/cruncher/class_CruncherTestUnitHelper.php diff --git a/.gitattributes b/.gitattributes index a612fca3a..b0c18b781 100644 --- a/.gitattributes +++ b/.gitattributes @@ -107,6 +107,8 @@ application/hub/interfaces/visitor/queue/.htaccess svneol=native#text/plain application/hub/interfaces/visitor/queue/class_QueueVisitor.php svneol=native#text/plain application/hub/interfaces/visitor/tasks/.htaccess -text svneol=unset#text/plain application/hub/interfaces/visitor/tasks/class_TaskVisitor.php -text svneol=unset#text/plain +application/hub/interfaces/work_units/.htaccess svneol=native#text/plain +application/hub/interfaces/work_units/class_UnitHelper.php svneol=native#text/plain application/hub/loader.php -text svneol=unset#text/plain application/hub/main/.htaccess -text svneol=unset#text/plain application/hub/main/class_ -text svneol=unset#text/plain @@ -264,6 +266,11 @@ application/hub/main/helper/hub/class_ -text svneol=unset#text/plain application/hub/main/helper/hub/class_BaseHubHelper.php -text svneol=unset#text/plain application/hub/main/helper/hub/connection/.htaccess -text svneol=unset#text/plain application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php svneol=native#text/plain +application/hub/main/helper/work_units/.htaccess svneol=native#text/plain +application/hub/main/helper/work_units/class_ -text +application/hub/main/helper/work_units/class_BaseWorkUnitHelper.php svneol=native#text/plain +application/hub/main/helper/work_units/cruncher/.htaccess svneol=native#text/plain +application/hub/main/helper/work_units/cruncher/class_CruncherTestUnitHelper.php svneol=native#text/plain application/hub/main/iterator/.htaccess -text svneol=unset#text/plain application/hub/main/iterator/class_ -text svneol=unset#text/plain application/hub/main/iterator/class_BaseIterator.php -text svneol=unset#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index 8d69b82e4..4de98c873 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -510,11 +510,17 @@ $cfg->setConfigEntry('external_ip', ''); // CFG: PACKAGE-FRAGMENTER-CLASS $cfg->setConfigEntry('package_fragmenter_class', 'PackageFragmenter'); -// CFG: CRUNCHER-ALLOW-TEST-WORK-UNITS -$cfg->setConfigEntry('cruncher_allow_test_units', 'Y'); +// CFG: CRUNCHER-TEST-UNITS-ENABLED +$cfg->setConfigEntry('cruncher_test_units_enabled', 'Y'); // CFG: CRUNCHER-IN-BUFFER-MIN-THRESHOLD $cfg->setConfigEntry('cruncher_in_buffer_min_threshold', 3); +// CFG: CRUNCHER-TEST-UNIT-GENERATOR-CLASS +$cfg->setConfigEntry('cruncher_test_unit_generator_class', 'CruncherTestUnitHelper'); + +// CFG: CRUNCHER-MAX-TEST-UNIT-AMOUNT +$cfg->setConfigEntry('cruncher_max_text_unit_amount', 10); + // [EOF] ?> diff --git a/application/hub/interfaces/work_units/.htaccess b/application/hub/interfaces/work_units/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/work_units/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/work_units/class_UnitHelper.php b/application/hub/interfaces/work_units/class_UnitHelper.php new file mode 100644 index 000000000..cada8ebc6 --- /dev/null +++ b/application/hub/interfaces/work_units/class_UnitHelper.php @@ -0,0 +1,34 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface UnitHelper extends FrameworkInterface { + /** + * Generates a work/test/foo unit instance + * + * @return $unitInstance A work unit instance + */ + function generateUnit (); +} + +// [EOF] +?> diff --git a/application/hub/main/cruncher/class_BaseHubCruncher.php b/application/hub/main/cruncher/class_BaseHubCruncher.php index 8a353d010..5e09d9e38 100644 --- a/application/hub/main/cruncher/class_BaseHubCruncher.php +++ b/application/hub/main/cruncher/class_BaseHubCruncher.php @@ -137,7 +137,7 @@ class BaseHubCruncher extends BaseHubSystem implements Updateable { $this->fillInBufferQueueWithWorkUnits(); // Is the buffer still not filled and are test-packages allowed? - if ((!$this->isInBufferQueueFilled()) && ($this->getConfigInstance()->getConfigEntry('cruncher_allow_test_units') == 'Y')) { + if ((!$this->isInBufferQueueFilled()) && ($this->getConfigInstance()->getConfigEntry('cruncher_test_units_enabled') == 'Y')) { // Then fill the in-buffer with (one) test-unit(s) $this->fillInBufferQueueWithTestUnits(); } // END - if diff --git a/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php b/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php index dd0c874f6..35e5dda0a 100644 --- a/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php +++ b/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php @@ -60,7 +60,23 @@ class HubMcryptCruncher extends BaseHubCruncher implements CruncherHelper, Regis * @return void */ protected function fillInBufferQueueWithTestUnits () { - $this->partialStub('Please implement this method.'); + // Are test units enabled? + if ($this->getConfigInstance()->getConfigEntry('cruncher_test_units_enabled') == 'N') { + // They are disabled, so skip any further steps + return; + } // END - if + + // Get a test-unit generator instance + $generatorInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_generator_class'); + + // We don't need an iterator here because we just need to generate some test units + for ($idx = 0; $idx < $this->getConfigInstance()->getConfigEntry('cruncher_max_text_unit_amount'); $idx++) { + // Get a test unit from it + $unitInstance = $generatorInstance->generateUnit(); + + // ... and finally queue it to the in-buffer queue + $this->queueUnitInstanceToInBuffer($unitInstance); + } // END - for } /** diff --git a/application/hub/main/helper/work_units/.htaccess b/application/hub/main/helper/work_units/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/helper/work_units/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/helper/work_units/class_ b/application/hub/main/helper/work_units/class_ new file mode 100644 index 000000000..1c6100e58 --- /dev/null +++ b/application/hub/main/helper/work_units/class_ @@ -0,0 +1,60 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class ???WorkUnitHelper extends BaseWorkUnitHelper implements UnitHelper { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $unitInstance An instance of a UnitHelper class + */ + public final static function create???WorkUnitHelper () { + // Get new instance + $unitInstance = new ???WorkUnitHelper(); + + // Return the prepared instance + return $unitInstance; + } + + /** + * Generates a work/test/foo unit instance + * + * @return $unitInstance A work unit instance + * @todo 0% done + */ + public function generateUnit () { + $this->partialStub('Please implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/helper/work_units/class_BaseWorkUnitHelper.php b/application/hub/main/helper/work_units/class_BaseWorkUnitHelper.php new file mode 100644 index 000000000..22811cb9d --- /dev/null +++ b/application/hub/main/helper/work_units/class_BaseWorkUnitHelper.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class BaseWorkUnitHelper extends BaseFrameworkSystem { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/hub/main/helper/work_units/cruncher/.htaccess b/application/hub/main/helper/work_units/cruncher/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/helper/work_units/cruncher/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/helper/work_units/cruncher/class_CruncherTestUnitHelper.php b/application/hub/main/helper/work_units/cruncher/class_CruncherTestUnitHelper.php new file mode 100644 index 000000000..1096f082d --- /dev/null +++ b/application/hub/main/helper/work_units/cruncher/class_CruncherTestUnitHelper.php @@ -0,0 +1,60 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class CruncherTestUnitHelper extends BaseWorkUnitHelper implements UnitHelper { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $unitInstance An instance of a UnitHelper class + */ + public final static function createCruncherTestUnitHelper () { + // Get new instance + $unitInstance = new CruncherTestUnitHelper(); + + // Return the prepared instance + return $unitInstance; + } + + /** + * Generates a work/test/foo unit instance + * + * @return $unitInstance A work unit instance + * @todo 0% done + */ + public function generateUnit () { + $this->partialStub('Please implement this method.'); + } +} + +// [EOF] +?> diff --git a/docs/TODOs.txt b/docs/TODOs.txt index 3b0fc8c74..f1ebd40ee 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -9,9 +9,9 @@ ./application/hub/main/connectors/query/local/class_LocalQueryConnector.php:10: * @todo Find an interface for: handleAllQueries() ./application/hub/main/connectors/query/local/class_LocalQueryConnector.php:78: * @TODO 0% done: Unfinished work here ./application/hub/main/connectors/queues/local/class_LocalQueueConnector.php:58: * @TODO 0% done: Unfinished work here -./application/hub/main/cruncher/class_BaseHubCruncher.php:131: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem -./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:112: * @todo 0% done -./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:61: * @todo Implement this method +./application/hub/main/cruncher/class_BaseHubCruncher.php:154: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem +./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:128: * @todo 0% done +./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:98: * @todo Implement this method ./application/hub/main/discovery/socket/class_PackageSocketDiscovery.php:102: // @TODO We may need some locking here ./application/hub/main/factories/socket/class_SocketFactory.php:10: * @todo Find an interface for hub helper ./application/hub/main/filter/activation/node/class_NodeActivationSelfAnnouncementFilter.php:54: * @todo 0% done @@ -39,6 +39,7 @@ ./application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php:10: * @todo Find an interface for hub helper ./application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php:65: * @todo Rewrite the ->renderXmlContent() call to no arguments ./application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php:10: * @todo Find an interface for hub helper +./application/hub/main/helper/work_units/cruncher/class_CruncherTestUnitHelper.php:52: * @todo 0% done ./application/hub/main/iterator/network/class_NetworkListenIterator.php:10: * @todo This current implementation is not recommended, use a ./application/hub/main/iterator/network/class_NetworkListenIterator.php:11: * @todo latency-based iteration or similar approaches ./application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php:10: * @todo This current implementation is not recommended, use a -- 2.39.5