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