@Test
  public void storeRemoveDirectoryAndRestartTest() throws Exception {
    // Make sure that we use segmented log files
    generateConfigs(true, false);
    MockDataNodeId dataNode = clusterMap.getDataNodes().get(0);
    ReplicaId replica = clusterMap.getReplicaIds(dataNode).get(0);
    ReplicaId goodReplica = clusterMap.getReplicaIds(dataNode).get(1);
    // Just start the storage manager and this will make sure all the replicas' directories are created
    // and the first log segment file is also created for each replica.
    StorageManager storageManager = createStorageManager(dataNode, metricRegistry, null);
    storageManager.start();
    // Both replicas should have blobstore returned
    assertNotNull(storageManager.getStore(replica.getPartitionId(), false));
    assertNotNull(storageManager.getStore(goodReplica.getPartitionId(), false));

    File file = getFileLogSegment(replica);
    assertTrue("First log segment file should exist " + file.getAbsolutePath(), file.exists());

    // Now shutdown the storage manager and modify the first log segment by truncating the size to half.
    // This will break the log segment file header
    storageManager.shutdown();
    corruptFirstLogSegment(replica);

    // Now restart the storage manager
    storageManager = createStorageManager(dataNode, metricRegistry, null);
    storageManager.start();
    assertEquals(1,
        getCounterValue(metricRegistry.getCounters(), DiskManager.class.getName(), "TotalStoreStartFailures"));
    // bad replica is not started, but the good replica is
    assertNull(storageManager.getStore(replica.getPartitionId(), false));
    assertNotNull(storageManager.getStore(goodReplica.getPartitionId(), false));

    storageManager.shutdown();

    // Now enable the feature to remove directory and restart blob store
    generateConfigs(true, false, false, 2, true, false);
    storageManager = createStorageManager(dataNode, metricRegistry, null);
    storageManager.start();

    // Getting blob stores for both replicas should both result in not null
    assertNotNull(storageManager.getStore(replica.getPartitionId(), false));
    assertNotNull(storageManager.getStore(goodReplica.getPartitionId(), false));
    storageManager.shutdown();
  }
Test the case where the blob store can't get started and we need to remove the directory and then restart the blobstore.
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/StorageManagerTest.java