HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestMiniBatchOperationInProgress.java
blob87d418537551659a99e24347acabc34f4dea811f
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.regionserver;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
24 import org.apache.hadoop.hbase.HBaseClassTestRule;
25 import org.apache.hadoop.hbase.client.Mutation;
26 import org.apache.hadoop.hbase.client.Put;
27 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
28 import org.apache.hadoop.hbase.testclassification.SmallTests;
29 import org.apache.hadoop.hbase.util.Bytes;
30 import org.apache.hadoop.hbase.util.Pair;
31 import org.apache.hadoop.hbase.wal.WALEdit;
32 import org.junit.ClassRule;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
36 @Category({RegionServerTests.class, SmallTests.class})
37 public class TestMiniBatchOperationInProgress {
39 @ClassRule
40 public static final HBaseClassTestRule CLASS_RULE =
41 HBaseClassTestRule.forClass(TestMiniBatchOperationInProgress.class);
43 @Test
44 public void testMiniBatchOperationInProgressMethods() {
45 Pair<Mutation, Integer>[] operations = new Pair[10];
46 OperationStatus[] retCodeDetails = new OperationStatus[10];
47 WALEdit[] walEditsFromCoprocessors = new WALEdit[10];
48 for (int i = 0; i < 10; i++) {
49 operations[i] = new Pair<>(new Put(Bytes.toBytes(i)), null);
51 MiniBatchOperationInProgress<Pair<Mutation, Integer>> miniBatch =
52 new MiniBatchOperationInProgress<>(operations, retCodeDetails,
53 walEditsFromCoprocessors, 0, 5, 5);
55 assertEquals(5, miniBatch.size());
56 assertTrue(Bytes.equals(Bytes.toBytes(0), miniBatch.getOperation(0).getFirst().getRow()));
57 assertTrue(Bytes.equals(Bytes.toBytes(2), miniBatch.getOperation(2).getFirst().getRow()));
58 assertTrue(Bytes.equals(Bytes.toBytes(4), miniBatch.getOperation(4).getFirst().getRow()));
59 try {
60 miniBatch.getOperation(5);
61 fail("Should throw Exception while accessing out of range");
62 } catch (ArrayIndexOutOfBoundsException e) {
64 miniBatch.setOperationStatus(1, OperationStatus.FAILURE);
65 assertEquals(OperationStatus.FAILURE, retCodeDetails[1]);
66 try {
67 miniBatch.setOperationStatus(6, OperationStatus.FAILURE);
68 fail("Should throw Exception while accessing out of range");
69 } catch (ArrayIndexOutOfBoundsException e) {
71 try {
72 miniBatch.setWalEdit(5, new WALEdit());
73 fail("Should throw Exception while accessing out of range");
74 } catch (ArrayIndexOutOfBoundsException e) {
77 miniBatch = new MiniBatchOperationInProgress<>(operations,
78 retCodeDetails, walEditsFromCoprocessors, 7, 10, 3);
79 try {
80 miniBatch.setWalEdit(-1, new WALEdit());
81 fail("Should throw Exception while accessing out of range");
82 } catch (ArrayIndexOutOfBoundsException e) {
84 try {
85 miniBatch.getOperation(-1);
86 fail("Should throw Exception while accessing out of range");
87 } catch (ArrayIndexOutOfBoundsException e) {
89 try {
90 miniBatch.getOperation(3);
91 fail("Should throw Exception while accessing out of range");
92 } catch (ArrayIndexOutOfBoundsException e) {
94 try {
95 miniBatch.getOperationStatus(9);
96 fail("Should throw Exception while accessing out of range");
97 } catch (ArrayIndexOutOfBoundsException e) {
99 try {
100 miniBatch.setOperationStatus(3, OperationStatus.FAILURE);
101 fail("Should throw Exception while accessing out of range");
102 } catch (ArrayIndexOutOfBoundsException e) {
104 assertTrue(Bytes.equals(Bytes.toBytes(7), miniBatch.getOperation(0).getFirst().getRow()));
105 assertTrue(Bytes.equals(Bytes.toBytes(9), miniBatch.getOperation(2).getFirst().getRow()));
106 miniBatch.setOperationStatus(1, OperationStatus.SUCCESS);
107 assertEquals(OperationStatus.SUCCESS, retCodeDetails[8]);
108 WALEdit wal = new WALEdit();
109 miniBatch.setWalEdit(0, wal);
110 assertEquals(wal, walEditsFromCoprocessors[7]);