/** * A method to test when there are no old format raw requests, * impressions and clicks. */ function testNoData() { $aConf =& $GLOBALS['_MAX']['CONF']; $aConf['maintenance']['operationInterval'] = 60; // Prepare an array of the required tables used in testing $aTables = array($aConf['table']['prefix'] . $aConf['table']['data_raw_ad_request'] => $aConf['table']['prefix'] . 'data_bkt_r', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_impression'] => $aConf['table']['prefix'] . 'data_bkt_m', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_click'] => $aConf['table']['prefix'] . 'data_bkt_c'); // Install the openXDeliveryLog plugin, which will create the // data bucket tables required for testing TestEnv::installPluginPackage('openXDeliveryLog', false); // Ensure that there are no old format raw data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($rawTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Ensure that there are no new format bucket data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Run the migration of raw data DAL code for a given OI $oStart = new Date('2009-01-09 12:00:00'); $oEnd = new Date('2009-01-09 12:59:59'); $this->oDal->migrateRawRequests($oStart, $oEnd); $this->oDal->migrateRawImpressions($oStart, $oEnd); $this->oDal->migrateRawClicks($oStart, $oEnd); // Re-test that there are still no new format bucket data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Uninstall the installed plugin TestEnv::uninstallPluginPackage('openXDeliveryLog', false); // Restore the test environment configuration TestEnv::restoreConfig(); }
/** * A method to migrate any old style raw requests into new style, bucket-based * requests, in the event of the requirement to process any such data on upgrade * to (or beyond) OpenX 2.8. * * @param PEAR::Date $oStart The start date of the operation interval to migrate. * @param PEAR::Date $oEnd The end date of the operation interval to migrate. */ function migrateRawRequests($oStart, $oEnd) { // Set the MySQL sort buffer size $this->setSortBufferSize(); // Call the parent method parent::migrateRawRequests($oStart, $oEnd); // Restore the MySQL sort buffer size $this->restoreSortBufferSize(); }
/** * A method to test when there are old format raw requests, * impressions and clicks, in the operation interval being * migrated. */ function testComplexValidData() { $aConf =& $GLOBALS['_MAX']['CONF']; $aConf['maintenance']['operationInterval'] = 60; // Prepare an array of the required tables used in testing $aTables = array($aConf['table']['prefix'] . $aConf['table']['data_raw_ad_request'] => $aConf['table']['prefix'] . 'data_bkt_r', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_impression'] => $aConf['table']['prefix'] . 'data_bkt_m', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_click'] => $aConf['table']['prefix'] . 'data_bkt_c'); // Install the openXDeliveryLog plugin, which will create the // data bucket tables required for testing TestEnv::installPluginPackage('openXDeliveryLog', false); // Ensure that there are no old format raw data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($rawTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Ensure that there are no new format bucket data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Insert some old style raw data in an operation interval // that will not be migrated foreach ($aTables as $rawTable => $bucketTable) { $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n (\n date_time,\n ad_id,\n creative_id,\n zone_id\n )\n VALUES\n (\n '2009-01-09 11:30:00',\n 1,\n 0,\n 1\n )"; $this->oDbh->exec($query); } // Ensure that the old format raw data was inserted correctly foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($rawTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 1); } // Insert some old style raw data in an operation interval // that will be migrated foreach ($aTables as $rawTable => $bucketTable) { $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n (\n date_time,\n ad_id,\n creative_id,\n zone_id\n )\n VALUES\n (\n '2009-01-09 12:30:00',\n 1,\n 0,\n 1\n )"; $this->oDbh->exec($query); $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n (\n date_time,\n ad_id,\n creative_id,\n zone_id\n )\n VALUES\n (\n '2009-01-09 12:31:00',\n 1,\n 0,\n 1\n )"; $this->oDbh->exec($query); $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n (\n date_time,\n ad_id,\n creative_id,\n zone_id\n )\n VALUES\n (\n '2009-01-09 12:32:00',\n 2,\n 0,\n 3\n )"; $this->oDbh->exec($query); } // Ensure that the old format raw data was inserted correctly foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($rawTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 4); } // Run the migration of raw data DAL code for a given OI $oStart = new Date('2009-01-09 12:00:00'); $oEnd = new Date('2009-01-09 12:59:59'); $this->oDal->migrateRawRequests($oStart, $oEnd); $this->oDal->migrateRawImpressions($oStart, $oEnd); $this->oDal->migrateRawClicks($oStart, $oEnd); // Test that the data was migrated correctly foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 2); $query = "\n SELECT\n *\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 2); $query = "\n SELECT\n *\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true) . "\n WHERE\n creative_id = 1"; $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['interval_start'], '2009-01-09 12:00:00'); $this->assertEqual($aRow['creative_id'], 1); $this->assertEqual($aRow['zone_id'], 1); $this->assertEqual($aRow['count'], 2); $query = "\n SELECT\n *\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true) . "\n WHERE\n creative_id = 2"; $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['interval_start'], '2009-01-09 12:00:00'); $this->assertEqual($aRow['creative_id'], 2); $this->assertEqual($aRow['zone_id'], 3); $this->assertEqual($aRow['count'], 1); } // Uninstall the installed plugin TestEnv::uninstallPluginPackage('openXDeliveryLog', false); // Restore the test environment configuration TestEnv::restoreConfig(); }