001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.wal; 019 020import static org.junit.Assert.assertNotNull; 021import static org.junit.Assert.fail; 022 023import java.io.IOException; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.HBaseTestingUtil; 027import org.apache.hadoop.hbase.TableName; 028import org.apache.hadoop.hbase.client.Get; 029import org.apache.hadoop.hbase.client.Put; 030import org.apache.hadoop.hbase.client.Result; 031import org.apache.hadoop.hbase.client.Table; 032import org.apache.hadoop.hbase.testclassification.MediumTests; 033import org.apache.hadoop.hbase.testclassification.RegionServerTests; 034import org.apache.hadoop.hbase.util.Bytes; 035import org.junit.After; 036import org.junit.AfterClass; 037import org.junit.Before; 038import org.junit.BeforeClass; 039import org.junit.ClassRule; 040import org.junit.Rule; 041import org.junit.Test; 042import org.junit.experimental.categories.Category; 043import org.junit.rules.TestName; 044import org.slf4j.Logger; 045import org.slf4j.LoggerFactory; 046 047@Category({ RegionServerTests.class, MediumTests.class }) 048public class TestDisabledWAL { 049 050 @ClassRule 051 public static final HBaseClassTestRule CLASS_RULE = 052 HBaseClassTestRule.forClass(TestDisabledWAL.class); 053 054 @Rule 055 public TestName name = new TestName(); 056 057 private static final Logger LOG = LoggerFactory.getLogger(TestDisabledWAL.class); 058 static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 059 private Table table; 060 private TableName tableName; 061 private byte[] fam = Bytes.toBytes("f1"); 062 063 @BeforeClass 064 public static void beforeClass() throws Exception { 065 Configuration conf = TEST_UTIL.getConfiguration(); 066 conf.setBoolean("hbase.regionserver.hlog.enabled", false); 067 try { 068 TEST_UTIL.startMiniCluster(); 069 } catch (RuntimeException | IOException e) { 070 LOG.error("Master failed to start.", e); 071 fail("Failed to start cluster. Reason being: " + e.getCause().getMessage()); 072 } 073 } 074 075 @AfterClass 076 public static void afterClass() throws Exception { 077 TEST_UTIL.shutdownMiniCluster(); 078 } 079 080 @Before 081 public void setup() throws Exception { 082 tableName = TableName.valueOf(name.getMethodName().replaceAll("[^a-zA-Z0-9]", "_")); 083 LOG.info("Creating table " + tableName); 084 table = TEST_UTIL.createTable(tableName, fam); 085 } 086 087 @After 088 public void cleanup() throws Exception { 089 LOG.info("Deleting table " + tableName); 090 TEST_UTIL.deleteTable(tableName); 091 } 092 093 @Test 094 public void testDisabledWAL() throws Exception { 095 LOG.info("Writing data to table " + tableName); 096 Put p = new Put(Bytes.toBytes("row")); 097 p.addColumn(fam, Bytes.toBytes("qual"), Bytes.toBytes("val")); 098 table.put(p); 099 100 LOG.info("Flushing table " + tableName); 101 TEST_UTIL.flush(tableName); 102 103 LOG.info("Getting data from table " + tableName); 104 Get get = new Get(Bytes.toBytes("row")); 105 106 Result result = table.get(get); 107 assertNotNull(result.getValue(fam, Bytes.toBytes("qual"))); 108 } 109}