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.replication; 019 020import static org.hamcrest.CoreMatchers.instanceOf; 021import static org.hamcrest.MatcherAssert.assertThat; 022import static org.junit.jupiter.api.Assertions.assertNotEquals; 023 024import java.io.IOException; 025import org.apache.hadoop.hbase.HBaseZKTestingUtil; 026import org.apache.hadoop.hbase.testclassification.MediumTests; 027import org.apache.hadoop.hbase.testclassification.ReplicationTests; 028import org.apache.hadoop.hbase.zookeeper.ZKUtil; 029import org.apache.zookeeper.KeeperException; 030import org.junit.jupiter.api.AfterAll; 031import org.junit.jupiter.api.BeforeAll; 032import org.junit.jupiter.api.Tag; 033 034@Tag(ReplicationTests.TAG) 035@Tag(MediumTests.TAG) 036public class TestZKReplicationPeerStorage extends ReplicationPeerStorageTestBase { 037 038 private static final HBaseZKTestingUtil UTIL = new HBaseZKTestingUtil(); 039 040 @BeforeAll 041 public static void setUp() throws Exception { 042 UTIL.startMiniZKCluster(); 043 STORAGE = new ZKReplicationPeerStorage(UTIL.getZooKeeperWatcher(), UTIL.getConfiguration()); 044 } 045 046 @AfterAll 047 public static void tearDown() throws IOException { 048 UTIL.shutdownMiniZKCluster(); 049 } 050 051 @Override 052 protected void removePeerSyncRelicationState(String peerId) throws Exception { 053 ZKReplicationPeerStorage storage = (ZKReplicationPeerStorage) STORAGE; 054 ZKUtil.deleteNode(UTIL.getZooKeeperWatcher(), storage.getSyncReplicationStateNode(peerId)); 055 ZKUtil.deleteNode(UTIL.getZooKeeperWatcher(), storage.getNewSyncReplicationStateNode(peerId)); 056 } 057 058 @Override 059 protected void assertPeerSyncReplicationStateCreate(String peerId) throws Exception { 060 ZKReplicationPeerStorage storage = (ZKReplicationPeerStorage) STORAGE; 061 assertNotEquals(-1, 062 ZKUtil.checkExists(UTIL.getZooKeeperWatcher(), storage.getSyncReplicationStateNode(peerId))); 063 assertNotEquals(-1, ZKUtil.checkExists(UTIL.getZooKeeperWatcher(), 064 storage.getNewSyncReplicationStateNode(peerId))); 065 } 066 067 @Override 068 protected void assertPeerNameControlException(ReplicationException e) { 069 assertThat(e.getCause(), instanceOf(KeeperException.NodeExistsException.class)); 070 } 071}