Skip to content
Extraits de code Groupes Projets
Valider 3ffd6f80 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Rename PurgerTest to ArchivePurgerTest and add tests for row counting logic in ArchivePurger.

parent 786592db
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -87,6 +87,7 @@ class ArchivePurger
* table that stores data for `$date`.
*
* @param Date $date The date identifying the archive table.
* @return int The total number of archive rows deleted (from both the blog & numeric tables).
*/
public function purgeInvalidatedArchivesFrom(Date $date)
{
......@@ -98,13 +99,13 @@ class ArchivePurger
$idSites = $this->model->getSitesWithInvalidatedArchive($numericTable);
if (empty($idSites)) {
$this->logger->info("No sites with invalidated archives found in {table}.", array('table' => $numericTable));
return;
return 0;
}
$archiveIds = $this->model->getInvalidatedArchiveIdsSafeToDelete($numericTable, $idSites);
if (empty($archiveIds)) {
$this->logger->info("No invalidated archives found in {table} with newer, valid archives.", array('table' => $numericTable));
return;
return 0;
}
$this->logger->info("Found {countArchiveIds} invalidated archives safe to delete in {table}.", array(
......@@ -116,6 +117,8 @@ class ArchivePurger
$this->logger->info("Deleted {count} rows in {table} and its associated blob table.", array(
'table' => $numericTable, 'count' => $deletedRowCount
));
return $deletedRowCount;
}
/**
......@@ -123,10 +126,12 @@ class ArchivePurger
* (meaning they are marked with a done flag of ArchiveWriter::DONE_OK_TEMPORARY or ArchiveWriter::DONE_ERROR)
*
* @param Date $dateStart Only the month will be used
* @return int Returns the total number of rows deleted.
*/
public function purgeOutdatedArchives(Date $dateStart)
{
$purgeArchivesOlderThan = $this->getOldestTemporaryArchiveToKeepThreshold();
$deletedRowCount = 0;
$idArchivesToDelete = $this->getOutdatedArchiveIds($dateStart, $purgeArchivesOlderThan);
if (!empty($idArchivesToDelete)) {
......@@ -145,6 +150,8 @@ class ArchivePurger
'yearMonth' => $dateStart->toString('Y-m'),
'deletedIds' => implode(',', $idArchivesToDelete)
));
return $deletedRowCount;
}
protected function getOutdatedArchiveIds(Date $date, $purgeArchivesOlderThan)
......@@ -167,6 +174,7 @@ class ArchivePurger
* Deleting "Custom Date Range" reports after 1 day, since they can be re-processed and would take up un-necessary space.
*
* @param $date Date
* @return int The total number of rows deleted from both the numeric & blob table.
*/
public function purgeArchivesWithPeriodRange(Date $date)
{
......@@ -183,6 +191,8 @@ class ArchivePurger
));
$this->logger->debug(" [ purged archives older than {threshold} ]", array('threshold' => $this->purgeCustomRangesOlderThan));
return $deletedCount;
}
/**
......
......@@ -22,6 +22,8 @@ use Piwik\Tests\Framework\Fixture;
*/
class RawArchiveDataWithTempAndInvalidated extends Fixture
{
const ROWS_PER_ARCHIVE = 5;
private static $dummyArchiveData = array(
// outdated temporary
array(
......@@ -317,7 +319,7 @@ class RawArchiveDataWithTempAndInvalidated extends Fixture
public function assertTemporaryArchivesPurged($isBrowserTriggeredArchivingEnabled, Date $date)
{
if ($isBrowserTriggeredArchivingEnabled) {
$expectedPurgedArchives = array(1,2,3,4,6,7); // only archives from 2 hours before "now" are purged
$expectedPurgedArchives = array(1,2,3,4,6,7,10); // only archives from 2 hours before "now" are purged
} else {
$expectedPurgedArchives = array(1,2,3,4,7); // only archives before start of "yesterday" are purged
}
......
......@@ -17,7 +17,7 @@ use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group Core
*/
class PurgerTest extends IntegrationTestCase
class ArchivePurgerTest extends IntegrationTestCase
{
/**
* @var RawArchiveDataWithTempAndInvalidated
......@@ -62,40 +62,48 @@ class PurgerTest extends IntegrationTestCase
{
$this->enableBrowserTriggeredArchiving();
$this->archivePurger->purgeOutdatedArchives($this->february);
$deletedRowCount = $this->archivePurger->purgeOutdatedArchives($this->february);
self::$fixture->assertTemporaryArchivesPurged($browserTriggeringEnabled = true, $this->february);
self::$fixture->assertCustomRangesNotPurged($this->february, $includeTemporary = false);
self::$fixture->assertTemporaryArchivesNotPurged($this->january);
$this->assertEquals(7 * RawArchiveDataWithTempAndInvalidated::ROWS_PER_ARCHIVE, $deletedRowCount);
}
public function test_purgeOutdatedArchives_PurgesCorrectTemporaryArchives_WhileKeepingNewerTemporaryArchives_WithBrowserTriggeringDisabled()
{
$this->disableBrowserTriggeredArchiving();
$this->archivePurger->purgeOutdatedArchives($this->february);
$deletedRowCount = $this->archivePurger->purgeOutdatedArchives($this->february);
self::$fixture->assertTemporaryArchivesPurged($browserTriggeringEnabled = false, $this->february);
self::$fixture->assertCustomRangesNotPurged($this->february);
self::$fixture->assertTemporaryArchivesNotPurged($this->january);
$this->assertEquals(5 * RawArchiveDataWithTempAndInvalidated::ROWS_PER_ARCHIVE, $deletedRowCount);
}
public function test_purgeInvalidatedArchivesFrom_PurgesAllInvalidatedArchives_AndMarksDatesAndSitesAsInvalidated()
{
$this->archivePurger->purgeInvalidatedArchivesFrom($this->february);
$deletedRowCount = $this->archivePurger->purgeInvalidatedArchivesFrom($this->february);
self::$fixture->assertInvalidatedArchivesPurged($this->february);
self::$fixture->assertInvalidatedArchivesNotPurged($this->january);
$this->assertEquals(4 * RawArchiveDataWithTempAndInvalidated::ROWS_PER_ARCHIVE, $deletedRowCount);
}
public function test_purgeArchivesWithPeriodRange_PurgesAllRangeArchives()
{
$this->archivePurger->purgeArchivesWithPeriodRange($this->february);
$deletedRowCount = $this->archivePurger->purgeArchivesWithPeriodRange($this->february);
self::$fixture->assertCustomRangesPurged($this->february);
self::$fixture->assertCustomRangesNotPurged($this->january);
$this->assertEquals(3 * RawArchiveDataWithTempAndInvalidated::ROWS_PER_ARCHIVE, $deletedRowCount);
}
private function configureCustomRangePurging()
......@@ -114,4 +122,4 @@ class PurgerTest extends IntegrationTestCase
}
}
PurgerTest::$fixture = new RawArchiveDataWithTempAndInvalidated();
\ No newline at end of file
ArchivePurgerTest::$fixture = new RawArchiveDataWithTempAndInvalidated();
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter