NihalJain commented on code in PR #5579:
URL: https://github.com/apache/hbase/pull/5579#discussion_r1431132156


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestManageTableErasureCodingPolicy.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.master.procedure;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThrows;
+
+import java.io.IOException;
+import java.util.function.Function;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.LocatedFileStatus;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.RemoteIterator;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseIOException;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
+import org.apache.hadoop.hbase.io.hfile.HFile;
+import org.apache.hadoop.hbase.regionserver.CompactedHFilesDischarger;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.testclassification.MasterTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.apache.hadoop.hbase.util.JVMClusterUtil;
+import org.apache.hadoop.hbase.util.TableDescriptorChecker;
+import org.apache.hadoop.hdfs.DistributedFileSystem;
+import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Category({ MasterTests.class, MediumTests.class })
+public class TestManageTableErasureCodingPolicy {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestManageTableErasureCodingPolicy.class);
+  private static final Logger LOG =
+    LoggerFactory.getLogger(TestManageTableErasureCodingPolicy.class);
+
+  private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();
+  private static final byte[] FAMILY = Bytes.toBytes("a");
+  private static final TableName NON_EC_TABLE = TableName.valueOf("foo");
+  private static final TableDescriptor NON_EC_TABLE_DESC = 
TableDescriptorBuilder
+    
.newBuilder(NON_EC_TABLE).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
+  private static final TableName EC_TABLE = TableName.valueOf("bar");
+  private static final TableDescriptor EC_TABLE_DESC =
+    
TableDescriptorBuilder.newBuilder(EC_TABLE).setErasureCodingPolicy("XOR-2-1-1024k")
+      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
+
+  @BeforeClass
+  public static void beforeClass() throws Exception {
+    // enable because we are testing the checks below
+    
UTIL.getConfiguration().setBoolean(TableDescriptorChecker.TABLE_SANITY_CHECKS, 
true);
+    UTIL.startMiniDFSCluster(3); // 3 necessary for XOR-2-1-1024k
+    UTIL.startMiniCluster(1);
+    DistributedFileSystem fs = (DistributedFileSystem) 
FileSystem.get(UTIL.getConfiguration());
+    fs.enableErasureCodingPolicy("XOR-2-1-1024k");
+    fs.enableErasureCodingPolicy("RS-6-3-1024k");
+    Table table = UTIL.createTable(NON_EC_TABLE_DESC, null);
+    UTIL.loadTable(table, FAMILY);
+    UTIL.flush();
+  }
+
+  @AfterClass
+  public static void afterClass() throws Exception {
+    UTIL.shutdownMiniCluster();
+    UTIL.shutdownMiniDFSCluster();
+  }
+
+  @Test
+  public void itValidatesPolicyNameForCreate() {
+    runValidatePolicyNameTest(unused -> EC_TABLE_DESC, Admin::createTable);
+  }
+
+  @Test
+  public void itValidatesPolicyNameForAlter() {
+    runValidatePolicyNameTest(admin -> {
+      try {
+        return admin.getDescriptor(NON_EC_TABLE);
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }, Admin::modifyTable);
+  }
+
+  @FunctionalInterface
+  interface ThrowingTableDescriptorConsumer {
+    void accept(Admin admin, TableDescriptor desc) throws IOException;
+  }
+
+  private void runValidatePolicyNameTest(Function<Admin, TableDescriptor> 
descriptorSupplier,
+    ThrowingTableDescriptorConsumer consumer) {
+    HBaseIOException thrown = assertThrows(HBaseIOException.class, () -> {
+      try (Admin admin = UTIL.getAdmin()) {
+        TableDescriptor desc = descriptorSupplier.apply(admin);
+        consumer.accept(admin,
+          
TableDescriptorBuilder.newBuilder(desc).setErasureCodingPolicy("foo").build());
+      }
+    });
+    assertThat(thrown.getMessage(),
+      containsString("Cannot set Erasure Coding policy: foo. Policy not 
found"));
+
+    thrown = assertThrows(HBaseIOException.class, () -> {
+      try (Admin admin = UTIL.getAdmin()) {
+        TableDescriptor desc = descriptorSupplier.apply(admin);
+        consumer.accept(admin,
+          
TableDescriptorBuilder.newBuilder(desc).setErasureCodingPolicy("RS-10-4-1024k").build());
+      }
+    });
+    assertThat(thrown.getMessage(), containsString(
+      "Cannot set Erasure Coding policy: RS-10-4-1024k. The policy must be 
enabled"));
+
+    // RS-6-3-1024k requires at least 6 datanodes, so should fail write test
+    thrown = assertThrows(HBaseIOException.class, () -> {
+      try (Admin admin = UTIL.getAdmin()) {
+        TableDescriptor desc = descriptorSupplier.apply(admin);
+        consumer.accept(admin,
+          
TableDescriptorBuilder.newBuilder(desc).setErasureCodingPolicy("RS-6-3-1024k").build());
+      }
+    });
+    assertThat(thrown.getMessage(), containsString("Failed write test for EC 
policy"));
+  }
+
+  @Test
+  public void testCreateTableErasureCodingSync() throws IOException {
+    try (Admin admin = UTIL.getAdmin(); Table table = 
UTIL.getConnection().getTable(EC_TABLE)) {
+      admin.createTable(EC_TABLE_DESC);
+      UTIL.loadTable(table, FAMILY);
+      UTIL.flush(EC_TABLE);
+      Path rootDir = CommonFSUtils.getRootDir(UTIL.getConfiguration());
+      DistributedFileSystem dfs = (DistributedFileSystem) 
FileSystem.get(UTIL.getConfiguration());
+      checkRegionDirAndFilePolicies(dfs, rootDir, EC_TABLE, "XOR-2-1-1024k", 
"XOR-2-1-1024k");
+    }
+  }
+
+  @Test
+  public void testModifyTableErasureCodingSync() throws IOException, 
InterruptedException {

Review Comment:
   ahh. ignore i see this test already covers the path



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to