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

enhance to load mocked properties from apollo.cache-dir #58

Merged
merged 14 commits into from
Apr 25, 2024

Conversation

cheese8
Copy link
Contributor

@cheese8 cheese8 commented Apr 10, 2024

What's the purpose of this PR

当没有配置apollo.cache-dir / apollo.cacheDir时,mock配置properties文件读取classpath下的mockdata-namespace.properties。
当配置了apollo.cache-dir / apollo.cacheDir时,mock配置properties文件从指定位置读取。

Ref #55

I have read the CLA Document and I hereby sign the CLA.

Summary by CodeRabbit

  • New Features

    • Enhanced the Apollo Testing Server to support dynamic loading and management of configuration properties from namespaces.
    • Introduced the capability to specify custom cache directories for configuration testing in Apollo.
  • Tests

    • Added new tests to verify the functionality of loading configurations from a custom cache directory.
  • Documentation

    • Updated CHANGES.md to reflect new functionalities related to configuration loading and cache management.

Copy link

github-actions bot commented Apr 10, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copy link
Contributor

coderabbitai bot commented Apr 10, 2024

Walkthrough

The recent updates enhance the Apollo Testing Server by improving how configuration data is handled. This includes better resource loading, file operations, and cache management. Additionally, new test setups verify the functionality with custom cache directories, ensuring configurations are loaded correctly from specified paths.

Changes

File Path Change Summary
.../apollo/mockserver/ApolloTestingServer.java Introduced ConfigUtil for better namespace property handling, including cache and file operations.
.../apollo/mockserver/.../ApolloMockServerApiTest.java Added tests for configuration loading from a custom cache directory using Mockito and utility classes.
.../apollo/mockserver/.../ApolloMockServerApiWhileCacheDirSpecifiedTest.java New test class to check config loading from a specified custom cache directory.
.../test/resources/config-cache/.../someNamespace.properties Updated configuration file with key-value pairs.
CHANGES.md Documented enhancements related to apollo.cache-dir functionality.

🐇✨
In the land of code, where the bits align,
A rabbit hopped, with changes divine.
Configs in cache, directories set right,
Tests all pass in the deep night.
Cheers to the devs, with every commit tight! 🌟
🐇✨


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 38d9601 and 31a19fa.
Files selected for processing (2)
  • CHANGES.md (1 hunks)
  • apollo-mockserver/src/main/java/com/ctrip/framework/apollo/mockserver/ApolloTestingServer.java (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apollo-mockserver/src/main/java/com/ctrip/framework/apollo/mockserver/ApolloTestingServer.java
Additional Context Used
LanguageTool (4)
CHANGES.md (4)

Near line 8: This sentence does not start with an uppercase letter.
Context: ...pollo Java 2.3.0 ------------------ * [add an initialize method to avoid DefaultPr...


Near line 8: Possible spelling mistake found.
Context: ...-- * [add an initialize method to avoid DefaultProviderManager's logic being triggered when using cust...


Near line 8: Possible spelling mistake found.
Context: ...logic being triggered when using custom ProviderManager.](https://github.com/apolloconfig/apoll...


Near line 10: Possible spelling mistake found.
Context: ...e to load mocked properties from apollo.cache-dir](https://github.com/apolloconfig/apollo...

Additional comments not posted (3)
CHANGES.md (3)

8-8: Capitalize the first letter of the list item for consistency.


10-10: Ensure the description clearly reflects the functionality added. Consider specifying that the enhancement allows dynamic loading from apollo.cache-dir or classpath based on configuration.


13-13: Ensure the file ends with a single newline character.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

@cheese8
Copy link
Contributor Author

cheese8 commented Apr 10, 2024

I have read the CLA Document and I hereby sign the CLA

@cheese8
Copy link
Contributor Author

cheese8 commented Apr 10, 2024

recheck

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

@nobodyiam
Copy link
Member

有几点疑问可以讨论下:

  1. 目前已经支持在 classpath 下放置 mockdata-{namespace}.properties 来 mock 配置,也支持了 addOrModifyProperty 和 deleteProperty 修改配置,是什么场景需要从 apollo.cache-dir 来 mock 配置?
  2. 如果支持 apollo.cache-dir 来 mock 配置,为什么不直接使用 ConfigUtil#getDefaultLocalCacheDir 来获取地址?
  3. 为什么 apollo.cache-dir 的 mock 配置优先级高于原先的 classpath 下的 mock 配置?

@cheese8
Copy link
Contributor Author

cheese8 commented Apr 12, 2024

回复如下,个人觉得apollo.cache-dir可能是比较好的使用方式,当然不大了解别的使用场景,可以讨论学习下。

有几点疑问可以讨论下:

  1. 目前已经支持在 classpath 下放置 mockdata-{namespace}.properties 来 mock 配置,也支持了 addOrModifyProperty 和 deleteProperty 修改配置,是什么场景需要从 apollo.cache-dir 来 mock 配置?

场景:拿apollo.cache-dir下的配置作为baseline,通过apollo. addOrModifyProperty()做极少量的变更来进行分支覆盖。主要是从管理维护配置的角度:

  1. 我们可以想象在apollo.cache-dir下面10来个配置文件,在src/test/resources/下面又拷贝10来个文件,仅仅只是改下名字。
  2. 当从apollo web页面修改配置,同步到apollo.cache-dir后,又要再拷贝到src/test/resource/下面,可能忘记,导致两处不一样,可能要排查很久。
  1. 如果支持 apollo.cache-dir 来 mock 配置,为什么不直接使用 ConfigUtil#getDefaultLocalCacheDir 来获取地址?

当apollo.cache-dir没有配置时,使用mockdata-*.properties,而getDefaultLocalCacheDir始终返回非空,所以用了getCustomizedCacheRoot,使用getCustomizedCacheRoot时,手工拼接文件夹路径,代码确实有点奇怪。

  1. 为什么 apollo.cache-dir 的 mock 配置优先级高于原先的 classpath 下的 mock 配置?

综上1和2,调整一下优先级,优先使用mockdata-*.properties,不存在时再读取apollo.cache-dir的配置。

@cheese8 cheese8 requested a review from nobodyiam April 16, 2024 11:40
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is an enhancement, please also update the CHANGES.md.

@cheese8 cheese8 requested a review from nobodyiam April 22, 2024 12:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

CHANGES.md Show resolved Hide resolved
CHANGES.md Show resolved Hide resolved
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nobodyiam nobodyiam merged commit bcc4053 into apolloconfig:main Apr 25, 2024
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 25, 2024
@nobodyiam nobodyiam added this to the 2.3.0 milestone Aug 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants