-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: Skip unnecessary RTS calls to optimise performance #37949
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
...erver/appsmith-server/src/test/java/com/appsmith/server/services/ce/ASTServiceCETest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| package com.appsmith.server.services.ce; | ||
|
|
||
| import com.appsmith.external.models.MustacheBindingToken; | ||
| import com.appsmith.server.services.AstService; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.mock.mockito.SpyBean; | ||
| import reactor.core.publisher.Mono; | ||
| import reactor.test.StepVerifier; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.Mockito.doReturn; | ||
|
|
||
| @SpringBootTest | ||
| @Slf4j | ||
| public class ASTServiceCETest { | ||
| @SpyBean | ||
| AstService astService; | ||
|
|
||
| @Test | ||
| void refactorNameInDynamicBindings_NullOrEmptyBindings_ReturnsEmptyMono() { | ||
| Mono<Map<MustacheBindingToken, String>> result = | ||
| astService.refactorNameInDynamicBindings(null, "abc", "xyz", 2, false); | ||
|
|
||
| StepVerifier.create(result).verifyComplete(); | ||
|
|
||
| result = astService.refactorNameInDynamicBindings(Collections.emptySet(), "abc", "xyz", 2, false); | ||
|
|
||
| StepVerifier.create(result).verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void refactorNameInDynamicBindings_BindingWithoutOldName_ReturnsUnchangedMap() { | ||
| MustacheBindingToken token1 = new MustacheBindingToken(); | ||
| token1.setValue("foo.bar"); | ||
| MustacheBindingToken token2 = new MustacheBindingToken(); | ||
| token2.setValue("baz.qux"); | ||
| Set<MustacheBindingToken> bindings = Set.of(token1, token2); | ||
|
|
||
| Mono<Map<MustacheBindingToken, String>> result = | ||
| astService.refactorNameInDynamicBindings(bindings, "abc", "xyz", 2, false); | ||
|
|
||
| StepVerifier.create(result) | ||
| .assertNext(map -> { | ||
| assertThat(map).hasSize(2); | ||
| assertThat(map.get(token1)).isEqualTo("foo.bar"); | ||
| assertThat(map.get(token2)).isEqualTo("baz.qux"); | ||
| }) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void refactorNameInDynamicBindings_ValidBindings_ReturnsUpdatedBindings() { | ||
| MustacheBindingToken token1 = new MustacheBindingToken(); | ||
| token1.setValue("abc['foo']"); | ||
| MustacheBindingToken token2 = new MustacheBindingToken(); | ||
| token2.setValue("xyz['bar']"); | ||
| Set<MustacheBindingToken> bindings = Set.of(token1, token2); | ||
|
|
||
| String refactoredScript1 = "xyz['foo']"; | ||
| String refactoredScript2 = "xyz['bar']"; | ||
|
|
||
| Map<MustacheBindingToken, String> responseMap1 = Map.of( | ||
| token1, refactoredScript1, | ||
| token2, refactoredScript2); | ||
|
|
||
| doReturn(Mono.just(responseMap1)) | ||
| .when(astService) | ||
| .refactorNameInDynamicBindings(Set.of(token1, token2), "abc", "xyz", 2, false); | ||
|
|
||
| Mono<Map<MustacheBindingToken, String>> result = | ||
| astService.refactorNameInDynamicBindings(bindings, "abc", "xyz", 2, false); | ||
|
|
||
| StepVerifier.create(result) | ||
| .assertNext(map -> { | ||
| assertThat(map).hasSize(2); // Only one binding refactored | ||
| assertThat(map.get(token1)).isEqualTo(refactoredScript1); | ||
| assertThat(map.get(token2)).isEqualTo(refactoredScript2); | ||
| }) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void refactorNameInDynamicBindings_whenValidJSObjectRequest_thenReturnUpdatedScript() { | ||
| MustacheBindingToken token = new MustacheBindingToken(); | ||
| token.setValue("export default { myFun1() { Api1.run(); return Api1.data;}}"); | ||
| Set<MustacheBindingToken> bindingValues = Set.of(token); | ||
| String oldName = "Api1"; | ||
| String newName = "GetUsers"; | ||
| int evalVersion = 2; | ||
| boolean isJSObject = true; | ||
|
|
||
| String refactoredScript = "export default { myFun1() { GetUsers.run(); return GetUsers.data;}}"; | ||
|
|
||
| Map<MustacheBindingToken, String> responseMap = Map.of(token, refactoredScript); | ||
|
|
||
| doReturn(Mono.just(responseMap)) | ||
| .when(astService) | ||
| .refactorNameInDynamicBindings(bindingValues, oldName, newName, evalVersion, isJSObject); | ||
|
|
||
| Mono<Map<MustacheBindingToken, String>> resultMono = | ||
| astService.refactorNameInDynamicBindings(bindingValues, oldName, newName, evalVersion, isJSObject); | ||
|
|
||
| StepVerifier.create(resultMono) | ||
| .assertNext(result -> { | ||
| assertThat(result).hasSize(1); | ||
|
|
||
| MustacheBindingToken key = bindingValues.iterator().next(); | ||
|
|
||
| assertThat(result.containsKey(key)).isTrue(); | ||
| assertThat(result.get(key)).isEqualTo(refactoredScript); | ||
| }) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void refactorNameInDynamicBindings_whenNoMatchingOldNameInJSObject_thenReturnOriginalScript() { | ||
| MustacheBindingToken token = new MustacheBindingToken(); | ||
| token.setValue("export default { myFun1() { GetUsers.run(); return GetUsers.data;}}"); | ||
| Set<MustacheBindingToken> bindingValues = Set.of(token); | ||
|
|
||
| String oldName = "Api1"; // oldName is not present in the script | ||
| String newName = "GetUsers"; | ||
| int evalVersion = 2; | ||
| boolean isJSObject = true; | ||
|
|
||
| String refactoredScript = "export default { myFun1() { GetUsers.run(); return GetUsers.data;}}"; | ||
|
|
||
| Map<MustacheBindingToken, String> responseMap = Map.of(token, refactoredScript); | ||
|
|
||
| doReturn(Mono.just(responseMap)) | ||
| .when(astService) | ||
| .refactorNameInDynamicBindings(bindingValues, oldName, newName, evalVersion, isJSObject); | ||
|
|
||
| Mono<Map<MustacheBindingToken, String>> resultMono = | ||
| astService.refactorNameInDynamicBindings(bindingValues, oldName, newName, evalVersion, isJSObject); | ||
|
|
||
| StepVerifier.create(resultMono) | ||
| .assertNext(result -> { | ||
| assertThat(result).hasSize(1); | ||
|
|
||
| MustacheBindingToken key = bindingValues.iterator().next(); | ||
|
|
||
| assertThat(result.containsKey(key)).isTrue(); | ||
| assertThat(result.get(key)).isEqualTo(token.getValue()); // Script remains unchanged | ||
| }) | ||
| .verifyComplete(); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.