forked from apache/cassandra
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DO NOT COMMIT Cherry-pick CNDB-7343: Fix RequestFailureReason reason …
…codes according to Appache and avoid future conflicts by assigning new codes to higher numbers CNDB-7343: Fix fromCode method and add a unit test CNDB-7343: Update forException method for IndexNotAvailable CNDB-7343: Make forException method more resiliant against partial updates
- Loading branch information
1 parent
dfd7707
commit 52a28ac
Showing
2 changed files
with
93 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
test/unit/org/apache/cassandra/exceptions/RequestFailureReasonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
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); | ||
} | ||
|
||
@Test | ||
public void testFromCode() | ||
{ | ||
// Test valid codes | ||
assertEquals(RequestFailureReason.UNKNOWN, RequestFailureReason.fromCode(0)); | ||
assertEquals(RequestFailureReason.READ_TOO_MANY_TOMBSTONES, RequestFailureReason.fromCode(1)); | ||
assertEquals(RequestFailureReason.TIMEOUT, RequestFailureReason.fromCode(2)); | ||
assertEquals(RequestFailureReason.INCOMPATIBLE_SCHEMA, RequestFailureReason.fromCode(3)); | ||
assertEquals(RequestFailureReason.INDEX_NOT_AVAILABLE, RequestFailureReason.fromCode(6)); | ||
assertEquals(RequestFailureReason.UNKNOWN_COLUMN, RequestFailureReason.fromCode(500)); | ||
assertEquals(RequestFailureReason.UNKNOWN_TABLE, RequestFailureReason.fromCode(501)); | ||
assertEquals(RequestFailureReason.REMOTE_STORAGE_FAILURE, RequestFailureReason.fromCode(502)); | ||
|
||
// Test invalid codes | ||
assertEquals(RequestFailureReason.UNKNOWN, RequestFailureReason.fromCode(200)); | ||
assertEquals(RequestFailureReason.UNKNOWN, RequestFailureReason.fromCode(999)); | ||
assertThrows(IllegalArgumentException.class, () -> RequestFailureReason.fromCode(-1)); | ||
} | ||
} |