Search in sources :

Example 1 with TestsOnDisk

use of org.evosuite.continuous.persistency.StorageManager.TestsOnDisk in project evosuite by EvoSuite.

the class JobExecutorIntTest method testActualExecutionOfSchedule.

@Test(timeout = 90_000)
public void testActualExecutionOfSchedule() throws IOException {
    Properties.TEST_SCAFFOLDING = true;
    boolean storageOK = storage.isStorageOk();
    assertTrue(storageOK);
    storageOK = storage.createNewTmpFolders();
    assertTrue(storageOK);
    List<TestsOnDisk> data = storage.gatherGeneratedTestsOnDisk();
    Assert.assertEquals(0, data.size());
    ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
    String classpath = ClassPathHandler.getInstance().getTargetProjectClasspath();
    int cores = 1;
    int memory = 1000;
    int minutes = 1;
    CtgConfiguration conf = new CtgConfiguration(memory, cores, minutes, 1, false, AvailableSchedule.SIMPLE);
    JobExecutor exe = new JobExecutor(storage, classpath, conf);
    JobDefinition simple = new JobDefinition(30, memory, com.examples.with.different.packagename.continuous.Simple.class.getName(), 0, null, null);
    JobDefinition trivial = new JobDefinition(30, memory, com.examples.with.different.packagename.continuous.Trivial.class.getName(), 0, null, null);
    assertTrue(simple.jobID < trivial.jobID);
    List<JobDefinition> jobs = Arrays.asList(simple, trivial);
    exe.executeJobs(jobs, cores);
    exe.waitForJobs();
    data = storage.gatherGeneratedTestsOnDisk();
    // if Properties.TEST_SCAFFOLDING is enabled, we should have
    // 4 java files (2 test cases and 2 scaffolding files), however
    // 'storage' just returns the 2 test cases
    boolean areThereFiles = (data.size() == 2);
    boolean areThereTests = true;
    // check if indeed they have tests
    for (TestsOnDisk tod : data) {
        String content = FileUtils.readFileToString(tod.testSuite);
        areThereTests = areThereTests && content.contains("@Test") && !content.contains(TestSuiteWriter.NOT_GENERATED_TEST_NAME);
    }
    String msg = "Tmp folder: " + Properties.CTG_DIR + "\n";
    if (!areThereFiles || !areThereTests) {
        // build a better error message by looking at the log files
        File logDir = storage.getTmpLogs();
        msg += "Log folder: " + logDir.getAbsolutePath() + "\n";
        List<File> files = FileIOUtils.getRecursivelyAllFilesInAllSubfolders(logDir, ".log");
        msg += "# log files: " + files.size() + "\n";
        for (File log : files) {
            String content = null;
            try {
                content = FileUtils.readFileToString(log);
            } catch (IOException e) {
                msg += "Failed to read file " + log.getName() + " due to: " + e.toString() + "\n";
            }
            if (content != null) {
                msg += "Content for file: " + log.getName() + "\n";
                msg += "--------------------------------------------------" + "\n";
                msg += content;
                msg += "\n" + "--------------------------------------------------" + "\n";
            }
        }
    }
    Assert.assertEquals(msg, 2, data.size());
    Assert.assertTrue(msg, areThereTests);
    boolean deleted = storage.clean();
    Assert.assertTrue(deleted);
}
Also used : CtgConfiguration(org.evosuite.continuous.CtgConfiguration) TestsOnDisk(org.evosuite.continuous.persistency.StorageManager.TestsOnDisk) IOException(java.io.IOException) Simple(com.examples.with.different.packagename.continuous.Simple) UsingSimpleAndTrivial(com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial) Trivial(com.examples.with.different.packagename.continuous.Trivial) File(java.io.File) Test(org.junit.Test)

Example 2 with TestsOnDisk

use of org.evosuite.continuous.persistency.StorageManager.TestsOnDisk in project evosuite by EvoSuite.

the class JobExecutorIntTest method testEventSequenceWhenWrongSchedule.

@Test
public void testEventSequenceWhenWrongSchedule() throws InterruptedException {
    boolean storageOK = storage.isStorageOk();
    assertTrue(storageOK);
    storageOK = storage.createNewTmpFolders();
    assertTrue(storageOK);
    List<TestsOnDisk> data = storage.gatherGeneratedTestsOnDisk();
    Assert.assertEquals(0, data.size());
    // no need to specify it, as com.examples are compiled with EvoSuite
    String classpath = System.getProperty("java.class.path");
    int cores = 1;
    int memory = 1000;
    int minutes = 10000;
    CtgConfiguration conf = new CtgConfiguration(memory, cores, minutes, 1, false, AvailableSchedule.SIMPLE);
    final JobExecutor exe = new JobExecutor(storage, classpath, conf);
    JobDefinition simple = new JobDefinition(30, memory, Simple.class.getName(), 0, null, null);
    JobDefinition trivial = new JobDefinition(30, memory, Trivial.class.getName(), 0, null, null);
    JobDefinition ust = new JobDefinition(30, memory, UsingSimpleAndTrivial.class.getName(), 0, new HashSet<>(Arrays.asList(new String[] { Simple.class.getName(), Trivial.class.getName() })), null);
    /*
		 * ust is in the middle, instead of last element.
		 * still, even if the schedule is wrong, the executor should be able
		 * to properly handle it 
		 */
    final List<JobDefinition> jobs = Arrays.asList(simple, ust, trivial);
    exe.initExecution(jobs);
    Thread t = new Thread() {

        @Override
        public void run() {
            exe.execute(jobs);
        }
    };
    try {
        t.start();
        exe.doneWithJob(exe.pollJob());
        exe.doneWithJob(exe.pollJob());
        JobDefinition last = exe.pollJob();
        exe.doneWithJob(last);
        Assert.assertEquals(ust.cut, last.cut);
    } finally {
        t.interrupt();
    }
    storage.clean();
}
Also used : CtgConfiguration(org.evosuite.continuous.CtgConfiguration) TestsOnDisk(org.evosuite.continuous.persistency.StorageManager.TestsOnDisk) Simple(com.examples.with.different.packagename.continuous.Simple) UsingSimpleAndTrivial(com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial) Trivial(com.examples.with.different.packagename.continuous.Trivial) UsingSimpleAndTrivial(com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial) Test(org.junit.Test)

Aggregations

Simple (com.examples.with.different.packagename.continuous.Simple)2 Trivial (com.examples.with.different.packagename.continuous.Trivial)2 UsingSimpleAndTrivial (com.examples.with.different.packagename.continuous.UsingSimpleAndTrivial)2 CtgConfiguration (org.evosuite.continuous.CtgConfiguration)2 TestsOnDisk (org.evosuite.continuous.persistency.StorageManager.TestsOnDisk)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1