Skip to content

Commit

Permalink
[FSTORE-814] StackOverflowException if you provide statistics columns…
Browse files Browse the repository at this point in the history
… in the statistics config (#1343)
  • Loading branch information
SirOibaf committed Apr 15, 2023
1 parent 63e302a commit c763572
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
4 changes: 4 additions & 0 deletions hopsworks-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,9 @@
<groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,12 @@ public boolean equals(Object o) {
return false;
}
StatisticColumn that = (StatisticColumn) o;
return Objects.equals(id, that.id) &&
Objects.equals(statisticsConfig, that.statisticsConfig) &&
Objects.equals(name, that.name);
return Objects.equals(id, that.id) && Objects.equals(name, that.name);
}

@Override
public int hashCode() {
int result = id.hashCode();
result = 31 * result + statisticsConfig.hashCode();
result = 31 * result + name.hashCode();
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* This file is part of Hopsworks
* Copyright (C) 2023, Hopsworks AB. All rights reserved
*
* Hopsworks is free software: you can redistribute it and/or modify it under the terms of
* the GNU Affero General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* Hopsworks is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

package io.hops.hopsworks.persistence.entity.featurestore.statistics;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;

public class TestStatisticsConfig {

// Test for FSTORE-814
@Test
public void testHashCodeWithColumns() {
StatisticsConfig statisticsConfig = new StatisticsConfig(true, true, true, true);

StatisticColumn statisticColumn = new StatisticColumn(statisticsConfig, "test");
statisticColumn.setId(1);

statisticsConfig.setId(1);
statisticsConfig.setStatisticColumns(Arrays.asList(statisticColumn));

// This should not throw an exception
statisticsConfig.hashCode();
}

@Test
public void testEqualsWithColumns() {
StatisticsConfig statisticsConfig1 = new StatisticsConfig(true, true, true, true);
StatisticColumn statisticColumn1 = new StatisticColumn(statisticsConfig1, "test");
statisticColumn1.setId(1);
statisticsConfig1.setId(1);
statisticsConfig1.setStatisticColumns(Arrays.asList(statisticColumn1));

StatisticsConfig statisticsConfig2 = new StatisticsConfig(true, true, true, true);
StatisticColumn statisticColumn2 = new StatisticColumn(statisticsConfig2, "test");
statisticColumn2.setId(1);
statisticsConfig2.setId(1);
statisticsConfig2.setStatisticColumns(Arrays.asList(statisticColumn2));

Assert.assertTrue(statisticsConfig1.equals(statisticsConfig2));
}
}

0 comments on commit c763572

Please sign in to comment.