@Test()
  public void testDeadlockWhileRestartingComponents() throws Exception {
    // for each host, install both components
    List<ServiceComponentHost> serviceComponentHosts = new ArrayList<>();
    for (String hostName : hostNames) {
      serviceComponentHosts.add(createNewServiceComponentHost("HDFS",
          "NAMENODE", hostName));

      serviceComponentHosts.add(createNewServiceComponentHost("HDFS",
          "DATANODE", hostName));
    }

    List<Thread> threads = new ArrayList<>();
    for (int i = 0; i < NUMBER_OF_THREADS; i++) {
      ClusterReaderThread clusterReaderThread = new ClusterReaderThread();
      ClusterWriterThread clusterWriterThread = new ClusterWriterThread();
      ServiceComponentRestartThread schWriterThread = new ServiceComponentRestartThread(
          serviceComponentHosts);

      threads.add(clusterReaderThread);
      threads.add(clusterWriterThread);
      threads.add(schWriterThread);

      clusterReaderThread.start();
      clusterWriterThread.start();
      schWriterThread.start();
    }

    DeadlockWarningThread wt = new DeadlockWarningThread(threads, 20, 1000);
    while (true) {
      if(!wt.isAlive()) {
          break;
      }
    }
    if (wt.isDeadlocked()){
      Assert.assertFalse(wt.getErrorMessages().toString(), wt.isDeadlocked());
    } else {
      Assert.assertFalse(wt.isDeadlocked());
    }
  }
Tests that no deadlock exists while restarting components and reading from
the cluster.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java