From e8f961f403a1a55a4837a576d744288599962d5a Mon Sep 17 00:00:00 2001 From: Sumanth Pasupuleti Date: Fri, 19 Feb 2021 23:25:02 -0800 Subject: [PATCH] Make speculative retry parameter case-insensitive for backward compatibility with 2.1 patch by Sumanth Pasupuleti; reviewed by Caleb Rackliffe and Ekaterina Dimitrova for CASSANDRA-16467 --- CHANGES.txt | 1 + .../schema/SpeculativeRetryParam.java | 9 +- .../SpeculativeRetryParamParseTest.java | 106 ++++++++++++++++++ 3 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 test/unit/org/apache/cassandra/schema/SpeculativeRetryParamParseTest.java diff --git a/CHANGES.txt b/CHANGES.txt index 0c263e8df5..be040fc1dd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.25: + * Make speculative retry parameter case-insensitive for backward compatibility with 2.1 (CASSANDRA-16467) * Push digest mismatch exceptions to trace (CASSANDRA-14900) * Support long names in nodetool output (CASSANDRA-14162) * Handle correctly the exceptions thrown by custom QueryHandler constructors (CASSANDRA-16703) diff --git a/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java b/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java index 43447f0160..5ecde41c82 100644 --- a/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java +++ b/src/java/org/apache/cassandra/schema/SpeculativeRetryParam.java @@ -89,7 +89,8 @@ public final class SpeculativeRetryParam public static SpeculativeRetryParam fromString(String value) { - if (value.toLowerCase(Locale.ENGLISH).endsWith("ms")) + String upperCaseValue = value.toUpperCase(Locale.ENGLISH); + if (upperCaseValue.endsWith("MS")) { try { @@ -101,7 +102,7 @@ public final class SpeculativeRetryParam } } - if (value.toUpperCase(Locale.ENGLISH).endsWith(Kind.PERCENTILE.toString())) + if (upperCaseValue.endsWith(Kind.PERCENTILE.toString())) { double threshold; try @@ -121,10 +122,10 @@ public final class SpeculativeRetryParam TableParams.Option.SPECULATIVE_RETRY)); } - if (value.equals(Kind.NONE.toString())) + if (upperCaseValue.equals(Kind.NONE.toString())) return NONE; - if (value.equals(Kind.ALWAYS.toString())) + if (upperCaseValue.equals(Kind.ALWAYS.toString())) return ALWAYS; throw new ConfigurationException(format("Invalid value %s for option '%s'", value, TableParams.Option.SPECULATIVE_RETRY)); diff --git a/test/unit/org/apache/cassandra/schema/SpeculativeRetryParamParseTest.java b/test/unit/org/apache/cassandra/schema/SpeculativeRetryParamParseTest.java new file mode 100644 index 0000000000..3dd2c29da1 --- /dev/null +++ b/test/unit/org/apache/cassandra/schema/SpeculativeRetryParamParseTest.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.cassandra.schema; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import org.apache.cassandra.exceptions.ConfigurationException; + +import static org.junit.Assert.assertEquals; +import static org.junit.runners.Parameterized.Parameters; + +@RunWith(Enclosed.class) +public class SpeculativeRetryParamParseTest +{ + + @RunWith(Parameterized.class) + public static class SuccessfulParseTest + { + private final String string; + private final SpeculativeRetryParam expectedValue; + + public SuccessfulParseTest(String string, SpeculativeRetryParam expectedValue) + { + this.string = string; + this.expectedValue = expectedValue; + } + + @Parameters + public static Collection generateData() + { + return Arrays.asList(new Object[][]{ + { "NONE", SpeculativeRetryParam.none() }, + { "ALWAYS", SpeculativeRetryParam.always() }, + { "10PERCENTILE", SpeculativeRetryParam.percentile(10.0) }, + { "121.1ms", SpeculativeRetryParam.custom(121.1) }, + { "21.7MS", SpeculativeRetryParam.custom(21.7) }, + { "None", SpeculativeRetryParam.none() }, + { "none", SpeculativeRetryParam.none() }, + { "Always", SpeculativeRetryParam.always() }, + { "always", SpeculativeRetryParam.always() }, + { "21.1percentile", SpeculativeRetryParam.percentile(21.1) }, + } + ); + } + + @Test + public void testParameterParse() + { + assertEquals(expectedValue, SpeculativeRetryParam.fromString(string)); + } + } + + @RunWith(Parameterized.class) + public static class FailedParseTest + { + private final String string; + + public FailedParseTest(String string) + { + this.string = string; + } + + @Parameters + public static Collection generateData() + { + return Arrays.asList(new Object[][]{ + { "" }, + { "-0.1PERCENTILE" }, + { "100.1PERCENTILE" }, + { "xPERCENTILE" }, + { "xyzms" }, + { "X" }, + { "21.1p" } + } + ); + } + + @Test(expected = ConfigurationException.class) + public void testParameterParse() + { + SpeculativeRetryParam.fromString(string); + } + } +} \ No newline at end of file