@Test
 public void testNetworkConfig() {
   NetworkConfig networkConfig = config.getNetworkConfig();
   assertNotNull(networkConfig);
   assertEquals(5700, networkConfig.getPort());
   assertFalse(networkConfig.isPortAutoIncrement());
   final Collection<String> allowedPorts = networkConfig.getOutboundPortDefinitions();
   assertEquals(2, allowedPorts.size());
   Iterator portIter = allowedPorts.iterator();
   assertEquals("35000-35100", portIter.next());
   assertEquals("36000,36100", portIter.next());
   assertFalse(networkConfig.getJoin().getMulticastConfig().isEnabled());
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(), 8);
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeToLive(), 16);
   assertFalse(networkConfig.getInterfaces().isEnabled());
   assertEquals(1, networkConfig.getInterfaces().getInterfaces().size());
   assertEquals("10.10.1.*", networkConfig.getInterfaces().getInterfaces().iterator().next());
   TcpIpConfig tcp = networkConfig.getJoin().getTcpIpConfig();
   assertNotNull(tcp);
   assertTrue(tcp.isEnabled());
   assertTrue(networkConfig.getSymmetricEncryptionConfig().isEnabled());
   final List<String> members = tcp.getMembers();
   assertEquals(members.toString(), 2, members.size());
   assertEquals("127.0.0.1:5700", members.get(0));
   assertEquals("127.0.0.1:5701", members.get(1));
   assertEquals("127.0.0.1:5700", tcp.getRequiredMember());
   AwsConfig aws = networkConfig.getJoin().getAwsConfig();
   assertFalse(aws.isEnabled());
   assertEquals("sample-access-key", aws.getAccessKey());
   assertEquals("sample-secret-key", aws.getSecretKey());
   assertEquals("sample-region", aws.getRegion());
   assertEquals("sample-group", aws.getSecurityGroupName());
   assertEquals("sample-tag-key", aws.getTagKey());
   assertEquals("sample-tag-value", aws.getTagValue());
 }
  public void doJoin(AtomicBoolean joined) {
    int tryCount = 0;
    long joinStartTime = Clock.currentTimeMillis();
    long maxJoinMillis = node.getGroupProperties().MAX_JOIN_SECONDS.getInteger() * 1000;

    while (node.isActive()
        && !joined.get()
        && (Clock.currentTimeMillis() - joinStartTime < maxJoinMillis)) {
      String msg = "Joining to master node: " + node.getMasterAddress();
      logger.log(Level.FINEST, msg);
      systemLogService.logJoin(msg);

      final Address masterAddressNow;
      if (targetAddress == null) {
        masterAddressNow = findMasterWithMulticast();
      } else {
        // if target address is set explicitly, try to join target address first.
        masterAddressNow = targetAddress;
        targetAddress = null;
      }

      node.setMasterAddress(masterAddressNow);
      if (masterAddressNow != null) {
        systemLogService.logJoin("Setting master address to " + masterAddressNow);
      }
      if (node.getMasterAddress() == null || node.address.equals(node.getMasterAddress())) {
        TcpIpConfig tcpIpConfig = config.getNetworkConfig().getJoin().getTcpIpConfig();
        if (tcpIpConfig != null && tcpIpConfig.isEnabled()) {
          doTCP(joined);
        } else {
          node.setAsMaster();
        }
        return;
      }
      if (++tryCount > 49) {
        failedJoiningToMaster(true, tryCount);
      }
      if (!node.getMasterAddress().equals(node.address)) {
        connectAndSendJoinRequest(node.getMasterAddress());
      } else {
        node.setMasterAddress(null);
        tryCount = 0;
      }
      try {
        //noinspection BusyWait
        Thread.sleep(500L);
      } catch (InterruptedException ignored) {
      }
    }
  }