1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
23
24 import org.apache.hadoop.hbase.client.Mutation;
25 import org.apache.hadoop.hbase.client.Put;
26 import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.apache.hadoop.hbase.util.Bytes;
29 import org.apache.hadoop.hbase.util.Pair;
30 import org.junit.Test;
31 import org.junit.experimental.categories.Category;
32
33 @Category(SmallTests.class)
34 public class TestMiniBatchOperationInProgress {
35
36 @Test
37 public void testMiniBatchOperationInProgressMethods() {
38 Pair<Mutation, Integer>[] operations = new Pair[10];
39 OperationStatus[] retCodeDetails = new OperationStatus[10];
40 WALEdit[] walEditsFromCoprocessors = new WALEdit[10];
41 for (int i = 0; i < 10; i++) {
42 operations[i] = new Pair<Mutation, Integer>(new Put(Bytes.toBytes(i)), null);
43 }
44 MiniBatchOperationInProgress<Pair<Mutation, Integer>> miniBatch =
45 new MiniBatchOperationInProgress<Pair<Mutation, Integer>>(operations, retCodeDetails,
46 walEditsFromCoprocessors, 0, 5);
47
48 assertEquals(5, miniBatch.size());
49 assertTrue(Bytes.equals(Bytes.toBytes(0), miniBatch.getOperation(0).getFirst().getRow()));
50 assertTrue(Bytes.equals(Bytes.toBytes(2), miniBatch.getOperation(2).getFirst().getRow()));
51 assertTrue(Bytes.equals(Bytes.toBytes(4), miniBatch.getOperation(4).getFirst().getRow()));
52 try {
53 miniBatch.getOperation(5);
54 fail("Should throw Exception while accessing out of range");
55 } catch (ArrayIndexOutOfBoundsException e) {
56 }
57 miniBatch.setOperationStatus(1, OperationStatus.FAILURE);
58 assertEquals(OperationStatus.FAILURE, retCodeDetails[1]);
59 try {
60 miniBatch.setOperationStatus(6, OperationStatus.FAILURE);
61 fail("Should throw Exception while accessing out of range");
62 } catch (ArrayIndexOutOfBoundsException e) {
63 }
64 try {
65 miniBatch.setWalEdit(5, new WALEdit());
66 fail("Should throw Exception while accessing out of range");
67 } catch (ArrayIndexOutOfBoundsException e) {
68 }
69
70 miniBatch = new MiniBatchOperationInProgress<Pair<Mutation, Integer>>(operations,
71 retCodeDetails, walEditsFromCoprocessors, 7, 10);
72 try {
73 miniBatch.setWalEdit(-1, new WALEdit());
74 fail("Should throw Exception while accessing out of range");
75 } catch (ArrayIndexOutOfBoundsException e) {
76 }
77 try {
78 miniBatch.getOperation(-1);
79 fail("Should throw Exception while accessing out of range");
80 } catch (ArrayIndexOutOfBoundsException e) {
81 }
82 try {
83 miniBatch.getOperation(3);
84 fail("Should throw Exception while accessing out of range");
85 } catch (ArrayIndexOutOfBoundsException e) {
86 }
87 try {
88 miniBatch.getOperationStatus(9);
89 fail("Should throw Exception while accessing out of range");
90 } catch (ArrayIndexOutOfBoundsException e) {
91 }
92 try {
93 miniBatch.setOperationStatus(3, OperationStatus.FAILURE);
94 fail("Should throw Exception while accessing out of range");
95 } catch (ArrayIndexOutOfBoundsException e) {
96 }
97 assertTrue(Bytes.equals(Bytes.toBytes(7), miniBatch.getOperation(0).getFirst().getRow()));
98 assertTrue(Bytes.equals(Bytes.toBytes(9), miniBatch.getOperation(2).getFirst().getRow()));
99 miniBatch.setOperationStatus(1, OperationStatus.SUCCESS);
100 assertEquals(OperationStatus.SUCCESS, retCodeDetails[8]);
101 WALEdit wal = new WALEdit();
102 miniBatch.setWalEdit(0, wal);
103 assertEquals(wal, walEditsFromCoprocessors[7]);
104 }
105 }