2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.master
;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
22 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
23 import org
.apache
.hadoop
.hbase
.ServerName
;
24 import org
.apache
.hadoop
.hbase
.testclassification
.MasterTests
;
25 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
26 import org
.apache
.hadoop
.hbase
.util
.EnvironmentEdgeManager
;
27 import org
.apache
.hadoop
.hbase
.util
.ManualEnvironmentEdge
;
28 import org
.apache
.hadoop
.hbase
.util
.Pair
;
29 import org
.junit
.Assert
;
30 import org
.junit
.Before
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.Test
;
33 import org
.junit
.experimental
.categories
.Category
;
35 @Category({MasterTests
.class, SmallTests
.class}) // Plays with the ManualEnvironmentEdge
36 public class TestClusterStatusPublisher
{
39 public static final HBaseClassTestRule CLASS_RULE
=
40 HBaseClassTestRule
.forClass(TestClusterStatusPublisher
.class);
42 private ManualEnvironmentEdge mee
= new ManualEnvironmentEdge();
45 public void before() {
47 EnvironmentEdgeManager
.injectEdge(mee
);
51 public void testEmpty() {
52 ClusterStatusPublisher csp
= new ClusterStatusPublisher() {
54 protected List
<Pair
<ServerName
, Long
>> getDeadServers(long since
) {
55 return new ArrayList
<>();
59 Assert
.assertTrue(csp
.generateDeadServersListToSend().isEmpty());
63 public void testMaxSend() {
64 ClusterStatusPublisher csp
= new ClusterStatusPublisher() {
65 @SuppressWarnings("MissingDefault")
67 protected List
<Pair
<ServerName
, Long
>> getDeadServers(long since
) {
68 List
<Pair
<ServerName
, Long
>> res
= new ArrayList
<>();
69 switch ((int) EnvironmentEdgeManager
.currentTime()) {
71 res
.add(new Pair
<>(ServerName
.valueOf("hn", 10, 10), 1L));
82 for (int i
= 0; i
< ClusterStatusPublisher
.NB_SEND
; i
++) {
83 Assert
.assertEquals("i=" + i
, 1, csp
.generateDeadServersListToSend().size());
86 Assert
.assertTrue(csp
.generateDeadServersListToSend().isEmpty());
90 public void testOrder() {
91 ClusterStatusPublisher csp
= new ClusterStatusPublisher() {
93 protected List
<Pair
<ServerName
, Long
>> getDeadServers(long since
) {
94 List
<Pair
<ServerName
, Long
>> res
= new ArrayList
<>();
95 for (int i
= 0; i
< 25; i
++) {
96 res
.add(new Pair
<>(ServerName
.valueOf("hn" + i
, 10, 10), 20L));
105 List
<ServerName
> allSNS
= csp
.generateDeadServersListToSend();
107 Assert
.assertEquals(10, ClusterStatusPublisher
.MAX_SERVER_PER_MESSAGE
);
108 Assert
.assertEquals(10, allSNS
.size());
110 List
<ServerName
> nextMes
= csp
.generateDeadServersListToSend();
111 Assert
.assertEquals(10, nextMes
.size());
112 for (ServerName sn
: nextMes
) {
113 if (!allSNS
.contains(sn
)) {
117 Assert
.assertEquals(20, allSNS
.size());
119 nextMes
= csp
.generateDeadServersListToSend();
120 Assert
.assertEquals(10, nextMes
.size());
121 for (ServerName sn
: nextMes
) {
122 if (!allSNS
.contains(sn
)) {
126 Assert
.assertEquals(25, allSNS
.size());
128 nextMes
= csp
.generateDeadServersListToSend();
129 Assert
.assertEquals(10, nextMes
.size());
130 for (ServerName sn
: nextMes
) {
131 if (!allSNS
.contains(sn
)) {
135 Assert
.assertEquals(25, allSNS
.size());