|
20 | 20 | import static org.junit.Assert.assertEquals;
|
21 | 21 | import static org.junit.Assert.assertFalse;
|
22 | 22 | import static org.junit.Assert.fail;
|
23 |
| - |
24 | 23 | import java.io.IOException;
|
25 | 24 | import java.util.Arrays;
|
26 | 25 | import java.util.Comparator;
|
27 | 26 | import java.util.List;
|
| 27 | +import java.util.concurrent.atomic.AtomicBoolean; |
28 | 28 | import java.util.stream.Collectors;
|
29 | 29 | import org.apache.hadoop.hbase.HBaseClassTestRule;
|
| 30 | +import org.apache.hadoop.hbase.TableName; |
30 | 31 | import org.apache.hadoop.hbase.client.SnapshotDescription;
|
31 | 32 | import org.apache.hadoop.hbase.client.SnapshotType;
|
| 33 | +import org.apache.hadoop.hbase.client.TableState; |
32 | 34 | import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
|
33 | 35 | import org.apache.hadoop.hbase.procedure2.Procedure;
|
34 | 36 | import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
|
|
39 | 41 | import org.junit.ClassRule;
|
40 | 42 | import org.junit.Test;
|
41 | 43 | import org.junit.experimental.categories.Category;
|
42 |
| - |
43 | 44 | import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
44 | 45 | import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos;
|
45 | 46 | import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos;
|
@@ -136,4 +137,46 @@ public void run() {
|
136 | 137 | SnapshotTestingUtils.confirmSnapshotValid(TEST_UTIL, snapshotProto, TABLE_NAME, CF);
|
137 | 138 | SnapshotTestingUtils.confirmSnapshotValid(TEST_UTIL, snapshotOnSameTableProto, TABLE_NAME, CF);
|
138 | 139 | }
|
| 140 | + |
| 141 | + @Test |
| 142 | + public void testItFailsIfTableIsNotDisabledOrEnabled() throws Exception { |
| 143 | + master.getTableStateManager().setTableState(TABLE_NAME, TableState.State.ENABLING); |
| 144 | + final AtomicBoolean failed = new AtomicBoolean(false); |
| 145 | + Thread snapshotThread = new Thread("snapshot") { |
| 146 | + @Override |
| 147 | + public void run() { |
| 148 | + try { |
| 149 | + TEST_UTIL.getAdmin().snapshot(snapshot); |
| 150 | + } catch (IOException e) { |
| 151 | + failed.set(true); |
| 152 | + } |
| 153 | + } |
| 154 | + }; |
| 155 | + snapshotThread.start(); |
| 156 | + SnapshotManager sm = master.getSnapshotManager(); |
| 157 | + TEST_UTIL.waitFor(60000, 50, |
| 158 | + () -> !sm.isTakingSnapshot(TABLE_NAME) && sm.isTableTakingAnySnapshot(TABLE_NAME)); |
| 159 | + |
| 160 | + TestEnableTableProcedure enableTable = |
| 161 | + new TestEnableTableProcedure(master.getMasterProcedureExecutor().getEnvironment(), TABLE_NAME, |
| 162 | + MasterProcedureProtos.EnableTableState.ENABLE_TABLE_SET_ENABLED_TABLE_STATE); |
| 163 | + master.getMasterProcedureExecutor().submitProcedure(enableTable); |
| 164 | + TEST_UTIL.waitFor(60000, |
| 165 | + () -> master.getTableStateManager().getTableState(TABLE_NAME).isEnabled() && failed.get()); |
| 166 | + TEST_UTIL.waitFor(60000, failed::get); |
| 167 | + } |
| 168 | + |
| 169 | + // Needs to be publicly accessible for Procedure validation |
| 170 | + public static class TestEnableTableProcedure extends EnableTableProcedure { |
| 171 | + // Necessary for Procedure validation |
| 172 | + public TestEnableTableProcedure() { |
| 173 | + } |
| 174 | + |
| 175 | + public TestEnableTableProcedure(MasterProcedureEnv env, TableName tableName, |
| 176 | + MasterProcedureProtos.EnableTableState state) { |
| 177 | + super(env, tableName); |
| 178 | + this.setNextState(state); |
| 179 | + } |
| 180 | + |
| 181 | + } |
139 | 182 | }
|
0 commit comments