test_class.declarator: multipleClientReportDownloader
test_class.modifier: private
test_class.original_string: private MultipleClientReportDownloader multipleClientReportDownloader;
test_class.type: MultipleClientReportDownloader
test_class.var_name: multipleClientReportDownloader
test_class.declarator: reportDefinition
test_class.modifier: private
test_class.original_string: private ReportDefinition reportDefinition;
test_class.type: ReportDefinition
test_class.var_name: reportDefinition
test_class.file: aw-reporting/src/test/java/com/google/api/ads/adwords/awreporting/downloader/MultipleClientReportDownloaderTest.java
test_class.identifier: MultipleClientReportDownloaderTest
test_case.body: @Test
    public void testDownloadReports() throws ReportProcessingException {
  
      AdWordsSession.Builder sessionBuilder =
        new AdWordsSession.Builder().withEndpoint("http://www.google.com")
          .withDeveloperToken("DeveloperToken")
          .withClientCustomerId("123")
          .withUserAgent("UserAgent")
          .withOAuth2Credential(new GoogleCredential.Builder().build());
  
      Set<Long> cids = ImmutableSet.of(1L, 2L, 3L, 4L, 5L);
      Collection<File> results =
          multipleClientReportDownloader.downloadReports(sessionBuilder, reportDefinition, cids);
  
      assertEquals(cids.size(), results.size());
    }
test_case.class_method_signature: MultipleClientReportDownloaderTest.testDownloadReports()
test_case.full_signature: @Test public void testDownloadReports()
test_case.identifier: testDownloadReports
test_case.invocations: withOAuth2Credential withUserAgent withClientCustomerId withDeveloperToken withEndpoint build of downloadReports assertEquals size size
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testDownloadReports()
focal_class.declarator: logger =
        LoggerFactory.getLogger(MultipleClientReportDownloader.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger =
        LoggerFactory.getLogger(MultipleClientReportDownloader.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: SEPARATOR = System.getProperty("line.separator")
focal_class.modifier: private static final
focal_class.original_string: private static final String SEPARATOR = System.getProperty("line.separator");
focal_class.type: String
focal_class.var_name: SEPARATOR
focal_class.declarator: numThreads
focal_class.modifier: private final
focal_class.original_string: private final int numThreads;
focal_class.type: int
focal_class.var_name: numThreads
focal_class.file: aw-reporting/src/main/java/com/google/api/ads/adwords/awreporting/downloader/MultipleClientReportDownloader.java
focal_class.identifier: MultipleClientReportDownloader
focal_class.class_method_signature: MultipleClientReportDownloader.MultipleClientReportDownloader(int numThreads)
focal_class.full_signature: public  MultipleClientReportDownloader(int numThreads)
focal_class.identifier: MultipleClientReportDownloader
focal_class.modifiers: public
focal_class.parameters: (int numThreads)
focal_class.signature:  MultipleClientReportDownloader(int numThreads)
focal_class.class_method_signature: MultipleClientReportDownloader.downloadReports(
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)
focal_class.full_signature: public Collection<File> downloadReports(
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)
focal_class.identifier: downloadReports
focal_class.modifiers: public
focal_class.parameters: (
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)
focal_class.return: Collection<File>
focal_class.signature: Collection<File> downloadReports(
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)
focal_class.class_method_signature: MultipleClientReportDownloader.genCallableReportDownloader(
        ImmutableAdWordsSession session, ReportDefinition reportDefinition)
focal_class.full_signature: protected CallableReportDownloader genCallableReportDownloader(
        ImmutableAdWordsSession session, ReportDefinition reportDefinition)
focal_class.identifier: genCallableReportDownloader
focal_class.modifiers: protected
focal_class.parameters: (
        ImmutableAdWordsSession session, ReportDefinition reportDefinition)
focal_class.return: CallableReportDownloader
focal_class.signature: CallableReportDownloader genCallableReportDownloader(
        ImmutableAdWordsSession session, ReportDefinition reportDefinition)
focal_method.body: public Collection<File> downloadReports(
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)
        throws ReportProcessingException {
      ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
      Stopwatch stopwatch = Stopwatch.createStarted();
      logger.info("Downloading {" + reportDefinition.getReportType() + "} reports...");
  
      List<Long> taskIds = Lists.newArrayList();
      List<CallableReportDownloader> taskJobs = Lists.newArrayList();
      Map<Long, String> failures = Maps.newHashMap();
      ImmutableAdWordsSession session = null;
      for (Long clientCustomerId : clientCustomerIds) {
        try {
          session = AdWordsSessionUtil.buildImmutableSessionForCid(sessionBuilder, clientCustomerId);
        } catch (ValidationException e) {
          logger.error("Failed to create valid adwords session for CID " + clientCustomerId
              + ", skipping it.");
          failures.put(clientCustomerId, e.getMessage());
          continue;
        }
  
        taskIds.add(clientCustomerId);
        taskJobs.add(genCallableReportDownloader(session, reportDefinition));
      }
  
      List<Future<File>> taskResults;
      try {
        //Note that invokeAll() returns results in the same sequence as input tasks.
        taskResults = executorService.invokeAll(taskJobs);
      } catch (InterruptedException e) {
        throw new ReportProcessingException(
          "MultipleClientReportDownloader encounters InterruptedException.", e);
      }
  
      List<File> results = Lists.newArrayList();
      for (int i = 0; i < taskResults.size(); i++) {
        try {
          results.add(taskResults.get(i).get());
        } catch (ExecutionException e) {
          failures.put(taskIds.get(i), e.getMessage());
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          throw new ReportProcessingException(
              "MultiClientReportDownloader encounters InterruptedException.", e);
        }
      }
  
      executorService.shutdown();
      stopwatch.stop();
  
      logger.info("Downloaded reports for " + clientCustomerIds.size() + " accounts in "
          + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds.");
      logger.info("Result: " +  results.size() + " successes, " + failures.size() + " failures.");
      if (!failures.isEmpty()) {
        StringBuilder sb = new StringBuilder("*** Account IDs of download failures ***");
        sb.append(SEPARATOR);
        sb.append(Joiner.on(SEPARATOR).withKeyValueSeparator(": ").join(failures));
        logger.error(sb.toString());
      }
  
      return results;
    }
focal_method.class_method_signature: MultipleClientReportDownloader.downloadReports(
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)
focal_method.full_signature: public Collection<File> downloadReports(
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)
focal_method.identifier: downloadReports
focal_method.invocations: newFixedThreadPool createStarted info getReportType newArrayList newArrayList newHashMap buildImmutableSessionForCid error put getMessage add add genCallableReportDownloader invokeAll newArrayList size add get get put get getMessage interrupt currentThread shutdown stop info size elapsed info size size isEmpty append append join withKeyValueSeparator on error toString
focal_method.modifiers: public
focal_method.parameters: (
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)
focal_method.return: Collection<File>
focal_method.signature: Collection<File> downloadReports(
        AdWordsSession.Builder sessionBuilder,
        ReportDefinition reportDefinition,
        Set<Long> clientCustomerIds)