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

[BUG] [Java Client]When getMessages() returns to default locale's translation, cache can't get updated translation(default locale) after it is expired. #664

Closed
lyiyu66 opened this issue Jul 13, 2020 · 5 comments · Fixed by #673 or #699
Assignees
Milestone

Comments

@lyiyu66
Copy link

lyiyu66 commented Jul 13, 2020

Describe the bug
Online or Mixed mode: When getMessages() returns to service default locale's translation, cache can't get updated translation(default locale) after it is expired.

To Reproduce
Steps to reproduce the behavior:

  1. Set config with pure online or mixed mode.
  2. Request a locale doesn't have its translation in service with getMessages(locale, component), then it will return default locale's translation from service.
  3. Get one key's value from step2 returned result.
  4. Update the default locale's value of that key and set the cache expired.
  5. Repeat the request in step 2.
  6. Repeat the request in step 2.
  7. Repeat step 3.
    Still get the original translation of default locale rather than the updated translation in step 4.

Expected behavior
Should get the updated translation of default locale once cache is expired and request is sent.

@lyiyu66 lyiyu66 changed the title [BUG] [Java Client]When getMessages() returns to service default locale's translation, cache can't get updated translation(default locale) after it is expired. [BUG] [Java Client]When getMessages() returns to default locale's translation, cache can't get updated translation(default locale) after it is expired. Jul 13, 2020
@lyiyu66
Copy link
Author

lyiyu66 commented Jul 13, 2020

The issue also is reproducible when getMessages() return to default locale's translation from offlineBundles in mixed mode.

@jessiejuachon
Copy link
Contributor

(Pasting the same comment I put in issue #662 )

I just tested this and it works for me. I am guessing there is something wrong with the steps you wrote above. Please check the following:

In step 2, how is the client cache expire time set? If you are testing the new client workflow, make sure to NOT set the cacheExpiredTime property in the properties config file. Otherwise, cacheExpiredTime will be used instead of the value set by the Singleton service in the cache-control max age header in the HTTP response.
In step 3, which default locale message do you update? Since you are testing online or mixed mode, you should update the message in the service because that takes priority over the offline message.
In step 3, how do you expire the client-side cache?
If the client had previously cached the response and its expire time (either using the cacheExpiredTime config or the cache-control max age header), then the cached messages will only expire after the configured expire time. Do you wait for the time to pass, or do you have some other way to expire the time?

@lyiyu66
Copy link
Author

lyiyu66 commented Jul 14, 2020

  • I have set the cache expired time as 0l in config file to make cacheExpiredTime use new workflow(from http response header).
    vipCfg.setCacheExpiredTime(0l);

  • Depends on which default locale message is used. If it uses service default locale message(when service has requested component with default locale), then update the service side's, else(when service hasn't the requested component with default locale, but offlineBundles has), update offline message.

  • Yes, I set cacahItem.setMaxAgeMillis(0l) or 1000l, then thread.sleep(2000), and also use cacheItem.isExpired() to check the expired status.

@gong-yu gong-yu added this to the Sprint 85 milestone Jul 17, 2020
@jessiejuachon jessiejuachon linked a pull request Jul 22, 2020 that will close this issue
jessiejuachon added a commit to jessiejuachon/singleton that referenced this issue Aug 3, 2020
@jessiejuachon
Copy link
Contributor

jessiejuachon commented Aug 14, 2020

@gong-yu ,@lyiyu66 , this is now ready for testing

@surite
Copy link
Contributor

surite commented Aug 27, 2020

Test pass on commit 3b6f338.

