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

Update existing performance tests to use more "modern" coding styles #63

Merged
Merged
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
22 changes: 13 additions & 9 deletions distribution/scripts/ballerina/bal/h1_h1_passthrough.bal
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
import ballerina/http;
import ballerina/log;

listener http:Listener securedEP = new(9090,
configurable string epKeyPath = ?;
configurable string epTrustStorePath = ?;
configurable string epKeyPassword = ?;

listener http:Listener securedEP = new (9090,
secureSocket = {
key: {
path: "${ballerina.home}/bre/security/ballerinaKeystore.p12",
password: "ballerina"
path: epKeyPath,
password: epKeyPassword
}
}
);

final http:Client nettyEP = check new("https://netty:8688",
final http:Client nettyEP = check new ("https://netty:8688",
secureSocket = {
cert: {
path: "${ballerina.home}/bre/security/ballerinaTruststore.p12",
password: "ballerina"
path: epTrustStorePath,
password: epKeyPassword
},
verifyHostName: false
}
);

service /passthrough on securedEP {
resource function post .(http:Caller caller, http:Request clientRequest) {
isolated resource function post .(http:Request clientRequest) returns http:Response {
http:Response|http:ClientError response = nettyEP->forward("/service/EchoService", clientRequest);
if (response is http:Response) {
error? result = caller->respond(response);
return response;
} else {
log:printError("Error at h1_h1_passthrough", 'error = response);
http:Response res = new;
res.statusCode = 500;
res.setPayload(response.message());
error? result = caller->respond(res);
return res;
}
}
}
69 changes: 34 additions & 35 deletions distribution/scripts/ballerina/bal/h1_transformation.bal
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,55 @@ import ballerina/http;
import ballerina/log;
import ballerina/xmldata;

listener http:Listener securedEP = new(9090,
configurable string epKeyPath = ?;
configurable string epTrustStorePath = ?;
configurable string epKeyPassword = ?;

listener http:Listener securedEP = new (9090,
secureSocket = {
key: {
path: "${ballerina.home}/bre/security/ballerinaKeystore.p12",
password: "ballerina"
path: epKeyPath,
password: epKeyPassword
}
}
);

final http:Client nettyEP = check new("https://netty:8688",
final http:Client nettyEP = check new ("https://netty:8688",
secureSocket = {
cert: {
path: "${ballerina.home}/bre/security/ballerinaTruststore.p12",
password: "ballerina"
path: epTrustStorePath,
password: epKeyPassword
},
verifyHostName: false
}
);

service /transform on securedEP {
resource function post .(http:Caller caller, http:Request req) {
isolated resource function post .(http:Request req) returns http:Response {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why we are not using data binding instead?

json|error payload = req.getJsonPayload();
if (payload is json) {
xml|xmldata:Error? xmlPayload = xmldata:fromJson(payload);
if (xmlPayload is xml) {
http:Request clinetreq = new;
clinetreq.setXmlPayload(xmlPayload);
http:Response|http:ClientError response = nettyEP->post("/service/EchoService", clinetreq);
if (response is http:Response) {
error? result = caller->respond(response);
} else {
log:printError("Error at h1_transformation", 'error = response);
http:Response res = new;
res.statusCode = 500;
res.setPayload(response.message());
error? result = caller->respond(res);
}
} else if (xmlPayload is xmldata:Error) {
log:printError("Error at h1_transformation", 'error = xmlPayload);
http:Response res = new;
res.statusCode = 400;
res.setPayload(xmlPayload.message());
error? result = caller->respond(res);
}
} else {
log:printError("Error at h1_transformation", 'error = payload);
http:Response res = new;
res.statusCode = 400;
res.setPayload(payload.message());
error? result = caller->respond(res);
if payload is error {
return getErrorResponse(payload, http:STATUS_BAD_REQUEST);
}
xml|xmldata:Error? xmlPayload = xmldata:fromJson(payload);
if xmlPayload is xmldata:Error? {
return getErrorResponse(xmlPayload, http:STATUS_BAD_REQUEST);
}
http:Request clinetreq = new;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, but also probably clientReq.

clinetreq.setXmlPayload(xmlPayload);
http:Response|http:ClientError response = nettyEP->post("/service/EchoService", clinetreq);
if response is http:ClientError {
return getErrorResponse(response, http:STATUS_INTERNAL_SERVER_ERROR);
}
return response;
}
}

isolated function getErrorResponse(error? err, int statusCode) returns http:Response {
log:printError("Error at h1_transformation", 'error = err);
http:Response res = new;
res.statusCode = statusCode;
if err != () {
res.setPayload(err.message());
}
return res;
}
10 changes: 5 additions & 5 deletions distribution/scripts/ballerina/bal/h1c_h1c_passthrough.bal
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import ballerina/http;
import ballerina/log;

final http:Client nettyEP = check new("http://netty:8688");
final http:Client nettyEP = check new ("http://netty:8688");

service /passthrough on new http:Listener(9090) {
resource function post .(http:Caller caller, http:Request clientRequest) {
isolated resource function post .(http:Request clientRequest) returns http:Response {
http:Response|http:ClientError response = nettyEP->forward("/service/EchoService", clientRequest);
if (response is http:Response) {
error? result = caller->respond(response);
return response;
} else {
log:printError("Error at h1c_h1c_passthrough", 'error = response);
log:printError("Error at h1_h1_passthrough", 'error = response);
http:Response res = new;
res.statusCode = 500;
res.setPayload(response.message());
error? result = caller->respond(res);
return res;
}
}
}
55 changes: 25 additions & 30 deletions distribution/scripts/ballerina/bal/h1c_transformation.bal
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,34 @@ import ballerina/http;
import ballerina/log;
import ballerina/xmldata;

final http:Client nettyEP = check new("http://netty:8688");
final http:Client nettyEP = check new ("http://netty:8688");

service /transform on new http:Listener(9090) {
resource function post .(http:Caller caller, http:Request req) {
isolated resource function post .(http:Request req) returns http:Response {
json|error payload = req.getJsonPayload();
if (payload is json) {
xml|xmldata:Error? xmlPayload = xmldata:fromJson(payload);
if (xmlPayload is xml) {
http:Request clinetreq = new;
clinetreq.setXmlPayload(xmlPayload);
http:Response|http:ClientError response = nettyEP->post("/service/EchoService", clinetreq);
if (response is http:Response) {
error? result = caller->respond(response);
} else {
log:printError("Error at h1c_transformation", 'error = response);
http:Response res = new;
res.statusCode = 500;
res.setPayload(response.message());
error? result = caller->respond(res);
}
} else if (xmlPayload is xmldata:Error) {
log:printError("Error at h1c_transformation", 'error = xmlPayload);
http:Response res = new;
res.statusCode = 400;
res.setPayload(xmlPayload.message());
error? result = caller->respond(res);
}
} else {
log:printError("Error at h1c_transformation", 'error = payload);
http:Response res = new;
res.statusCode = 400;
res.setPayload(payload.message());
error? result = caller->respond(res);
if payload is error {
return getErrorResponse(payload, http:STATUS_BAD_REQUEST);
}
xml|xmldata:Error? xmlPayload = xmldata:fromJson(payload);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably change these to use the new xmldata module?

if xmlPayload is xmldata:Error? {
return getErrorResponse(xmlPayload, http:STATUS_BAD_REQUEST);
}
http:Request clinetreq = new;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

clinetreq.setXmlPayload(xmlPayload);
http:Response|http:ClientError response = nettyEP->post("/service/EchoService", clinetreq);
if response is http:ClientError {
return getErrorResponse(response, http:STATUS_INTERNAL_SERVER_ERROR);
}
return response;
}
}

isolated function getErrorResponse(error? err, int statusCode) returns http:Response {
log:printError("Error at h1_transformation", 'error = err);
http:Response res = new;
res.statusCode = statusCode;
if err != () {
res.setPayload(err.message());
}
return res;
}
25 changes: 14 additions & 11 deletions distribution/scripts/ballerina/bal/h2_h1_passthrough.bal
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import ballerina/http;
import ballerina/log;

listener http:Listener securedEP = new(9090,
httpVersion = "2.0",
configurable string epKeyPath = ?;
configurable string epTrustStorePath = ?;
configurable string epKeyPassword = ?;

listener http:Listener securedEP = new (9090,
secureSocket = {
key: {
path: "${ballerina.home}/bre/security/ballerinaKeystore.p12",
password: "ballerina"
path: epKeyPath,
password: epKeyPassword
}
}
);

final http:Client nettyEP = check new("https://netty:8688",
final http:Client nettyEP = check new ("https://netty:8688",
secureSocket = {
cert: {
path: "${ballerina.home}/bre/security/ballerinaTruststore.p12",
password: "ballerina"
path: epTrustStorePath,
password: epKeyPassword
},
verifyHostName: false
}
);

service /passthrough on securedEP {
resource function post .(http:Caller caller, http:Request clientRequest) {
isolated resource function post .(http:Request clientRequest) returns http:Response {
http:Response|http:ClientError response = nettyEP->forward("/service/EchoService", clientRequest);
if (response is http:Response) {
error? result = caller->respond(response);
return response;
} else {
log:printError("Error at h2_h1_passthrough", 'error = response);
log:printError("Error at h1_h1_passthrough", 'error = response);
http:Response res = new;
res.statusCode = 500;
res.setPayload(response.message());
error? result = caller->respond(res);
return res;
}
}
}
18 changes: 10 additions & 8 deletions distribution/scripts/ballerina/bal/h2_h1c_passthrough.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@
import ballerina/http;
import ballerina/log;

listener http:Listener securedEP = new(9090,
configurable string epTrustStorePath = ?;
configurable string epKeyPassword = ?;
listener http:Listener securedEP = new (9090,
httpVersion = "2.0",
secureSocket = {
key: {
path: "${ballerina.home}/bre/security/ballerinaKeystore.p12",
password: "ballerina"
path: epTrustStorePath,
password: epKeyPassword
}
}
);

final http:Client nettyEP = check new("http://netty:8688");
final http:Client nettyEP = check new ("http://netty:8688");

service /passthrough on securedEP {
resource function post .(http:Caller caller, http:Request clientRequest) {
isolated resource function post .(http:Request clientRequest) returns http:Response {
http:Response|http:ClientError response = nettyEP->forward("/service/EchoService", clientRequest);
if (response is http:Response) {
error? result = caller->respond(response);
return response;
} else {
log:printError("Error at h2_h1c_passthrough", 'error = response);
log:printError("Error at h1_h1_passthrough", 'error = response);
http:Response res = new;
res.statusCode = 500;
res.setPayload(response.message());
error? result = caller->respond(res);
return res;
}
}
}
26 changes: 14 additions & 12 deletions distribution/scripts/ballerina/bal/h2_h2_passthrough.bal
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
import ballerina/http;
import ballerina/log;

listener http:Listener securedEP = new(9090,
httpVersion = "2.0",
configurable string epKeyPath = ?;
configurable string epTrustStorePath = ?;
configurable string epKeyPassword = ?;

listener http:Listener securedEP = new (9090,
secureSocket = {
key: {
path: "${ballerina.home}/bre/security/ballerinaKeystore.p12",
password: "ballerina"
path: epKeyPath,
password: epKeyPassword
}
}
);

final http:Client nettyEP = check new("https://netty:8688",
httpVersion = "2.0",
final http:Client nettyEP = check new ("https://netty:8688",
secureSocket = {
cert: {
path: "${ballerina.home}/bre/security/ballerinaTruststore.p12",
password: "ballerina"
path: epTrustStorePath,
password: epKeyPassword
},
verifyHostName: false
}
);

service /passthrough on securedEP {
resource function post .(http:Caller caller, http:Request clientRequest) {
isolated resource function post .(http:Request clientRequest) returns http:Response {
http:Response|http:ClientError response = nettyEP->forward("/service/EchoService", clientRequest);
if (response is http:Response) {
error? result = caller->respond(response);
return response;
} else {
log:printError("Error at h2_h2_passthrough", 'error = response);
log:printError("Error at h1_h1_passthrough", 'error = response);
http:Response res = new;
res.statusCode = 500;
res.setPayload(response.message());
error? result = caller->respond(res);
return res;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ballerina/data.jsondata;
import ballerina/http;

configurable string epKeyPath = ?;
configurable string epTrustStorePath = ?;
configurable string epKeyPassword = ?;

listener http:Listener securedEP = new (9090,
Expand All @@ -32,7 +33,7 @@ listener http:Listener securedEP = new (9090,
final http:Client nettyEP = check new ("netty:8688",
secureSocket = {
cert: {
path: epKeyPath,
path: epTrustStorePath,
password: epKeyPassword
},
verifyHostName: false
Expand Down
Loading