]> source.dussan.org Git - vaadin-framework.git/commitdiff
No inherited threadlocal
authorIlia Motornyi <elmot@vaadin.com>
Tue, 13 Dec 2016 09:05:04 +0000 (11:05 +0200)
committerGitHub <noreply@github.com>
Tue, 13 Dec 2016 09:05:04 +0000 (11:05 +0200)
Fixes vaadin/framework8-issues#514

13 files changed:
server/src/main/java/com/vaadin/server/VaadinPortlet.java
server/src/main/java/com/vaadin/server/VaadinService.java
server/src/main/java/com/vaadin/server/VaadinServlet.java
server/src/main/java/com/vaadin/server/VaadinSession.java
server/src/main/java/com/vaadin/ui/UI.java
server/src/main/java/com/vaadin/util/CurrentInstance.java
server/src/test/java/com/vaadin/util/CurrentInstanceTest.java
uitest/src/main/java/com/vaadin/tests/components/ui/CurrentUiRetained.java [deleted file]
uitest/src/main/java/com/vaadin/tests/components/ui/UIAccess.java
uitest/src/main/java/com/vaadin/tests/components/ui/UIAccessExceptionHandling.java
uitest/src/test/java/com/vaadin/tests/application/ThreadLocalInstancesTest.java
uitest/src/test/java/com/vaadin/tests/components/ui/CurrentUiRetainedTest.java [deleted file]
uitest/src/test/java/com/vaadin/tests/components/ui/UIAccessTest.java

index 84f90d70e3baf21f266c676797a3a1f4461c2bf4..16489da95d4712331a9a5d4d7fbb9d50eb5fe66d 100644 (file)
@@ -643,12 +643,11 @@ public class VaadinPortlet extends GenericPortlet
 
     /**
      * Gets the currently used Vaadin portlet. The current portlet is
-     * automatically defined when initializing the portlet and when processing
-     * requests to the server and in threads started at a point when the current
-     * portlet is defined (see {@link InheritableThreadLocal}). In other cases,
-     * (e.g. from background threads started in some other way), the current
-     * portlet is not automatically defined.
-     * <p>
+     * automatically defined when processing requests related to the service
+     * (see {@link ThreadLocal}) and in {@link VaadinSession#access(Command)}
+     * and {@link UI#access(Command)}. In other cases, (e.g. from background
+     * threads, the current service is not automatically defined.
+     *
      * The current portlet is derived from the current service using
      * {@link VaadinService#getCurrent()}
      *
index d07413f2379b07a1f2bb000a84943d71eb0bf7cc..d3788756e224a51a476890f6c562cdd99176d7a0 100644 (file)
@@ -922,11 +922,10 @@ public abstract class VaadinService implements Serializable {
 
     /**
      * Gets the currently used Vaadin service. The current service is
-     * automatically defined when processing requests related to the service and
-     * in threads started at a point when the current service is defined (see
-     * {@link InheritableThreadLocal}). In other cases, (e.g. from background
-     * threads started in some other way), the current service is not
-     * automatically defined.
+     * automatically defined when processing requests related to the service
+     * (see {@link ThreadLocal}) and in {@link VaadinSession#access(Command)}
+     * and {@link UI#access(Command)}. In other cases, (e.g. from background
+     * threads, the current service is not automatically defined.
      *
      * @return the current Vaadin service instance if available, otherwise
      *         <code>null</code>
@@ -973,7 +972,7 @@ public abstract class VaadinService implements Serializable {
      * @param service
      */
     public static void setCurrent(VaadinService service) {
-        CurrentInstance.setInheritable(VaadinService.class, service);
+        CurrentInstance.set(VaadinService.class, service);
     }
 
     /**
@@ -1860,18 +1859,13 @@ public abstract class VaadinService implements Serializable {
             return;
         }
 
-        Map<Class<?>, CurrentInstance> oldInstances = CurrentInstance
-                .getInstances(false);
-
         FutureAccess pendingAccess;
+        Map<Class<?>, CurrentInstance> oldInstances = CurrentInstance
+                .setCurrent(session);
         try {
             while ((pendingAccess = session.getPendingAccessQueue()
                     .poll()) != null) {
                 if (!pendingAccess.isCancelled()) {
-                    CurrentInstance.clearAll();
-                    CurrentInstance.restoreInstances(
-                            pendingAccess.getCurrentInstances());
-                    CurrentInstance.setCurrent(session);
                     pendingAccess.run();
 
                     try {
index b932a9cc04c08f34d3f9e0f075ed2af38cf5208c..a8b9a0b90a53e48eba8bc0bf4f627e5c61b66e7b 100644 (file)
@@ -297,10 +297,10 @@ public class VaadinServlet extends HttpServlet implements Constants {
     /**
      * Gets the currently used Vaadin servlet. The current servlet is
      * automatically defined when initializing the servlet and when processing
-     * requests to the server and in threads started at a point when the current
-     * servlet is defined (see {@link InheritableThreadLocal}). In other cases,
-     * (e.g. from background threads started in some other way), the current
-     * servlet is not automatically defined.
+     * requests to the server (see {@link ThreadLocal}) and in
+     * {@link VaadinSession#access(Runnable)} and {@link UI#access(Runnable)}. In
+     * other cases, (e.g. from background threads), the current servlet is not
+     * automatically defined.
      * <p>
      * The current servlet is derived from the current service using
      * {@link VaadinService#getCurrent()}
index 84808e89da18e49b8bc4ff897087f9b760b4c534..9b87c081bcdf88502a89f9ab0ac90d600117e98d 100644 (file)
@@ -79,12 +79,6 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
      * @author Vaadin Ltd
      */
     public static class FutureAccess extends FutureTask<Void> {
-        /**
-         * Snapshot of all non-inheritable current instances at the time this
-         * object was created.
-         */
-        private final Map<Class<?>, CurrentInstance> instances = CurrentInstance
-                .getInstances(true);
         private final VaadinSession session;
         private final Runnable runnable;
 
@@ -120,18 +114,6 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
             return super.get();
         }
 
