@Test
  public void testConcurrentServiceConfigVersions() throws Exception {
    long nextVersion = serviceConfigDAO.findNextServiceConfigVersion(
        cluster.getClusterId(), "HDFS");

    Assert.assertEquals(nextVersion, 1);

    List<Thread> threads = new ArrayList<>();
    for (int i = 0; i < NUMBER_OF_THREADS; i++) {
      Thread thread = new ConcurrentServiceConfigThread(cluster);
      threads.add(thread);

      thread.start();
    }

    for (Thread thread : threads) {
      thread.join();
    }

    long maxVersion = NUMBER_OF_THREADS * NUMBER_OF_SERVICE_CONFIG_VERSIONS;
    nextVersion = serviceConfigDAO.findNextServiceConfigVersion(
        cluster.getClusterId(), "HDFS");

    Assert.assertEquals(maxVersion + 1, nextVersion);
  }
Tests that creating service config versions from multiple threads doesn't
violate unique constraints.

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