-
Notifications
You must be signed in to change notification settings - Fork 5
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 #26 from ETS-TAF/gatling
Gatling integration
- Loading branch information
Showing
68 changed files
with
5,624 additions
and
4 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
backend/src/main/java/ca/etsmtl/taf/controller/GatlingApiController.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,54 @@ | ||
package ca.etsmtl.taf.controller; | ||
|
||
import ca.etsmtl.taf.entity.GatlingRequest; | ||
import ca.etsmtl.taf.provider.GatlingJarPathProvider; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@CrossOrigin(origins = "*", maxAge = 3600) | ||
@RestController | ||
@RequestMapping("/api/gatling") | ||
public class GatlingApiController { | ||
|
||
@PostMapping("/runSimulation") | ||
public String runSimulation(@RequestBody GatlingRequest gatlingRequest) { | ||
try { | ||
String gatlingJarPath = new GatlingJarPathProvider().getGatlingJarPath(); | ||
|
||
String testRequest = "{\\\"baseUrl\\\":\\\""+gatlingRequest.getTestBaseUrl()+"\\\",\\\"scenarioName\\\":\\\""+gatlingRequest.getTestScenarioName()+"\\\",\\\"requestName\\\":\\\""+gatlingRequest.getTestRequestName()+"\\\",\\\"uri\\\":\\\""+gatlingRequest.getTestUri()+"\\\",\\\"requestBody\\\":\\\""+gatlingRequest.getTestRequestBody()+"\\\",\\\"methodType\\\":\\\""+gatlingRequest.getTestMethodType()+"\\\",\\\"usersNumber\\\":\\\""+gatlingRequest.getTestUsersNumber()+"\\\"}"; | ||
//Construire une liste d'arguments de ligne de commande à transmettre à Gatling | ||
List<String> commandArgs = new ArrayList<>(); | ||
commandArgs.add("java"); | ||
commandArgs.add("-jar"); | ||
commandArgs.add(gatlingJarPath); | ||
commandArgs.add("-DrequestJson=" + testRequest); | ||
|
||
// Exécuter la simulation Gatling en tant que processus distinct | ||
ProcessBuilder processBuilder = new ProcessBuilder(commandArgs); | ||
Process process = processBuilder.start(); | ||
// Lire le résultat du processus | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); | ||
String line; | ||
StringBuilder output = new StringBuilder(); | ||
while ((line = reader.readLine()) != null) { | ||
output.append(line).append('\n'); | ||
} | ||
|
||
int exitCode = process.waitFor(); | ||
return "Exit Code: " + exitCode + "\nOutput:\n" + output.toString(); | ||
} catch (IOException e) { | ||
return "Error: " + e.getMessage(); | ||
} catch (URISyntaxException e) { | ||
return "Error: " + e.getMessage(); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
return "Error: " + e.getMessage(); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
backend/src/main/java/ca/etsmtl/taf/entity/GatlingRequest.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,67 @@ | ||
package ca.etsmtl.taf.entity; | ||
|
||
public class GatlingRequest { | ||
private String testBaseUrl; | ||
private String testScenarioName; | ||
private String testRequestName; | ||
private String testUri; | ||
private String testRequestBody; | ||
private String testMethodType; | ||
private int testUsersNumber; | ||
|
||
public String getTestBaseUrl() { | ||
return testBaseUrl; | ||
} | ||
|
||
public void setTestBaseUrl(String testBaseUrl) { | ||
this.testBaseUrl = testBaseUrl; | ||
} | ||
|
||
public String getTestScenarioName() { | ||
return testScenarioName; | ||
} | ||
|
||
public void setTestScenarioName(String testScenarioName) { | ||
this.testScenarioName = testScenarioName; | ||
} | ||
|
||
public String getTestRequestName() { | ||
return testRequestName; | ||
} | ||
|
||
public void setTestRequestName(String testRequestName) { | ||
this.testRequestName = testRequestName; | ||
} | ||
|
||
public String getTestUri() { | ||
return testUri; | ||
} | ||
|
||
public void setTestUri(String testUri) { | ||
this.testUri = testUri; | ||
} | ||
|
||
public String getTestRequestBody() { | ||
return testRequestBody; | ||
} | ||
|
||
public void setTestRequestBody(String testRequestBody) { | ||
this.testRequestBody = testRequestBody; | ||
} | ||
|
||
public String getTestMethodType() { | ||
return testMethodType; | ||
} | ||
|
||
public void setTestMethodType(String testMethodType) { | ||
this.testMethodType = testMethodType; | ||
} | ||
|
||
public int getTestUsersNumber() { | ||
return testUsersNumber; | ||
} | ||
|
||
public void setTestUsersNumber(int testUsersNumber) { | ||
this.testUsersNumber = testUsersNumber; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/ca/etsmtl/taf/provider/GatlingJarPathProvider.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,22 @@ | ||
package ca.etsmtl.taf.provider; | ||
|
||
import java.io.File; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class GatlingJarPathProvider { | ||
public String getGatlingJarPath() throws URISyntaxException { | ||
|
||
Path backendDirectory = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getParent().getParent(); | ||
Path parentDirectory = backendDirectory.getParent(); | ||
|
||
//Construire le chemin vers le Gatling JAR | ||
File gatlingJar = parentDirectory.resolve("gatling").resolve("target").resolve("gatling-1.0-SNAPSHOT-jar-with-dependencies.jar").toFile(); | ||
if (gatlingJar.exists()) { | ||
return gatlingJar.getAbsolutePath(); | ||
} else { | ||
return "Gatling JAR not found!"; | ||
} | ||
} | ||
} |
Binary file not shown.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
16 changes: 16 additions & 0 deletions
16
frontend/src/app/_services/performance-test-api.service.spec.ts
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,16 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { TestBed, async, inject } from '@angular/core/testing'; | ||
import { PerformanceTestApiService } from './performance-test-api.service'; | ||
|
||
describe('Service: PerformanceTestApi', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [PerformanceTestApiService] | ||
}); | ||
}); | ||
|
||
it('should ...', inject([PerformanceTestApiService], (service: PerformanceTestApiService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
30 changes: 30 additions & 0 deletions
30
frontend/src/app/_services/performance-test-api.service.ts
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,30 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { environment } from '../../environments/environment'; | ||
import { GatlingRequest } from '../performance-test-api/gatling-api/gatling-request'; | ||
|
||
|
||
const GATLING_API = `${environment.apiUrl}/api/gatling/runSimulation`; | ||
|
||
const httpOptions = { | ||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }) | ||
}; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class PerformanceTestApiService { | ||
|
||
|
||
constructor(private http: HttpClient) { } | ||
|
||
sendGatlingRequest(request: GatlingRequest): Observable<any> { | ||
const url = `${GATLING_API}`; | ||
const headers = new HttpHeaders({ | ||
'Content-Type': 'application/json' | ||
}); | ||
return this.http.post(url, request, httpOptions); | ||
} | ||
|
||
} |
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
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,5 @@ | ||
#app, .container{ | ||
height: 100%; | ||
max-width: 100%; | ||
padding: 0; | ||
} |
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
Oops, something went wrong.