You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2019/12/13 08:03:48 UTC

[GitHub] [sling-org-apache-sling-i18n] Buuhuu commented on a change in pull request #3: SLING-8915 Lazily replace previously cached ResourceBundles

Buuhuu commented on a change in pull request #3: SLING-8915 Lazily replace previously cached ResourceBundles 
URL: https://github.com/apache/sling-org-apache-sling-i18n/pull/3#discussion_r357523576
 
 

 ##########
 File path: src/test/java/org/apache/sling/i18n/impl/ConcurrentJcrResourceBundleLoadingTest.java
 ##########
 @@ -155,4 +177,35 @@ public void newBundleUsedAsParentAfterReload() throws Exception {
         verifyPrivate(provider, times(2)).invoke("createResourceBundle", any(ResourceResolver.class), eq(null), eq(Locale.ENGLISH));
         verifyPrivate(provider, times(2)).invoke("createResourceBundle", any(ResourceResolver.class), eq(null), eq(Locale.GERMAN));
     }
+
+    /**
+     * Test that when a ResourceBundle is reloaded the already cached ResourceBundle is returned (preload=true) as long as a long running
+     * call to createResourceBundle() takes. For preload=false that will be blocking in getResourceBundle() instead.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void newBundleReplacesOldBundleAfterReload() throws Exception {
+        final ResourceBundle oldBundle = provider.getResourceBundle(Locale.ENGLISH);
+        final ResourceBundle newBundle = mock(JcrResourceBundle.class);
+        final AtomicBoolean newBundleReady = new AtomicBoolean(false);
+
+        doAnswer(new Answer<ResourceBundle>() {
+            @Override public ResourceBundle answer(InvocationOnMock invocationOnMock) throws Throwable {
+                Thread.sleep(1000);
+                newBundleReady.set(true);
+                return newBundle;
+            }
+        }).when(provider, "createResourceBundle", any(ResourceResolver.class), eq(null), eq(Locale.ENGLISH));
+
+        Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new Runnable() {
+            @Override
+            public void run() {
+                ResourceBundle expected = newBundleReady.get() ? newBundle : oldBundle;
+                assertSame(expected, provider.getResourceBundle(Locale.ENGLISH));
 
 Review comment:
   maybe we should verify here that for the preload=true case getResourceBundle() in fact is non-blocking now.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services