From 4aa578d8c084db3f6f22d7c788543a88eacd54d6 Mon Sep 17 00:00:00 2001 From: Ansku Date: Tue, 10 Oct 2017 18:45:44 +0300 Subject: [PATCH] Prevent Grid refreshAll from getting stuck due mismatched state (#10161) Fixes #10038 --- .../data/provider/DataCommunicator.java | 3 - .../grid/GridDataProviderRefresh.java | 93 +++++++++++++++++++ 2 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridDataProviderRefresh.java diff --git a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java index b41a5f3546..e4c483536b 100644 --- a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java +++ b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java @@ -766,9 +766,6 @@ public class DataCommunicator extends AbstractExtension { } private void hardReset() { - if (reset) { - return; - } reset = true; markAsDirty(); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDataProviderRefresh.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDataProviderRefresh.java new file mode 100644 index 0000000000..4dc17950c0 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDataProviderRefresh.java @@ -0,0 +1,93 @@ +/* + * Copyright 2000-2017 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.grid; + +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Stream; + +import com.vaadin.data.provider.AbstractBackEndDataProvider; +import com.vaadin.data.provider.Query; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; + +/** + * Tests that Grid refresh doesn't get stuck when filtering doesn't match row + * requests. + * + * @author Vaadin Ltd + */ +public class GridDataProviderRefresh extends SimpleGridUI { + + private volatile Boolean filter = false; + + private Stream> fetchValue(Boolean filter) { + if (filter) { + return Arrays + .asList("One", String.valueOf(System.currentTimeMillis())) + .stream().map(s -> new AtomicReference<>(s)); + } else { + return Stream.empty(); + } + } + + @Override + protected void setup(VaadinRequest request) { + AbstractBackEndDataProvider, Object> dataProvider = new AbstractBackEndDataProvider, Object>() { + @Override + protected Stream> fetchFromBackEnd( + Query, Object> query) { + try { + Thread.sleep(250); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return fetchValue(filter); + } + + @Override + protected int sizeInBackEnd( + Query, Object> query) { + return (int) fetchValue(filter).count(); + } + }; + + Grid> grid = new Grid<>(); + grid.setDataProvider(dataProvider); + grid.addColumn(AtomicReference::get); + addComponent(grid); + + Button button = new Button("Refresh"); + button.addClickListener(event1 -> { + filter = new Boolean(!filter); + dataProvider.refreshAll(); + }); + addComponent(button); + } + + @Override + protected String getTestDescription() { + return "Grid refreshAll shouldn't get stuck when filtering doesn't match row requests " + + "(randomly triggered when button is clicked fast enough " + + "several times in a row, especially if using old and slow Windows)"; + } + + @Override + protected Integer getTicketNumber() { + return 10038; + } +} -- 2.39.5