@Test
  public void testMultipleNewAlertEvents() throws Exception {
    assertEquals(0, m_dao.findCurrent().size());

    final String definitionName = ALERT_DEFINITION + "1";
    List<Thread> threads = new ArrayList<>();
    final AlertReceivedListener listener = m_injector.getInstance(AlertReceivedListener.class);

    // spawn a bunch of concurrent threasd which will try to create teh same
    // alert over and over
    for (int i = 0; i < 10; i++) {
      Thread thread = new Thread() {
        /**
         * {@inheritDoc}
         */
        @Override
        public void run() {
          Alert alert = new Alert(definitionName, null, "HDFS", null, HOST1, AlertState.OK);
          alert.setClusterId(m_cluster.getClusterId());
          alert.setLabel(ALERT_LABEL);
          alert.setText("HDFS is OK ");
          alert.setTimestamp(System.currentTimeMillis());

          final AlertReceivedEvent event = new AlertReceivedEvent(m_cluster.getClusterId(), alert);
          try {
            listener.onAlertEvent(event);
          } catch (AmbariException e) {
            e.printStackTrace();
          }
        }
      };

      threads.add(thread);
      thread.start();
    }

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

    assertEquals(1, m_dao.findCurrent().size());
  }
Tests that multiple threads can't create duplicate new alerts. This will
spawn several threads, each one trying to create the same alert.
ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java