sharmaar12 commented on code in PR #6757:
URL: https://github.com/apache/hbase/pull/6757#discussion_r2024580991
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyController.java:
##########
@@ -0,0 +1,105 @@
+package org.apache.hadoop.hbase.security.access;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Coprocessor;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Put;
+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.coprocessor.CoprocessorHost;
+import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
+import org.apache.hadoop.hbase.master.HMaster;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.apache.hadoop.hbase.testclassification.SecurityTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@Category({ SecurityTests.class, LargeTests.class })
+@SuppressWarnings("deprecation")
+public class TestReadOnlyController {
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestReadOnlyController.class);
+
+ private static final Logger LOG =
LoggerFactory.getLogger(TestAccessController.class);
+ private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
+ private static TableName TEST_TABLE = TableName.valueOf("readonlytesttable");
+ private static byte[] TEST_FAMILY = Bytes.toBytes("readonlytablecolfam");
+ private static Configuration conf;
+ private static Connection connection;
+
+ private static RegionServerCoprocessorEnvironment RSCP_ENV;
+
+ private static Table TestTable;
+ @Rule
+ public TestName name = new TestName();
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ conf = TEST_UTIL.getConfiguration();
+ // Only try once so that if there is failure in connection then test
should fail faster
+ conf.setInt("hbase.ipc.client.connect.max.retries", 1);
+ // Shorter session timeout is added so that in case failures test should
not take more time
+ conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
+ // Enable ReadOnly mode for the cluster
+ conf.setBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY, true);
+ // Add the ReadOnlyController coprocessor to interrupt any write operation
+ conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
ReadOnlyController.class.getName());
+ // Start the test cluster
+ TEST_UTIL.startMiniCluster(2);
+ // Get connection to the HBase
+ connection = ConnectionFactory.createConnection(conf);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ // Cleanup for Connection and HBase cluster
+ connection.close();
+ TEST_UTIL.shutdownMiniCluster();
+ }
+
+ @Test
+ public void testReadOnlyEnabled() {
+ Configuration c = TEST_UTIL.getConfiguration();
+ assertTrue(c.getBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY,
false));
+ }
+
+ @Test
+ public void testPut() throws IOException {
Review Comment:
Will be adding it in further commit. Planning to create separate test files
based on the values of readonly.enabled property and coprocessor.
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyController.java:
##########
@@ -0,0 +1,105 @@
+package org.apache.hadoop.hbase.security.access;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Coprocessor;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Put;
+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.coprocessor.CoprocessorHost;
+import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
+import org.apache.hadoop.hbase.master.HMaster;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.apache.hadoop.hbase.testclassification.SecurityTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@Category({ SecurityTests.class, LargeTests.class })
+@SuppressWarnings("deprecation")
+public class TestReadOnlyController {
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestReadOnlyController.class);
+
+ private static final Logger LOG =
LoggerFactory.getLogger(TestAccessController.class);
+ private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
+ private static TableName TEST_TABLE = TableName.valueOf("readonlytesttable");
+ private static byte[] TEST_FAMILY = Bytes.toBytes("readonlytablecolfam");
+ private static Configuration conf;
+ private static Connection connection;
+
+ private static RegionServerCoprocessorEnvironment RSCP_ENV;
+
+ private static Table TestTable;
+ @Rule
+ public TestName name = new TestName();
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ conf = TEST_UTIL.getConfiguration();
+ // Only try once so that if there is failure in connection then test
should fail faster
+ conf.setInt("hbase.ipc.client.connect.max.retries", 1);
+ // Shorter session timeout is added so that in case failures test should
not take more time
+ conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
+ // Enable ReadOnly mode for the cluster
+ conf.setBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY, true);
+ // Add the ReadOnlyController coprocessor to interrupt any write operation
+ conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
ReadOnlyController.class.getName());
+ // Start the test cluster
+ TEST_UTIL.startMiniCluster(2);
+ // Get connection to the HBase
+ connection = ConnectionFactory.createConnection(conf);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ // Cleanup for Connection and HBase cluster
+ connection.close();
+ TEST_UTIL.shutdownMiniCluster();
+ }
+
+ @Test
+ public void testReadOnlyEnabled() {
+ Configuration c = TEST_UTIL.getConfiguration();
+ assertTrue(c.getBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY,
false));
+ }
+
+ @Test
+ public void testPut() throws IOException {
+ // Create a test table
+ TestTable = TEST_UTIL.createTable(TEST_TABLE, TEST_FAMILY);
+ final byte[] row1 = Bytes.toBytes("row1");
+ final byte[] value = Bytes.toBytes("abcd");
+ // Put a row in the table which should throw and exception
+ Put put = new Put(row1);
+ put.addColumn(TEST_FAMILY, null, value);
+ TestTable.put(put);
+ // This should throw IOException
+ exception.expect(IOException.class);
+ TEST_UTIL.deleteTable(TEST_TABLE);
Review Comment:
Moved the creation of deletion of table into the setup and teardown method
as of now. Will change in future in case needed.
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyController.java:
##########
@@ -0,0 +1,105 @@
+package org.apache.hadoop.hbase.security.access;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Coprocessor;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Put;
+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.coprocessor.CoprocessorHost;
+import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
+import org.apache.hadoop.hbase.master.HMaster;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.apache.hadoop.hbase.testclassification.SecurityTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@Category({ SecurityTests.class, LargeTests.class })
+@SuppressWarnings("deprecation")
+public class TestReadOnlyController {
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestReadOnlyController.class);
+
+ private static final Logger LOG =
LoggerFactory.getLogger(TestAccessController.class);
+ private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
+ private static TableName TEST_TABLE = TableName.valueOf("readonlytesttable");
+ private static byte[] TEST_FAMILY = Bytes.toBytes("readonlytablecolfam");
+ private static Configuration conf;
+ private static Connection connection;
+
+ private static RegionServerCoprocessorEnvironment RSCP_ENV;
+
+ private static Table TestTable;
+ @Rule
+ public TestName name = new TestName();
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ conf = TEST_UTIL.getConfiguration();
+ // Only try once so that if there is failure in connection then test
should fail faster
+ conf.setInt("hbase.ipc.client.connect.max.retries", 1);
+ // Shorter session timeout is added so that in case failures test should
not take more time
+ conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
+ // Enable ReadOnly mode for the cluster
+ conf.setBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY, true);
+ // Add the ReadOnlyController coprocessor to interrupt any write operation
+ conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
ReadOnlyController.class.getName());
Review Comment:
Added it. Thanks for pointing out.
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestReadOnlyController.java:
##########
@@ -0,0 +1,105 @@
+package org.apache.hadoop.hbase.security.access;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Coprocessor;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Put;
+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.coprocessor.CoprocessorHost;
+import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment;
+import org.apache.hadoop.hbase.master.HMaster;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.apache.hadoop.hbase.testclassification.SecurityTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+@Category({ SecurityTests.class, LargeTests.class })
+@SuppressWarnings("deprecation")
+public class TestReadOnlyController {
+
+ @ClassRule
+ public static final HBaseClassTestRule CLASS_RULE =
+ HBaseClassTestRule.forClass(TestReadOnlyController.class);
+
+ private static final Logger LOG =
LoggerFactory.getLogger(TestAccessController.class);
+ private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
+ private static TableName TEST_TABLE = TableName.valueOf("readonlytesttable");
+ private static byte[] TEST_FAMILY = Bytes.toBytes("readonlytablecolfam");
+ private static Configuration conf;
+ private static Connection connection;
+
+ private static RegionServerCoprocessorEnvironment RSCP_ENV;
+
+ private static Table TestTable;
+ @Rule
+ public TestName name = new TestName();
+
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ conf = TEST_UTIL.getConfiguration();
+ // Only try once so that if there is failure in connection then test
should fail faster
+ conf.setInt("hbase.ipc.client.connect.max.retries", 1);
+ // Shorter session timeout is added so that in case failures test should
not take more time
+ conf.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
+ // Enable ReadOnly mode for the cluster
+ conf.setBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY, true);
+ // Add the ReadOnlyController coprocessor to interrupt any write operation
+ conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
ReadOnlyController.class.getName());
+ // Start the test cluster
+ TEST_UTIL.startMiniCluster(2);
+ // Get connection to the HBase
+ connection = ConnectionFactory.createConnection(conf);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ // Cleanup for Connection and HBase cluster
+ connection.close();
+ TEST_UTIL.shutdownMiniCluster();
+ }
+
+ @Test
+ public void testReadOnlyEnabled() {
+ Configuration c = TEST_UTIL.getConfiguration();
+ assertTrue(c.getBoolean(HConstants.HBASE_GLOBAL_READONLY_ENABLED_KEY,
false));
+ }
Review Comment:
Removed the tests.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]