Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Integration Benchmark tests for performance analysis of API-Manager #3425 #13610

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.wso2.am</groupId>
<artifactId>tests-common</artifactId>
<version>4.4.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<groupId>org.wso2.am.integration.backend.service</groupId>
<artifactId>ssl-server</artifactId>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.wso2.am.integration.backend.service;

import com.sun.net.httpserver.HttpsServer;

import java.io.IOException;
import java.net.ServerSocket;

public class AbstractSSLServer {
private HttpsServer server;

public AbstractSSLServer() {
System.out.println("initiating "+ this.getClass().getSimpleName() +" server ");
}

public void setServer(HttpsServer server) {
this.server = server;
}

public void run(int port, String content, int statusCode) throws Exception {}

// public void shutdownServer() throws InterruptedException {
// try {
// while (!isserverdone){
// Thread.sleep(10);
// }
// System.out.println("Shutting down the "+ this.getClass().getSimpleName() +" server");
// ss.close();
// } catch (IOException e) {
// System.out.println("Error while shutting down the server ");
// }
// }
public void stop() {
if (server != null) {
server.stop(0); // Stops the server immediately (0-second delay)
System.out.println("SSL Server has been stopped.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.wso2.am.integration.backend.service;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;

// Define the handler that processes incoming HTTP requests
public class Handler implements HttpHandler {
int statusCode;
String content;

public Handler(int statusCode, String content){
this.statusCode = statusCode;
this.content = content;
}
@Override
public void handle(HttpExchange exchange) throws IOException {
// Set the response headers (matching the ones from the SSL socket server)
exchange.getResponseHeaders().set("Access-Control-Expose-Headers", "");
exchange.getResponseHeaders().set("Access-Control-Allow-Origin", "*");
exchange.getResponseHeaders().set("X-Correlation-ID", "9f22c69b-6673-4326-8aff-0c0c097cd3c0");
exchange.getResponseHeaders().set("Access-Control-Allow-Headers",
"authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction,apikey,testKey,Authorization");
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.getResponseHeaders().set("Date", "Tue, 14 Dec 2021 08:15:17 GMT");
exchange.getResponseHeaders().set("Connection", "Close");

// Send response headers with status code and the length of the JSON response

exchange.sendResponseHeaders(statusCode, content.getBytes().length);

// Write the JSON response to the output stream
OutputStream os = exchange.getResponseBody();
os.write(content.getBytes());
os.close();
}

public static String readFile(String fileLocation) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(fileLocation));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();

while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
String everything = sb.toString();
return everything;
} finally {
br.close();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.wso2.am.integration.backend.service;

import com.sun.net.httpserver.HttpsServer;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.*;
import java.net.InetSocketAddress;
import java.security.KeyStore;
import java.util.concurrent.Executors;

public class SSLServerSendImmediateResponse extends AbstractSSLServer {

public void run(int port, String content, int statusCode) throws InterruptedException {
// Create a new thread to run the server
try {
// Initialize the SSL context with the keystore
SSLContext sslContext = SSLContext.getInstance("TLS");

KeyStore keyStore = KeyStore.getInstance("JKS");
FileInputStream fis = new FileInputStream("../src/test/resources/keystores/products/wso2carbon.jks");
keyStore.load(fis, "wso2carbon".toCharArray());

KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(keyStore, "wso2carbon".toCharArray());

TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(keyStore);

sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

// Create an HttpsServer instance
HttpsServer server = HttpsServer.create(new InetSocketAddress(8100), 0);
this.setServer(server);
server.setHttpsConfigurator(new com.sun.net.httpserver.HttpsConfigurator(sslContext));

server.createContext("/", new Handler(statusCode,content));
server.setExecutor(Executors.newSingleThreadExecutor());
server.start();

System.out.println("SSL Server is listening on port 8100...");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.wso2.am.integration.backend.service;

import com.sun.net.httpserver.HttpsServer;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.security.KeyStore;
import java.util.concurrent.Executors;

public class SimpleHTTPSServer {

private final String keyStoreLocation;
private final String keyStorePassword;

public SimpleHTTPSServer(String keyStoreLocation, String keyStorePassword){
this.keyStoreLocation = keyStoreLocation;
this.keyStorePassword =keyStorePassword;
}

public void run() throws InterruptedException {
// Create a new thread to run the server
try {
// Initialize the SSL context with the keystore
SSLContext sslContext = SSLContext.getInstance("TLS");

KeyStore keyStore = KeyStore.getInstance("JKS");
FileInputStream fis = new FileInputStream(this.keyStoreLocation);
keyStore.load(fis, this.keyStorePassword.toCharArray());

KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(keyStore, this.keyStorePassword.toCharArray());

TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(keyStore);

sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

// Create an HttpsServer instance
HttpsServer server = HttpsServer.create(new InetSocketAddress(8100), 0);
server.setHttpsConfigurator(new com.sun.net.httpserver.HttpsConfigurator(sslContext));

server.createContext("/", new SimpleHTTPSServer.MyHandler());
server.setExecutor(Executors.newSingleThreadExecutor());
server.start();

System.out.println("SSL Server is listening on port 8100...");
} catch (Exception e) {
e.printStackTrace();
}
}

// Define the handler that processes incoming HTTP requests
public static class MyHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
// Respond with status code 200 for any request method
t.sendResponseHeaders(200, 0);
OutputStream os = t.getResponseBody();
os.close();
}
}
}

1 change: 1 addition & 0 deletions modules/integration/tests-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ under the License.
<module>ui-pages</module>
<module>clients</module>
<module>extenstions</module>
<module>backend-service/ssl-server</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -451,5 +451,11 @@ under the License.
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.am.integration.backend.service</groupId>
<artifactId>ssl-server</artifactId>
<version>4.4.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading
Loading