Ejemplo n.º 1
0
 /**
  * The method to run the Maintenance Priority Engine process.
  *
  * @static
  * @param boolean $alwaysRun Default value is false. If true, the Maintenance
  *                           Priority Engine process will always run, even if
  *                           instant priority updates have been disabled in the
  *                           configuration. Used to ensure that the maintenance
  *                           script process can always update priorities.
  * @return boolean True on MPE running correctly, false otherwise.
  */
 function run($alwaysRun = false)
 {
     OA::switchLogIdent('maintenance');
     // Get the configuration
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Should the MPE process run?
     if (!$alwaysRun) {
         // Is instant update for priority set?
         if (!$aConf['priority']['instantUpdate']) {
             OA::debug('Instant update of priorities disabled, not running MPE', PEAR_LOG_INFO);
             return false;
         }
         OA::debug();
     }
     // Log the start of the process
     OA::debug('Running Maintenance Priority Engine', PEAR_LOG_INFO);
     // Set longer time out, and ignore user abort
     if (!ini_get('safe_mode')) {
         @set_time_limit($aConf['maintenance']['timeLimitScripts']);
         @ignore_user_abort(true);
     }
     // Attempt to increase PHP memory
     OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance'));
     // Run the following code as the "Maintenance" user
     OA_Permission::switchToSystemProcessUser('Maintenance');
     // Create a Maintenance DAL object
     $oDal = new OA_Dal_Maintenance_Priority();
     // Try to get the MPE database-level lock
     $lock = $oDal->obtainPriorityLock();
     if (!$lock) {
         OA::debug('Unable to obtain database-level lock, not running MPE', PEAR_LOG_ERR);
         return false;
     }
     // Ensure the the current time is registered with the OA_ServiceLocator
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oDate =& $oServiceLocator->get('now');
     if (!$oDate) {
         // Record the current time, and register with the OA_ServiceLocator
         $oDate = new Date();
         $oServiceLocator->register('now', $oDate);
     }
     // Run the MPE process for the AdServer module
     require_once MAX_PATH . '/lib/OA/Maintenance/Priority/AdServer.php';
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // TODO: OA_Maintenance_Priority_AdServer::updatePriorities
     //       should be refactored to return a boolean we can check here.
     $oMaintenancePriority->updatePriorities();
     // Release the MPE database-level lock
     $result = $oDal->releasePriorityLock();
     if (PEAR::isError($result)) {
         // Unable to continue!
         OA::debug('Unable to release database-level lock', PEAR_LOG_ERR);
         return false;
     }
     // Return to the "normal" user
     OA_Permission::switchToSystemProcessUser();
     // Log the end of the process
     OA::debug('Maintenance Priority Engine Completed (Started at ' . $oDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oDate->tz->getShortName() . ')', PEAR_LOG_INFO);
     OA::switchLogIdent();
     return true;
 }
