#! /usr/bin/env perl
#testreq: personal
##**************************************************************
##
## Copyright (C) 1990-2012, 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 strict;
use warnings;

use CondorTest;
use CondorUtils;
use Check::SimpleJob;

my $testname = "job_filexfer_limitback_van";
my $result = 0;

my $pid = $$;
my $baseoutfile = "submit_filetrans_output" . $pid;
my $oute = $baseoutfile . "e.txt";
my $outf = $baseoutfile . "f.txt";
my $outg = $baseoutfile . "g.txt";

my $execute = sub {
    my %args = @_;
    my $cluster = $args{"cluster"};
    CondorTest::debug("Running $cluster\n", 1);
};

my $success = sub {
    my $errors = 0;
    CondorTest::debug("Base file transfer job!\n", 1);
    if(-f $oute) {
        print "$oute arrived unexpectedly\n";
        $errors++;
    }
    if(!-f $outf) {
        print "$outf failed to arrive\n";
        $errors++;
    }
    if(!-f $outg) {
        print "$outg failed to arrive\n";
        $errors++;
    }

    if($errors > 0) {
        exit(1);
    }
};

my $abort = sub {
    CondorTest::debug("Job is gone now, cool.\n", 1);
};

my $timed = sub {
    die "Job should have ended by now. file transfer broken!\n";
};

# make some needed files. All 0 sized and xxxxxx.txt for easy cleanup
CondorTest::debug("PID = $pid\n", 1);
my $args = "--job=$pid --onesetout ";

SimpleJob::RunCheck(
    runthis=>"x_job_filexfer_testjob.pl",
    duration=>"$args",
    transfer_output_files=>"$outf,$outg",
    should_transfer_files=>"YES",
    when_to_transfer_output=>"ON_EXIT",
    on_success=>$success,
    on_execute=>$execute,
    on_abort=>$abort,
);

CondorTest::EndTest();
print scalar localtime() . "\n";

if( $result != 0 )
{
    exit(1);
}

CondorTest::debug("$testname SUCCESS\n",1);
exit(0);
