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

[Master] Fix caching issues with execute action #2015

Merged
merged 6 commits into from
May 29, 2024
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
6 changes: 3 additions & 3 deletions ballerina-tests/http-advanced-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_advanced_tests"
version = "2.11.0"
version = "2.11.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.11.0"
version = "2.11.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.11.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.11.1-SNAPSHOT.jar"
8 changes: 4 additions & 4 deletions ballerina-tests/http-advanced-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.0"
version = "2.7.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -72,7 +72,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -105,7 +105,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_advanced_tests"
version = "2.11.0"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
Expand All @@ -125,7 +125,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ isolated int noCacheHitCountNew = 0;
isolated int maxAgeHitCountNew = 0;
isolated int numberOfHitsNew = 0;
isolated int statusHits = 0;
isolated int greetingHits = 0;
final readonly & xml maxAgePayload1 = xml `<message>before cache expiration</message>`;
final readonly & xml maxAgePayload2 = xml `<message>after cache expiration</message>`;
readonly & string errorBody = "Error";
Expand Down Expand Up @@ -160,6 +161,13 @@ service / on new http:Listener(cacheAnnotationTestPort2, httpVersion = http:HTTP
return err;
}
}

resource function default greeting() returns @http:Cache {maxAge: 10} json {
lock {
greetingHits += 1;
}
return {"message": "Hello, World!"};
}
}

@test:Config {}
Expand Down Expand Up @@ -318,3 +326,50 @@ function testReturnStatusCodeResponsesWithAnnotation() returns error? {
common:assertTextPayload(response.getTextPayload(), errorBody);
return;
}

@test:Config {}
function testBasicCachingBehaviourWithExecute() returns error? {
check checkBasicCachingBehaviourWithExecute("GET", 1);
runtime:sleep(1);
check checkBasicCachingBehaviourWithExecute("get", 1);
runtime:sleep(1);
check checkBasicCachingBehaviourWithExecute("HEAD", 2);
runtime:sleep(1);
check checkBasicCachingBehaviourWithExecute("head", 2);
}

function checkBasicCachingBehaviourWithExecute(string method, int hitCount) returns error? {
http:Response|error response = cacheBackendEP->execute(method, "/greeting", new http:Request());
if response is http:Response {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
lock {
test:assertEquals(greetingHits, hitCount);
}
} else {
test:assertFail(msg = "Found unexpected output type: " + response.message());
}

runtime:sleep(1);

response = cacheBackendEP->execute(method, "/greeting", new http:Request());
if response is http:Response {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
lock {
test:assertEquals(greetingHits, hitCount);
}
} else {
test:assertFail(msg = "Found unexpected output type: " + response.message());
}

runtime:sleep(1);

response = cacheBackendEP->execute(method, "/greeting", new http:Request());
if response is http:Response {
test:assertEquals(response.statusCode, 200, msg = "Found unexpected output");
lock {
test:assertEquals(greetingHits, hitCount);
}
} else {
test:assertFail(msg = "Found unexpected output type: " + response.message());
}
}
6 changes: 3 additions & 3 deletions ballerina-tests/http-client-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_client_tests"
version = "2.11.0"
version = "2.11.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.11.0"
version = "2.11.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.11.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.11.1-SNAPSHOT.jar"
8 changes: 4 additions & 4 deletions ballerina-tests/http-client-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ modules = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.0"
version = "2.7.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -102,7 +102,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_client_tests"
version = "2.11.0"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
Expand All @@ -121,7 +121,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-dispatching-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_dispatching_tests"
version = "2.11.0"
version = "2.11.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.11.0"
version = "2.11.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.11.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.11.1-SNAPSHOT.jar"
8 changes: 4 additions & 4 deletions ballerina-tests/http-dispatching-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ modules = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.0"
version = "2.7.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -102,7 +102,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_dispatching_tests"
version = "2.11.0"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
Expand All @@ -124,7 +124,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-interceptor-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_interceptor_tests"
version = "2.11.0"
version = "2.11.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.11.0"
version = "2.11.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.11.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.11.1-SNAPSHOT.jar"
8 changes: 4 additions & 4 deletions ballerina-tests/http-interceptor-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.0"
version = "2.7.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -99,7 +99,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_interceptor_tests"
version = "2.11.0"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -115,7 +115,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-misc-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_misc_tests"
version = "2.11.0"
version = "2.11.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.11.0"
version = "2.11.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.11.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.11.1-SNAPSHOT.jar"
8 changes: 4 additions & 4 deletions ballerina-tests/http-misc-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.0"
version = "2.7.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -99,7 +99,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_misc_tests"
version = "2.11.0"
version = "2.11.1"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -118,7 +118,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.11.0"
version = "2.11.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-resiliency-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
org = "ballerina"
name = "http_resiliency_tests"
version = "2.11.0"
version = "2.11.1"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.11.0"
version = "2.11.1"

[platform.java17]
graalvmCompatible = true

[[platform.java17.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.11.0.jar"
path = "../../test-utils/build/libs/http-test-utils-2.11.1-SNAPSHOT.jar"
Loading
Loading