示例#1
0
  /**
   * Persists {@code this} test report to the given {@link
   * com.google.appengine.api.datastore.DatastoreService} and invalidate the cache.
   *
   * @param reports the reports entry point
   */
  public void save(Reports reports) {
    final Entity entity = new Entity(TEST_REPORT, buildTypeId + buildId);
    entity.setProperty("buildTypeId", buildTypeId);
    entity.setProperty("buildId", buildId);
    entity.setProperty("buildDate", buildDate);
    entity.setProperty("buildDuration", buildDuration);
    entity.setProperty("numberOfPassedTests", numberOfPassedTests);
    entity.setProperty("numberOfIgnoredTests", numberOfIgnoredTests);
    entity.setProperty("numberOfFailedTests", numberOfFailedTests);

    final JSONArray jsonArrayFailedTests = new JSONArray();
    for (Test oneFailingTest : failedTests) {
      jsonArrayFailedTests.put(oneFailingTest.asJson());
    }
    entity.setProperty("failedTests", new Text(jsonArrayFailedTests.toString()));

    final JSONArray jsonArrayIgnoredTests = new JSONArray();
    for (Test oneIgnoredTest : ignoredTests) {
      jsonArrayIgnoredTests.put(oneIgnoredTest.asJson());
    }
    entity.setProperty("ignoredTests", new Text(jsonArrayIgnoredTests.toString()));

    final DatastoreService datastoreService = reports.getDatastoreService();
    datastoreService.put(entity);

    final MemcacheService memcacheService = reports.getMemcacheService();
    memcacheService.delete(buildTypeId); // invalidate cache
  }
示例#2
0
  /**
   * Finds the {@code TestReport} with the given build type id ordered by build id in the descendant
   * order.
   *
   * @param buildTypeId the build type id.
   * @param limit the optional fetch limit, by default {@link
   *     com.google.appengine.tck.site.endpoints.TestReport#DEFAULT_FETCH_LIMIT}.
   * @param reports the reports entry point
   * @return the matching test reports list or an empty one if none.
   */
  @SuppressWarnings("unchecked")
  public static List<TestReport> findByBuildTypeIdOrderByBuildIdDesc(
      String buildTypeId, Optional<Integer> limit, Reports reports) {
    final MemcacheService memcacheService = reports.getMemcacheService();
    List<TestReport> results = (List<TestReport>) memcacheService.get(buildTypeId);
    if (results == null) {
      final Filter buildTypeFilter =
          new Query.FilterPredicate("buildTypeId", FilterOperator.EQUAL, buildTypeId);
      final Query query =
          new Query(TEST_REPORT).setFilter(buildTypeFilter).addSort("buildId", DESCENDING);

      final DatastoreService datastoreService = reports.getDatastoreService();
      final PreparedQuery preparedQuery = datastoreService.prepare(query);
      final List<Entity> entities =
          preparedQuery.asList(FetchOptions.Builder.withLimit(limit.or(DEFAULT_FETCH_LIMIT)));

      results = new ArrayList<>();
      for (Entity oneEntity : entities) {
        final TestReport report = from(oneEntity);
        results.add(report);
      }

      memcacheService.put(buildTypeId, results);
    }
    return results;
  }