@surite surite closed this as completed Aug 27, 2020
@surite surite reopened this Aug 27, 2020
@surite surite closed this as completed Aug 27, 2020
jessiejuachon added a commit that referenced this issue Oct 23, 2020
…/variables that will never be null (#829)

* Loading configuration from the JSON configuration file

* Removing code that is not yet ready to be used from the sample application

* fixing failing code scan
https://sonarcloud.io/project/issues?id=jessiejuachon-java-client-g11n-java-client&issues=AXDG68NFL24bPpi-pS5s&open=AXDG68NFL24bPpi-pS5s
https://sonarcloud.io/project/issues?id=jessiejuachon-java-client-g11n-java-client&issues=AXDG68IGL24bPpi-pS2r&open=AXDG68IGL24bPpi-pS2r

Signed-off-by: Jessie <jessiejuachon@gmail.com>

* Adding a cache properties map to hold cache details such as etag and cache control

* Removing white space

Signed-off-by: Jessie <jessiejuachon@gmail.com>

* Fixing failing unit test

* Parse headers, response code, response message from an HTTP response and return them upstream.

* Storing response headers in Map of cache properties

* Fixing failing unit test due to NullPointerException when doing Map.putAll(null)

* Changes after code review.

* Removing exception handling for now

* Deprecating VIPCfg.initialize; cleaning up code

* Storing the http response code in the cache

* Using cached etag as if-none-match request header value in the request in order to get a 304 NOT MODIFIED http response

* Handling 404 response from Singleton service

* Using HTTP repsonse's Cache-Control max-age and timestamp to dertermine if component locale's cache has expired

* Moving constants to URLUtils

* Fixing failing test

* Fixing failing code scan

* Cleaning up import in ComponentService,java

* Cleaning up code - caching/expiry

* Adding tests for new caching workflow; enabling old caching workflow using cacheExpiredTime config

* Fixing a failing test

* Adding mock server response

* Removing unused file sampleconfig.json

* Changes from code review

* Value of VIPCfg.cacheExpiredTime is -1 when value is not set in config file. This means max age from server will be used. Setting VIPCfg.cacheExpiredTime to 0 disables caching.

* Changing a LinkedHashMap to a HashMap because insertion order does not need to be maintained.

* Adding CacheItem object to contain map of data and a another map for any other cache properties

* Fixing failing unit test

* Fixing code scan issues

* Code cleanup

* Lazily instantiating cacheProps; code clean up and comments

* Changes after code review

* Adding header to CacheItem.java

* Fixing code san issue. Synchronize on a final field

* Fixing code scan bug

* Changes after code review

* Updating CasheService.isContainComponent to return false if cache key is stored but has a null value

* HttpRequester if-none-match header and other customized headers are added to each specific request locally.

* Code clean up; keep old caching expiration logic

* Fixing code scan bug

* code clean up

* Removing response code and response msg from cache; Passing cacheItem object to be updated down the line.

* Changes after code review

* Adding header to CacheItem.java file

* Fixing failing unit test

* Changes after code review

* Fixing code scan bugs

* Not storing anything in cache if response is neither 200 nor 304

* Loading messages from specified offline resource bundles

* Adding header

* Fixing failing unie test

* Code changes after review; code clean up

* Using java.nio.file.Paths

* Offline mode as fallback when service fetch fails

* Resetting VIPCfg and I18nFactory instances for each test

* Resetting VIPCfg and I18nFactory after test

* Fixing tests

* Limit to wiremock test logging

* Decreasing unit test log

* this test is timing out and trying to connect 70+ times

* Adding comments to code

* Adding timestamp to cache fromn local bundle

* Deprecating methods in TranslationMessage; adding new method getMessage

* Added tests for TranslationMessage.getMessage

* Fixing test

* Fixing test

* Fixing test

* Removing comment field because source collection is not supported anymore; cleaning up tests; adding comments for javadoc

* Code clean up

* Changes from code review

* Code clean up

* Optional SourceOpt in initialization

Signed-off-by: Jessie <jessiejuachon@gmail.com>

* Fixing test

* Adding comments to code

* Adding comment for javadoc

* Cleaning up code

* Code clean up

* Fixing test

* Removing source message fallback from this PR

* Default locale in config file instead of hardcoded; get supported locales for offline mode; fixing some bugs in getting supported locales

* Fixing test

* Fixing tests

* Default locale to Locale.ENGLISH if not set in config file

* Changed after code review: code clean up, bug fix

* Update src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* Update src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* code clean up, error logging, bug fix

* code clean up

* code clean up

* Using messages_source.json for source locale messages.

* code clean up

* Commenting out a test

* code clean up

* code clean up

* Error logging when fetch failed

* bug fix

* code clean up

* Updating sample application

* fixing failing smoke test

* code clean up

* fixing code scan

* Fixing code scan

* Adding prodMode configuration

* code clean up

* Setting default prodMode to true

* Removing prodMode configuration and logic. Throwing exception if source key not found. Returning default locale message if locale not supported.

* Updating javadoc

* Fixing bug: Fallback shall apply to both TranslationMessage.getMessage and TranslationMessage.getMessages

* Adding test for Translateion.getMessages, locale not supported

* code comments

* code clean up

* Fix issue: #622

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* Fix for #661

* adding license header

* changes after code review

* Update src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalComponentOpt.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* Update src/main/java/com/vmware/vipclient/i18n/messages/service/ProductService.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* changes after code review

* changes after code review

* fix for issues: 664, 662, 686

* code clean up

* code clean up

* Adding LocaleDTO

* code clean up

* code clean up

* changes after code review

* Bug fix #604, #664, #662

* code clean up

* Mapping to the fallback locale's cache

* code clean up

* changes after code review

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* Fixing bug on reading offline bundles in jar file.

* sample shared library

* sample application with shared library

* Adding license header

* Fix for #746 MsgOriginsQueue cannot be cleared once initializing VIPCfg

* code clean up

* Adding list of supported locales used by L3 in cache

* Removing logic of adding a cacheItem with an empty dataMap to cache

* code clean up

* Update src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentService.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* changes based on review comments

* Enablling locale fallback for matched locale

* code clean up for MessageCacheItem

* removing unrelated changes

* removing unrelated changes

* changes in expire logic

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>
jessiejuachon added a commit that referenced this issue Oct 28, 2020
…tch for a non-supported locale (#823)

* Loading configuration from the JSON configuration file

* Removing code that is not yet ready to be used from the sample application

* fixing failing code scan
https://sonarcloud.io/project/issues?id=jessiejuachon-java-client-g11n-java-client&issues=AXDG68NFL24bPpi-pS5s&open=AXDG68NFL24bPpi-pS5s
https://sonarcloud.io/project/issues?id=jessiejuachon-java-client-g11n-java-client&issues=AXDG68IGL24bPpi-pS2r&open=AXDG68IGL24bPpi-pS2r

Signed-off-by: Jessie <jessiejuachon@gmail.com>

* Adding a cache properties map to hold cache details such as etag and cache control

* Removing white space

Signed-off-by: Jessie <jessiejuachon@gmail.com>

* Fixing failing unit test

* Parse headers, response code, response message from an HTTP response and return them upstream.

* Storing response headers in Map of cache properties

* Fixing failing unit test due to NullPointerException when doing Map.putAll(null)

* Changes after code review.

* Removing exception handling for now

* Deprecating VIPCfg.initialize; cleaning up code

* Storing the http response code in the cache

* Using cached etag as if-none-match request header value in the request in order to get a 304 NOT MODIFIED http response

* Handling 404 response from Singleton service

* Using HTTP repsonse's Cache-Control max-age and timestamp to dertermine if component locale's cache has expired

* Moving constants to URLUtils

* Fixing failing test

* Fixing failing code scan

* Cleaning up import in ComponentService,java

* Cleaning up code - caching/expiry

* Adding tests for new caching workflow; enabling old caching workflow using cacheExpiredTime config

* Fixing a failing test

* Adding mock server response

* Removing unused file sampleconfig.json

* Changes from code review

* Value of VIPCfg.cacheExpiredTime is -1 when value is not set in config file. This means max age from server will be used. Setting VIPCfg.cacheExpiredTime to 0 disables caching.

* Changing a LinkedHashMap to a HashMap because insertion order does not need to be maintained.

* Adding CacheItem object to contain map of data and a another map for any other cache properties

* Fixing failing unit test

* Fixing code scan issues

* Code cleanup

* Lazily instantiating cacheProps; code clean up and comments

* Changes after code review

* Adding header to CacheItem.java

* Fixing code san issue. Synchronize on a final field

* Fixing code scan bug

* Changes after code review

* Updating CasheService.isContainComponent to return false if cache key is stored but has a null value

* HttpRequester if-none-match header and other customized headers are added to each specific request locally.

* Code clean up; keep old caching expiration logic

* Fixing code scan bug

* code clean up

* Removing response code and response msg from cache; Passing cacheItem object to be updated down the line.

* Changes after code review

* Adding header to CacheItem.java file

* Fixing failing unit test

* Changes after code review

* Fixing code scan bugs

* Not storing anything in cache if response is neither 200 nor 304

* Loading messages from specified offline resource bundles

* Adding header

* Fixing failing unie test

* Code changes after review; code clean up

* Using java.nio.file.Paths

* Offline mode as fallback when service fetch fails

* Resetting VIPCfg and I18nFactory instances for each test

* Resetting VIPCfg and I18nFactory after test

* Fixing tests

* Limit to wiremock test logging

* Decreasing unit test log

* this test is timing out and trying to connect 70+ times

* Adding comments to code

* Adding timestamp to cache fromn local bundle

* Deprecating methods in TranslationMessage; adding new method getMessage

* Added tests for TranslationMessage.getMessage

* Fixing test

* Fixing test

* Fixing test

* Removing comment field because source collection is not supported anymore; cleaning up tests; adding comments for javadoc

* Code clean up

* Changes from code review

* Code clean up

* Optional SourceOpt in initialization

Signed-off-by: Jessie <jessiejuachon@gmail.com>

* Fixing test

* Adding comments to code

* Adding comment for javadoc

* Cleaning up code

* Code clean up

* Fixing test

* Removing source message fallback from this PR

* Default locale in config file instead of hardcoded; get supported locales for offline mode; fixing some bugs in getting supported locales

* Fixing test

* Fixing tests

* Default locale to Locale.ENGLISH if not set in config file

* Changed after code review: code clean up, bug fix

* Update src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* Update src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalLocaleOpt.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* code clean up, error logging, bug fix

* code clean up

* code clean up

* Using messages_source.json for source locale messages.

* code clean up

* Commenting out a test

* code clean up

* code clean up

* Error logging when fetch failed

* bug fix

* code clean up

* Updating sample application

* fixing failing smoke test

* code clean up

* fixing code scan

* Fixing code scan

* Adding prodMode configuration

* code clean up

* Setting default prodMode to true

* Removing prodMode configuration and logic. Throwing exception if source key not found. Returning default locale message if locale not supported.

* Updating javadoc

* Fixing bug: Fallback shall apply to both TranslationMessage.getMessage and TranslationMessage.getMessages

* Adding test for Translateion.getMessages, locale not supported

* code comments

* code clean up

* Fix issue: #622

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* Fix for #661

* adding license header

* changes after code review

* Update src/main/java/com/vmware/vipclient/i18n/messages/api/opt/local/LocalComponentOpt.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* Update src/main/java/com/vmware/vipclient/i18n/messages/service/ProductService.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* changes after code review

* changes after code review

* fix for issues: 664, 662, 686

* code clean up

* code clean up

* Adding LocaleDTO

* code clean up

* code clean up

* changes after code review

* Bug fix #604, #664, #662

* code clean up

* Mapping to the fallback locale's cache

* code clean up

* changes after code review

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* Fixing bug on reading offline bundles in jar file.

* sample shared library

* sample application with shared library

* Adding license header

* Fix for #746 MsgOriginsQueue cannot be cleared once initializing VIPCfg

* Fix for bug 781 - L3's CacheService.getSupportedLocalesFromCache is incorrectly using L2's data.

* code clean up

* code clean up

* Fix for issue 781: CacheService.getCacheOfComponent cannot get "matchedLocale" properly if L2 supported locale list cache is not yet populated.

* adding test

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* code clean up

* adding test

* fixing test

* fixing test

* fixing test

* fixing test

* code clean up

* code clean up

* code cleanup

* code clean up

* Update src/main/java/com/vmware/vipclient/i18n/messages/service/CacheService.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* adding comments to code

* clean up code

* code clean up

* code clean up

* Adding list of supported locales used by L3 in cache

* Removing logic of adding a cacheItem with an empty dataMap to cache

* code clean up

* code clean up

* code clean up

* Removing locale property from MessageCacheItem

* Update src/main/java/com/vmware/vipclient/i18n/messages/service/ComponentService.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* changes based on review comments

* Enablling locale fallback for matched locale

* merging changes

* Fixing bug 754 - Performance impact on the very first L3 fetch for a non-supported locale

* more test cases

* fixing intermittently failing test

* code clean up for readability

* fixing incorrect if statement

* code optimization

* Update src/main/java/com/vmware/vipclient/i18n/util/LocaleUtility.java

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>

* rolling back change

* changing Chinese locale matching rule

* correcting incorrect merge

* Do Locale matching first in Componentservice.getMessages

Co-authored-by: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment