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.security.access;
019
020import static org.junit.jupiter.api.Assertions.assertThrows;
021import static org.mockito.Mockito.mock;
022
023import org.apache.hadoop.hbase.WriteAttemptedOnReadOnlyClusterException;
024import org.apache.hadoop.hbase.coprocessor.ObserverContext;
025import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
026import org.apache.hadoop.hbase.testclassification.SecurityTests;
027import org.apache.hadoop.hbase.testclassification.SmallTests;
028import org.junit.jupiter.api.AfterEach;
029import org.junit.jupiter.api.BeforeEach;
030import org.junit.jupiter.api.Tag;
031import org.junit.jupiter.api.Test;
032
033// Tests methods of BulkLoad Observer which are implemented in ReadOnlyController,
034// by mocking the coprocessor environment and dependencies
035@Tag(SecurityTests.TAG)
036@Tag(SmallTests.TAG)
037public class TestReadOnlyControllerBulkLoadObserver {
038
039  BulkLoadReadOnlyController bulkLoadReadOnlyController;
040
041  // Region Server Coprocessor mocking variables
042  ObserverContext<RegionCoprocessorEnvironment> ctx;
043
044  @BeforeEach
045  public void setup() throws Exception {
046    bulkLoadReadOnlyController = new BulkLoadReadOnlyController();
047
048    // mocking variables initialization
049    ctx = mock(ObserverContext.class);
050  }
051
052  @AfterEach
053  public void tearDown() throws Exception {
054
055  }
056
057  @Test
058  public void testPrePrepareBulkLoadReadOnlyException() {
059    assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> {
060      bulkLoadReadOnlyController.prePrepareBulkLoad(ctx);
061    });
062  }
063
064  @Test
065  public void testPreCleanupBulkLoadReadOnlyException() {
066    assertThrows(WriteAttemptedOnReadOnlyClusterException.class, () -> {
067      bulkLoadReadOnlyController.preCleanupBulkLoad(ctx);
068    });
069  }
070}