diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/common/test/Java8FunctionsPerformanceTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/common/test/Java8FunctionsPerformanceTest.java new file mode 100755 index 00000000000..e34574a0fdf --- /dev/null +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/common/test/Java8FunctionsPerformanceTest.java @@ -0,0 +1,87 @@ +package com.sap.sailing.domain.common.test; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; +import java.util.stream.IntStream; + +import org.junit.Before; +import org.junit.Test; +import org.omg.CORBA.LongHolder; + +/** + * Compare Java 8 stream and function performance to direct method call performance + * + * @author Axel Uhl (D043530) + * + */ +public class Java8FunctionsPerformanceTest { + private static final Logger logger = Logger.getLogger(Java8FunctionsPerformanceTest.class.getName()); + private List intList; + private final static int SIZE = 10000000; + + @Before + public void setUp() { + intList = new ArrayList(SIZE); + for (int i=0; i sum.value += i); + long end = System.currentTimeMillis(); + assertEquals(((long) SIZE)*((long) SIZE-1l)/2, sum.value); + logger.info("took "+(end-start)+"ms"); + } + + @Test + public void intArraySumWithForEach() { + long start = System.currentTimeMillis(); + final LongHolder sum = new LongHolder(0); + intList.forEach((i) -> sum.value += i); + long end = System.currentTimeMillis(); + assertEquals(((long) SIZE)*((long) SIZE-1l)/2, sum.value); + logger.info("took "+(end-start)+"ms"); + } + + @Test + public void intArraySumWithIntRangeStream() { + IntStream is = IntStream.range(0, SIZE); + long start = System.currentTimeMillis(); + final LongHolder sum = new LongHolder(0); + is.forEach(i -> sum.value += i); + long end = System.currentTimeMillis(); + assertEquals(((long) SIZE)*((long) SIZE-1l)/2, sum.value); + logger.info("took "+(end-start)+"ms"); + } + + @Test + public void intSum() { + long start = System.currentTimeMillis(); + long sum = 0; + for (int i=0; i regattaAndRaceIdentifiers, boolean isTracked) { + public void racesStoppedTracking(Iterable regattaAndRaceIdentifiers) { + // nothing needs to be done here; the race doesn't change its linkedness status only because it stopped tracking + } + + /** + * When a race is removed from the server, it will also have been unlinked. Represent the unlinking by clearing the + * tracked race link for any race column / fleet that points to it: + */ + @Override + public void racesRemoved(Iterable regattaAndRaceIdentifiers) { for (RegattaAndRaceIdentifier regattaAndRaceIdentifier : regattaAndRaceIdentifiers) { for (RaceColumnDTOAndFleetDTOWithNameBasedEquality raceColumnAndFleetName : raceColumnTable.getDataProvider().getList()) { - if (raceColumnAndFleetName.getA().getRaceColumnName().equals(regattaAndRaceIdentifier.getRaceName())) { - raceColumnAndFleetName.getA().setRaceIdentifier(raceColumnAndFleetName.getB(), - regattaAndRaceIdentifier); + if (Util.equalsWithNull(raceColumnAndFleetName.getA().getRaceIdentifier(raceColumnAndFleetName.getB()), regattaAndRaceIdentifier)) { + raceColumnAndFleetName.getA().setRaceIdentifier(raceColumnAndFleetName.getB(), null); } } raceColumnTable.getDataProvider().refresh(); diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/LeaderboardConfigPanel.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/LeaderboardConfigPanel.java index 20bd6638151..5e9bc8d3c8c 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/LeaderboardConfigPanel.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/LeaderboardConfigPanel.java @@ -312,7 +312,6 @@ TrackedRaceChangedListener, LeaderboardsDisplayer { @Override public boolean isEnabled() { return getSelectedLeaderboard() != null && !getSelectedLeaderboard().type.isRegattaLeaderboard(); - } })) { @Override diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/TrackedRaceChangedListener.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/TrackedRaceChangedListener.java index f17d8e2adf9..dbf9df32110 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/TrackedRaceChangedListener.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/TrackedRaceChangedListener.java @@ -3,5 +3,7 @@ package com.sap.sailing.gwt.ui.adminconsole; import com.sap.sailing.domain.common.RegattaAndRaceIdentifier; public interface TrackedRaceChangedListener { - void changeTrackingRace(Iterable regattaAndRaceIdentifiers, boolean isTracked); + void racesStoppedTracking(Iterable regattaAndRaceIdentifiers); + + void racesRemoved(Iterable regattaAndRaceIdentifiers); } diff --git a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/TrackedRacesListComposite.java b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/TrackedRacesListComposite.java index 9725e4e675d..0005057ca1e 100755 --- a/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/TrackedRacesListComposite.java +++ b/java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/TrackedRacesListComposite.java @@ -72,7 +72,7 @@ public class TrackedRacesListComposite extends AbstractTrackedRacesListComposite public void onSuccess(Void result) { regattaRefresher.fillRegattas(); for (TrackedRaceChangedListener listener : raceIsTrackedRaceChangeListener) { - listener.changeTrackingRace(racesToStopTracking, false); + listener.racesStoppedTracking(racesToStopTracking); } } })); @@ -95,7 +95,7 @@ public class TrackedRacesListComposite extends AbstractTrackedRacesListComposite public void onSuccess(Void result) { regattaRefresher.fillRegattas(); for (TrackedRaceChangedListener listener : raceIsTrackedRaceChangeListener) { - listener.changeTrackingRace(regattaNamesAndRaceNames, false); + listener.racesRemoved(regattaNamesAndRaceNames); } } })); diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/leaderboard/LeaderboardDetailsPanelPO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/leaderboard/LeaderboardDetailsPanelPO.java index 801efe1bc6c..fec90980d3d 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/leaderboard/LeaderboardDetailsPanelPO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/leaderboard/LeaderboardDetailsPanelPO.java @@ -9,16 +9,13 @@ import org.openqa.selenium.WebElement; import com.sap.sailing.selenium.core.BySeleniumId; import com.sap.sailing.selenium.core.FindBy; - import com.sap.sailing.selenium.pages.PageArea; - import com.sap.sailing.selenium.pages.adminconsole.ActionsHelper; - import com.sap.sailing.selenium.pages.adminconsole.tracking.TrackedRacesListPO.TrackedRaceDescriptor; - import com.sap.sailing.selenium.pages.gwt.CellTablePO; import com.sap.sailing.selenium.pages.gwt.DataEntryPO; import com.sap.sailing.selenium.pages.gwt.GenericCellTablePO; +import com.sap.sse.common.Util; public class LeaderboardDetailsPanelPO extends PageArea { public static class RaceDescriptor { @@ -124,22 +121,22 @@ public class LeaderboardDetailsPanelPO extends PageArea { public List getRaces() { List result = new ArrayList<>(); - CellTablePO racesTable = getRacesTable(); - for(DataEntryPO entry : racesTable.getEntries()) { - String name = entry.getColumnContent("Race"); - String fleet = entry.getColumnContent("Fleet"); - //String medalRace = entry.getColumnContent("Medal Race"); - //String linked = entry.getColumnContent("Is linked"); - //String factor = entry.getColumnContent("Factor"); - - result.add(new RaceDescriptor(name, fleet, false, false, 0.0)); + result.add(createRaceDescriptor(entry)); } - return result; } - + + private RaceDescriptor createRaceDescriptor(DataEntryPO entry) { + String name = entry.getColumnContent("Race"); + String fleet = entry.getColumnContent("Fleet"); + String medalRace = entry.getColumnContent("Medal Race"); + String linked = entry.getColumnContent("Is linked"); + String factorColumnContent = entry.getColumnContent("Factor"); + double factor = factorColumnContent.trim().isEmpty() ? 0.0 : Double.valueOf(factorColumnContent); + return new RaceDescriptor(name, fleet, Util.equalsWithNull("x", medalRace), Util.equalsWithNull("Yes", linked), factor); + } // public RaceEditDialog editRace(RaceDescriptor race) { @@ -183,20 +180,12 @@ public class LeaderboardDetailsPanelPO extends PageArea { private DataEntryPO findRace(RaceDescriptor race) { CellTablePO racesTable = getRacesTable(); - for(DataEntryPO entry : racesTable.getEntries()) { - String name = entry.getColumnContent("Race"); - String fleet = entry.getColumnContent("Fleet"); - //String medalRace = entry.getColumnContent("Medal Race"); - //String linked = entry.getColumnContent("Is linked"); - //String factor = entry.getColumnContent("Factor"); - - RaceDescriptor descriptor = new RaceDescriptor(name, fleet, false, false, 0.0); - - if(descriptor.equals(race)) + RaceDescriptor descriptor = createRaceDescriptor(entry); + if (descriptor.equals(race)) { return entry; + } } - return null; } diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/tracking/TrackedRacesListPO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/tracking/TrackedRacesListPO.java index b143b337e53..6837d24daec 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/tracking/TrackedRacesListPO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/tracking/TrackedRacesListPO.java @@ -249,11 +249,8 @@ public class TrackedRacesListPO extends PageArea { public void stopTracking(List races, boolean waitForFinished) { selectRaces(races); - this.stopTrackingButton.click(); - waitForAjaxRequests(); - if(waitForFinished) { waitForTrackedRaces(races, Status.FINISHED); } @@ -292,18 +289,7 @@ public class TrackedRacesListPO extends PageArea { } private void selectRaces(List races) { - List trackedRaces = getTrackedRaces(races); - Iterator iterator = trackedRaces.iterator(); - - while(iterator.hasNext()) { - DataEntryPO trackedRace = iterator.next(); - - if(trackedRace == null) { - iterator.remove(); - } - } - CellTablePO table = getTrackedRacesTable(); - table.selectEntries(trackedRaces); + table.selectEntries(() -> getTrackedRaces(races).stream().filter(tr -> tr != null)); } } diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/tractrac/TracTracEventManagementPanelPO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/tractrac/TracTracEventManagementPanelPO.java index 357f936bbe4..8bae5665dd2 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/tractrac/TracTracEventManagementPanelPO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/adminconsole/tractrac/TracTracEventManagementPanelPO.java @@ -2,7 +2,6 @@ package com.sap.sailing.selenium.pages.adminconsole.tractrac; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -15,13 +14,13 @@ import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.Select; -import com.sap.sailing.selenium.core.FindBy; import com.sap.sailing.selenium.core.BySeleniumId; +import com.sap.sailing.selenium.core.FindBy; import com.sap.sailing.selenium.pages.PageArea; import com.sap.sailing.selenium.pages.adminconsole.regatta.RegattaListCompositePO.RegattaDescriptor; import com.sap.sailing.selenium.pages.adminconsole.tracking.TrackedRacesListPO; -import com.sap.sailing.selenium.pages.gwt.DataEntryPO; import com.sap.sailing.selenium.pages.gwt.CellTablePO; +import com.sap.sailing.selenium.pages.gwt.DataEntryPO; import com.sap.sailing.selenium.pages.gwt.GenericCellTablePO; /** @@ -235,19 +234,8 @@ public class TracTracEventManagementPanelPO extends PageArea { public void startTrackingForRaces(List races) { CellTablePO table = getTrackableRacesTable(); - List entries = table.getEntries(); - Iterator iterator = entries.iterator(); - while (iterator.hasNext()) { - DataEntryPO entry = iterator.next(); - String event = entry.getColumnContent("Event"); - String race = entry.getColumnContent("Race"); - String boatClass = entry.getColumnContent("Boat Class"); - TrackableRaceDescriptor descriptor = new TrackableRaceDescriptor(event, race, boatClass); - if (!races.contains(descriptor)) { - iterator.remove(); - } - } - table.selectEntries(entries); + table.selectEntries(() -> table.getEntries().stream().filter(e -> races.contains( + new TrackableRaceDescriptor(e.getColumnContent("Event"), e.getColumnContent("Race"), e.getColumnContent("Boat Class"))))); this.startTrackingButton.click(); ExpectedCondition condition = ExpectedConditions.alertIsPresent(); if (condition.apply(this.driver) == null) { diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/CellTablePO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/CellTablePO.java index 9f5f4f67258..9ada618b4e9 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/CellTablePO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/CellTablePO.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Objects; +import java.util.function.Supplier; +import java.util.stream.Stream; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; @@ -226,22 +228,20 @@ public abstract class CellTablePO extends PageArea { *

Selects the specified entries.

* *

Note: If an entry is not contained in the table it will not be selected.

- * - * @param entries - * The entries to select. + * @param entryFetcher + * The provider to use to obtain the table entries to select */ - public void selectEntries(List entries) { + public void selectEntries(Supplier> entryFetcher) { // First deselect all selected entries for (T entry : getSelectedEntries()) { entry.deselect(); } - // Select all specified entries - for (T entry : entries) { + entryFetcher.get().forEach(entry -> { if (this.getWebElement().equals(entry.table.getWebElement())) { entry.appendToSelection(); } - } + }); } /** diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/DataEntryPO.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/DataEntryPO.java index 53329c9f2ca..dcff179c457 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/DataEntryPO.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/pages/gwt/DataEntryPO.java @@ -96,7 +96,7 @@ public class DataEntryPO extends CellTableRowPO { * @return * The element on which to click to select or deselect the data entry in the table. */ - protected WebElement getElementForSelect() { + private WebElement getElementForSelect() { final int columnToUseForSelection; if (this.columns.size() > 1) { // could be a selection checkbox column in the first column, so use second column to be on the safe side: @@ -109,11 +109,16 @@ public class DataEntryPO extends CellTableRowPO { protected Action getModifiedSelectAction() { Actions actions = new Actions(this.driver); - actions.keyDown(Keys.CONTROL); - actions.moveToElement(getElementForSelect(), 1, 1); - actions.click(); - actions.keyUp(Keys.CONTROL); - + if (table.getColumnHeaders().get(0).equals("\u2713")) { + // it's a checkbox column + actions.moveToElement(this.columns.isEmpty() ? getWebElement() : this.columns.get(0)); + actions.click(); + } else { + actions.keyDown(Keys.CONTROL); + actions.moveToElement(getElementForSelect(), 1, 1); + actions.click(); + actions.keyUp(Keys.CONTROL); + } return actions.build(); } diff --git a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/leaderboard/TestColumnsInLeaderboard.java b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/leaderboard/TestColumnsInLeaderboard.java index 58948f674db..c1e0847d810 100644 --- a/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/leaderboard/TestColumnsInLeaderboard.java +++ b/java/com.sap.sailing.selenium.test/src/com/sap/sailing/selenium/test/leaderboard/TestColumnsInLeaderboard.java @@ -1,7 +1,10 @@ package com.sap.sailing.selenium.test.leaderboard; import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import java.util.List; @@ -82,6 +85,34 @@ public class TestColumnsInLeaderboard extends AbstractSeleniumTest { } while (stateHasChanged); } + /** + * See bug 2425, comments 5, 6 and 7. This is testing that the leaderboard panel receives a refresh when shown. + */ + @Test + public void testLeaderboardPanelRefresh() { + // Open the admin console + AdminConsolePage adminConsole = AdminConsolePage.goToPage(getWebDriver(), getContextRoot()); + // Remove the tracked race, expecting the column in the leaderboard configuration page to show linked=No after the refresh + TracTracEventManagementPanelPO tracTracEvents = adminConsole.goToTracTracEvents(); + tracTracEvents.getTrackedRacesList().remove(trackedRace); + { + LeaderboardConfigurationPanelPO leaderboardConfiguration = adminConsole.goToLeaderboardConfiguration(); + LeaderboardDetailsPanelPO leaderboardDetails = leaderboardConfiguration.getLeaderboardDetails(LEADERBOARD); + final List races = leaderboardDetails.getRaces(); + assertEquals(1, races.size()); + assertFalse(races.iterator().next().isLinked()); // removing the race must make the race column unlinked. + } + // now back to the TracTrac management panel, load the race again and make sure it is auto-linked to the column + startTrackingRaceAndStopWhenFinished(adminConsole); + { + LeaderboardConfigurationPanelPO leaderboardConfiguration = adminConsole.goToLeaderboardConfiguration(); + LeaderboardDetailsPanelPO details = leaderboardConfiguration.getLeaderboardDetails(LEADERBOARD); + final List races = details.getRaces(); + assertEquals(1, races.size()); + assertTrue(races.iterator().next().isLinked()); // removing the race must make the race column unlinked. + } + } + private void configureLeaderboard() { // Open the admin console for some configuration steps AdminConsolePage adminConsole = AdminConsolePage.goToPage(getWebDriver(), getContextRoot()); @@ -93,6 +124,17 @@ public class TestColumnsInLeaderboard extends AbstractSeleniumTest { seriesDialog.addRaces(1, 1); seriesDialog.pressOk(); // Start the tracking for the races and wait until they are ready to use + startTrackingRaceAndStopWhenFinished(adminConsole); + LeaderboardConfigurationPanelPO leaderboardConfiguration = adminConsole.goToLeaderboardConfiguration(); + leaderboardConfiguration.createRegattaLeaderboard(this.regatta); + LeaderboardDetailsPanelPO leaderboardDetails = leaderboardConfiguration.getLeaderboardDetails(LEADERBOARD); + leaderboardDetails.linkRace(this.raceColumn, this.trackedRace); + } + + /** + * @param adminConsole + */ + private void startTrackingRaceAndStopWhenFinished(AdminConsolePage adminConsole) { TracTracEventManagementPanelPO tracTracEvents = adminConsole.goToTracTracEvents(); tracTracEvents.listTrackableRaces(KIELER_WOCHE_2013_JSON_URL); tracTracEvents.setReggataForTracking(this.regatta); @@ -101,9 +143,7 @@ public class TestColumnsInLeaderboard extends AbstractSeleniumTest { TrackedRacesListPO trackedRacesList = tracTracEvents.getTrackedRacesList(); trackedRacesList.waitForTrackedRace(this.trackedRace, Status.FINISHED); // TracAPI puts REPLAY races into FINISHED mode when done loading trackedRacesList.stopTracking(this.trackedRace); - LeaderboardConfigurationPanelPO leaderboardConfiguration = adminConsole.goToLeaderboardConfiguration(); - leaderboardConfiguration.createRegattaLeaderboard(this.regatta); - LeaderboardDetailsPanelPO leaderboardDetails = leaderboardConfiguration.getLeaderboardDetails(LEADERBOARD); - leaderboardDetails.linkRace(this.raceColumn, this.trackedRace); } + + } diff --git a/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/AdminConsolePanel.java b/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/AdminConsolePanel.java index 1ba0975b1c7..cbc6b8efaaf 100755 --- a/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/AdminConsolePanel.java +++ b/java/com.sap.sse.gwt.adminconsole/src/com/sap/sse/gwt/adminconsole/AdminConsolePanel.java @@ -101,7 +101,7 @@ public class AdminConsolePanel extends DockLayoutPanel { TabLayoutPanel selectedTabLayoutPanel = (TabLayoutPanel) widgetAssociatedToVerticalTab; final int selectedIndex = selectedTabLayoutPanel.getSelectedIndex(); if (selectedIndex >= 0) { - widgetAssociatedToVerticalTab = selectedTabLayoutPanel.getWidget(selectedIndex); + widgetAssociatedToVerticalTab = unwrapScrollPanel(selectedTabLayoutPanel.getWidget(selectedIndex)); } } refreshDataFor(widgetAssociatedToVerticalTab);