diff options
author | Leif Åstrand <legioth@gmail.com> | 2017-01-05 10:27:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-05 10:27:22 +0200 |
commit | 948ce0333a353d49f484500dc932da21c61946ce (patch) | |
tree | 8bb3a7cefaab81f79a73dbaba4f00f92a63d265e | |
parent | 6ef75bda79099953f85e1c48a0e833a6ed258acf (diff) | |
download | vaadin-framework-948ce0333a353d49f484500dc932da21c61946ce.tar.gz vaadin-framework-948ce0333a353d49f484500dc932da21c61946ce.zip |
Restore all current instance values after running access tasks (#8131)
* Restore all current instance values after running access tasks
Fixes vaadin/framework8-issues#593
-rw-r--r-- | server/src/main/java/com/vaadin/server/VaadinService.java | 5 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/server/VaadinServiceTest.java | 37 |
2 files changed, 37 insertions, 5 deletions
diff --git a/server/src/main/java/com/vaadin/server/VaadinService.java b/server/src/main/java/com/vaadin/server/VaadinService.java index c5a5aeec18..6ae9df2408 100644 --- a/server/src/main/java/com/vaadin/server/VaadinService.java +++ b/server/src/main/java/com/vaadin/server/VaadinService.java @@ -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) { diff --git a/server/src/test/java/com/vaadin/server/VaadinServiceTest.java b/server/src/test/java/com/vaadin/server/VaadinServiceTest.java index d0e0c591b3..59ddaf3e67 100644 --- a/server/src/test/java/com/vaadin/server/VaadinServiceTest.java +++ b/server/src/test/java/com/vaadin/server/VaadinServiceTest.java @@ -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; + } + } |