@Test
  public void testBadCases() {
    // Invalid state model def
    props.setProperty("clustermap.state.model.definition", "InvalidStateModelDef");
    props.setProperty(ClusterMapConfig.ENABLE_PROPERTY_STORE_CLEAN_UP_TASK, Boolean.toString(false));
    try {
      new ClusterMapConfig(new VerifiableProperties(props));
      fail("should fail due to invalid state model definition");
    } catch (IllegalArgumentException e) {
      //expected and restore previous props
      props.setProperty("clustermap.state.model.definition", stateModelDef);
    }
    // Connect failure.
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    helixManagerFactory.getHelixManager(InstanceType.PARTICIPANT).beBad = true;
    HelixParticipant helixParticipant =
        new HelixParticipant(mock(HelixClusterManager.class), clusterMapConfig, helixManagerFactory,
            new MetricRegistry(), getDefaultZkConnectStr(clusterMapConfig), true);
    try {
      helixParticipant.participateAndBlockStateTransition(Collections.emptyList(), null, null);
      fail("Participation should have failed");
    } catch (IOException e) {
      // OK
    }

    // Bad param during instantiation.
    props.setProperty("clustermap.cluster.name", "");
    clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    try {
      new HelixParticipant(mock(HelixClusterManager.class), clusterMapConfig, helixManagerFactory, new MetricRegistry(),
          getDefaultZkConnectStr(clusterMapConfig), true);
      fail("Instantiation should have failed");
    } catch (IllegalStateException e) {
      // OK
    }

    props.setProperty("clustermap.cluster.name", "HelixParticipantTestCluster");
    props.setProperty("clustermap.dcs.zk.connect.strings", "");
    clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    try {
      new HelixClusterAgentsFactoryWithMockClusterMap(clusterMapConfig, new MetricRegistry()).getClusterParticipants();
      fail("Instantiation should have failed");
    } catch (IOException e) {
      // OK
    }
  }
Test bad instantiation and initialization scenarios of the {@link HelixParticipant}
ambry-clustermap/src/test/java/com/github/ambry/clustermap/HelixParticipantTest.java