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.master; 019 020import static org.junit.jupiter.api.Assertions.assertNotEquals; 021 022import java.io.IOException; 023import java.util.List; 024import org.apache.hadoop.hbase.HBaseTestingUtil; 025import org.apache.hadoop.hbase.ServerName; 026import org.apache.hadoop.hbase.testclassification.MasterTests; 027import org.apache.hadoop.hbase.testclassification.MediumTests; 028import org.apache.hadoop.hbase.util.JVMClusterUtil; 029import org.junit.jupiter.api.AfterAll; 030import org.junit.jupiter.api.BeforeAll; 031import org.junit.jupiter.api.Tag; 032import org.junit.jupiter.api.Test; 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035 036@Tag(MasterTests.TAG) 037@Tag(MediumTests.TAG) 038public class TestNewStartedRegionServerVersion { 039 040 private static final Logger LOG = 041 LoggerFactory.getLogger(TestNewStartedRegionServerVersion.class); 042 043 private static HBaseTestingUtil UTIL = new HBaseTestingUtil(); 044 045 @BeforeAll 046 public static void setUp() throws Exception { 047 UTIL.startMiniCluster(1); 048 } 049 050 @AfterAll 051 public static void tearDown() throws Exception { 052 UTIL.shutdownMiniCluster(); 053 } 054 055 @Test 056 public void test() throws InterruptedException { 057 // Start 3 new region server 058 Thread t = new Thread(() -> { 059 for (int i = 0; i < 3; i++) { 060 try { 061 JVMClusterUtil.RegionServerThread newRS = UTIL.getMiniHBaseCluster().startRegionServer(); 062 newRS.waitForServerOnline(); 063 } catch (IOException e) { 064 LOG.error("Failed to start a new RS", e); 065 } 066 } 067 }); 068 t.start(); 069 070 HMaster master = UTIL.getMiniHBaseCluster().getMaster(); 071 while (t.isAlive()) { 072 List<ServerName> serverNames = master.getServerManager().getOnlineServersList(); 073 for (ServerName serverName : serverNames) { 074 assertNotEquals(0, master.getServerManager().getVersionNumber(serverName)); 075 } 076 Thread.sleep(100); 077 } 078 } 079}