Exemple #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);
  }
Exemple #2
0
 @Test
 public void listCacheNamesTextList() throws Exception {
   RestResponse r = adminSession.get("/config/server/caches/?format=TEXT_LIST");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
   String result = new String(Base64.decode(r.getEntityContent()), UTF_8.name());
   List<String> list = Arrays.asList(result.split("\n"));
   assertThat(list).contains("accounts");
   assertThat(list).contains("projects");
   assertThat(Ordering.natural().isOrdered(list)).isTrue();
 }
Exemple #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();
 }
Exemple #4
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();
  }
Exemple #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();
 }
Exemple #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();
  }
Exemple #7
0
  @Test
  public void flushWebSessionsCache_Forbidden() throws Exception {
    allowGlobalCapabilities(
        REGISTERED_USERS, GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES);
    try {
      RestResponse r = userSession.post("/config/server/caches/accounts/flush");
      assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
      r.consume();

      r = userSession.post("/config/server/caches/web_sessions/flush");
      assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
    } finally {
      removeGlobalCapabilities(
          REGISTERED_USERS, GlobalCapability.VIEW_CACHES, GlobalCapability.FLUSH_CACHES);
    }
  }
Exemple #8
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);
  }
Exemple #9
0
 @Test
 public void listCaches_BadRequest() throws Exception {
   RestResponse r = adminSession.get("/config/server/caches/?format=NONSENSE");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
 }
Exemple #10
0
 @Test
 public void listCaches_Forbidden() throws Exception {
   RestResponse r = userSession.get("/config/server/caches/");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
 }
Exemple #11
0
 @Test
 public void getCacheWithGerritPrefix() throws Exception {
   RestResponse r = adminSession.get("/config/server/caches/gerrit-accounts");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
 }
Exemple #12
0
 @Test
 public void getCache_NotFound() throws Exception {
   RestResponse r = adminSession.get("/config/server/caches/nonExisting");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
 }
 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());
 }
Exemple #15
0
 @Test
 public void flushWebSessionsCache() throws Exception {
   RestResponse r = adminSession.post("/config/server/caches/web_sessions/flush");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
 }
Exemple #16
0
 @Test
 public void flushCache_Forbidden() throws Exception {
   RestResponse r = userSession.post("/config/server/caches/accounts/flush");
   assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
 }