#! /usr/bin/env perl
##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************

use Condor;
use CondorTest;
use Check::SimpleJob;
use Check::CondorLog;

#testreq: personal
my $config = <<CONDOR_TESTREQ_CONFIG;
  RANK = TARGET.TimeSensitive =?= True
  MaxJobRetirementTime = 0
  PREEMPTION_REQUIREMENTS = False
  NUM_CPUS = 1
  DAEMON_LIST = MASTER,COLLECTOR,NEGOTIATOR,SCHEDD,STARTD
CONDOR_TESTREQ_CONFIG
#endtestreq


my $testname = CondorTest::GetDefaultTestName();

my $normal_submit = CondorTest::TempFileName("$testname.normal.submit");

open( SUBMIT, ">$normal_submit" ) || die "error writing to $normal_submit: $!\n";
print SUBMIT "universe = vanilla\n";
print SUBMIT "executable = x_sleep.pl\n";
print SUBMIT "arguments = 600\n";
print SUBMIT "notification = never\n";
print SUBMIT "priority = 100\n";
print SUBMIT "queue\n";
close( SUBMIT );

my $normal_jobid = Condor::Submit($normal_submit);

my $append_submit_info = '
+TimeSensitive = true
priority = 1
';

# verify that a time sensitive job runs
SimpleJob::RunCheck(
    append_submit_commands => $append_submit_info
);

# verify that the startd preempted a job based on machine rank
CondorLog::RunCheck(
    daemon => "STARTD",
    match_regexp => "preempting claim based on machine rank"
);

CondorTest::EndTest();
