HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestInvalidMutationDurabilityException.java
blobf5142cd62810d03ca1f95babfb3bddbf74c12414
1 /**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org.apache.hadoop.hbase.client;
21 import org.apache.hadoop.hbase.HBaseClassTestRule;
22 import org.apache.hadoop.hbase.HBaseTestingUtil;
23 import org.apache.hadoop.hbase.HConstants;
24 import org.apache.hadoop.hbase.TableName;
25 import org.apache.hadoop.hbase.regionserver.InvalidMutationDurabilityException;
26 import org.apache.hadoop.hbase.testclassification.ClientTests;
27 import org.apache.hadoop.hbase.testclassification.MediumTests;
28 import org.apache.hadoop.hbase.util.Bytes;
29 import org.junit.AfterClass;
30 import org.junit.BeforeClass;
31 import org.junit.ClassRule;
32 import org.junit.Test;
33 import org.junit.experimental.categories.Category;
35 @Category({ MediumTests.class, ClientTests.class })
36 public class TestInvalidMutationDurabilityException {
38 @ClassRule
39 public static final HBaseClassTestRule CLASS_RULE =
40 HBaseClassTestRule.forClass(TestInvalidMutationDurabilityException.class);
42 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
44 private static TableName TABLE_NOT_REPLICATE = TableName.valueOf("TableNotReplicate");
46 private static TableName TABLE_NEED_REPLICATE = TableName.valueOf("TableNeedReplicate");
48 private static byte[] CF = Bytes.toBytes("cf");
50 private static byte[] CQ = Bytes.toBytes("cq");
52 private static Table tableNotReplicate;
54 private static Table tableNeedReplicate;
56 @BeforeClass
57 public static void setUp() throws Exception {
58 UTIL.startMiniCluster();
59 UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(TABLE_NOT_REPLICATE)
60 .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF).build()).build());
61 UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(TABLE_NEED_REPLICATE)
62 .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF)
63 .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).build());
64 tableNotReplicate = UTIL.getConnection().getTable(TABLE_NOT_REPLICATE);
65 tableNeedReplicate = UTIL.getConnection().getTable(TABLE_NEED_REPLICATE);
68 @AfterClass
69 public static void tearDown() throws Exception {
70 UTIL.getAdmin().disableTable(TABLE_NOT_REPLICATE);
71 UTIL.getAdmin().disableTable(TABLE_NEED_REPLICATE);
72 UTIL.getAdmin().deleteTable(TABLE_NOT_REPLICATE);
73 UTIL.getAdmin().deleteTable(TABLE_NEED_REPLICATE);
74 UTIL.shutdownMiniCluster();
77 private Put newPutWithSkipWAL() {
78 Put put = new Put(Bytes.toBytes("row"));
79 put.addColumn(CF, CQ, Bytes.toBytes("value"));
80 put.setDurability(Durability.SKIP_WAL);
81 return put;
84 @Test
85 public void testPutToTableNotReplicate() throws Exception {
86 tableNotReplicate.put(newPutWithSkipWAL());
89 @Test(expected = InvalidMutationDurabilityException.class)
90 public void testPutToTableNeedReplicate() throws Exception {
91 tableNeedReplicate.put(newPutWithSkipWAL());
94 private Delete newDeleteWithSkipWAL() {
95 Delete delete = new Delete(Bytes.toBytes("row"));
96 delete.addColumn(CF, CQ);
97 delete.setDurability(Durability.SKIP_WAL);
98 return delete;
101 @Test
102 public void testDeleteToTableNotReplicate() throws Exception {
103 tableNotReplicate.delete(newDeleteWithSkipWAL());
106 @Test(expected = InvalidMutationDurabilityException.class)
107 public void testDeleteToTableNeedReplicate() throws Exception {
108 tableNeedReplicate.delete(newDeleteWithSkipWAL());
111 private Append newAppendWithSkipWAL() {
112 Append append = new Append(Bytes.toBytes("row"));
113 append.addColumn(CF, CQ, Bytes.toBytes("value"));
114 append.setDurability(Durability.SKIP_WAL);
115 return append;
118 @Test
119 public void testAppendToTableNotReplicate() throws Exception {
120 tableNotReplicate.append(newAppendWithSkipWAL());
123 @Test(expected = InvalidMutationDurabilityException.class)
124 public void testAppendToTableNeedReplicate() throws Exception {
125 tableNeedReplicate.append(newAppendWithSkipWAL());
128 private Increment newIncrementWithSkipWAL() {
129 Increment increment = new Increment(Bytes.toBytes("row"));
130 increment.addColumn(CF, CQ, 1);
131 increment.setDurability(Durability.SKIP_WAL);
132 return increment;
135 @Test
136 public void testIncrementToTableNotReplicate() throws Exception {
137 tableNotReplicate.increment(newIncrementWithSkipWAL());
140 @Test(expected = InvalidMutationDurabilityException.class)
141 public void testIncrementToTableNeedReplicate() throws Exception {
142 tableNeedReplicate.increment(newIncrementWithSkipWAL());
145 @Test
146 public void testCheckWithMutateToTableNotReplicate() throws Exception {
147 tableNotReplicate.checkAndMutate(Bytes.toBytes("row"), CF).qualifier(CQ).ifNotExists()
148 .thenPut(newPutWithSkipWAL());
151 @Test(expected = InvalidMutationDurabilityException.class)
152 public void testCheckWithMutateToTableNeedReplicate() throws Exception {
153 tableNeedReplicate.checkAndMutate(Bytes.toBytes("row"), CF).qualifier(CQ).ifNotExists()
154 .thenPut(newPutWithSkipWAL());