#! /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.
##
##**************************************************************
##
## This test check availability and usage contol of the new
## local, resources in both a static configuration and in psolts.
## It is model after what we did to test concurrency limits
## as we are checking the same sorts of things. bt
##
##**************************************************************

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

my @submitfiles =	();

my $pid = $$;
my $ClusterId = 0;

my $firstappend_condor_config = '
	DAEMON_LIST = MASTER,SCHEDD,COLLECTOR,NEGOTIATOR,STARTD
	WANT_SUSPEND = FALSE
	ALL_DEBUG = D_ALWAYS
';

$configfile = CondorTest::CreateLocalConfig($firstappend_condor_config,"jobmassiveconfig");

my $testname = "job_massive_config";
my @massiveconfig = ();
GenerateMassive(1000);

# First order up the config but do not start it. If the condor_config_val fails
# there is no reason to go on

CondorTest::StartCondorWithParams(
	condor_name => "jobmassiveconfig",
	fresh_local => "TRUE",
	condorlocalsrc => "$configfile",
	append_condor_config_plus => \@massiveconfig,
	do_not_start => "TRUE",
);

print "************************** CONDOR_CONFIG now set to:$ENV{CONDOR_CONFIG} ******************\n";

my $res = system("condor_config_val -dump");

if($res == 0) {
	RegisterResult(1,test_name,$testname);
	# continue to starting condor check
} else {
	RegisterResult(1,test_name,$testname);
	print "Massve config condor_config_val failed(status $res)\n";
	CondorTest::EndTest();
	exit(0);
}

# now start the personal condor to ensure it comes up

CondorTest::StartCondorWithParamsStart();

#Do a job before setting tesing exit codes
print "First test basic job\n";
my $result = SimpleJob::RunCheck(); # jobid 1


CondorTest::EndTest();

sub GenerateMassive {
	my $iterations = shift;
	my $counter = 0;
	my $pattern = "x";
	my $unique = "unique";
	my $genunique = "";
	while($counter < $iterations) {
		$genunique = "$unique$counter = $pattern";
		push @massiveconfig,"$genunique\n";
		$counter++;
		$pattern = $pattern . "xxxxxxxxxxxx";
	}
};
