Skip to content

Commit

Permalink
Fix flaky test - org.apache.cassandra.cql3.validation.operations.Inse…
Browse files Browse the repository at this point in the history
…rtUpdateIfConditionTest.testConditionalUpdate

patch by Berenguer Blasi; reviewed by Benjamin Lerer for CASSANDRA-17653
  • Loading branch information
bereng committed Jul 11, 2022
1 parent 31eb685 commit 1d80dd0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/java/org/apache/cassandra/gms/Gossiper.java
Expand Up @@ -2356,12 +2356,21 @@ public boolean hasMajorVersion3Nodes()
* Returns {@code true} if there are nodes on version lower than the provided version
*/
public boolean isUpgradingFromVersionLowerThan(CassandraVersion referenceVersion)
{
return isUpgradingFromVersionLowerThanC17653(referenceVersion).left;
}

/* TODO: Aux method for debug purposes on fixing C17653. To be removed*/
@VisibleForTesting
public Pair<Boolean, CassandraVersion> isUpgradingFromVersionLowerThanC17653(CassandraVersion referenceVersion)
{
CassandraVersion v = upgradeFromVersionMemoized.get();
if (CassandraVersion.NULL_VERSION.equals(v) && scheduledGossipTask == null)
return false;
return Pair.create(false, v);

boolean res = v != null && v.compareTo(referenceVersion) < 0;

return v != null && v.compareTo(referenceVersion) < 0;
return Pair.create(res, v);
}

private boolean nodesAgreeOnSchema(Collection<InetAddressAndPort> nodes)
Expand Down
Expand Up @@ -71,8 +71,7 @@ public T get() {
else
return t.value();

nanos = now + this.durationNanos;
this.expirationNanos = nanos == 0L ? 1L : nanos;
this.expirationNanos = now + this.durationNanos;
return t.value();
}
}
Expand All @@ -81,7 +80,7 @@ public T get() {
}

@VisibleForTesting
public void expire()
public synchronized void expire()
{
this.expirationNanos = 0;
}
Expand Down
Expand Up @@ -21,6 +21,8 @@
import java.util.Arrays;
import java.util.Collection;

import com.google.common.annotations.VisibleForTesting;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
Expand All @@ -36,6 +38,7 @@
import org.apache.cassandra.schema.SchemaConstants;
import org.apache.cassandra.schema.SchemaKeyspaceTables;
import org.apache.cassandra.utils.CassandraVersion;
import org.apache.cassandra.utils.Pair;

import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
Expand All @@ -61,14 +64,18 @@ public class InsertUpdateIfConditionTest extends CQLTester
public static Collection<Object[]> data()
{
return Arrays.asList(new Object[]{ "3.0", (Runnable) () -> {
assertTrue(Gossiper.instance.isUpgradingFromVersionLowerThan(new CassandraVersion("3.11")));
Pair<Boolean, CassandraVersion> res = Gossiper.instance.isUpgradingFromVersionLowerThanC17653(new CassandraVersion("3.11"));
assertTrue(debugMsgCASSANDRA17653(res), res.left);
} },
new Object[]{ "3.11", (Runnable) () -> {
assertTrue(Gossiper.instance.isUpgradingFromVersionLowerThan(SystemKeyspace.CURRENT_VERSION));
assertFalse(Gossiper.instance.isUpgradingFromVersionLowerThan(new CassandraVersion("3.11")));
Pair<Boolean, CassandraVersion> res = Gossiper.instance.isUpgradingFromVersionLowerThanC17653(SystemKeyspace.CURRENT_VERSION);
assertTrue(debugMsgCASSANDRA17653(res), res.left);
res = Gossiper.instance.isUpgradingFromVersionLowerThanC17653(new CassandraVersion("3.11"));
assertFalse(debugMsgCASSANDRA17653(res), res.left);
} },
new Object[]{ SystemKeyspace.CURRENT_VERSION.toString(), (Runnable) () -> {
assertFalse(Gossiper.instance.isUpgradingFromVersionLowerThan(SystemKeyspace.CURRENT_VERSION));
Pair<Boolean, CassandraVersion> res = Gossiper.instance.isUpgradingFromVersionLowerThanC17653(SystemKeyspace.CURRENT_VERSION);
assertFalse(debugMsgCASSANDRA17653(res), res.left);
} });
}

Expand Down Expand Up @@ -959,4 +966,10 @@ public void testConditionalOnDurationColumns() throws Throwable

assertRows(execute("SELECT * FROM %s WHERE k = 1"), row(1, Duration.from("10s"), 6));
}

// Helper to debug on the next occurrence of CASSANDRA-17653
private static String debugMsgCASSANDRA17653(Pair<Boolean, CassandraVersion> res)
{
return("Failed on Cass Version: " + res.right == null ? "null" : res.right + " boolean:" + res.left);
}
}

0 comments on commit 1d80dd0

Please sign in to comment.