@Test
  public void testInitDNodeList() throws Throwable {
    SploutConfiguration config = SploutConfiguration.getTestConfig();
    QNodeHandler handler = new QNodeHandler();
    try {
      HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
      CoordinationStructures coord = new CoordinationStructures(hz);

      SploutConfiguration dNodeConfig = SploutConfiguration.getTestConfig();
      dNodeConfig.setProperty(DNodeProperties.PORT, 1000);

      coord.getDNodes().put("/localhost:1000", new DNodeInfo(dNodeConfig));

      dNodeConfig = SploutConfiguration.getTestConfig();
      dNodeConfig.setProperty(DNodeProperties.PORT, 1001);

      coord.getDNodes().put("/localhost:1001", new DNodeInfo(dNodeConfig));

      try {
        handler.init(config);
      } catch (Exception e) {
        // since the handler will try to connect to "localhost:1000" we skip the Exception and
        // continue
        // the things we want to assert should be present anyway.
      }
      Assert.assertEquals(
          handler.getContext().getCoordinationStructures().getDNodes().values().size(), 2);
    } finally {
      handler.close();
      Hazelcast.shutdownAll();
    }
  }
  @Test
  public void testInitVersionListAndVersionChange() throws Throwable {
    final QNodeHandler handler = new QNodeHandler();
    SploutConfiguration config = SploutConfiguration.getTestConfig();
    try {

      HazelcastInstance hz = Hazelcast.newHazelcastInstance(HazelcastConfigBuilder.build(config));
      CoordinationStructures coord = new CoordinationStructures(hz);

      handler.init(config);

      Map<String, Long> versionsBeingServed = new HashMap<String, Long>();
      versionsBeingServed.put("t1", 0l);
      coord
          .getVersionsBeingServed()
          .put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED, versionsBeingServed);

      versionsBeingServed.put("t2", 1l);
      coord
          .getVersionsBeingServed()
          .put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED, versionsBeingServed);

      new TestUtils.NotWaitingForeverCondition() {

        @Override
        public boolean endCondition() {
          return handler.getContext().getCurrentVersionsMap().get("t1") != null
              && handler.getContext().getCurrentVersionsMap().get("t1") == 0l
              && handler.getContext().getCurrentVersionsMap().get("t2") != null
              && handler.getContext().getCurrentVersionsMap().get("t2") == 1l;
        }
      }.waitAtMost(5000);

      versionsBeingServed.put("t2", 0l);
      versionsBeingServed.put("t1", 1l);
      coord
          .getVersionsBeingServed()
          .put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED, versionsBeingServed);

      new TestUtils.NotWaitingForeverCondition() {

        @Override
        public boolean endCondition() {
          return handler.getContext().getCurrentVersionsMap().get("t1") != null
              && handler.getContext().getCurrentVersionsMap().get("t1") == 1l
              && handler.getContext().getCurrentVersionsMap().get("t2") != null
              && handler.getContext().getCurrentVersionsMap().get("t2") == 0l;
        }
      }.waitAtMost(5000);

      versionsBeingServed.put("t2", 1l);
      versionsBeingServed.put("t1", 0l);
      coord
          .getVersionsBeingServed()
          .put(CoordinationStructures.KEY_FOR_VERSIONS_BEING_SERVED, versionsBeingServed);

      Thread.sleep(100);

      Assert.assertEquals(0l, (long) handler.getContext().getCurrentVersionsMap().get("t1"));
      Assert.assertEquals(1l, (long) handler.getContext().getCurrentVersionsMap().get("t2"));
    } finally {
      handler.close();
      Hazelcast.shutdownAll();
    }
  }