diff options
author | Sara Seppola <sara@vaadin.com> | 2014-11-04 11:44:45 +0200 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-11-25 14:42:44 +0200 |
commit | 0507127d674d67052ff2e2d9f139e3a69d871169 (patch) | |
tree | 05be65646882d885a2861eaee4210d1e56cd7928 /uitest | |
parent | 53c1e10c0a76f26bdd055916e794621264001f52 (diff) | |
download | vaadin-framework-0507127d674d67052ff2e2d9f139e3a69d871169.tar.gz vaadin-framework-0507127d674d67052ff2e2d9f139e3a69d871169.zip |
Table is not caching thousands of rows in vain (#13576)
Change-Id: I6f6382dd3468db40c36e507b94f84ab1191e100f
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRows.java | 92 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRowsTest.java | 48 |
2 files changed, 140 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRows.java b/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRows.java new file mode 100644 index 0000000000..745f2344a3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRows.java @@ -0,0 +1,92 @@ +package com.vaadin.tests.components.table; + +import java.io.Serializable; +import java.util.List; + +import com.vaadin.data.util.BeanContainer; +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.Table; + +@SuppressWarnings("serial") +public class TableCacheMinimizingOnFetchRows extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + getLayout().setMargin(true); + + final Table table = new Table("Beans of All Sorts"); + + BeanContainer<String, Bean> beans = new BeanContainer<String, Bean>( + Bean.class) { + @Override + public List<String> getItemIds(int startIndex, int numberOfIds) { + + // numberOfIds should be about 60 after scrolling down the table + log.log("requested " + numberOfIds + " rows"); + + return super.getItemIds(startIndex, numberOfIds); + } + }; + beans.setBeanIdProperty("name"); + + for (int i = 0; i < 10000; i++) { + beans.addBean(new Bean("Common bean" + i, i)); + } + + table.setContainerDataSource(beans); + table.setPageLength(20); + table.setVisibleColumns(new Object[] { "name", "value" }); + table.setWidth("800px"); + + Button button = new Button("scroll down"); + button.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + table.setCurrentPageFirstItemIndex(table.size()); + } + }); + + addComponent(table); + addComponent(button); + } + + public class Bean implements Serializable { + + String name; + int value; + + public Bean(String name, int value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + } + + @Override + protected String getTestDescription() { + return "Ensure that when scrolling from top to bottom in a big table with 10000 items, not all rows in the range are cached"; + } + + @Override + protected Integer getTicketNumber() { + return 13576; + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRowsTest.java b/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRowsTest.java new file mode 100644 index 0000000000..edb0f3851a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableCacheMinimizingOnFetchRowsTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2014 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.table; + +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TableCacheMinimizingOnFetchRowsTest extends MultiBrowserTest { + + @Test + public void testCacheSize() throws InterruptedException { + + openTestURL(); + + scrollToBottomOfTable(); + + // the row request might vary slightly with different browsers + String logtext1 = "requested 60 rows"; + String logtext2 = "requested 61 rows"; + + assertThat("Requested cached rows did not match expected", + logContainsText(logtext1) || logContainsText(logtext2)); + + } + + private void scrollToBottomOfTable() { + waitForElementPresent(By.className("v-button")); + $(ButtonElement.class).first().click(); + } +} |