@Test
  public void testGetUUIDInParallel() throws Exception {
    int numThreads = 5;
    int parallelCalls = 10;
    int numAPICallsPerThread = 10;
    ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
    List<Future<List<String>>> futures = new ArrayList<>();
    for (int n = 0; n < parallelCalls; n++) {
      futures.add(executorService.submit(new Callable<List<String>>() {
        @Override
        public List<String> call() throws Exception {
          HiveMetaStoreClient testClient = new HiveMetaStoreClient(conf);
          List<String> uuids = new ArrayList<>(10);
          for (int i = 0; i < numAPICallsPerThread; i++) {
            String uuid = testClient.getMetastoreDbUuid();
            uuids.add(uuid);
          }
          return uuids;
        }
      }));
    }

    String firstUUID = null;
    List<String> allUuids = new ArrayList<>();
    for (Future<List<String>> future : futures) {
      for (String uuid : future.get()) {
        if (firstUUID == null) {
          firstUUID = uuid;
        } else {
          assertEquals(firstUUID.toLowerCase(), uuid.toLowerCase());
        }
        allUuids.add(uuid);
      }
    }
    int size = allUuids.size();
    assertEquals(numAPICallsPerThread * parallelCalls, size);
  }
This method checks if persistence manager cache is cleaned up properly under some circumstances.
There is a chance that cleanup process removes elements created not only by this test, so we don't check
exact equality, instead check that no new elements can be seen in the cache (so newSet.removeAll(oldSet) should be empty).
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java