diff options
author | Artur <artur@vaadin.com> | 2017-07-24 08:43:52 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-07-24 08:43:52 +0300 |
commit | 94f2e1f4227c59b21011747ab04ed553cfa235a8 (patch) | |
tree | 52852074a507c5f9dafed71f978883385ba8ecd5 /uitest | |
parent | 913e55ae4084c1f3e8c41b7620f3d7496710ba03 (diff) | |
download | vaadin-framework-94f2e1f4227c59b21011747ab04ed553cfa235a8.tar.gz vaadin-framework-94f2e1f4227c59b21011747ab04ed553cfa235a8.zip |
Do full connector tracker cleanup when the session lock is released (#9707)
As there is no "request end" call after invoking UI.access() from a background thread,
the connector map was not earlier properly cleaned afterwards. If you toggled visibility of a
component from the background thread, the tracker state became inconsistent.
If this becomes a performance problem, it could probably be optimized to that cleanup
is done in request end and only at the end of access if not inside a request.
Fixes #9654
Diffstat (limited to 'uitest')
3 files changed, 110 insertions, 5 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/application/MissingHierarchyDetection.java b/uitest/src/main/java/com/vaadin/tests/application/MissingHierarchyDetection.java index 54c19c3353..2b85318ea4 100644 --- a/uitest/src/main/java/com/vaadin/tests/application/MissingHierarchyDetection.java +++ b/uitest/src/main/java/com/vaadin/tests/application/MissingHierarchyDetection.java @@ -23,7 +23,7 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import com.vaadin.server.VaadinRequest; -import com.vaadin.server.VaadinService; +import com.vaadin.server.VaadinSession; import com.vaadin.tests.components.AbstractReindeerTestUIWithLog; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -60,15 +60,15 @@ public class MissingHierarchyDetection extends AbstractReindeerTestUIWithLog { @Override protected void setup(VaadinRequest request) { // Catch log messages so we can see if there is an error - Logger vaadinServiceLogger = Logger - .getLogger(VaadinService.class.getName()); - vaadinServiceLogger.addHandler(new Handler() { + Logger vaadinSessionLogger = Logger + .getLogger(VaadinSession.class.getName()); + vaadinSessionLogger.addHandler(new Handler() { @Override public void publish(LogRecord record) { if (record.getThrown() instanceof AssertionError) { pendingErrors.add(record); - vaadinServiceLogger.removeHandler(this); + vaadinSessionLogger.removeHandler(this); } } diff --git a/uitest/src/main/java/com/vaadin/tests/push/PushToggleComponentVisibility.java b/uitest/src/main/java/com/vaadin/tests/push/PushToggleComponentVisibility.java new file mode 100644 index 0000000000..bbb004bcb1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/push/PushToggleComponentVisibility.java @@ -0,0 +1,62 @@ +/* + * 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.push; + +import com.vaadin.annotations.Push; +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +@Push +@Widgetset("com.vaadin.DefaultWidgetSet") +public class PushToggleComponentVisibility extends UI { + + @Override + protected void init(VaadinRequest request) { + VerticalLayout mainLayout = new VerticalLayout(); + setContent(mainLayout); + + Label label = new Label("Please wait"); + label.setId("label"); + label.setVisible(false); + mainLayout.addComponent(label); + + Button button = new Button("Hide me 3 secondes"); + button.setId("hide"); + button.addClickListener(event1 -> { + button.setVisible(false); + label.setVisible(true); + + new Thread(() -> { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + button.getUI().access(() -> { + button.setVisible(true); + label.setVisible(false); + button.getUI().push(); + }); + }).start(); + }); + mainLayout.addComponent(button); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/push/PushToggleComponentVisibilityTest.java b/uitest/src/test/java/com/vaadin/tests/push/PushToggleComponentVisibilityTest.java new file mode 100644 index 0000000000..831d6a11b2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/push/PushToggleComponentVisibilityTest.java @@ -0,0 +1,43 @@ +/* + * 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.push; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class PushToggleComponentVisibilityTest extends SingleBrowserTest { + + private static final String HIDE = "hide"; + + @Test + public void ensureComponentVisible() { + openTestURL(); + + $(ButtonElement.class).id(HIDE).click(); + Assert.assertEquals("Please wait", + $(LabelElement.class).first().getText()); + + waitForElementPresent(By.id(HIDE)); + $(ButtonElement.class).id(HIDE).click(); + Assert.assertEquals("Please wait", + $(LabelElement.class).first().getText()); + } +} |