View Javadoc

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
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.hadoop.hbase.client;
20  
21  import org.apache.hadoop.hbase.SmallTests;
22  import org.junit.Assert;
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.junit.experimental.categories.Category;
26  
27  /**
28   * Tests for testing methods added in HBASE-9093. This set of tests is meant
29   * to test the {@linkplain Mutation#setWriteToWAL(boolean)}
30   * and {@linkplain Mutation#getWriteToWAL()} methods which provide
31   * a compatibility layer with HBase versions < 95's client side WAL semantics.
32   */
33  @Category(SmallTests.class)
34  public class TestPutWriteToWal {
35  
36    private Put put;
37    @Before
38    public void setUp() throws Exception {
39      put = new Put("test".getBytes());
40    }
41  
42    @Test
43    public void testWriteToWAL(){
44      put.setWriteToWAL(true);
45      Assert.assertEquals(Durability.USE_DEFAULT, put.getDurability());
46    }
47  
48    @Test
49    public void testNoWriteToWAL() {
50      put.setWriteToWAL(false);
51      Assert.assertEquals(Durability.SKIP_WAL, put.getDurability());
52    }
53  
54    @Test
55    public void testWriteToWALSwitch() {
56      put.setWriteToWAL(false);
57      Assert.assertEquals(Durability.SKIP_WAL, put.getDurability());
58      put.setWriteToWAL(true);
59      Assert.assertEquals(Durability.USE_DEFAULT, put.getDurability());
60    }
61  
62    @Test
63    public void testPutCopy() {
64      put.setWriteToWAL(false);
65      Put putCopy1 = new Put(put);
66      Assert.assertEquals(Durability.SKIP_WAL, putCopy1.getDurability());
67  
68      put.setWriteToWAL(true);
69      Put putCopy2 = new Put(put);
70      Assert.assertEquals(Durability.USE_DEFAULT, putCopy2.getDurability());
71    }
72  }