示例#1
0
  @Test
  public void listCaches() throws Exception {
    RestResponse r = adminSession.get("/config/server/caches/");
    assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
    Map<String, CacheInfo> result =
        newGson().fromJson(r.getReader(), new TypeToken<Map<String, CacheInfo>>() {}.getType());

    assertThat(result).containsKey("accounts");
    CacheInfo accountsCacheInfo = result.get("accounts");
    assertThat(accountsCacheInfo.type).isEqualTo(CacheType.MEM);
    assertThat(accountsCacheInfo.entries.mem).isAtLeast(1L);
    assertThat(accountsCacheInfo.averageGet).isNotNull();
    assertThat(accountsCacheInfo.averageGet).endsWith("s");
    assertThat(accountsCacheInfo.entries.disk).isNull();
    assertThat(accountsCacheInfo.entries.space).isNull();
    assertThat(accountsCacheInfo.hitRatio.mem).isAtLeast(0);
    assertThat(accountsCacheInfo.hitRatio.mem).isAtMost(100);
    assertThat(accountsCacheInfo.hitRatio.disk).isNull();

    userSession.get("/config/server/version").consume();
    r = adminSession.get("/config/server/caches/");
    assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
    result =
        newGson().fromJson(r.getReader(), new TypeToken<Map<String, CacheInfo>>() {}.getType());
    assertThat(result.get("accounts").entries.mem).isEqualTo(2);
  }
示例#2
0
  @Test
  public void flushCache() throws Exception {
    RestResponse r = adminSession.get("/config/server/caches/groups");
    CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(result.entries.mem).isGreaterThan((long) 0);

    r = adminSession.post("/config/server/caches/groups/flush");
    assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
    r.consume();

    r = adminSession.get("/config/server/caches/groups");
    result = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(result.entries.mem).isNull();
  }
示例#3
0
 @Test
 public void listCacheNames() throws Exception {
   RestResponse r = adminSession.get("/config/server/caches/?format=LIST");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
   List<String> result =
       newGson().fromJson(r.getReader(), new TypeToken<List<String>>() {}.getType());
   assertThat(result).contains("accounts");
   assertThat(result).contains("projects");
   assertThat(Ordering.natural().isOrdered(result)).isTrue();
 }
示例#4
0
  @Test
  public void getCache() throws Exception {
    RestResponse r = adminSession.get("/config/server/caches/accounts");
    assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
    CacheInfo result = newGson().fromJson(r.getReader(), CacheInfo.class);

    assertThat(result.name).isEqualTo("accounts");
    assertThat(result.type).isEqualTo(CacheType.MEM);
    assertThat(result.entries.mem).isAtLeast(1L);
    assertThat(result.averageGet).isNotNull();
    assertThat(result.averageGet).endsWith("s");
    assertThat(result.entries.disk).isNull();
    assertThat(result.entries.space).isNull();
    assertThat(result.hitRatio.mem).isAtLeast(0);
    assertThat(result.hitRatio.mem).isAtMost(100);
    assertThat(result.hitRatio.disk).isNull();

    userSession.get("/config/server/version").consume();
    r = adminSession.get("/config/server/caches/accounts");
    assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
    result = newGson().fromJson(r.getReader(), CacheInfo.class);
    assertThat(result.entries.mem).isEqualTo(2);
  }
示例#5
0
 private void checkMergeResult(ChangeInfo change) throws IOException {
   // Get the revision of the branch after the submit to compare with the
   // newRev of the ChangeMergedEvent.
   RestResponse b = adminSession.get("/projects/" + change.project + "/branches/" + change.branch);
   if (b.getStatusCode() == HttpStatus.SC_OK) {
     BranchInfo branch =
         newGson().fromJson(b.getReader(), new TypeToken<BranchInfo>() {}.getType());
     assertThat(mergeResults).isNotEmpty();
     String newRev = mergeResults.get(Integer.toString(change._number));
     assertThat(newRev).isNotNull();
     assertThat(branch.revision).isEqualTo(newRev);
   }
   b.consume();
 }
示例#6
0
  private void submit(String changeId, int expectedStatus) throws Exception {
    approve(changeId);
    SubmitInput subm = new SubmitInput();
    RestResponse r = adminSession.post("/changes/" + changeId + "/submit", subm);
    assertThat(r.getStatusCode()).isEqualTo(expectedStatus);
    if (expectedStatus == HttpStatus.SC_OK) {
      ChangeInfo change =
          newGson().fromJson(r.getReader(), new TypeToken<ChangeInfo>() {}.getType());
      assertThat(change.status).isEqualTo(ChangeStatus.MERGED);

      checkMergeResult(change);
    }
    r.consume();
  }
 private AccountInfo GET_ONE(String endpoint) throws IOException {
   RestResponse r = adminSession.get(endpoint);
   assertEquals(HttpStatus.SC_OK, r.getStatusCode());
   return newGson().fromJson(r.getReader(), AccountInfo.class);
 }
 private List<AccountInfo> GET(String endpoint) throws IOException {
   RestResponse r = adminSession.get(endpoint);
   assertEquals(HttpStatus.SC_OK, r.getStatusCode());
   return newGson().fromJson(r.getReader(), new TypeToken<List<AccountInfo>>() {}.getType());
 }