Search in sources :

Example 1 with ChangeIndexedCounter

use of com.google.gerrit.acceptance.ChangeIndexedCounter in project gerrit by GerritCodeReview.

the class IndexChangesIT method indexNonVisibleChange.

@Test
public void indexNonVisibleChange() throws Exception {
    ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedCounter)) {
        String changeId = createChange().getChangeId();
        ChangeInfo changeInfo = info(changeId);
        projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/heads/master").group(REGISTERED_USERS)).update();
        IndexChanges.Input in = new IndexChanges.Input();
        changeIndexedCounter.clear();
        in.changes = ImmutableSet.of(changeId);
        adminRestSession.post("/config/server/index.changes", in).assertOK();
        assertThat(changeIndexedCounter.getCount(changeInfo)).isEqualTo(1);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) IndexChanges(com.google.gerrit.server.restapi.config.IndexChanges) ChangeIndexedCounter(com.google.gerrit.acceptance.ChangeIndexedCounter) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with ChangeIndexedCounter

use of com.google.gerrit.acceptance.ChangeIndexedCounter in project gerrit by GerritCodeReview.

the class IndexChangesIT method indexRequestFromNonAdminRejected.

@Test
public void indexRequestFromNonAdminRejected() throws Exception {
    ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedCounter)) {
        String changeId = createChange().getChangeId();
        IndexChanges.Input in = new IndexChanges.Input();
        in.changes = ImmutableSet.of(changeId);
        changeIndexedCounter.clear();
        userRestSession.post("/config/server/index.changes", in).assertForbidden();
        assertThat(changeIndexedCounter.getCount(info(changeId))).isEqualTo(0);
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) IndexChanges(com.google.gerrit.server.restapi.config.IndexChanges) ChangeIndexedCounter(com.google.gerrit.acceptance.ChangeIndexedCounter) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with ChangeIndexedCounter

use of com.google.gerrit.acceptance.ChangeIndexedCounter in project gerrit by GerritCodeReview.

the class AbstractIndexTests method indexChange.

@Test
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
public void indexChange() throws Exception {
    ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedCounter)) {
        PushOneCommit.Result change = createChange("first change", "test1.txt", "test1");
        String changeId = change.getChangeId();
        String changeLegacyId = change.getChange().getId().toString();
        ChangeInfo changeInfo = gApi.changes().id(changeId).get();
        disableChangeIndexWrites();
        amendChange(changeId, "second test", "test2.txt", "test2");
        assertChangeQuery(change.getChange(), false);
        enableChangeIndexWrites();
        changeIndexedCounter.clear();
        String cmd = Joiner.on(" ").join("gerrit", "index", "changes", changeLegacyId);
        adminSshSession.exec(cmd);
        adminSshSession.assertSuccess();
        changeIndexedCounter.assertReindexOf(changeInfo, 1);
        assertChangeQuery(change.getChange(), true);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeIndexedCounter(com.google.gerrit.acceptance.ChangeIndexedCounter) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with ChangeIndexedCounter

use of com.google.gerrit.acceptance.ChangeIndexedCounter in project gerrit by GerritCodeReview.

the class ChangeIT method starUnstar.

@Test
public void starUnstar() throws Exception {
    ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedCounter)) {
        PushOneCommit.Result r = createChange();
        String triplet = project.get() + "~master~" + r.getChangeId();
        changeIndexedCounter.clear();
        gApi.accounts().self().starChange(triplet);
        ChangeInfo change = info(triplet);
        assertThat(change.starred).isTrue();
        assertThat(change.stars).contains(DEFAULT_LABEL);
        changeIndexedCounter.assertReindexOf(change);
        gApi.accounts().self().unstarChange(triplet);
        change = info(triplet);
        assertThat(change.starred).isNull();
        assertThat(change.stars).isNull();
        changeIndexedCounter.assertReindexOf(change);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeIndexedCounter(com.google.gerrit.acceptance.ChangeIndexedCounter) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with ChangeIndexedCounter

use of com.google.gerrit.acceptance.ChangeIndexedCounter in project gerrit by GerritCodeReview.

the class IndexChangesIT method indexMultipleChanges.

@Test
public void indexMultipleChanges() throws Exception {
    ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedCounter)) {
        ImmutableSet.Builder<String> changeIds = ImmutableSet.builder();
        for (int i = 0; i < 10; i++) {
            changeIds.add(createChange().getChangeId());
        }
        IndexChanges.Input in = new IndexChanges.Input();
        in.changes = changeIds.build();
        changeIndexedCounter.clear();
        adminRestSession.post("/config/server/index.changes", in).assertOK();
        for (String changeId : in.changes) {
            assertThat(changeIndexedCounter.getCount(info(changeId))).isEqualTo(1);
        }
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) IndexChanges(com.google.gerrit.server.restapi.config.IndexChanges) ChangeIndexedCounter(com.google.gerrit.acceptance.ChangeIndexedCounter) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)7 ChangeIndexedCounter (com.google.gerrit.acceptance.ChangeIndexedCounter)7 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)7 Test (org.junit.Test)7 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)4 IndexChanges (com.google.gerrit.server.restapi.config.IndexChanges)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)2 ImmutableSet (com.google.common.collect.ImmutableSet)1