Ejemplo n.º 2
0
 /**
  * execute the Priority engine tasks
  */
 function runPriority()
 {
     // Run maintenance before recalculating priorities
     $this->runMaintenance();
     $this->printHeading('Starting updatePriorities; date: ' . $this->_getDateTimeString(), 3);
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     $oMaintenancePriority->updatePriorities();
     $this->printPriorities();
     $this->printHeading('End updatePriorities; date: ' . $this->_getDateTimeString(), 3);
     // Hack! The TestEnv class doesn't always drop temp tables for some
     // reason, so drop them "by hand", just in case.
     $dbType = strtolower($GLOBALS['_MAX']['CONF']['database']['type']);
     $oTable =& OA_DB_Table_Priority::singleton();
     $oTable->dropTable("tmp_ad_required_impression");
     $oTable->dropTable("tmp_ad_zone_impression");
 }
 /**
  * A method to perform basic end-to-end integration testing of the Maintenance
  * Priority Engine classes for the Ad Server.
  *
  * Test 0: Test that no zone forecast or priority data exists to begin with.
  * Test 1: Run the MPE without any stats, and without the stats engine ever
  *         having been run before. Test that zone forecasts are updated
  *         with the appropriate values, and that the correct priorities are
  *         generated.
  * Test 2: Run the MPE without any stats, but with the stats engine having
  *         reported that it has run. Test that zone forecasts are updated
  *         with the appropriate values, and that the correct priorities are
  *         generated.
  * Test 3: Run the MPE again, as for Test 2, but with a later date used as
  *         for when the stats engine reported having run.
  */
 function testAdServer()
 {
     // Test 0: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 0: Ensure no links in the ad_zone_assoc table have priority > 0
     $this->assertEqual($this->_azaRows(true), 0);
     // Test 0: Ensure no links in the data_summary_ad_zone_assoc table have priority > 0
     $this->assertEqual($this->_dsazaRows(true), 0);
     // Test 0: Ensure no data in the log_maintenance_priority table
     $this->_assertLogMaintenance();
     // Test 1: Set "current" date for the MPE run
     $oDate = new Date('2005-06-15 13:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 1: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 1: Store the date before the MPE runs
     $oTest1BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 1: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 1: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest1AfterUpdateDate = new Date();
     // Test 1: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 1: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 1: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority >
     $this->assertEqual($this->_dsazaRows(true), 7);
     // Test 1: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero = array();
     $aTestOneZero['ad_id'] = 1;
     $aTestOneZero['zone_id'] = 0;
     $aTestOneZero['priority'] = 11 / 200;
     // 200 is 10 (default forecast) / 0.05 (factor)
     $aTestOneZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestOneZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 11, 'requested_impressions' => 11, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero = array();
     $aTestTwoZero['ad_id'] = 2;
     $aTestTwoZero['zone_id'] = 0;
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestTwoZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero = array();
     $aTestThreeZero['ad_id'] = 3;
     $aTestThreeZero['zone_id'] = 0;
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne = array();
     $aTestOneOne['ad_id'] = 1;
     $aTestOneOne['zone_id'] = 1;
     $aTestOneOne['priority'] = 10 / 200;
     // Constant, only priority_factor increases
     $aTestOneOne['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestOneOne['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 11, 'requested_impressions' => 10, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree = array();
     $aTestTwoThree['ad_id'] = 2;
     $aTestTwoThree['zone_id'] = 3;
     $aTestTwoThree['priority'] = 8 / 200;
     // Constant, only priority_factor increases
     $aTestTwoThree['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestTwoThree['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 12, 'requested_impressions' => 8, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree = array();
     $aTestThreeThree['ad_id'] = 3;
     $aTestThreeThree['zone_id'] = 3;
     $aTestThreeThree['priority'] = 2 / 200;
     // Constant, only priority_factor increases
     $aTestThreeThree['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeThree['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 3, 'requested_impressions' => 2, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour = array();
     $aTestThreeFour['ad_id'] = 3;
     $aTestThreeFour['zone_id'] = 4;
     $aTestThreeFour['priority'] = 3 / 200;
     // Constant, only priority_factor increases
     $aTestThreeFour['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeFour['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 3, 'requested_impressions' => 3, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeFour);
     // Test 1: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     // Insert data that indicates that the Maintenance Statistics Engine
     // has recently updated the available stats, but don't insert any
     // stats into the tables
     $this->oServiceLocator =& OA_ServiceLocator::instance();
     $startDate = new Date('2005-06-15 14:00:01');
     $this->oServiceLocator->register('now', $startDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->updateFinal = true;
     $aOiDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($startDate);
     $oMaintenanceStatistics->oUpdateIntermediateToDate = $aOiDates['end'];
     $oMaintenanceStatistics->oUpdateFinalToDate = $aOiDates['end'];
     $this->oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion();
     $oLogCompletion->run();
     // Test 2: Set "previous" date for the MPE run
     $oPreviousDate = new Date('2005-06-15 13:01:01');
     $previousOperationIntervalID = $currentOperationIntervalID;
     // Test 2: Set "current" date for the MPE run
     $oDate = new Date('2005-06-15 14:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 2: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 2: Store the date before the MPE runs
     $oTest2BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 2: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 2: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest2AfterUpdateDate = new Date();
     // Test 2: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 2: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 2: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_dsazaRows(true), 14);
     // Test 2: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero['priority'] = 12 / 200;
     $aTestOneZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestOneZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestTwoZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestThreeZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestOneOne['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 10, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestTwoThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 8, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 3, 'requested_impressions' => 2, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeFour['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 3, 'requested_impressions' => 3, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeFour);
     // Test 2: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     $this->_assertLogMaintenance(6, $oTest2BeforeUpdateDate, $oTest2AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     // Insert data that indicates that the Maintenance Statistics Engine
     // has recently updated the available stats
     $this->oServiceLocator =& OA_ServiceLocator::instance();
     $startDate = new Date('2005-06-19 00:00:01');
     $this->oServiceLocator->register('now', $startDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->updateFinal = true;
     $aOiDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($startDate);
     $oMaintenanceStatistics->oUpdateIntermediateToDate = $aOiDates['end'];
     $oMaintenanceStatistics->oUpdateFinalToDate = $aOiDates['end'];
     $this->oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion();
     $oLogCompletion->run();
     // Insert some stats for an ad zone combination
     $doDIA = OA_DAL::factoryDO('data_intermediate_ad');
     $doDIA->ad_id = 3;
     $doDIA->zone_id = 3;
     $doDIA->impressions = 20;
     $doDIA->date_time = $aOiDates['start']->getDate();
     $doDIA->interval_start = $aOiDates['start']->getDate();
     $doDIA->interval_end = $aOiDates['end']->getDate();
     $doDIA->operation_interval = 60;
     $doDIA->operation_interval_id = OX_OperationInterval::convertDateToOperationIntervalID($aOiDates['start']);
     $doDIA->insert();
     // Test 3: Set "current" date for the MPE run
     $oDate = new Date('2005-06-19 00:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 3: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 3: Store the date before the MPE runs
     $oTest3BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 3: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 3: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest3AfterUpdateDate = new Date();
     $oLastUpdatedTo1 = new Date('2005-06-15 14:00:00');
     $oNowUpdatedTo1 = new Date('2005-06-15 15:00:00');
     $oSpan = new Date_Span();
     $oLastUpdatedTo1Copy = new Date();
     $oLastUpdatedTo1Copy->copy($oLastUpdatedTo1);
     $oNowUpdatedTo1Copy = new Date();
     $oNowUpdatedTo1Copy->copy($oNowUpdatedTo1);
     $oSpan->setFromDateDiff($oLastUpdatedTo1Copy, $oNowUpdatedTo1Copy);
     $hours1 = $oSpan->toHours();
     $oLastUpdatedTo2 = new Date('2005-06-15 15:00:00');
     $oNowUpdatedTo2 = new Date('2005-06-19 01:00:00');
     $oSpan = new Date_Span();
     $oLastUpdatedTo2Copy = new Date();
     $oLastUpdatedTo2Copy->copy($oLastUpdatedTo2);
     $oNowUpdatedTo2Copy = new Date();
     $oNowUpdatedTo2Copy->copy($oNowUpdatedTo2);
     $oSpan->setFromDateDiff($oLastUpdatedTo2Copy, $oNowUpdatedTo2Copy);
     $hours2 = $oSpan->toHours();
     // Test 3: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 3: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 3: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_dsazaRows(true), 21);
     // Test 3: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero['priority'] = 5 / 200;
     $aTestOneZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestOneZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 5, 'requested_impressions' => 5, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestTwoZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestThreeZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne['priority'] = 5 / 200;
     // Changed, skipped OIs
     $aTestOneOne['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestOneOne['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 5, 'requested_impressions' => 5, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree['priority'] = 12 / 20;
     // Zone has had some impressions, we have a forecast now
     $aTestTwoThree['priority_factor'] = 10;
     // But this ad didn't deliver. Factor increased
     $aTestTwoThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree['priority'] = 4 / 20;
     // Ad/Zone has delivered!
     $aTestThreeThree['priority_factor'] = 2 / 20;
     // Overdelivered quite a bit!
     $aTestThreeThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 4, 'requested_impressions' => 4, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => 1);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour['priority'] = 2 / 200;
     // Ad has delivered, but not in this zone
     $aTestThreeFour['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeFour['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 2, 'requested_impressions' => 2, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeFour);
     // Test 3: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     $this->_assertLogMaintenance(6, $oTest2BeforeUpdateDate, $oTest2AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
 }