@Test
  public void testExitIfDisksReshuffled() throws Exception {
    ClusterSetupHelper clusterHelper = new ClusterSetupHelper();
    clusterHelper.setupCluster();
    clusterHelper.createAllMountPaths();
    clusterHelper.turnFullAutoOnForLocalhost();

    HelixClusterManager clusterMap = clusterHelper.clusterMap;
    HelixParticipant helixParticipant = clusterHelper.helixParticipant;
    DataNodeId localNode = clusterHelper.localNode;
    generateConfigs(true, true, false, 2, true, true);

    Map<DiskId, List<ReplicaId>> diskToReplicaMap = new HashMap<>();
    for (ReplicaId replica : clusterMap.getReplicaIds(localNode)) {
      DiskId disk = replica.getDiskId();
      diskToReplicaMap.computeIfAbsent(disk, key -> new ArrayList<>()).add(replica);
    }

    System.setSecurityManager(new SystemExitSecurityManager());
    exceptionRule.expect(SecurityException.class);
    exceptionRule.expectMessage("System.exit() was called");

    PartitionFinder mockPartitionFinder = Mockito.mock(PartitionFinder.class);
    Set<String> emptySet = new HashSet<>();
    Map<DiskId, DiskId> reshuffledDisks = new HashMap<>();
    reshuffledDisks.put(diskToReplicaMap.keySet().iterator().next(), diskToReplicaMap.keySet().iterator().next());
    when(mockPartitionFinder.findPartitionsOnDisk(Mockito.any())).thenReturn(emptySet);
    ReplicaPlacementValidator mockReplicaPlacementValidator = Mockito.mock(ReplicaPlacementValidator.class);
    when(mockReplicaPlacementValidator.reshuffleDisks(Mockito.any(), Mockito.any())).thenReturn(reshuffledDisks);

    StorageManager storageManager = new StorageManager(storeConfig, diskManagerConfig, Utils.newScheduler(1, false), metricRegistry, new MockIdFactory(), clusterMap, localNode, new DummyMessageStoreHardDelete(),
            Collections.singletonList(helixParticipant), SystemTime.getInstance(), new DummyMessageStoreRecovery(), new InMemAccountService(false, false));
    storageManager.reshuffleDisksAndMaybeExit(diskToReplicaMap, new PartitionFinder(), mockReplicaPlacementValidator);
    System.setSecurityManager(originalSecurityManager);
  }
When disks are reshuffled, System.exit() should be called.
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/StorageManagerTest.java