Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/service-type-support' into servi…
Browse files Browse the repository at this point in the history
…ce-type-support
  • Loading branch information
TharmiganK committed Jul 25, 2024
2 parents fa6644c + 57634cb commit 4dcf9ed
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 15 deletions.
12 changes: 6 additions & 6 deletions ballerina-tests/http-advanced-tests/tests/http2_caching_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ service /cachingBackend on http2CachingListener2 { //new http:Listener(9240) {
isolated resource function 'default .(http:Caller caller, http:Request req) returns error? {
http:Response res = new;
http:ResponseCacheControl resCC = new;
resCC.maxAge = 60;
resCC.maxAge = 60.54;
resCC.isPrivate = false;

res.cacheControl = resCC;
Expand Down Expand Up @@ -158,28 +158,28 @@ function testHttp2BasicCachingBehaviour() returns error? {
@test:Config {}
function testHttp2RequestCacheControlBuildCacheControlDirectives() {
http:RequestCacheControl reqCC = new;
reqCC.maxAge = 60;
reqCC.maxAge = 60.34;
reqCC.noCache = true;
reqCC.noStore = true;
reqCC.noTransform = true;
reqCC.onlyIfCached = true;
reqCC.maxStale = 120;
reqCC.minFresh = 6;
reqCC.maxStale = 120.04;
reqCC.minFresh = 6.0;
test:assertEquals(reqCC.buildCacheControlDirectives(),
"no-cache, no-store, no-transform, only-if-cached, max-age=60, max-stale=120, min-fresh=6");
}

@test:Config {}
function testHttp2ResponseCacheControlBuildCacheControlDirectives() {
http:ResponseCacheControl resCC = new;
resCC.maxAge = 60;
resCC.maxAge = 60.54;
resCC.isPrivate = false;
resCC.mustRevalidate = true;
resCC.noCache = true;
resCC.noStore = true;
resCC.noTransform = true;
resCC.proxyRevalidate = true;
resCC.sMaxAge = 60;
resCC.sMaxAge = 60.32;
test:assertEquals(resCC.buildCacheControlDirectives(),
"must-revalidate, no-cache, no-store, no-transform, public, proxy-revalidate, max-age=60, s-maxage=60");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ service / on new http:Listener(cacheAnnotationTestPort2, httpVersion = http:HTTP
}
}

resource function default maxAgeBE(http:Request req) returns @http:Cache {maxAge: 5, mustRevalidate: false} xml {
resource function default maxAgeBE(http:Request req) returns @http:Cache {maxAge: 5.32, mustRevalidate: false} xml {
int count = 0;
lock {
maxAgeHitCountNew += 1;
Expand Down
6 changes: 3 additions & 3 deletions ballerina/caching_request_cache_control.bal
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ public class RequestCacheControl {
}

if self.maxAge >= 0d {
directives[i] = MAX_AGE + "=" + self.maxAge.toString();
directives[i] = string `${MAX_AGE}=${decimal:floor(self.maxAge)}`;
i += 1;
}

if self.maxStale == MAX_STALE_ANY_AGE {
directives[i] = MAX_STALE;
i += 1;
} else if self.maxStale >= 0d {
directives[i] = MAX_STALE + "=" + self.maxStale.toString();
directives[i] = string `${MAX_STALE}=${decimal:floor(self.maxStale)}`;
i += 1;
}

if self.minFresh >= 0d {
directives[i] = MIN_FRESH + "=" + self.minFresh.toString();
directives[i] = string `${MIN_FRESH}=${decimal:floor(self.minFresh)}`;
i += 1;
}

Expand Down
8 changes: 4 additions & 4 deletions ballerina/caching_response_cache_control.bal
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class ResponseCacheControl {
self.noTransform = cacheConfig.noTransform;
self.isPrivate = cacheConfig.isPrivate;
self.proxyRevalidate = cacheConfig.proxyRevalidate;
self.maxAge = cacheConfig.maxAge;
self.sMaxAge = cacheConfig.sMaxAge;
self.maxAge = decimal:floor(cacheConfig.maxAge);
self.sMaxAge = decimal:floor(cacheConfig.sMaxAge);
self.noCacheFields = cacheConfig.noCacheFields;
self.privateFields = cacheConfig.privateFields;
}
Expand Down Expand Up @@ -94,12 +94,12 @@ public class ResponseCacheControl {
}

if self.maxAge >= 0d {
directives[i] = MAX_AGE + "=" + self.maxAge.toString();
directives[i] = string `${MAX_AGE}=${decimal:floor(self.maxAge)}`;
i += 1;
}

if self.sMaxAge >= 0d {
directives[i] = S_MAX_AGE + "=" + self.sMaxAge.toString();
directives[i] = string `${S_MAX_AGE}=${decimal:floor(self.sMaxAge)}`;
i += 1;
}

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [Add connection eviction feature to handle connections that receive GO_AWAY from the client](https://github.com/ballerina-platform/ballerina-library/issues/6734)
- [Enhanced the configurability of Ballerina access logging by introducing multiple configuration options.](https://github.com/ballerina-platform/ballerina-library/issues/6111)

### Fixed

- [Fix number format exception with decimal values for cache configuration](https://github.com/ballerina-platform/ballerina-library/issues/6765)

## [2.11.2] - 2024-06-14

### Added
Expand Down
1 change: 1 addition & 0 deletions load-tests/accesslog_enabled/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ HTTP Request,7818281,24,19,51,66,98,1,540,0.00%,2246.7,539.7,20.60,1721131655,50
HTTP Request,9328792,20,16,41,55,84,0,603,0.00%,2680.7,644.0,17.34,1721153590,50,60
HTTP Request,8880880,21,17,44,58,88,0,627,0.00%,2552.0,613.1,18.29,1721240055,50,60
HTTP Request,8895106,21,17,44,57,88,0,823,0.00%,2556.1,614.0,18.34,1721326452,50,60
HTTP Request,8829667,21,17,44,58,88,0,635,0.00%,2537.3,609.5,18.28,1721412813,50,60
1 change: 1 addition & 0 deletions load-tests/h1_h1_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,4 @@ HTTP Request,10834466,17,12,36,50,86,0,602,0.00%,3113.4,747.9,17.11,1721067229,5
HTTP Request,11410791,16,12,34,47,81,0,598,0.00%,3279.0,787.7,16.06,1721157485,50,60
HTTP Request,10725454,17,12,37,50,87,0,647,0.00%,3082.1,740.4,17.10,1721243982,50,60
HTTP Request,10766384,17,12,37,50,86,0,660,0.00%,3093.9,743.2,16.92,1721330379,50,60
HTTP Request,10798360,17,12,36,49,86,0,548,0.00%,3103.0,745.4,16.93,1721416732,50,60
1 change: 1 addition & 0 deletions load-tests/h1_transformation/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,4 @@ HTTP Request,8775943,23,21,40,46,62,1,293,0.00%,2521.9,689.6,12.61,1721071141,50
HTTP Request,9398979,21,20,37,42,57,1,352,0.00%,2700.9,738.5,11.57,1721161388,50,60
HTTP Request,8627989,23,21,41,47,62,1,477,0.00%,2479.3,677.9,12.84,1721247894,50,60
HTTP Request,8937180,22,21,39,45,60,1,367,0.00%,2568.2,702.2,12.22,1721334286,50,60
HTTP Request,8924313,22,21,39,45,60,1,305,0.00%,2564.5,701.2,12.22,1721420656,50,60
1 change: 1 addition & 0 deletions load-tests/h1c_h1c_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,4 @@ HTTP Request,12399580,15,13,31,37,57,0,374,0.00%,3563.1,633.3,11.63,1721075048,5
HTTP Request,13200993,14,12,29,35,55,0,296,0.00%,3793.5,674.2,11.01,1721165304,50,60
HTTP Request,12637087,15,12,30,37,56,0,579,0.00%,3631.4,645.4,11.44,1721251832,50,60
HTTP Request,12744425,15,12,30,36,56,0,279,0.00%,3662.2,650.9,11.37,1721338205,50,60
HTTP Request,12660491,15,12,30,36,56,0,389,0.00%,3638.2,646.6,11.40,1721424552,50,60
1 change: 1 addition & 0 deletions load-tests/h1c_transformation/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,4 @@ HTTP Request,8949421,22,20,36,48,70,1,291,0.00%,2571.7,542.5,12.17,1721078965,50
HTTP Request,9434173,21,19,34,45,67,1,202,0.00%,2711.0,571.8,11.57,1721169209,50,60
HTTP Request,8789867,23,20,36,48,74,1,448,0.00%,2525.8,532.8,12.79,1721255751,50,60
HTTP Request,9085049,22,20,35,50,69,1,228,0.00%,2610.7,550.7,12.23,1721342111,50,60
HTTP Request,8907717,23,20,36,51,70,1,217,0.00%,2559.8,539.9,12.41,1721428475,50,60
1 change: 1 addition & 0 deletions load-tests/h2_h1c_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,4 @@ H2-H1C Passthrough,5859,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1721079841,0,1
H2-H1C Passthrough,5872,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1721170059,0,1
H2-H1C Passthrough,5842,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1721256597,0,1
H2-H1C Passthrough,5859,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1721342961,0,1
H2-H1C Passthrough,5856,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1721429351,0,1
1 change: 1 addition & 0 deletions load-tests/interceptors_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,4 @@ Test Request,254062,824,26,137,272,30026,1,56472,3.30%,72.4,10.7,4528.16,1721083
Test Request,238029,879,25,132,272,30024,1,54635,3.58%,68.0,9.9,4678.91,1721173934,50,60
Test Request,237911,880,27,131,258,30026,1,49757,3.41%,67.9,10.1,4752.61,1721260511,50,60
Test Request,238702,878,25,130,272,30005,1,54753,3.59%,68.1,9.1,4678.00,1721346847,50,60
Test Request,1198543,174,57,127,159,362,0,49992,51.88%,343.0,68.7,1659.71,1721433226,50,60
1 change: 1 addition & 0 deletions load-tests/observability_enabled/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,4 @@ HTTP Request,16031745,12,5,27,46,113,0,1177,0.00%,4606.9,688.3,23.37,1721087666,
HTTP Request,16978542,11,5,26,44,110,0,917,0.00%,4879.0,729.0,22.53,1721177881,50,60
HTTP Request,16376648,12,5,27,46,112,0,1033,0.00%,4706.0,703.1,23.26,1721264437,50,60
HTTP Request,16329990,12,5,27,46,116,0,1106,0.00%,4692.6,701.1,24.19,1721350769,50,60
HTTP Request,16474314,11,5,26,44,110,0,1158,0.00%,4734.1,707.3,22.67,1721437149,50,60
1 change: 1 addition & 0 deletions load-tests/snowpeak_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,4 @@ Retrieve Available Locations,6919239,29,18,66,71,85,0,488,0.00%,1988.2,192.2,23.
Retrieve Available Locations,7379817,27,16,65,69,84,0,411,0.00%,2120.6,205.0,23.30,1721181838,50,60
Retrieve Available Locations,6976594,29,18,66,71,86,0,466,0.00%,2004.8,193.8,23.57,1721268334,50,60
Retrieve Available Locations,7127215,28,17,66,70,84,0,492,0.00%,2048.1,198.0,23.51,1721354695,50,60
Retrieve Available Locations,6655350,31,19,67,71,81,1,504,0.00%,1912.4,184.9,23.48,1721441067,50,60
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ private boolean getBooleanValue(BObject responseCacheControl, BString fieldName)
}

private long getIntValue(BObject responseCacheControl, BString fieldName) {
return Long.parseLong(responseCacheControl.get(fieldName).toString());
try {
String value = responseCacheControl.get(fieldName).toString();
// The value is decimal, and need to compute the floor value
return Long.parseLong(value.split("\\.")[0]);
} catch (NumberFormatException e) {
// Ignore the exception and set 0 as the value
return 0;
}
}
}

0 comments on commit 4dcf9ed

Please sign in to comment.