]> source.dussan.org Git - vaadin-framework.git/commitdiff
Timeout redirect timer is reset on server activity (#12446)
authorHenrik Paul <henrik@vaadin.com>
Tue, 26 Nov 2013 12:49:12 +0000 (14:49 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 3 Dec 2013 13:35:56 +0000 (13:35 +0000)
Change-Id: Iec2e3de627bc1cf5c7d39bf98715b1bf343e7519

WebContent/WEB-INF/web.xml
client/src/com/vaadin/client/ApplicationConnection.java
uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java [new file with mode: 0644]

index 8a917966a102580b2cb671de1496fdefadf5d587..f98b7c78d1d25574ae8e0cb77af7e46f1d4d660b 100644 (file)
         <async-supported>true</async-supported>
     </servlet>
 
+    <servlet>
+        <!-- 
+            This servlet is a separate instance for the sole purpose of 
+            testing #12446 (com.vaadin.tests.components.ui.TimeoutRedirectResetsOnActivity) 
+            because it modifies the VaadinService timeout parameters 
+        -->
+        <servlet-name>VaadinApplicationRunnerWithTimeoutRedirect</servlet-name>
+        <servlet-class>com.vaadin.launcher.ApplicationRunnerServlet</servlet-class>
+    </servlet>
+    
     <servlet>
         <servlet-name>VaadinApplicationRunnerWithPush</servlet-name>
         <servlet-class>com.vaadin.launcher.ApplicationRunnerServlet</servlet-class>
         <url-pattern>/run/*</url-pattern>
     </servlet-mapping>
 
+    <servlet-mapping>
+        <servlet-name>VaadinApplicationRunnerWithTimeoutRedirect</servlet-name>
+        <url-pattern>/12446/*</url-pattern>
+    </servlet-mapping>
+
     <servlet-mapping>
         <servlet-name>VaadinApplicationRunnerWithPush</servlet-name>
         <url-pattern>/run-push/*</url-pattern>
index f95cec4fbc6363d2c325d6833446f6a5f037450e..a87fa3e3425ab46e99f735df375214b73071cc13 100644 (file)
@@ -64,7 +64,6 @@ import com.google.gwt.user.client.Window.ClosingHandler;
 import com.google.gwt.user.client.ui.HasWidgets;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.client.ApplicationConfiguration.ErrorMessage;
-import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent;
 import com.vaadin.client.ResourceLoader.ResourceLoadEvent;
 import com.vaadin.client.ResourceLoader.ResourceLoadListener;
 import com.vaadin.client.communication.HasJavaScriptConnectorHelper;
@@ -1417,6 +1416,9 @@ public class ApplicationConnection {
                     if (meta.containsKey("timedRedirect")) {
                         final ValueMap timedRedirect = meta
                                 .getValueMap("timedRedirect");
+                        if (redirectTimer != null) {
+                            redirectTimer.cancel();
+                        }
                         redirectTimer = new Timer() {
                             @Override
                             public void run() {
diff --git a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java
new file mode 100644 (file)
index 0000000..2c649c9
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2000-2013 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 com.vaadin.server.CustomizedSystemMessages;
+import com.vaadin.server.SystemMessages;
+import com.vaadin.server.SystemMessagesInfo;
+import com.vaadin.server.SystemMessagesProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class TimeoutRedirectResetsOnActivity extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        setupTimout(request);
+
+        addComponent(new Button("clicky", new Button.ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent event) {
+                // NOOP
+            }
+        }));
+    }
+
+    private void setupTimout(VaadinRequest request) {
+        request.getService().setSystemMessagesProvider(
+                new SystemMessagesProvider() {
+                    @Override
+                    public SystemMessages getSystemMessages(
+                            SystemMessagesInfo systemMessagesInfo) {
+                        CustomizedSystemMessages msgs = new CustomizedSystemMessages();
+                        msgs.setSessionExpiredMessage(null);
+                        msgs.setSessionExpiredCaption(null);
+                        msgs.setSessionExpiredNotificationEnabled(true);
+                        msgs.setSessionExpiredURL("http://example.com/");
+                        return msgs;
+                    }
+                });
+        /*
+         * NOTE: in practice, this means a timeout after 25 seconds, because of
+         * implementation details in
+         * com.vaadin.server.communication.MetadataWriter
+         */
+        getSession().getSession().setMaxInactiveInterval(10);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "The timeout redirect timer should reset if there's activity between the client and server.";
+    }
+
+    @Override
+    @SuppressWarnings("boxing")
+    protected Integer getTicketNumber() {
+        return 12446;
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java
new file mode 100644 (file)
index 0000000..272bacb
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2000-2013 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 static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class TimeoutRedirectResetsOnActivityTest extends MultiBrowserTest {
+    @Test
+    public void verifyRedirectWorks() throws Exception {
+        setDebug(true);
+        openTestURL();
+
+        long startTime = System.currentTimeMillis();
+        while (System.currentTimeMillis() - startTime < 30000) {
+            clickTheButton();
+            Thread.sleep(1000);
+        }
+
+        assertTrue("button disappeared before timeout", buttonIsStillThere());
+
+        Thread.sleep(30000);
+        assertTrue("no redirection occurred within 30 seconds",
+                !buttonIsStillThere());
+    }
+
+    private boolean buttonIsStillThere() {
+        try {
+            return getButton() != null;
+        } catch (NoSuchElementException e) {
+            return false;
+        }
+    }
+
+    private void clickTheButton() {
+        getButton().click();
+    }
+
+    private WebElement getButton() {
+        /*
+         * For some reason, the vaadinElement() method doesn't work when tests
+         * are run outside of "/run/" and "/run-push/" contexts. The given error
+         * message says that the generated Vaadin path doesn't match any
+         * elements, but when that selector is put into the recorder, the
+         * recorder finds it.
+         * 
+         * XPath works fine.
+         */
+        /*-
+        return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]");
+         */
+        return getDriver().findElement(
+                By.xpath("//div[contains(@class,'v-button')]"));
+    }
+
+    @Override
+    protected String getDeploymentPath() {
+        /*
+         * AbstractTB3Test assumes only /run/ and /run-push/ contexts, so this
+         * method needs some overriding.
+         */
+        return "/12446/"
+                + TimeoutRedirectResetsOnActivity.class.getCanonicalName()
+                + "?restartApplication&debug";
+    }
+}