Skip to content

Commit

Permalink
FateOperation enum refactor, new FateOperationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrr888 committed Jan 6, 2025
1 parent ee7056a commit 30e4753
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 24 deletions.
67 changes: 43 additions & 24 deletions core/src/main/java/org/apache/accumulo/core/fate/Fate.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,49 @@ public enum TxInfo {
}

public enum FateOperation {
COMMIT_COMPACTION,
NAMESPACE_CREATE,
NAMESPACE_DELETE,
NAMESPACE_RENAME,
SHUTDOWN_TSERVER,
SYSTEM_SPLIT,
TABLE_BULK_IMPORT2,
TABLE_CANCEL_COMPACT,
TABLE_CLONE,
TABLE_COMPACT,
TABLE_CREATE,
TABLE_DELETE,
TABLE_DELETE_RANGE,
TABLE_EXPORT,
TABLE_IMPORT,
TABLE_MERGE,
TABLE_OFFLINE,
TABLE_ONLINE,
TABLE_RENAME,
TABLE_SPLIT,
TABLE_TABLET_AVAILABILITY;

public static FateOperation fromThrift(TFateOperation tFateOp) {
return FateOperation.valueOf(tFateOp.name());
COMMIT_COMPACTION(null),
NAMESPACE_CREATE(TFateOperation.NAMESPACE_CREATE),
NAMESPACE_DELETE(TFateOperation.NAMESPACE_DELETE),
NAMESPACE_RENAME(TFateOperation.NAMESPACE_RENAME),
SHUTDOWN_TSERVER(null),
SYSTEM_SPLIT(null),
TABLE_BULK_IMPORT2(TFateOperation.TABLE_BULK_IMPORT2),
TABLE_CANCEL_COMPACT(TFateOperation.TABLE_CANCEL_COMPACT),
TABLE_CLONE(TFateOperation.TABLE_CLONE),
TABLE_COMPACT(TFateOperation.TABLE_COMPACT),
TABLE_CREATE(TFateOperation.TABLE_CREATE),
TABLE_DELETE(TFateOperation.TABLE_DELETE),
TABLE_DELETE_RANGE(TFateOperation.TABLE_DELETE_RANGE),
TABLE_EXPORT(TFateOperation.TABLE_EXPORT),
TABLE_IMPORT(TFateOperation.TABLE_IMPORT),
TABLE_MERGE(TFateOperation.TABLE_MERGE),
TABLE_OFFLINE(TFateOperation.TABLE_OFFLINE),
TABLE_ONLINE(TFateOperation.TABLE_ONLINE),
TABLE_RENAME(TFateOperation.TABLE_RENAME),
TABLE_SPLIT(TFateOperation.TABLE_SPLIT),
TABLE_TABLET_AVAILABILITY(TFateOperation.TABLE_TABLET_AVAILABILITY);

private final TFateOperation top;
private static final EnumSet<FateOperation> nonThriftOps =
EnumSet.of(COMMIT_COMPACTION, SHUTDOWN_TSERVER, SYSTEM_SPLIT);

FateOperation(TFateOperation top) {
this.top = top;
}

public static FateOperation fromThrift(TFateOperation top) {
return FateOperation.valueOf(top.name());
}

public static EnumSet<FateOperation> getNonThriftOps() {
return nonThriftOps;
}

public TFateOperation toThrift() {
if (top == null) {
throw new IllegalStateException(this + " does not have an equivalent thrift form");
}
return top;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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
*
* https://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.accumulo.core.fate;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.accumulo.core.manager.thrift.TFateOperation;
import org.junit.jupiter.api.Test;

public class FateOperationTest {

@Test
public void testFateOperation() {
// ensures that all TFateOperation have an equivalent FateOperation
assertTrue(TFateOperation.values().length > 0);
for (var top : TFateOperation.values()) {
assertEquals(top, Fate.FateOperation.fromThrift(top).toThrift());
}
// ensures that all FateOperation are valid: either specified not to have an equivalent thrift
// form or do have an equivalent thrift form
assertTrue(Fate.FateOperation.values().length > 0);
for (var op : Fate.FateOperation.values()) {
if (Fate.FateOperation.getNonThriftOps().contains(op)) {
assertThrows(IllegalStateException.class, op::toThrift);
} else {
assertEquals(op, Fate.FateOperation.fromThrift(op.toThrift()));
}
}
}
}

0 comments on commit 30e4753

Please sign in to comment.