Skip to content

Commit

Permalink
Fix RequestFailureReason reason codes according to Appache and avoid …
Browse files Browse the repository at this point in the history
…future conflicts

by assigning new codes to higher numbers
  • Loading branch information
ekaterinadimitrova2 committed Dec 5, 2024
1 parent f4fd013 commit 2a1cfcd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public enum RequestFailureReason
READ_TOO_MANY_TOMBSTONES (1),
TIMEOUT (2),
INCOMPATIBLE_SCHEMA (3),
INDEX_NOT_AVAILABLE (4),
UNKNOWN_COLUMN (5),
UNKNOWN_TABLE (6),
REMOTE_STORAGE_FAILURE (7);
INDEX_NOT_AVAILABLE (6), // We match it to Apache Cassandra's INDEX_NOT_AVAILABLE code introcued in 5.0
// The following codes are not present in Apache Cassandra's RequestFailureReason
// We should add new codes in CC (which do not exist in Apache Cassandra) only with big numbers, to avoid conflicts
UNKNOWN_COLUMN (500),
UNKNOWN_TABLE (501),
REMOTE_STORAGE_FAILURE (502);

public static final Serializer serializer = new Serializer();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.exceptions;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class RequestFailureReasonTest
{
private static final RequestFailureReason[] REASONS = RequestFailureReason.values();
private static final Object[][] EXPECTED_VALUES =
{
{ 0, "UNKNOWN" },
{ 1, "READ_TOO_MANY_TOMBSTONES" },
{ 2, "TIMEOUT" },
{ 3, "INCOMPATIBLE_SCHEMA" },
{ 6, "INDEX_NOT_AVAILABLE" },
{ 500, "UNKNOWN_COLUMN" },
{ 501, "UNKNOWN_TABLE" },
{ 502, "REMOTE_STORAGE_FAILURE" }
};
@Test
public void testEnumCodesAndNames()
{
for (int i = 0; i < REASONS.length; i++)
{
assertEquals("RequestFailureReason code mismatch for " +
REASONS[i].name(), EXPECTED_VALUES[i][0], REASONS[i].code);
assertEquals("RequestFailureReason name mismatch for code " +
REASONS[i].code, EXPECTED_VALUES[i][1], REASONS[i].name());
}
assertEquals("Number of RequestFailureReason enum constants has changed. Update the test.",
EXPECTED_VALUES.length, REASONS.length);
}
}

0 comments on commit 2a1cfcd

Please sign in to comment.