@Test()
  public void testAddingHostComponentsWhileReading() throws Exception {
    Service service = cluster.getService("HDFS");
    ServiceComponent nameNodeComponent = service.getServiceComponent("NAMENODE");
    ServiceComponent dataNodeComponent = service.getServiceComponent("DATANODE");

    List<Thread> threads = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
      ServiceComponentReaderWriterThread thread = new ServiceComponentReaderWriterThread();
      thread.setDataNodeComponent(dataNodeComponent);
      thread.setNameNodeComponent(nameNodeComponent);
      thread.start();
      threads.add(thread);
    }

    DeadlockWarningThread wt = new DeadlockWarningThread(threads);

    while (true) {
      if(!wt.isAlive()) {
          break;
      }
    }
    if (wt.isDeadlocked()){
      Assert.assertFalse(wt.getErrorMessages().toString(), wt.isDeadlocked());
    } else {
      Assert.assertFalse(wt.isDeadlocked());
    }
  }
Tests that while serializing a service component, writes to that service
component do not cause a deadlock with the global cluster lock.

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