Program: 20650
Project: 20650
Buggy source:
@Test public void downloadMergedIndex() throws Exception {
  File tmpIndexDir=new File(System.getProperty("String_Node_Str") + "String_Node_Str");
  if (tmpIndexDir.exists()) {
    FileUtils.deleteDirectory(tmpIndexDir);
  }
  String id=Long.toString(System.currentTimeMillis());
  ManagedRepository managedRepository=new ManagedRepository();
  managedRepository.setId(id);
  managedRepository.setName("String_Node_Str" + id);
  managedRepository.setLocation(System.getProperty("String_Node_Str") + "String_Node_Str");
  managedRepository.setIndexDirectory(System.getProperty("String_Node_Str") + "String_Node_Str" + id);
  ManagedRepositoriesService managedRepositoriesService=getManagedRepositoriesService();
  if (managedRepositoriesService.getManagedRepository(id) != null) {
    managedRepositoriesService.deleteManagedRepository(id,false);
  }
  getManagedRepositoriesService().addManagedRepository(managedRepository);
  RepositoriesService repositoriesService=getRepositoriesService();
  repositoriesService.scanRepositoryNow(id,true);
  int timeout=20000;
  while (timeout > 0 && repositoriesService.alreadyScanning(id)) {
    Thread.sleep(500);
    timeout-=500;
  }
  RepositoryGroupService repositoryGroupService=getRepositoryGroupService();
  RepositoryGroup repositoryGroup=new RepositoryGroup();
  repositoryGroup.setId("String_Node_Str");
  repositoryGroup.setRepositories(Arrays.asList(id));
  repositoryGroupService.addRepositoryGroup(repositoryGroup);
  id=Long.toString(System.currentTimeMillis());
  managedRepository=new ManagedRepository();
  managedRepository.setId(id);
  managedRepository.setName("String_Node_Str" + id);
  managedRepository.setLocation(System.getProperty("String_Node_Str") + "String_Node_Str");
  managedRepository.setIndexDirectory(System.getProperty("String_Node_Str") + "String_Node_Str" + id);
  if (managedRepositoriesService.getManagedRepository(id) != null) {
    managedRepositoriesService.deleteManagedRepository(id,false);
  }
  getManagedRepositoriesService().addManagedRepository(managedRepository);
  RemoteRepository remoteRepository=new RemoteRepository();
  remoteRepository.setId("String_Node_Str");
  remoteRepository.setName("String_Node_Str");
  remoteRepository.setDownloadRemoteIndex(true);
  remoteRepository.setUrl("String_Node_Str" + port + "String_Node_Str");
  remoteRepository.setRemoteIndexUrl("String_Node_Str" + port + "String_Node_Str");
  remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
  remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
  getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
  ProxyConnectorService proxyConnectorService=getProxyConnectorService();
  ProxyConnector proxyConnector=new ProxyConnector();
  proxyConnector.setProxyId("String_Node_Str");
  proxyConnector.setSourceRepoId(id);
  proxyConnector.setTargetRepoId("String_Node_Str");
  proxyConnectorService.addProxyConnector(proxyConnector);
  repositoriesService.scheduleDownloadRemoteIndex("String_Node_Str",true,true);
  timeout=20000;
  while (timeout > 0) {
    Thread.sleep(500);
    timeout-=500;
  }
  SearchService searchService=getSearchService();
  SearchRequest request=new SearchRequest();
  request.setRepositories(Arrays.asList(id));
  request.setGroupId("String_Node_Str");
  List<Artifact> artifacts=searchService.searchArtifacts(request);
  Assertions.assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}

Fixed version (ground truth):
@Test public void downloadMergedIndex() throws Exception {
  File tmpIndexDir=new File(System.getProperty("String_Node_Str") + "String_Node_Str");
  if (tmpIndexDir.exists()) {
    FileUtils.deleteDirectory(tmpIndexDir);
  }
  String id=Long.toString(System.currentTimeMillis());
  ManagedRepository managedRepository=new ManagedRepository();
  managedRepository.setId(id);
  managedRepository.setName("String_Node_Str" + id);
  managedRepository.setLocation(System.getProperty("String_Node_Str") + "String_Node_Str");
  managedRepository.setIndexDirectory(System.getProperty("String_Node_Str") + "String_Node_Str" + id);
  ManagedRepositoriesService managedRepositoriesService=getManagedRepositoriesService();
  if (managedRepositoriesService.getManagedRepository(id) != null) {
    managedRepositoriesService.deleteManagedRepository(id,false);
  }
  getManagedRepositoriesService().addManagedRepository(managedRepository);
  RepositoriesService repositoriesService=getRepositoriesService();
  repositoriesService.scanRepositoryNow(id,true);
  int timeout=20000;
  while (timeout > 0 && repositoriesService.alreadyScanning(id)) {
    Thread.sleep(500);
    timeout-=500;
  }
  RepositoryGroupService repositoryGroupService=getRepositoryGroupService();
  String repoGroupId="String_Node_Str";
  if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
    repositoryGroupService.deleteRepositoryGroup(repoGroupId);
  }
  RepositoryGroup repositoryGroup=new RepositoryGroup();
  repositoryGroup.setId(repoGroupId);
  repositoryGroup.setRepositories(Arrays.asList(id));
  repositoryGroupService.addRepositoryGroup(repositoryGroup);
  id=Long.toString(System.currentTimeMillis());
  managedRepository=new ManagedRepository();
  managedRepository.setId(id);
  managedRepository.setName("String_Node_Str" + id);
  managedRepository.setLocation(System.getProperty("String_Node_Str") + "String_Node_Str");
  managedRepository.setIndexDirectory(System.getProperty("String_Node_Str") + "String_Node_Str" + id);
  if (managedRepositoriesService.getManagedRepository(id) != null) {
    managedRepositoriesService.deleteManagedRepository(id,false);
  }
  getManagedRepositoriesService().addManagedRepository(managedRepository);
  RemoteRepository remoteRepository=new RemoteRepository();
  remoteRepository.setId("String_Node_Str");
  remoteRepository.setName("String_Node_Str");
  remoteRepository.setDownloadRemoteIndex(true);
  remoteRepository.setUrl("String_Node_Str" + port + "String_Node_Str");
  remoteRepository.setRemoteIndexUrl("String_Node_Str" + port + "String_Node_Str");
  remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
  remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
  getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
  ProxyConnectorService proxyConnectorService=getProxyConnectorService();
  ProxyConnector proxyConnector=new ProxyConnector();
  proxyConnector.setProxyId("String_Node_Str");
  proxyConnector.setSourceRepoId(id);
  proxyConnector.setTargetRepoId("String_Node_Str");
  proxyConnectorService.addProxyConnector(proxyConnector);
  repositoriesService.scheduleDownloadRemoteIndex("String_Node_Str",true,true);
  timeout=20000;
  while (timeout > 0) {
    Thread.sleep(500);
    timeout-=500;
  }
  SearchService searchService=getSearchService();
  SearchRequest request=new SearchRequest();
  request.setRepositories(Arrays.asList(id));
  request.setGroupId("String_Node_Str");
  List<Artifact> artifacts=searchService.searchArtifacts(request);
  Assertions.assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}