protected short sampleStoreTopicReplicationFactor(Map<String, ?> config, AdminClient adminClient) {
    if (_sampleStoreTopicReplicationFactor != null) {
      return _sampleStoreTopicReplicationFactor;
    }

    int maxRetryCount = Integer.parseInt(config.get(MonitorConfig.FETCH_METRIC_SAMPLES_MAX_RETRY_COUNT_CONFIG).toString());
    AtomicInteger numberOfBrokersInCluster = new AtomicInteger(0);
    AtomicReference<String> errorMsg = new AtomicReference<>("");

    boolean success = CruiseControlMetricsUtils.retry(() -> {
      try {
        numberOfBrokersInCluster.set(adminClient.describeCluster().nodes().get(CLIENT_REQUEST_TIMEOUT_MS,
                TimeUnit.MILLISECONDS).size());
      } catch (InterruptedException | ExecutionException | TimeoutException e) {
        errorMsg.set("Auto creation of sample store topics failed due to failure to describe cluster. " + e);
        return true;
      }

      if (numberOfBrokersInCluster.get() <= 1) {
        errorMsg.set(String.format("Kafka cluster has less than 2 brokers (brokers in cluster=%d)",
                numberOfBrokersInCluster.get()));
        return true;
      }

      numberOfBrokersInCluster.set(Math.min(DEFAULT_SAMPLE_STORE_TOPIC_REPLICATION_FACTOR, numberOfBrokersInCluster.get()));
      return false;
    }, maxRetryCount);

    if (success) {
      return (short) numberOfBrokersInCluster.get();
    } else {
      throw new IllegalStateException(errorMsg.get());
    }
  }
@Test
    public void testSampleStoreTopicReplicationFactorWhenValueNotExistsAndNodeCountIsTwo() throws Exception {
        short expected = 2;
        Map<String, Object> config = createFilledConfigMap();
        AdminClient adminClient = EasyMock.mock(AdminClient.class);
        prepareForNumberOfBrokersCall(adminClient, true);
        AbstractKafkaSampleStore kafkaSampleStore = EasyMock.partialMockBuilder(AbstractKafkaSampleStore.class).createMock();
        EasyMock.replay(adminClient, kafkaSampleStore);

        short actual = kafkaSampleStore.sampleStoreTopicReplicationFactor(config, adminClient);

        assertEquals(expected, actual);
        EasyMock.verify(adminClient, kafkaSampleStore);
    }