|
18 | 18 | package org.apache.hadoop.hdfs.server.balancer; |
19 | 19 |
|
20 | 20 | import static org.junit.Assert.assertEquals; |
| 21 | +import static org.mockito.ArgumentMatchers.any; |
| 22 | +import static org.mockito.ArgumentMatchers.anyLong; |
| 23 | +import static org.mockito.Mockito.times; |
| 24 | +import static org.mockito.Mockito.verify; |
| 25 | + |
21 | 26 | import java.net.URI; |
| 27 | +import java.util.ArrayList; |
22 | 28 | import java.util.Collection; |
| 29 | +import java.util.List; |
23 | 30 |
|
24 | 31 | import org.apache.hadoop.conf.Configuration; |
25 | 32 | import org.apache.hadoop.fs.FileSystem; |
|
33 | 40 | import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; |
34 | 41 | import org.apache.hadoop.hdfs.protocol.ClientProtocol; |
35 | 42 | import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster; |
| 43 | +import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; |
| 44 | +import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; |
36 | 45 | import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil; |
37 | 46 | import org.apache.hadoop.hdfs.server.namenode.ha.ObserverReadProxyProvider; |
38 | 47 | import org.junit.Test; |
@@ -128,12 +137,24 @@ public void testBalancerWithObserver() throws Exception { |
128 | 137 | cluster = qjmhaCluster.getDfsCluster(); |
129 | 138 | cluster.waitClusterUp(); |
130 | 139 | cluster.waitActive(); |
| 140 | + List<FSNamesystem> namesystemSpies = new ArrayList<>(); |
| 141 | + for (int i = 0; i < cluster.getNumNameNodes(); i++) { |
| 142 | + namesystemSpies.add( |
| 143 | + NameNodeAdapter.spyOnNamesystem(cluster.getNameNode(i))); |
| 144 | + } |
131 | 145 |
|
132 | 146 | DistributedFileSystem dfs = HATestUtil.configureObserverReadFs( |
133 | 147 | cluster, conf, ObserverReadProxyProvider.class, true); |
134 | 148 | client = dfs.getClient().getNamenode(); |
135 | 149 |
|
136 | 150 | doTest(conf); |
| 151 | + for (int i = 0; i < cluster.getNumNameNodes(); i++) { |
| 152 | + // First observer node is at idx 2 so it should get both getBlocks calls |
| 153 | + // all other NameNodes should see 0 getBlocks calls |
| 154 | + int expectedCount = (i == 2) ? 2 : 0; |
| 155 | + verify(namesystemSpies.get(i), times(expectedCount)) |
| 156 | + .getBlocks(any(), anyLong(), anyLong()); |
| 157 | + } |
137 | 158 | } finally { |
138 | 159 | if (qjmhaCluster != null) { |
139 | 160 | qjmhaCluster.shutdown(); |
|
0 commit comments