-        /**
-         * Gets the current instance values that should be used when running
-         * this task.
-         *
-         * @see CurrentInstance#restoreInstances(Map)
-         *
-         * @return a map of current instances.
-         */
-        public Map<Class<?>, CurrentInstance> getCurrentInstances() {
-            return instances;
-        }
-
         /**
          * Handles exceptions thrown during the execution of this task.
          *
@@ -693,12 +675,11 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
     }
 
     /**
-     * Gets the currently used session. The current session is automatically
-     * defined when processing requests to the server and in threads started at
-     * a point when the current session is defined (see
-     * {@link InheritableThreadLocal}). In other cases, (e.g. from background
-     * threads started in some other way), the current session is not
-     * automatically defined.
+     * Gets the currently used session. The current session is
+     * automatically defined when processing requests related to the session
+     * (see {@link ThreadLocal}) and in {@link VaadinSession#access(Command)}
+     * and {@link UI#access(Command)}. In other cases, (e.g. from background
+     * threads, the current session is not automatically defined.
      * <p>
      * The session is stored using a weak reference to avoid leaking memory in
      * case it is not explicitly cleared.
@@ -735,7 +716,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
      * @since 7.0
      */
     public static void setCurrent(VaadinSession session) {
-        CurrentInstance.setInheritable(VaadinSession.class, session);
+        CurrentInstance.set(VaadinSession.class, session);
     }
 
     /**
@@ -1379,12 +1360,11 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
      * <p>
      * Please note that the runnable might be invoked on a different thread or
      * later on the current thread, which means that custom thread locals might
-     * not have the expected values when the runnable is executed. Inheritable
-     * values in {@link CurrentInstance} will have the same values as when this
-     * method was invoked. {@link VaadinSession#getCurrent()} and
-     * {@link VaadinService#getCurrent()} are set according to this session
-     * before executing the runnable. Non-inheritable CurrentInstance values
-     * including {@link VaadinService#getCurrentRequest()} and
+     * not have the expected values when the command is executed.
+     * {@link VaadinSession#getCurrent()} and {@link VaadinService#getCurrent()}
+     * are set according to this session before executing the command. Other
+     * standard CurrentInstance values such as
+     * {@link VaadinService#getCurrentRequest()} and
      * {@link VaadinService#getCurrentResponse()} will not be defined.
      * </p>
      * <p>
index ad6a60d96df11320fc2f13381d30cc91b4ad5cfc..9f0cc6d0dc07191ede24ded56fce1a24cafccf10 100644 (file)
@@ -831,7 +831,7 @@ public abstract class UI extends AbstractSingleComponentContainer
      * @see ThreadLocal
      */
     public static void setCurrent(UI ui) {
-        CurrentInstance.setInheritable(UI.class, ui);
+        CurrentInstance.set(UI.class, ui);
     }
 
     /**
@@ -1448,12 +1448,10 @@ public abstract class UI extends AbstractSingleComponentContainer
      * <p>
      * Please note that the runnable might be invoked on a different thread or
      * later on the current thread, which means that custom thread locals might
-     * not have the expected values when the runnable is executed. Inheritable
-     * values in {@link CurrentInstance} will have the same values as when this
-     * method was invoked. {@link UI#getCurrent()},
-     * {@link VaadinSession#getCurrent()} and {@link VaadinService#getCurrent()}
-     * are set according to this UI before executing the runnable.
-     * Non-inheritable CurrentInstance values including
+     * not have the expected values when the command is executed.
+     * {@link UI#getCurrent()}, {@link VaadinSession#getCurrent()} and
+     * {@link VaadinService#getCurrent()} are set according to this UI before
+     * executing the command. Other standard CurrentInstance values such as
      * {@link VaadinService#getCurrentRequest()} and
      * {@link VaadinService#getCurrentResponse()} will not be defined.
      * </p>
index 43b158a4ff978a98469095bc15f66c890a0fc684..327c61d4b09bd7064fe19da289adbefd5dd6e18a 100644 (file)
@@ -35,10 +35,7 @@ import com.vaadin.ui.UI;
 /**
  * Keeps track of various current instances for the current thread. All the
  * instances are automatically cleared after handling a request from the client
- * to avoid leaking memory. The inheritable values are also maintained when
- * execution is moved to another thread, both when a new thread is created and
- * when {@link VaadinSession#access(Runnable)} or {@link UI#access(Runnable)} is
- * used.
+ * to avoid leaking memory.
  * <p>
  * Please note that the instances are stored using {@link WeakReference}. This
  * means that the a current instance value may suddenly disappear if there a no
@@ -47,10 +44,8 @@ import com.vaadin.ui.UI;
  * Currently the framework uses the following instances:
  * </p>
  * <p>
- * Inheritable: {@link UI}, {@link VaadinService}, {@link VaadinSession}.
- * </p>
- * <p>
- * Non-inheritable: {@link VaadinRequest}, {@link VaadinResponse}.
+ * {@link UI}, {@link VaadinService}, {@link VaadinSession},
+ * {@link VaadinRequest}, {@link VaadinResponse}.
  * </p>
  *
  * @author Vaadin Ltd
@@ -58,36 +53,14 @@ import com.vaadin.ui.UI;
  */
 public class CurrentInstance implements Serializable {
     private static final Object NULL_OBJECT = new Object();
-    private static final CurrentInstance CURRENT_INSTANCE_NULL = new CurrentInstance(
-            NULL_OBJECT, true);
+    private static final CurrentInstance CURRENT_INSTANCE_NULL = new CurrentInstance(NULL_OBJECT);
 
     private final WeakReference<Object> instance;
-    private final boolean inheritable;
-
-    private static final InheritableThreadLocal<Map<Class<?>, CurrentInstance>> instances = new InheritableThreadLocal<Map<Class<?>, CurrentInstance>>() {
-        @Override
-        protected Map<Class<?>, CurrentInstance> childValue(
-                Map<Class<?>, CurrentInstance> parentValue) {
-            if (parentValue == null) {
-                return null;
-            }
-
-            Map<Class<?>, CurrentInstance> value = new HashMap<>();
 
-            // Copy all inheritable values to child map
-            for (Entry<Class<?>, CurrentInstance> e : parentValue.entrySet()) {
-                if (e.getValue().inheritable) {
-                    value.put(e.getKey(), e.getValue());
-                }
-            }
-
-            return value;
-        }
-    };
+    private static final ThreadLocal<Map<Class<?>, CurrentInstance>> instances = new ThreadLocal<>();
 
-    private CurrentInstance(Object instance, boolean inheritable) {
+    private CurrentInstance(Object instance) {
         this.instance = new WeakReference<>(instance);
-        this.inheritable = inheritable;
     }
 
     /**
@@ -152,7 +125,6 @@ public class CurrentInstance implements Serializable {
     /**
      * Sets the current instance of the given type.
      *
-     * @see #setInheritable(Class, Object)
      * @see ThreadLocal
      *
      * @param type
@@ -161,31 +133,7 @@ public class CurrentInstance implements Serializable {
      * @param instance
      *            the actual instance
      */
-    public static <T> void set(Class<T> type, T instance) {
-        set(type, instance, false);
-    }
-
-    /**
-     * Sets the current inheritable instance of the given type. A current
-     * instance that is inheritable will be available for child threads and in
-     * code run by {@link VaadinSession#access(Runnable)} and
-     * {@link UI#access(Runnable)}.
-     *
-     * @see #set(Class, Object)
-     * @see InheritableThreadLocal
-     *
-     * @param type
-     *            the class that should be used when getting the current
-     *            instance back
-     * @param instance
-     *            the actual instance
-     */
-    public static <T> void setInheritable(Class<T> type, T instance) {
-        set(type, instance, true);
-    }
-
-    private static <T> CurrentInstance set(Class<T> type, T instance,
-            boolean inheritable) {
+    public static <T> CurrentInstance set(Class<T> type, T instance) {
         Map<Class<?>, CurrentInstance> map = instances.get();
         CurrentInstance previousInstance = null;
         if (instance == null) {
@@ -204,14 +152,7 @@ public class CurrentInstance implements Serializable {
                 instances.set(map);
             }
 
-            previousInstance = map.put(type,
-                    new CurrentInstance(instance, inheritable));
-            if (previousInstance != null) {
-                assert previousInstance.inheritable == inheritable : "Inheritable status mismatch for "
-                        + type + " (previous was "
-                        + previousInstance.inheritable + ", new is "
-                        + inheritable + ")";
-            }
+            previousInstance = map.put(type, new CurrentInstance(instance));
         }
         if (previousInstance == null) {
             previousInstance = CURRENT_INSTANCE_NULL;
@@ -261,7 +202,7 @@ public class CurrentInstance implements Serializable {
                  */
                 v = null;
             }
-            set(c, v, ci.inheritable);
+            set(c, v);
         }
 
         if (removeStale) {
@@ -275,13 +216,9 @@ public class CurrentInstance implements Serializable {
      *
      * @since 7.1
      *
-     * @param onlyInheritable
-     *            <code>true</code> if only the inheritable instances should be
-     *            included; <code>false</code> to get all instances.
      * @return a map containing the current instances
      */
-    public static Map<Class<?>, CurrentInstance> getInstances(
-            boolean onlyInheritable) {
+    public static Map<Class<?>, CurrentInstance> getInstances() {
         Map<Class<?>, CurrentInstance> map = instances.get();
         if (map == null) {
             return Collections.emptyMap();
@@ -292,7 +229,7 @@ public class CurrentInstance implements Serializable {
                 CurrentInstance ci = map.get(c);
                 if (ci.instance.get() == null) {
                     removeStale = true;
-                } else if (ci.inheritable || !onlyInheritable) {
+                } else {
                     copy.put(c, ci);
                 }
             }
@@ -320,7 +257,7 @@ public class CurrentInstance implements Serializable {
      */
     public static Map<Class<?>, CurrentInstance> setCurrent(UI ui) {
         Map<Class<?>, CurrentInstance> old = setCurrent(ui.getSession());
-        old.put(UI.class, set(UI.class, ui, true));
+        old.put(UI.class, set(UI.class, ui));
         return old;
     }
 
@@ -339,12 +276,12 @@ public class CurrentInstance implements Serializable {
     public static Map<Class<?>, CurrentInstance> setCurrent(
             VaadinSession session) {
         Map<Class<?>, CurrentInstance> old = new HashMap<>();
-        old.put(VaadinSession.class, set(VaadinSession.class, session, true));
+        old.put(VaadinSession.class, set(VaadinSession.class, session));
         VaadinService service = null;
         if (session != null) {
             service = session.getService();
         }
-        old.put(VaadinService.class, set(VaadinService.class, service, true));
+        old.put(VaadinService.class, set(VaadinService.class, service));
         return old;
     }
 
index 0d698b19e864dd1c51f15f8a02518d75f759aca6..3505ef7532d832e0c7efc491ac570354b4d10571 100644 (file)
  */
 package com.vaadin.util;
 
-import static org.junit.Assert.assertNull;
-
-import java.lang.ref.WeakReference;
-import java.lang.reflect.Field;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
-
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinService;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.ui.UI;
 import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinService;
-import com.vaadin.server.VaadinSession;
-import com.vaadin.ui.UI;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import static org.junit.Assert.assertNull;
 
 public class CurrentInstanceTest {
 
@@ -55,83 +58,6 @@ public class CurrentInstanceTest {
         assertCleared();
     }
 
-    @Test
-    public void testClearedAfterRemoveInheritable() throws Exception {
-        CurrentInstance.clearAll();
-
-        CurrentInstance.setInheritable(CurrentInstanceTest.class, this);
-        Assert.assertEquals(this,
-                CurrentInstance.get(CurrentInstanceTest.class));
-        CurrentInstance.setInheritable(CurrentInstanceTest.class, null);
-
-        assertCleared();
-    }
-
-    @Test
-    public void testInheritableThreadLocal() throws Exception {
-        final AtomicBoolean threadFailed = new AtomicBoolean(true);
-
-        CurrentInstance.setInheritable(CurrentInstanceTest.class, this);
-        Assert.assertEquals(this,
-                CurrentInstance.get(CurrentInstanceTest.class));
-        Thread t = new Thread() {
-            @Override
-            public void run() {
-                Assert.assertEquals(CurrentInstanceTest.this,
-                        CurrentInstance.get(CurrentInstanceTest.class));
-                threadFailed.set(false);
-            }
-        };
-        t.start();
-        CurrentInstance.set(CurrentInstanceTest.class, null);
-
-        assertCleared();
-        while (t.isAlive()) {
-            Thread.sleep(1000);
-        }
-        Assert.assertFalse("Thread failed", threadFailed.get());
-
-    }
-
-    @Test
-    public void testClearedAfterRemoveInSeparateThread() throws Exception {
-        final AtomicBoolean threadFailed = new AtomicBoolean(true);
-
-        CurrentInstance.setInheritable(CurrentInstanceTest.class, this);
-        Assert.assertEquals(this,
-                CurrentInstance.get(CurrentInstanceTest.class));
-        Thread t = new Thread() {
-            @Override
-            public void run() {
-                try {
-                    Assert.assertEquals(CurrentInstanceTest.this,
-                            CurrentInstance.get(CurrentInstanceTest.class));
-                    CurrentInstance.set(CurrentInstanceTest.class, null);
-                    assertCleared();
-
-                    threadFailed.set(false);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-        };
-        t.start();
-
-        while (t.isAlive()) {
-            Thread.sleep(1000);
-        }
-        Assert.assertFalse("Thread failed", threadFailed.get());
-
-        // Clearing the threadlocal in the thread should not have cleared it
-        // here
-        Assert.assertEquals(this,
-                CurrentInstance.get(CurrentInstanceTest.class));
-
-        // Clearing the only remaining threadlocal should free all memory
-        CurrentInstance.set(CurrentInstanceTest.class, null);
-        assertCleared();
-    }
-
     @Test
     public void testClearedWithClearAll() throws Exception {
         CurrentInstance.set(CurrentInstanceTest.class, this);
@@ -147,12 +73,12 @@ public class CurrentInstanceTest {
         Assert.assertNull(getInternalCurrentInstanceVariable().get());
     }
 
-    private InheritableThreadLocal<Map<Class<?>, CurrentInstance>> getInternalCurrentInstanceVariable()
+    private ThreadLocal<Map<Class<?>, CurrentInstance>> getInternalCurrentInstanceVariable()
             throws SecurityException, NoSuchFieldException,
             IllegalAccessException {
         Field f = CurrentInstance.class.getDeclaredField("instances");
         f.setAccessible(true);
-        return (InheritableThreadLocal<Map<Class<?>, CurrentInstance>>) f
+        return (ThreadLocal<Map<Class<?>, CurrentInstance>>) f
                 .get(null);
     }
 
@@ -245,4 +171,21 @@ public class CurrentInstanceTest {
         }
         Assert.fail("Value was not garbage collected.");
     }
+
+    @Test
+    public void nonInheritableThreadLocals()
+            throws InterruptedException, ExecutionException {
+        CurrentInstance.clearAll();
+        CurrentInstance.set(CurrentInstanceTest.class, this);
+
+        Assert.assertNotNull(CurrentInstance.get(CurrentInstanceTest.class));
+
+        Callable<Void> runnable = () -> {
+            Assert.assertNull(CurrentInstance.get(CurrentInstanceTest.class));
+            return null;
+        };
+        ExecutorService service = Executors.newSingleThreadExecutor();
+        Future<Void> future = service.submit(runnable);
+        future.get();
+    }
 }
diff --git a/uitest/src/main/java/com/vaadin/tests/components/ui/CurrentUiRetained.java b/uitest/src/main/java/com/vaadin/tests/components/ui/CurrentUiRetained.java
deleted file mode 100644 (file)
index dcb1dcf..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.tests.components.ui;
-
-import java.util.ArrayList;
-
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUIWithLog;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.UI;
-import com.vaadin.util.CurrentInstance;
-
-public class CurrentUiRetained extends AbstractTestUIWithLog {
-    public static class GcProbe {
-
-    }
-
-    @Override
-    protected void setup(VaadinRequest request) {
-        final ArrayList<UI> uiLog = new ArrayList<>();
-        final ArrayList<Boolean> probeLog = new ArrayList<>();
-
-        final Thread thread = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    uiLog.add(UI.getCurrent());
-
-                    GcProbe gcProbe = new GcProbe();
-                    CurrentInstance.set(GcProbe.class, gcProbe);
-                    probeLog.add(CurrentInstance.get(GcProbe.class) != null);
-                    gcProbe = null;
-
-                    Thread.sleep(500l);
-                    System.gc();
-                    Thread.sleep(500l);
-
-                    probeLog.add(CurrentInstance.get(GcProbe.class) != null);
-                    uiLog.add(UI.getCurrent());
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-            }
-        });
-        thread.start();
-
-        addComponent(new Button("Show result", new Button.ClickListener() {
-            @Override
-            public void buttonClick(ClickEvent event) {
-                try {
-                    thread.join();
-
-                    log("Correct UI.getCurrent before GC: "
-                            + (uiLog.get(0) == CurrentUiRetained.this));
-                    log("Correct UI.getCurrent after GC: "
-                            + (uiLog.get(1) == CurrentUiRetained.this));
-
-                    log("GC probe available before GC: " + probeLog.get(0));
-                    log("GC probe available after GC: " + probeLog.get(1));
-
-                } catch (InterruptedException e) {
-                    throw new RuntimeException(e);
-                }
-            }
-        }));
-    }
-
-    @Override
-    protected String getTestDescription() {
-        return "Tests that garbage collection removes stale CurrentInstance values while retaining values not collected.";
-    }
-
-    @Override
-    protected Integer getTicketNumber() {
-        return Integer.valueOf(12509);
-    }
-
-}
index cdedb6235aa550386681c68da769b5249bc202e4..7cf6325e7319a1c3bab66bfd1ea636328a43f638 100644 (file)
@@ -257,7 +257,7 @@ public class UIAccess extends AbstractTestUIWithLog {
                     public void buttonClick(ClickEvent event) {
                         log.clear();
                         // accessSynchronously should maintain values
-                        CurrentInstance.setInheritable(
+                        CurrentInstance.set(
                                 CurrentInstanceTestType.class,
                                 new CurrentInstanceTestType(
                                         "Set before access"));
@@ -269,13 +269,13 @@ public class UIAccess extends AbstractTestUIWithLog {
                                 log.log("Test value in access: "
                                         + CurrentInstance.get(
                                                 CurrentInstanceTestType.class));
-                                CurrentInstance.setInheritable(
+                                CurrentInstance.set(
                                         CurrentInstanceTestType.class,
                                         new CurrentInstanceTestType(
                                                 "Set in access"));
                             }
                         });
-                        CurrentInstance.setInheritable(
+                        CurrentInstance.set(
                                 CurrentInstanceTestType.class,
                                 new CurrentInstanceTestType(
                                         "Set before run pending"));
index 2874074e670eb61acde0f2f2c562dec9b32de330..5321827ed3ab77102244e2a30609d1546249dee4 100644 (file)
@@ -96,7 +96,7 @@ public class UIAccessExceptionHandling extends AbstractTestUIWithLog
                                         .getCurrent() == UIAccessExceptionHandling.this;
 
                                 Map<Class<?>, CurrentInstance> instances = CurrentInstance
-                                        .getInstances(false);
+                                        .getInstances();
                                 CurrentInstance.clearAll();
 
                                 assert UI.getCurrent() == null;
index 9498413f9bf53195f91dfacb41c19a5c097337cb..4600e89862b308ce09ae1de6f51a7f88c3d974ae 100644 (file)
@@ -21,8 +21,8 @@ public class ThreadLocalInstancesTest extends MultiBrowserTest {
         assertLogText("8. this root in root init", 8);
         assertLogText("9. some app in root paint", 7);
         assertLogText("10. this root in root paint", 6);
-        assertLogText("11. some app in background thread", 5);
-        assertLogText("12. this root in background thread", 4);
+        assertLogText("11. null app in background thread", 5);
+        assertLogText("12. null root in background thread", 4);
         assertLogText("13. some app in resource handler", 3);
         assertLogText("14. this root in resource handler", 2);
         assertLogText("15. some app in button listener", 1);
diff --git a/uitest/src/test/java/com/vaadin/tests/components/ui/CurrentUiRetainedTest.java b/uitest/src/test/java/com/vaadin/tests/components/ui/CurrentUiRetainedTest.java
deleted file mode 100644 (file)
index d4e1ecb..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.vaadin.tests.components.ui;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.vaadin.testbench.elements.ButtonElement;
-import com.vaadin.tests.tb3.MultiBrowserTest;
-
-public class CurrentUiRetainedTest extends MultiBrowserTest {
-    @Test
-    public void testCurrentUiRetained() throws Exception {
-        openTestURL();
-        $(ButtonElement.class).first().click();
-        assertLogText(3, "1. Correct UI.getCurrent before GC: true");
-        assertLogText(2, "2. Correct UI.getCurrent after GC: true");
-        assertLogText(1, "3. GC probe available before GC: true");
-        assertLogText(0, "4. GC probe available after GC: false");
-    }
-
-    private void assertLogText(int index, String expected) {
-        Assert.assertEquals("Unexpected log contents,", expected,
-                getLogRow(index));
-    }
-}
index a421ab721b6ade59b2a0e43982fcef237a39af86..d73696144dcdb0d98cec50b9358454ca7a744788 100644 (file)
@@ -117,16 +117,4 @@ public class UIAccessTest extends MultiBrowserTest {
                 "3. Test value after accessSynchornously: Set in accessSynchronosly"));
     }
 
-    @Test
-    public void currentInstanceCanAccessValue() {
-        $(ButtonElement.class).get(6).click();
-
-        assertTrue(logContainsText("0. access has request? false"));
-        assertTrue(
-                logContainsText("1. Test value in access: Set before access"));
-        assertTrue(logContainsText("2. has request after access? true"));
-        assertTrue(logContainsText(
-                "3. Test value after access: Set before run pending"));
-    }
-
 }