Search in sources :

Example 1 with UseSystemTime

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

the class CreateChangeIT method sha1sOfTwoNewChangesDiffer.

@Test
@UseSystemTime
public void sha1sOfTwoNewChangesDiffer() throws Exception {
    ChangeInput changeInput = newChangeInput(ChangeStatus.NEW);
    ChangeInfo info1 = assertCreateSucceeds(changeInput);
    ChangeInfo info2 = assertCreateSucceeds(changeInput);
    assertThat(info1.currentRevision).isNotEqualTo(info2.currentRevision);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseSystemTime(com.google.gerrit.acceptance.UseSystemTime)

Example 2 with UseSystemTime

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

the class CreateChangeIT method sha1sOfTwoNewChangesDifferIfCreatedConcurrently.

@Test
@UseSystemTime
public void sha1sOfTwoNewChangesDifferIfCreatedConcurrently() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(2);
    try {
        for (int i = 0; i < 10; i++) {
            ChangeInput changeInput = newChangeInput(ChangeStatus.NEW);
            CyclicBarrier sync = new CyclicBarrier(2);
            Callable<ChangeInfo> createChange = () -> {
                requestScopeOperations.setApiUser(admin.id());
                sync.await();
                return assertCreateSucceeds(changeInput);
            };
            Future<ChangeInfo> changeInfo1 = executor.submit(createChange);
            Future<ChangeInfo> changeInfo2 = executor.submit(createChange);
            assertThat(changeInfo1.get().currentRevision).isNotEqualTo(changeInfo2.get().currentRevision);
        }
    } finally {
        executor.shutdown();
        executor.awaitTermination(5, TimeUnit.SECONDS);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ExecutorService(java.util.concurrent.ExecutorService) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) CyclicBarrier(java.util.concurrent.CyclicBarrier) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseSystemTime(com.google.gerrit.acceptance.UseSystemTime)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 UseSystemTime (com.google.gerrit.acceptance.UseSystemTime)2 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)2 ChangeInput (com.google.gerrit.extensions.common.ChangeInput)2 Test (org.junit.Test)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExecutorService (java.util.concurrent.ExecutorService)1