Search in sources :

Example 11 with Change

use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method rebuilderRespectsReadOnlyInNoteDbChangeState.

@Test
public void rebuilderRespectsReadOnlyInNoteDbChangeState() throws Exception {
    TestTimeUtil.resetWithClockStep(1, SECONDS);
    PushOneCommit.Result r = createChange();
    PatchSet.Id psId1 = r.getPatchSetId();
    Change.Id id = psId1.getParentKey();
    checker.rebuildAndCheckChanges(id);
    setNotesMigration(true, true);
    ReviewDb db = getUnwrappedDb();
    Change c = db.changes().get(id);
    NoteDbChangeState state = NoteDbChangeState.parse(c);
    Timestamp until = new Timestamp(TimeUtil.nowMs() + MILLISECONDS.convert(1, DAYS));
    state = state.withReadOnlyUntil(until);
    c.setNoteDbState(state.toString());
    db.changes().update(Collections.singleton(c));
    try {
        rebuilderWrapper.rebuild(db, id);
        assert_().fail("expected rebuild to fail");
    } catch (OrmRuntimeException e) {
        assertThat(e.getMessage()).contains("read-only until");
    }
    TestTimeUtil.setClock(new Timestamp(until.getTime() + MILLISECONDS.convert(1, SECONDS)));
    rebuilderWrapper.rebuild(db, id);
}
Also used : OrmRuntimeException(com.google.gwtorm.server.OrmRuntimeException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) NoteDbChangeState(com.google.gerrit.server.notedb.NoteDbChangeState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with Change

use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.

the class NoteDbPrimaryIT method migrateToNoteDbFailsRebuildingOnceAndRetries.

@Test
public void migrateToNoteDbFailsRebuildingOnceAndRetries() throws Exception {
    Change.Id id = createChange().getChange().getId();
    Change c = db.changes().get(id);
    c.setNoteDbState("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
    db.changes().update(Collections.singleton(c));
    rebuilderWrapper.failNextUpdate();
    migrator = newMigrator(RetryerBuilder.<NoteDbChangeState>newBuilder().retryIfException().withStopStrategy(StopStrategies.neverStop()).build());
    migrator.migrateToNoteDbPrimary(id);
    assertNoteDbPrimary(id);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with Change

use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.

the class NoteDbPrimaryIT method migrateToNoteDbWithRebuildingFirst.

@Test
public void migrateToNoteDbWithRebuildingFirst() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getChange().getId();
    Change c = db.changes().get(id);
    c.setNoteDbState("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
    db.changes().update(Collections.singleton(c));
    testMigrateToNoteDb(id);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with Change

use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.

the class NoteDbPrimaryIT method migrateToNoteDbMissingOldState.

@Test
public void migrateToNoteDbMissingOldState() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getChange().getId();
    Change c = db.changes().get(id);
    c.setNoteDbState(null);
    db.changes().update(Collections.singleton(c));
    exception.expect(OrmRuntimeException.class);
    exception.expectMessage("no note_db_state");
    migrator.migrateToNoteDbPrimary(id);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with Change

use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.

the class NoteDbPrimaryIT method migrateToNoteDbAlreadyReadOnly.

@Test
public void migrateToNoteDbAlreadyReadOnly() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getChange().getId();
    Change c = db.changes().get(id);
    NoteDbChangeState state = NoteDbChangeState.parse(c);
    Timestamp until = new Timestamp(TimeUtil.nowMs() + MILLISECONDS.convert(1, DAYS));
    state = state.withReadOnlyUntil(until);
    c.setNoteDbState(state.toString());
    db.changes().update(Collections.singleton(c));
    exception.expect(OrmRuntimeException.class);
    exception.expectMessage("read-only until " + until);
    migrator.migrateToNoteDbPrimary(id);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) NoteDbChangeState(com.google.gerrit.server.notedb.NoteDbChangeState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Change (com.google.gerrit.reviewdb.client.Change)191 Test (org.junit.Test)96 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)53 ObjectId (org.eclipse.jgit.lib.ObjectId)32 Timestamp (java.sql.Timestamp)31 Account (com.google.gerrit.reviewdb.client.Account)30 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 OrmException (com.google.gwtorm.server.OrmException)28 Project (com.google.gerrit.reviewdb.client.Project)27 Repository (org.eclipse.jgit.lib.Repository)27 RevWalk (org.eclipse.jgit.revwalk.RevWalk)24 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)23 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)22 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)21 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)17 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)17 ChangeData (com.google.gerrit.server.query.change.ChangeData)16 RevId (com.google.gerrit.reviewdb.client.RevId)15