/*
 * ################################################################
 *
 * ProActive Parallel Suite(TM): The Java(TM) library for
 *    Parallel, Distributed, Multi-Core Computing for
 *    Enterprise Grids & Clouds
 *
 * Copyright (C) 1997-2011 INRIA/University of
 *                 Nice-Sophia Antipolis/ActiveEon
 * Contact: proactive@ow2.org or contact@activeeon.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; version 3 of
 * the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * If needed, contact us to obtain a release under GPL Version 2 or 3
 * or a different license than the AGPL.
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s): ActiveEon Team - http://www.activeeon.com
 *
 * ################################################################
 * $$ACTIVEEON_CONTRIBUTOR$$
 */
package functionaltests;

import junit.framework.Assert;

import org.ow2.proactive.scheduler.common.job.JobId;
import org.ow2.proactive.scheduler.common.job.JobResult;

import functionalTests.FunctionalTest;


/**
 * This class tests the failure of the scheduler.
 * Even if it is in pending, running, or finished list, the scheduled jobs must be restarted
 * as expected after the scheduler restart.
 * This test case is about the behavior of the scheduler after a failure.
 *
 * This test will first commit 3 jobs.
 * When the each one will be in each list (pending, running, finished), the scheduler will
 * be interrupt abnormally.
 * After restart, It will check that every data, tags, status are those expected.
 * It will finally check if the scheduling process will terminate.
 *
 * @author The ProActive Team
 * @date 2 jun 08
 * @since ProActive Scheduling 1.0
 */
public class TestJobRecover extends FunctionalTest {

    private static String jobDescriptor = TestJobRecover.class.getResource(
            "/functionaltests/descriptors/Job_PI_recover.xml").getPath();

    /**
     * Tests start here.
     *
     * @throws Throwable any exception that can be thrown during the test.
     */
    @org.junit.Test
    public void run() throws Throwable {

        JobId idJ1 = SchedulerTHelper.submitJob(jobDescriptor);
        JobId idJ2 = SchedulerTHelper.submitJob(jobDescriptor);
        JobId idJ3 = SchedulerTHelper.submitJob(jobDescriptor);

        SchedulerTHelper.waitForEventJobRunning(idJ1);

        SchedulerTHelper.log("Waiting for job 1 to finish");
        SchedulerTHelper.waitForFinishedJob(idJ1);

        SchedulerTHelper.log("Kill Scheduler");
        SchedulerTHelper.killAndRestartScheduler(SchedulerTHelper.class.getResource(
                "config/functionalTSchedulerProperties-updateDB.ini").getPath());

        SchedulerTHelper.getSchedulerInterface();

        SchedulerTHelper.log("Waiting for job 2 to finish");
        SchedulerTHelper.waitForFinishedJob(idJ2);
        SchedulerTHelper.log("Waiting for job 3 to finish");
        SchedulerTHelper.waitForFinishedJob(idJ3);

        SchedulerTHelper.log("check result job 1");
        JobResult result = SchedulerTHelper.getJobResult(idJ1);
        //        for (int i = 1; i <= 6; i++) {
        //            TaskResult tr = result.getResult("Computation" + i);
        //            System.out.println(tr.getTaskId().getReadableName() + " : " + tr.value());
        //        }
        Assert.assertEquals(6, result.getAllResults().size());
        for (int i = 1; i <= 6; i++) {
            Assert.assertNotNull(result.getResult("Computation" + i).value());
            Assert.assertNull(result.getResult("Computation" + i).getException());
        }

        SchedulerTHelper.log("check result job 2");
        result = SchedulerTHelper.getJobResult(idJ2);
        //        for (int i = 1; i <= 6; i++) {
        //            TaskResult tr = result.getResult("Computation" + i);
        //            System.out.println(tr.getTaskId().getReadableName() + " : " + tr.value());
        //        }
        Assert.assertEquals(6, result.getAllResults().size());
        for (int i = 1; i <= 6; i++) {
            Assert.assertNotNull(result.getResult("Computation" + i).value());
            Assert.assertNull(result.getResult("Computation" + i).getException());
        }

        SchedulerTHelper.log("check result job 3");
        result = SchedulerTHelper.getJobResult(idJ3);
        //        for (int i = 1; i <= 6; i++) {
        //            TaskResult tr = result.getResult("Computation" + i);
        //            System.out.println(tr.getTaskId().getReadableName() + " : " + tr.value());
        //        }
        Assert.assertEquals(6, result.getAllResults().size());
        for (int i = 1; i <= 6; i++) {
            Assert.assertNotNull(result.getResult("Computation" + i).value());
            Assert.assertNull(result.getResult("Computation" + i).getException());
        }

    }
}

@@ -1497,16 +1497,59 @@
 tests;%0A%0A
+import java.io.File;%0Aimport java.net.URL;%0A%0A
 import j
@@ -1571,16 +1571,16 @@
 Assert;%0A
-
 %0Aimport 
@@ -2466,14 +2466,11 @@
 tic 
-String
+URL
  job
@@ -2498,37 +2498,24 @@
 ecover.class
-.getResource(
 %0A           
@@ -2515,16 +2515,29 @@
         
+.getResource(
 %22/functi
@@ -2578,26 +2578,16 @@
 er.xml%22)
-.getPath()
 ;%0A%0A    /
@@ -2806,32 +2806,41 @@
 elper.submitJob(
+new File(
 jobDescriptor);%0A
@@ -2828,32 +2828,59 @@
 le(jobDescriptor
+.toURI()).getAbsolutePath()
 );%0A        JobId
@@ -2906,32 +2906,41 @@
 elper.submitJob(
+new File(
 jobDescriptor);%0A
@@ -2936,16 +2936,43 @@
 scriptor
+.toURI()).getAbsolutePath()
 );%0A     
@@ -3014,16 +3014,25 @@
 bmitJob(
+new File(
 jobDescr
@@ -3036,16 +3036,43 @@
 scriptor
+.toURI()).getAbsolutePath()
 );%0A%0A    
@@ -3333,16 +3333,25 @@
 heduler(
+new File(
 Schedule
@@ -3448,19 +3448,36 @@
 B.ini%22).
-get
+toURI()).getAbsolute
 Path());

Fix bad URI API usage