### Question:
ClusterBootstrapper { public void bootstrapNewNodes(Long stackId, Set<String> upscaleCandidateAddresses, Collection<String> recoveryHostNames) throws CloudbreakException { Stack stack = stackService.getByIdWithListsInTransaction(stackId); Set<Node> nodes = new HashSet<>(); Set<Node> allNodes = new HashSet<>(); boolean recoveredNodes = Integer.valueOf(recoveryHostNames.size()).equals(upscaleCandidateAddresses.size()); Set<InstanceMetaData> metaDataSet = stack.getReachableInstanceMetaDataSet() .stream() .filter(im -> im.getPrivateIp() != null && im.getPublicIpWrapper() != null) .collect(Collectors.toSet()); String clusterDomain = getClusterDomain(metaDataSet, stack.getCustomDomain()); Map<String, AtomicLong> hostGroupNodeIndexes = new HashMap<>(); Set<String> clusterNodeNames = stack.getNotTerminatedInstanceMetaDataList().stream() .map(InstanceMetaData::getShortHostname).collect(Collectors.toSet()); Iterator<String> iterator = recoveryHostNames.iterator(); for (InstanceMetaData im : metaDataSet) { Node node = createNode(stack, im, clusterDomain, hostGroupNodeIndexes, clusterNodeNames); if (upscaleCandidateAddresses.contains(im.getPrivateIp())) { if (recoveredNodes && isNoneBlank(node.getHostname())) { node.setHostname(iterator.next().split("\\.")[0]); LOGGER.debug("Set the hostname to {} for address: {}", node.getHostname(), im.getPrivateIp()); } nodes.add(node); } allNodes.add(node); } try { List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack); bootstrapNewNodesOnHost(stack, allGatewayConfigs, nodes, allNodes); } catch (CloudbreakOrchestratorCancelledException e) { throw new CancellationException(e.getMessage()); } catch (CloudbreakOrchestratorException e) { throw new CloudbreakException(e); } }  void bootstrapMachines(Long stackId); void reBootstrapMachines(Long stackId); @SuppressFBWarnings("REC_CATCH_EXCEPTION") void bootstrapOnHost(Stack stack); void reBootstrapOnHost(Stack stack); ClusterComponent updateSaltComponent(Stack stack); void bootstrapNewNodes(Long stackId, Set<String> upscaleCandidateAddresses, Collection<String> recoveryHostNames);  }### Answer:
@Test public void shouldUseReachableInstances() throws CloudbreakException, CloudbreakImageNotFoundException { when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack); InstanceMetaData instanceMetaData = new InstanceMetaData(); instanceMetaData.setPrivateIp("1.1.1.1"); instanceMetaData.setPublicIp("2.2.2.2"); instanceMetaData.setDiscoveryFQDN("FQDN"); InstanceGroup instanceGroup = new InstanceGroup(); instanceGroup.setGroupName("master"); Template template = new Template(); template.setInstanceType("GATEWAY"); instanceGroup.setTemplate(template); instanceMetaData.setInstanceGroup(instanceGroup); when(stack.getId()).thenReturn(1L); when(stack.getReachableInstanceMetaDataSet()).thenReturn(Set.of(instanceMetaData)); when(stack.getCustomDomain()).thenReturn("CUSTOM_DOMAIN"); Cluster cluster = new Cluster(); cluster.setGateway(new Gateway()); when(stack.getCluster()).thenReturn(cluster); when(gatewayConfigService.getAllGatewayConfigs(any())).thenReturn(List.of(gatewayConfig)); when(componentConfigProviderService.getImage(anyLong())).thenReturn(image); underTest.bootstrapNewNodes(1L, Set.of("1.1.1.1"), List.of("host1")); verify(stack).getReachableInstanceMetaDataSet(); verify(gatewayConfigService).getAllGatewayConfigs(stack); verify(componentConfigProviderService).getImage(1L); }