]> source.dussan.org Git - vaadin-framework.git/commitdiff
Restore all current instance values after running access tasks (#8131)
authorLeif Åstrand <legioth@gmail.com>
Thu, 5 Jan 2017 08:27:22 +0000 (10:27 +0200)
committerGitHub <noreply@github.com>
Thu, 5 Jan 2017 08:27:22 +0000 (10:27 +0200)
* Restore all current instance values after running access tasks

Fixes vaadin/framework8-issues#593

server/src/main/java/com/vaadin/server/VaadinService.java
server/src/test/java/com/vaadin/server/VaadinServiceTest.java

index c5a5aeec182ad65359cab1e0eca82175e9ecfddb..6ae9df24087097866c24a8fc4def5b46c28b7187 100644 (file)
@@ -1860,8 +1860,11 @@ public abstract class VaadinService implements Serializable {
         }
 
         FutureAccess pendingAccess;
+
+        // Dump all current instances, not only the ones dumped by setCurrent
         Map<Class<?>, CurrentInstance> oldInstances = CurrentInstance
-                .setCurrent(session);
+                .getInstances();
+        CurrentInstance.setCurrent(session);
         try {
             while ((pendingAccess = session.getPendingAccessQueue()
                     .poll()) != null) {
index d0e0c591b3563f39d2a37d32b153ee47f4728fd1..59ddaf3e67fbfb774eebcf379c446c7176e958be 100644 (file)
@@ -26,6 +26,8 @@ import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Test;
 
+import com.vaadin.util.CurrentInstance;
+
 /**
  *
  * @author Vaadin Ltd
@@ -50,10 +52,7 @@ public class VaadinServiceTest {
 
     @Test
     public void testFireSessionDestroy() throws ServletException {
-        ServletConfig servletConfig = new MockServletConfig();
-        VaadinServlet servlet = new VaadinServlet();
-        servlet.init(servletConfig);
-        VaadinService service = servlet.getService();
+        VaadinService service = createService();
 
         TestSessionDestroyListener listener = new TestSessionDestroyListener();
 
@@ -140,4 +139,34 @@ public class VaadinServiceTest {
 
         assertThat(notification, containsString("\"url\":null"));
     }
+
+    @Test
+    public void currentInstancesAfterPendingAccessTasks() {
+        VaadinService service = createService();
+
+        MockVaadinSession session = new MockVaadinSession(service);
+        session.lock();
+        service.accessSession(session, () -> {
+            CurrentInstance.set(String.class, "Set in task");
+        });
+
+        CurrentInstance.set(String.class, "Original value");
+        service.runPendingAccessTasks(session);
+        Assert.assertEquals(
+                "Original CurrentInstance should be set after the task has been run",
+                "Original value", CurrentInstance.get(String.class));
+    }
+
+    private static VaadinService createService() {
+        ServletConfig servletConfig = new MockServletConfig();
+        VaadinServlet servlet = new VaadinServlet();
+        try {
+            servlet.init(servletConfig);
+        } catch (ServletException e) {
+            throw new RuntimeException(e);
+        }
+        VaadinService service = servlet.getService();
+        return service;
+    }
+
 }