Skip to content

Commit 9a250ad

Browse files
Update test file names
1 parent 159d38a commit 9a250ad

File tree

6 files changed

+51
-52
lines changed

6 files changed

+51
-52
lines changed

ballerina-tests/tests/44_server_caches.bal

+42-42
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ isolated function testServerSideCacheWithDataLoader(string documentFile, string[
6868
resetDispatchCounters();
6969
}
7070

71+
function dataProviderServerCacheWithDataloader() returns map<[string, string[], json, string[]]> {
72+
map<[string, string[], json, string[]]> dataSet = {
73+
"1": ["server_cache_with_dataloader", ["server_cache_with_dataloader_1", "server_cache_with_dataloader_2", "server_cache_with_dataloader_1"], (), ["A", "B", "A"]],
74+
"2": ["server_cache_eviction_with_dataloader", ["server_cache_with_dataloader_1", "server_cache_with_dataloader_2", "server_cache_with_dataloader_3"], (), ["A", "B", "A"]]
75+
};
76+
return dataSet;
77+
}
78+
7179
@test:Config {
7280
groups: ["server_cache", "data_loader"],
7381
dataProvider: dataProviderServerCacheWithDataloaderInOperationalLevel
@@ -83,6 +91,14 @@ isolated function testServerSideCacheWithDataLoaderInOperationalLevel(string doc
8391
resetDispatchCounters();
8492
}
8593

94+
function dataProviderServerCacheWithDataloaderInOperationalLevel() returns map<[string, string[], json, string[]]> {
95+
map<[string, string[], json, string[]]> dataSet = {
96+
"1": ["server_cache_with_dataloader_operational", ["server_cache_with_dataloader_3", "server_cache_with_dataloader_5", "server_cache_with_dataloader_3"], (), ["A", "B", "A"]],
97+
"2": ["server_cache_eviction_with_dataloader_operational", ["server_cache_with_dataloader_3", "server_cache_with_dataloader_5", "server_cache_with_dataloader_4"], (), ["A", "B", "A"]]
98+
};
99+
return dataSet;
100+
}
101+
86102
@test:Config {
87103
groups: ["server_cache"],
88104
dataProvider: dataProviderServerCacheOperationalLevel
@@ -97,33 +113,6 @@ isolated function testServerSideCacheInOperationalLevel(string documentFile, str
97113
}
98114
}
99115

100-
@test:Config {
101-
groups: ["server_cache"]
102-
}
103-
isolated function testServerSideCacheInOperationalLevelWithTTL() returns error? {
104-
string url = "http://localhost:9091/server_cache_operations";
105-
string document = check getGraphqlDocumentFromFile("server_cache_with_ttl");
106-
runtime:sleep(21);
107-
108-
json actualPayload = check getJsonPayloadFromService(url, document, (), "A");
109-
json expectedPayload = check getJsonContentFromFile("server_cache_1");
110-
assertJsonValuesWithOrder(actualPayload, expectedPayload);
111-
112-
actualPayload = check getJsonPayloadFromService(url, document, (), "B");
113-
expectedPayload = check getJsonContentFromFile("server_cache_10");
114-
assertJsonValuesWithOrder(actualPayload, expectedPayload);
115-
116-
actualPayload = check getJsonPayloadFromService(url, document, (), "A");
117-
expectedPayload = check getJsonContentFromFile("server_cache_1");
118-
assertJsonValuesWithOrder(actualPayload, expectedPayload);
119-
120-
runtime:sleep(21);
121-
122-
actualPayload = check getJsonPayloadFromService(url, document, (), "A");
123-
expectedPayload = check getJsonContentFromFile("server_cache_9");
124-
assertJsonValuesWithOrder(actualPayload, expectedPayload);
125-
}
126-
127116
function dataProviderServerCacheOperationalLevel() returns map<[string, string[], json, string[]]> {
128117
map<[string, string[], json, string[]]> dataSet = {
129118
"1": ["server_cache", ["server_cache_1", "server_cache_2", "server_cache_1"], (), ["A", "B", "A"]],
@@ -146,14 +135,6 @@ function dataProviderServerCacheOperationalLevel() returns map<[string, string[]
146135
return dataSet;
147136
}
148137

149-
function dataProviderServerCacheWithDataloader() returns map<[string, string[], json, string[]]> {
150-
map<[string, string[], json, string[]]> dataSet = {
151-
"1": ["server_cache_with_dataloader", ["server_cache_with_dataloader_1", "server_cache_with_dataloader_2", "server_cache_with_dataloader_1"], (), ["A", "B", "A"]],
152-
"2": ["server_cache_eviction_with_dataloader", ["server_cache_with_dataloader_1", "server_cache_with_dataloader_2", "server_cache_with_dataloader_3"], (), ["A", "B", "A"]]
153-
};
154-
return dataSet;
155-
}
156-
157138
@test:Config {
158139
groups: ["server_cache", "interceptors"],
159140
dataProvider: dataProviderServerCacheWithInterceptors
@@ -190,20 +171,39 @@ function dataProviderServerCacheWithInterceptors() returns map<[string, string[]
190171
return dataSet;
191172
}
192173

193-
function dataProviderServerCacheWithDataloaderInOperationalLevel() returns map<[string, string[], json, string[]]> {
194-
map<[string, string[], json, string[]]> dataSet = {
195-
"1": ["server_cache_with_dataloader_operational", ["server_cache_with_dataloader_3", "server_cache_with_dataloader_5", "server_cache_with_dataloader_3"], (), ["A", "B", "A"]],
196-
"2": ["server_cache_eviction_with_dataloader_operational", ["server_cache_with_dataloader_3", "server_cache_with_dataloader_5", "server_cache_with_dataloader_4"], (), ["A", "B", "A"]]
197-
};
198-
return dataSet;
174+
@test:Config {
175+
groups: ["server_cache"]
176+
}
177+
isolated function testServerSideCacheInOperationalLevelWithTTL() returns error? {
178+
string url = "http://localhost:9091/server_cache_operations";
179+
string document = check getGraphqlDocumentFromFile("server_cache_operations_with_TTL");
180+
runtime:sleep(21);
181+
182+
json actualPayload = check getJsonPayloadFromService(url, document, (), "A");
183+
json expectedPayload = check getJsonContentFromFile("server_cache_1");
184+
assertJsonValuesWithOrder(actualPayload, expectedPayload);
185+
186+
actualPayload = check getJsonPayloadFromService(url, document, (), "B");
187+
expectedPayload = check getJsonContentFromFile("server_cache_10");
188+
assertJsonValuesWithOrder(actualPayload, expectedPayload);
189+
190+
actualPayload = check getJsonPayloadFromService(url, document, (), "A");
191+
expectedPayload = check getJsonContentFromFile("server_cache_1");
192+
assertJsonValuesWithOrder(actualPayload, expectedPayload);
193+
194+
runtime:sleep(21);
195+
196+
actualPayload = check getJsonPayloadFromService(url, document, (), "A");
197+
expectedPayload = check getJsonContentFromFile("server_cache_9");
198+
assertJsonValuesWithOrder(actualPayload, expectedPayload);
199199
}
200200

201201
@test:Config {
202202
groups: ["server_cache"]
203203
}
204204
isolated function testServerCacheEvictionWithTTL() returns error? {
205205
string url = "http://localhost:9091/field_caching_with_interceptors";
206-
string document = check getGraphqlDocumentFromFile("server_cache_with_TTL");
206+
string document = check getGraphqlDocumentFromFile("server_cache_fields_with_TTL");
207207

208208
json actualPayload = check getJsonPayloadFromService(url, document, (), "A");
209209
json expectedPayload = check getJsonContentFromFile("server_cache_eviction_with_TTL_1");

ballerina-tests/tests/test_services.bal

+1-2
Original file line numberDiff line numberDiff line change
@@ -2951,8 +2951,7 @@ service /field_caching_with_interceptors on basicListener {
29512951
@graphql:ServiceConfig {
29522952
cacheConfig:{
29532953
enabled: true
2954-
},
2955-
contextInit: initContext2
2954+
}
29562955
}
29572956
service /caching_with_interceptor_operations on basicListener {
29582957
private string name = "voldemort";

ballerina/engine.bal

+8-6
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ isolated class Engine {
6363
}
6464

6565
isolated function addToCache(string key, any value, decimal maxAge) returns any|error {
66-
if self.cache is cache:Cache {
67-
return (<cache:Cache>self.cache).put(key, value, maxAge);
66+
cache:Cache? cache = self.cache;
67+
if cache is cache:Cache {
68+
return cache.put(key, value, maxAge);
6869
}
6970
return error("Cache table not found!");
7071
}
@@ -383,7 +384,7 @@ isolated class Engine {
383384
_ = resourcePath.pop();
384385
}
385386

386-
private isolated function getFieldValue(Context context,Field 'field, ResponseGenerator responseGenerator) returns any|error {
387+
private isolated function getFieldValue(Context context, Field 'field, ResponseGenerator responseGenerator) returns any|error {
387388
if 'field.getOperationType() == parser:OPERATION_QUERY {
388389
return self.resolveResourceMethod(context, 'field, responseGenerator);
389390
} else if 'field.getOperationType() == parser:OPERATION_MUTATION {
@@ -399,15 +400,16 @@ isolated class Engine {
399400
return key.startsWith(path);
400401
});
401402
foreach string key in keys {
402-
_ = check (<cache:Cache>self.cache).invalidate(key);
403+
_ = check cache.invalidate(key);
403404
}
404405
}
405406
return;
406407
}
407408

408409
isolated function invalidateAll() returns error? {
409-
if self.cache is cache:Cache {
410-
return (<cache:Cache>self.cache).invalidateAll();
410+
cache:Cache? cache = self.cache;
411+
if cache is cache:Cache {
412+
return cache.invalidateAll();
411413
}
412414
return;
413415
}

compiler-plugin-tests/src/test/resources/ballerina_sources/validator_tests/86_invalid_service_config_modification/service.bal

-2
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,3 @@ public function main() returns error? {
7171
TestService serviceClass = new ();
7272
check serviceClass.startService();
7373
}
74-
75-

0 commit comments

Comments
 (0)