You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2026/07/23 11:41:24 UTC
(struts) 09/10: WW-5540 test(core): tighten localized-text cache tests
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch WW-5540-localized-text-provider-caching
in repository https://gitbox.apache.org/repos/asf/struts.git
commit b1e0071804d13bbfcfd4f5ec50f432fae2b4f769
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Thu Jul 23 13:35:15 2026 +0200
WW-5540 test(core): tighten localized-text cache tests
Assert single cache entry in the per-call-format tests (proves the raw
pattern is cached, not the formatted result), and mirror the package-cache
clearBundle/clearMissingBundlesCache invalidation test.
Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
.../struts2/text/StrutsLocalizedTextProviderTest.java | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/core/src/test/java/org/apache/struts2/text/StrutsLocalizedTextProviderTest.java b/core/src/test/java/org/apache/struts2/text/StrutsLocalizedTextProviderTest.java
index ad35de8e4..e4dc0c831 100644
--- a/core/src/test/java/org/apache/struts2/text/StrutsLocalizedTextProviderTest.java
+++ b/core/src/test/java/org/apache/struts2/text/StrutsLocalizedTextProviderTest.java
@@ -582,6 +582,7 @@ public class StrutsLocalizedTextProviderTest extends XWorkTestCase {
String y = provider.findText(CacheFixture.class, "cache.withparam", Locale.ENGLISH, null, new Object[]{"Y"}, valueStack);
assertEquals("Value with param X", x);
assertEquals("Value with param Y", y);
+ assertEquals("Raw pattern should be cached once, not per format ?", 1, provider.classHierarchyCacheSize());
}
public void testOgnlTranslationIsPerCall() {
@@ -597,6 +598,7 @@ public class StrutsLocalizedTextProviderTest extends XWorkTestCase {
assertEquals("Hello World", world);
assertEquals("Hello Mars", mars);
+ assertEquals("Raw pattern should be cached once across value stacks ?", 1, provider.classHierarchyCacheSize());
}
public void testNullFormattingFallsThroughToDefault() {
@@ -663,6 +665,21 @@ public class StrutsLocalizedTextProviderTest extends XWorkTestCase {
assertEquals("Reload did not clear package hierarchy cache ?", 0, provider.packageHierarchyCacheSize());
}
+ public void testClearBundleAndClearMissingCacheEmptyPackageHierarchyCache() {
+ TestStrutsLocalizedTextProvider provider = new TestStrutsLocalizedTextProvider();
+ ValueStack valueStack = ActionContext.getContext().getValueStack();
+
+ provider.findText(org.apache.struts2.test.ModelDrivenAction2.class, "package.properties", Locale.getDefault(), null, null, valueStack);
+ assertEquals("Package cache not populated ?", 1, provider.packageHierarchyCacheSize());
+ provider.callClearBundleWithLocale("org/apache/struts2/test/package", Locale.getDefault());
+ assertEquals("clearBundle did not empty package hierarchy cache ?", 0, provider.packageHierarchyCacheSize());
+
+ provider.findText(org.apache.struts2.test.ModelDrivenAction2.class, "package.properties", Locale.getDefault(), null, null, valueStack);
+ assertEquals("Package cache not repopulated ?", 1, provider.packageHierarchyCacheSize());
+ provider.callClearMissingBundlesCache();
+ assertEquals("clearMissingBundlesCache did not empty package hierarchy cache ?", 0, provider.packageHierarchyCacheSize());
+ }
+
public void testDeprecatedFindMessageStillDelegates() {
// findMessage leaves findText's hot path in this task; this locks the deprecated delegator.
TestStrutsLocalizedTextProvider provider = new TestStrutsLocalizedTextProvider();