Skip to content

Commit

Permalink
Merge pull request #2011 from ballerina-platform/caching-with-execute…
Browse files Browse the repository at this point in the history
…-6.x

[2201.6.x] Fix caching issues with execute action
  • Loading branch information
TharmiganK authored May 29, 2024
2 parents 3a47f24 + c1c2a56 commit 7756f3d
Show file tree
Hide file tree
Showing 27 changed files with 130 additions and 69 deletions.
6 changes: 3 additions & 3 deletions ballerina-tests/http-advanced-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
org = "ballerina"
name = "http_advanced_tests"
version = "2.8.6"
version = "2.8.7"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.8.6"
version = "2.8.7"

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.8.6.jar"
path = "../../test-utils/build/libs/http-test-utils-2.8.7-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-advanced-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -104,7 +104,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_advanced_tests"
version = "2.8.6"
version = "2.8.7"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
Expand All @@ -124,7 +124,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.8.6"
version = "2.8.7"
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,14 +1,14 @@
[package]
org = "ballerina"
name = "http_client_tests"
version = "2.8.6"
version = "2.8.7"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.8.6"
version = "2.8.7"

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.8.6.jar"
path = "../../test-utils/build/libs/http-test-utils-2.8.7-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-client-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -101,7 +101,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_client_tests"
version = "2.8.6"
version = "2.8.7"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
Expand All @@ -120,7 +120,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.8.6"
version = "2.8.7"
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,14 +1,14 @@
[package]
org = "ballerina"
name = "http_dispatching_tests"
version = "2.8.6"
version = "2.8.7"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.8.6"
version = "2.8.7"

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.8.6.jar"
path = "../../test-utils/build/libs/http-test-utils-2.8.7-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-dispatching-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -101,7 +101,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_dispatching_tests"
version = "2.8.6"
version = "2.8.7"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
Expand All @@ -123,7 +123,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.8.6"
version = "2.8.7"
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,14 +1,14 @@
[package]
org = "ballerina"
name = "http_interceptor_tests"
version = "2.8.6"
version = "2.8.7"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.8.6"
version = "2.8.7"

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.8.6.jar"
path = "../../test-utils/build/libs/http-test-utils-2.8.7-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-interceptor-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -98,7 +98,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_interceptor_tests"
version = "2.8.6"
version = "2.8.7"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -114,7 +114,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.8.6"
version = "2.8.7"
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,14 +1,14 @@
[package]
org = "ballerina"
name = "http_misc_tests"
version = "2.8.6"
version = "2.8.7"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.8.6"
version = "2.8.7"

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.8.6.jar"
path = "../../test-utils/build/libs/http-test-utils-2.8.7-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-misc-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -98,7 +98,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_misc_tests"
version = "2.8.6"
version = "2.8.7"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "http_test_common"},
Expand All @@ -117,7 +117,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.8.6"
version = "2.8.7"
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,14 +1,14 @@
[package]
org = "ballerina"
name = "http_resiliency_tests"
version = "2.8.6"
version = "2.8.7"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.8.6"
version = "2.8.7"

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.8.6.jar"
path = "../../test-utils/build/libs/http-test-utils-2.8.7-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-resiliency-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -98,7 +98,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_resiliency_tests"
version = "2.8.6"
version = "2.8.7"
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.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
6 changes: 3 additions & 3 deletions ballerina-tests/http-security-tests/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
org = "ballerina"
name = "http_security_tests"
version = "2.8.6"
version = "2.8.7"

[[dependency]]
org = "ballerina"
name = "http_test_common"
repository = "local"
version = "2.8.6"
version = "2.8.7"

[[platform.java11.dependency]]
scope = "testOnly"
path = "../../test-utils/build/libs/http-test-utils-2.8.6.jar"
path = "../../test-utils/build/libs/http-test-utils-2.8.7-SNAPSHOT.jar"
6 changes: 3 additions & 3 deletions ballerina-tests/http-security-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "auth"},
Expand Down Expand Up @@ -101,7 +101,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_security_tests"
version = "2.8.6"
version = "2.8.7"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "http"},
Expand All @@ -119,7 +119,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http_test_common"
version = "2.8.6"
version = "2.8.7"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "lang.string"},
Expand Down
Loading

0 comments on commit 7756f3d

Please sign in to comment.