Skip to content

Iteration order can change when using Columns.from(…) #1196

@LeoYimingLi

Description

@LeoYimingLi
  • The flakiness in ColumnsUnitTests#shouldCreateFromColumns

    @Test // DATACASS-343
    void shouldCreateFromColumns() {
    Columns columns = Columns.from("asc", "bar");
    assertThat(columns.toString()).isEqualTo("asc, bar");
    }
    is due to the function Columns from(String... columnNames) where HashMap is used and the order of map is not guaranteed.
    public static Columns from(String... columnNames) {
    Assert.notNull(columnNames, "Column names must not be null");
    Map<ColumnName, Selector> columns = new HashMap<>(columnNames.length, 1);
    Arrays.stream(columnNames)
    .forEach(columnName -> columns.put(ColumnName.from(columnName), ColumnSelector.from(columnName)));
    return new Columns(columns);

  • We can use LinkedHashMap to replace HashMap to keep the order deterministic. Tentative PR to fix the flaky test: https://github.com/LeoYimingLi/spring-data-cassandra/pull/1/files

  • version of spring data
    SHA: 880787f

  • JVM version

    openjdk version "1.8.0_292"
    OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10)
    OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

  • The way to reproduce the flaky test failure:

    • 0.Environment setup: Maven 3.6.0 and Java 1.8.0_292
    • 1.clone the repo:
    git clone https://github.com/spring-projects/spring-data-cassandra
    cd spring-data-cassandra
    git checkout 880787ff8841b461c3bff6d0755a485171867a59
    
    • 2.run with Nondex tool (which explores different behaviors of under-determined APIs and reports test failures)
    mvn install -pl spring-data-cassandra -am -DskipTests
    mvn -pl spring-data-cassandra edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest=org.springframework.data.cassandra.core.query.ColumnsUnitTests#shouldCreateFromColumns
    
    • 3.And we can get the test failure screenshot:
      image

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions