Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-03-26 00:16:30 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-03-26 00:16:30 +0400
commit08a0e53818168fcee38d0c3d2264831cab2873b3 (patch)
tree1d88ee41ea2b5187d90eb6ccd820b45b071a8cec
parent257d6c779d3071b27537a4927999c86100127cd9 (diff)
refs #4903 added tests and fixed some issues
-rw-r--r--core/ArchiveProcessor/FixedSiteIds.php12
-rw-r--r--core/ArchiveProcessor/SharedSiteIds.php14
-rw-r--r--core/CronArchive.php3
-rw-r--r--tests/PHPUnit/Core/ArchiveProcessor/FixedSiteIdsTest.php55
-rw-r--r--tests/PHPUnit/Core/ArchiveProcessor/SharedSiteIdsTest.php108
5 files changed, 189 insertions, 3 deletions
diff --git a/core/ArchiveProcessor/FixedSiteIds.php b/core/ArchiveProcessor/FixedSiteIds.php
index 5bf54ccc3f..8e70f9b18a 100644
--- a/core/ArchiveProcessor/FixedSiteIds.php
+++ b/core/ArchiveProcessor/FixedSiteIds.php
@@ -20,7 +20,9 @@ class FixedSiteIds
public function __construct($websiteIds)
{
- $this->siteIds = $websiteIds;
+ if (!empty($websiteIds)) {
+ $this->siteIds = $websiteIds;
+ }
}
/**
@@ -40,7 +42,13 @@ class FixedSiteIds
*/
public function getNumProcessedWebsites()
{
- return $this->index + 1;
+ $numProcessed = $this->index + 1;
+
+ if ($numProcessed > $this->getNumSites()) {
+ return $this->getNumSites();
+ }
+
+ return $numProcessed;
}
public function getNextSiteId()
diff --git a/core/ArchiveProcessor/SharedSiteIds.php b/core/ArchiveProcessor/SharedSiteIds.php
index 84d6b6dcff..0deeda80bb 100644
--- a/core/ArchiveProcessor/SharedSiteIds.php
+++ b/core/ArchiveProcessor/SharedSiteIds.php
@@ -20,9 +20,14 @@ class SharedSiteIds
{
private $siteIds = array();
private $currentSiteId;
+ private $done = false;
public function __construct($websiteIds)
{
+ if (empty($websiteIds)) {
+ $websiteIds = array();
+ }
+
$self = $this;
$this->siteIds = $this->runExclusive(function () use ($self, $websiteIds) {
// if there are already sites to be archived registered, prefer the list of existing archive, meaning help
@@ -56,6 +61,10 @@ class SharedSiteIds
*/
public function getNumProcessedWebsites()
{
+ if ($this->done) {
+ return $this->getNumSites();
+ }
+
if (empty($this->currentSiteId)) {
return 0;
}
@@ -103,6 +112,7 @@ class SharedSiteIds
private function runExclusive($closure)
{
$process = new Process('archive.sharedsiteids');
+
while ($process->isRunning() && $process->getSecondsSinceCreation() < 5) {
// wait max 5 seconds, such an operation should not take longer
usleep(25);
@@ -145,6 +155,10 @@ class SharedSiteIds
return $nextSiteId;
});
+ if (is_null($this->currentSiteId)) {
+ $this->done = true;
+ }
+
return $this->currentSiteId;
}
diff --git a/core/CronArchive.php b/core/CronArchive.php
index 2c5cc4fd96..f14545ee01 100644
--- a/core/CronArchive.php
+++ b/core/CronArchive.php
@@ -284,7 +284,8 @@ Notes:
// Also reprocess when day has ended since last run
if ($dayHasEndedMustReprocess
- && !$this->hasBeenProcessedSinceMidnight($idsite, $lastTimestampWebsiteProcessedDay) // it might have reprocessed for that day by another cron
+ // it might have reprocessed for that day by another cron
+ && !$this->hasBeenProcessedSinceMidnight($idsite, $lastTimestampWebsiteProcessedDay)
&& !$existingArchiveIsValid) {
$skipDayArchive = false;
}
diff --git a/tests/PHPUnit/Core/ArchiveProcessor/FixedSiteIdsTest.php b/tests/PHPUnit/Core/ArchiveProcessor/FixedSiteIdsTest.php
new file mode 100644
index 0000000000..6d0c6cf78e
--- /dev/null
+++ b/tests/PHPUnit/Core/ArchiveProcessor/FixedSiteIdsTest.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+use \Piwik\ArchiveProcessor\FixedSiteIds;
+
+/**
+ * @group Core
+ */
+class FixedSiteIdsTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * @var FixedSiteIds
+ */
+ private $fixedSiteIds;
+
+ public function setUp()
+ {
+ $this->fixedSiteIds = new FixedSiteIds(array(1,2,5,9));
+ }
+
+ public function test_construct_withEmptyValue()
+ {
+ $siteIds = new FixedSiteIds(null);
+ $this->assertEquals(0, $siteIds->getNumSites());
+ $this->assertNull($siteIds->getNextSiteId());
+ }
+
+ public function test_getNumSites()
+ {
+ $this->assertEquals(4, $this->fixedSiteIds->getNumSites());
+ }
+
+ public function test_getNumProcessedWebsites_getNextSiteId()
+ {
+ $this->assertEquals(0, $this->fixedSiteIds->getNumProcessedWebsites());
+ $this->assertEquals(1, $this->fixedSiteIds->getNextSiteId());
+ $this->assertEquals(1, $this->fixedSiteIds->getNumProcessedWebsites());
+ $this->assertEquals(2, $this->fixedSiteIds->getNextSiteId());
+ $this->assertEquals(2, $this->fixedSiteIds->getNumProcessedWebsites());
+ $this->assertEquals(5, $this->fixedSiteIds->getNextSiteId());
+ $this->assertEquals(3, $this->fixedSiteIds->getNumProcessedWebsites());
+ $this->assertEquals(9, $this->fixedSiteIds->getNextSiteId());
+ $this->assertEquals(4, $this->fixedSiteIds->getNumProcessedWebsites());
+
+ $this->assertNull($this->fixedSiteIds->getNextSiteId());
+ $this->assertEquals(4, $this->fixedSiteIds->getNumProcessedWebsites());
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/PHPUnit/Core/ArchiveProcessor/SharedSiteIdsTest.php b/tests/PHPUnit/Core/ArchiveProcessor/SharedSiteIdsTest.php
new file mode 100644
index 0000000000..e8df2c9d23
--- /dev/null
+++ b/tests/PHPUnit/Core/ArchiveProcessor/SharedSiteIdsTest.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+use \Piwik\ArchiveProcessor\SharedSiteIds;
+
+/**
+ * @group Core
+ */
+class SharedSiteIdsTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * @var SharedSiteIds
+ */
+ private $sharedSiteIds;
+
+ public function setUp()
+ {
+ $this->sharedSiteIds = new SharedSiteIds(array(1,2,5,9));
+ }
+
+ public function tearDown()
+ {
+ $this->sharedSiteIds->setSiteIdsToArchive(array());
+ }
+
+ public function test_construct_withEmptyValue()
+ {
+ $this->sharedSiteIds->setSiteIdsToArchive(array());
+
+ $siteIds = new SharedSiteIds(null);
+ $this->assertEquals(0, $siteIds->getNumSites());
+ $this->assertNull($siteIds->getNextSiteId());
+ }
+
+ public function test_isSupported()
+ {
+ $this->assertTrue(SharedSiteIds::isSupported());
+ }
+
+ public function test_getNumSites()
+ {
+ $this->assertEquals(4, $this->sharedSiteIds->getNumSites());
+ }
+
+ public function test_getAllSiteIdsToArchive()
+ {
+ $this->assertEquals(array(1,2,5,9), $this->sharedSiteIds->getAllSiteIdsToArchive());
+ }
+
+ public function test_getNumProcessedWebsites_getNextSiteId()
+ {
+ $this->assertEquals(0, $this->sharedSiteIds->getNumProcessedWebsites());
+
+ $this->assertEquals(1, $this->sharedSiteIds->getNextSiteId());
+ $this->assertEquals(1, $this->sharedSiteIds->getNumProcessedWebsites());
+
+ $this->assertEquals(2, $this->sharedSiteIds->getNextSiteId());
+ $this->assertEquals(2, $this->sharedSiteIds->getNumProcessedWebsites());
+
+ $this->assertEquals(5, $this->sharedSiteIds->getNextSiteId());
+ $this->assertEquals(3, $this->sharedSiteIds->getNumProcessedWebsites());
+
+ $this->assertEquals(9, $this->sharedSiteIds->getNextSiteId());
+ $this->assertEquals(4, $this->sharedSiteIds->getNumProcessedWebsites());
+
+ $this->assertNull($this->sharedSiteIds->getNextSiteId());
+ $this->assertEquals(4, $this->sharedSiteIds->getNumProcessedWebsites());
+ }
+
+ public function test_usingMultipleSharedSiteIds()
+ {
+ $second = new SharedSiteIds(array(7,9,11,6,1,2));
+
+ // should ignore his queue and help processing the existing queue
+ $this->assertEquals(4, $second->getNumSites());
+ $this->assertEquals(4, $this->sharedSiteIds->getNumSites());
+
+ $this->assertEquals(array(1,2,5,9), $second->getAllSiteIdsToArchive());
+ $this->assertEquals(1, $second->getNextSiteId());
+ $this->assertEquals(1, $second->getNumProcessedWebsites());
+
+ $this->assertEquals(array(2,5,9), $this->sharedSiteIds->getAllSiteIdsToArchive());
+ $this->assertEquals(2, $this->sharedSiteIds->getNextSiteId());
+ $this->assertEquals(2, $this->sharedSiteIds->getNumProcessedWebsites());
+
+ $this->assertEquals(array(5,9), $second->getAllSiteIdsToArchive());
+ $this->assertEquals(5, $second->getNextSiteId());
+ $this->assertEquals(3, $second->getNumProcessedWebsites());
+
+ $this->assertEquals(array(9), $this->sharedSiteIds->getAllSiteIdsToArchive());
+ $this->assertEquals(9, $this->sharedSiteIds->getNextSiteId());
+ $this->assertEquals(4, $this->sharedSiteIds->getNumProcessedWebsites());
+
+ $this->assertNull($second->getNextSiteId());
+ $this->assertEquals(4, $second->getNumProcessedWebsites());
+ $this->assertEquals(array(), $second->getAllSiteIdsToArchive());
+
+ $this->assertNull($this->sharedSiteIds->getNextSiteId());
+ $this->assertEquals(4, $this->sharedSiteIds->getNumProcessedWebsites());
+ $this->assertEquals(array(), $this->sharedSiteIds->getAllSiteIdsToArchive());
+ }
+
+} \ No newline at end of file