protected ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(
      ServerLocator locator, int topologyMembers) throws Exception {
    CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);

    locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));

    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory();
    addSessionFactory(sf);

    Assert.assertTrue(
        "topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));
    return sf;
  }