-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from virtualansoftware/parallelExecution
Parallel execution
- Loading branch information
Showing
40 changed files
with
1,035 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
modules/idaithalam/src/main/java/io/virtualan/idaithalam/contract/ExecutionClassloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.virtualan.idaithalam.contract; | ||
|
||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
|
||
/** | ||
* The type Execution classloader. | ||
*/ | ||
public class ExecutionClassloader extends URLClassLoader { | ||
|
||
/** | ||
* Instantiates a new Execution classloader. | ||
* | ||
* @param urls the urls | ||
* @param classLoader the class loader | ||
*/ | ||
public ExecutionClassloader(URL[] urls, ClassLoader classLoader) { | ||
super(urls, classLoader); | ||
} | ||
|
||
@Override | ||
public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { | ||
return super.loadClass(name, resolve); | ||
} | ||
|
||
@Override | ||
protected Class<?> findClass(String name) throws ClassNotFoundException { | ||
return super.findClass(name); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
modules/idaithalam/src/main/java/io/virtualan/idaithalam/core/api/MassApiExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.virtualan.idaithalam.core.api; | ||
|
||
import io.virtualan.idaithalam.core.domain.ExecutionPlanner; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.yaml.snakeyaml.Yaml; | ||
import org.yaml.snakeyaml.constructor.Constructor; | ||
|
||
@Slf4j | ||
public class MassApiExecutor { | ||
|
||
private static final int NTHREDS = 1; | ||
|
||
public static boolean invoke(String configMapper) throws InterruptedException { | ||
Yaml yaml = new Yaml(new Constructor(ExecutionPlanner.class)); | ||
InputStream inputStream = MassApiExecutor.class.getClassLoader() | ||
.getResourceAsStream(configMapper); | ||
ExecutionPlanner executionPlanner = yaml.load(inputStream); | ||
ExecutorService executor = Executors | ||
.newFixedThreadPool(executionPlanner.getApiExecutor().size()); | ||
List<Future<Integer>> futures = new ArrayList<>(); | ||
executionPlanner.getApiExecutor().stream().forEach( | ||
x -> { | ||
Callable worker = new ParallelExecutor(x); | ||
Future future = executor.submit(worker); | ||
futures.add(future); | ||
}); | ||
|
||
// This will make the executor accept no new threads | ||
// and finish all existing threads in the queue | ||
executor.shutdown(); | ||
while (!executor.isTerminated()) { | ||
} | ||
// Wait until all threads are finish | ||
executor.awaitTermination(executionPlanner.getTimeout(), TimeUnit.MINUTES); | ||
boolean bool = futures.stream().anyMatch(x -> { | ||
try { | ||
return x.get() != 0; | ||
} catch (InterruptedException | ExecutionException e) { | ||
return false; | ||
} | ||
}); | ||
|
||
log.info("Finished all api execution"); | ||
return true; | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
modules/idaithalam/src/main/java/io/virtualan/idaithalam/core/api/ParallelExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.virtualan.idaithalam.core.api; | ||
|
||
import io.virtualan.idaithalam.contract.IdaithalamExecutor; | ||
import io.virtualan.idaithalam.core.domain.ApiExecutorParam; | ||
import io.virtualan.idaithalam.core.generator.ExcelToCollectionGenerator; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.concurrent.Callable; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class ParallelExecutor implements Callable<Integer> { | ||
|
||
private String outputDir; | ||
private String inputExcel; | ||
private String env; | ||
private String reportTitle; | ||
private Map<String, String> cucumblanProperies; | ||
|
||
ParallelExecutor(ApiExecutorParam apiExecutorPrarm) { | ||
this.outputDir = apiExecutorPrarm.getOutputDir(); | ||
this.inputExcel = apiExecutorPrarm.getInputExcel(); | ||
this.env = apiExecutorPrarm.getEnv(); | ||
this.reportTitle = apiExecutorPrarm.getReportTitle(); | ||
this.cucumblanProperies = apiExecutorPrarm.getCucumblanProperies(); | ||
} | ||
|
||
|
||
@Override | ||
public Integer call() { | ||
int status = 0; | ||
try { | ||
File f = new File(outputDir); | ||
if (!f.exists()) { | ||
f.mkdirs(); | ||
} | ||
ExcelToCollectionGenerator.createCollection(null, inputExcel, outputDir); | ||
|
||
if(cucumblanProperies != null && !cucumblanProperies.isEmpty()) { | ||
File file = new File(outputDir +File.separator+"cucumblan.properties"); | ||
Properties properties = new Properties(); | ||
properties.load(new FileInputStream(file)); | ||
cucumblanProperies.entrySet().stream().forEach( | ||
x -> { | ||
properties.setProperty(x.getKey(), x.getValue()); | ||
} | ||
); | ||
ExcelToCollectionGenerator.createPrpos(outputDir, | ||
(Map)properties, | ||
"cucumblan.properties"); | ||
} | ||
//Generate feature and summary page html report for the selected testcase from the excel | ||
status = IdaithalamExecutor | ||
.validateContract(env + " : " + reportTitle, | ||
outputDir); | ||
} catch (Exception e) { | ||
log.warn(env + " : " + reportTitle + " : " + e.getMessage()); | ||
status = 1; | ||
e.printStackTrace(); | ||
} | ||
log.info(env + " : " + reportTitle + " : status : " + status); | ||
return status; | ||
} | ||
} |
Oops, something went wrong.