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.regionserver.wal; 019 020import static org.junit.Assert.assertArrayEquals; 021import static org.junit.Assert.assertFalse; 022 023import java.io.IOException; 024import java.util.Arrays; 025import java.util.List; 026import org.apache.hadoop.fs.FSDataOutputStream; 027import org.apache.hadoop.fs.Path; 028import org.apache.hadoop.fs.StreamCapabilities; 029import org.apache.hadoop.hbase.HBaseClassTestRule; 030import org.apache.hadoop.hbase.HBaseTestingUtil; 031import org.apache.hadoop.hbase.TableName; 032import org.apache.hadoop.hbase.client.Get; 033import org.apache.hadoop.hbase.client.Put; 034import org.apache.hadoop.hbase.client.Table; 035import org.apache.hadoop.hbase.testclassification.LargeTests; 036import org.apache.hadoop.hbase.testclassification.RegionServerTests; 037import org.apache.hadoop.hbase.util.Bytes; 038import org.apache.hadoop.hbase.util.CommonFSUtils; 039import org.apache.hadoop.hbase.wal.WALFactory; 040import org.apache.hadoop.hdfs.DFSTestUtil; 041import org.apache.hadoop.hdfs.DistributedFileSystem; 042import org.apache.hadoop.hdfs.MiniDFSCluster; 043import org.apache.hadoop.hdfs.client.HdfsAdmin; 044import org.junit.After; 045import org.junit.Before; 046import org.junit.BeforeClass; 047import org.junit.ClassRule; 048import org.junit.Test; 049import org.junit.experimental.categories.Category; 050import org.junit.runner.RunWith; 051import org.junit.runners.Parameterized; 052import org.junit.runners.Parameterized.Parameter; 053import org.junit.runners.Parameterized.Parameters; 054 055@RunWith(Parameterized.class) 056@Category({ RegionServerTests.class, LargeTests.class }) 057public class TestHBaseWalOnEC { 058 059 @ClassRule 060 public static final HBaseClassTestRule CLASS_RULE = 061 HBaseClassTestRule.forClass(TestHBaseWalOnEC.class); 062 063 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 064 065 @BeforeClass 066 public static void setUpBeforeClass() throws Exception { 067 MiniDFSCluster cluster = UTIL.startMiniDFSCluster(3); // Need 3 DNs for RS-3-2 policy 068 DistributedFileSystem fs = cluster.getFileSystem(); 069 070 DFSTestUtil.enableAllECPolicies(fs); 071 072 HdfsAdmin hdfsAdmin = new HdfsAdmin(fs.getUri(), UTIL.getConfiguration()); 073 hdfsAdmin.setErasureCodingPolicy(new Path("/"), "RS-3-2-1024k"); 074 075 try (FSDataOutputStream out = fs.create(new Path("/canary"))) { 076 // If this comes back as having hflush then some test setup assumption is wrong. 077 // Fail the test so that a developer has to look and triage 078 assertFalse("Did not enable EC!", out.hasCapability(StreamCapabilities.HFLUSH)); 079 } 080 081 UTIL.getConfiguration().setBoolean(CommonFSUtils.UNSAFE_STREAM_CAPABILITY_ENFORCE, true); 082 083 } 084 085 @Parameter 086 public String walProvider; 087 088 @Parameters 089 public static List<Object[]> params() { 090 return Arrays.asList(new Object[] { "asyncfs" }, new Object[] { "filesystem" }); 091 } 092 093 @Before 094 public void setUp() throws Exception { 095 UTIL.getConfiguration().set(WALFactory.WAL_PROVIDER, walProvider); 096 UTIL.startMiniCluster(3); 097 } 098 099 @After 100 public void tearDown() throws Exception { 101 UTIL.shutdownMiniCluster(); 102 } 103 104 @Test 105 public void testReadWrite() throws IOException { 106 byte[] row = Bytes.toBytes("row"); 107 byte[] cf = Bytes.toBytes("cf"); 108 byte[] cq = Bytes.toBytes("cq"); 109 byte[] value = Bytes.toBytes("value"); 110 111 TableName name = TableName.valueOf(getClass().getSimpleName()); 112 113 Table t = UTIL.createTable(name, cf); 114 t.put(new Put(row).addColumn(cf, cq, value)); 115 116 UTIL.getAdmin().flush(name); 117 118 assertArrayEquals(value, t.get(new Get(row)).getValue(cf, cq)); 119 } 120}