|
25 | 25 | import java.util.Map; |
26 | 26 | import java.util.UUID; |
27 | 27 |
|
| 28 | +import org.apache.commons.io.FileUtils; |
28 | 29 | import org.apache.hadoop.hdds.conf.OzoneConfiguration; |
29 | 30 | import org.apache.hadoop.hdds.protocol.DatanodeDetails; |
30 | 31 | import org.apache.hadoop.hdds.protocol.proto.HddsProtos; |
|
79 | 80 | import org.junit.jupiter.api.io.TempDir; |
80 | 81 | import org.mockito.Mockito; |
81 | 82 |
|
| 83 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
82 | 84 | import static org.junit.jupiter.api.Assertions.assertEquals; |
83 | 85 | import static org.mockito.Mockito.mock; |
84 | 86 | import static org.mockito.Mockito.when; |
@@ -285,6 +287,32 @@ public void testDnLayoutVersionFile() throws Exception { |
285 | 287 | = new DatanodeLayoutStorage(ozoneConf, |
286 | 288 | "na_expect_storage_initialized"); |
287 | 289 | assertEquals(scmServerImpl.getClusterId(), layout.getClusterID()); |
| 290 | + |
| 291 | + // Delete storage volume info |
| 292 | + File storageDir = ozoneContainer.getVolumeSet() |
| 293 | + .getVolumesList().get(0).getStorageDir(); |
| 294 | + FileUtils.forceDelete(storageDir); |
| 295 | + |
| 296 | + // Format volume VERSION file with |
| 297 | + // different clusterId than SCM clusterId. |
| 298 | + ozoneContainer.getVolumeSet().getVolumesList() |
| 299 | + .get(0).format("different_cluster_id"); |
| 300 | + // Update layout clusterId and persist it. |
| 301 | + layout.setClusterId("different_cluster_id"); |
| 302 | + layout.persistCurrentState(); |
| 303 | + |
| 304 | + // As the volume level clusterId didn't match with SCM clusterId |
| 305 | + // Even after the version call, the datanode layout file should |
| 306 | + // not update its clusterID field. |
| 307 | + rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION); |
| 308 | + versionTask.call(); |
| 309 | + DatanodeLayoutStorage layout1 |
| 310 | + = new DatanodeLayoutStorage(ozoneConf, |
| 311 | + "na_expect_storage_initialized"); |
| 312 | + |
| 313 | + assertEquals("different_cluster_id", layout1.getClusterID()); |
| 314 | + assertNotEquals(scmServerImpl.getClusterId(), layout1.getClusterID()); |
| 315 | + FileUtils.forceDelete(storageDir); |
288 | 316 | } |
289 | 317 | } |
290 | 318 |
|
|
0 commit comments