Search in sources :

Example 6 with StageHistoryEntry

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.

the class StageServiceIntegrationTest method shouldReturnLatestPipelineHistory.

@Test
public void shouldReturnLatestPipelineHistory() {
    StageHistoryEntry[] stages = createFiveStages();
    StageInstanceModels history = stageService.findStageHistoryViaCursor(new Username(new CaseInsensitiveString("admin1")), savedPipeline.getName(), savedPipeline.getFirstStage().getName(), 0, 0, 10);
    assertThat(history.size(), is(5));
    assertThat(history.get(0).getId(), is(stages[4].getId()));
    assertThat(history.get(4).getId(), is(stages[0].getId()));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Example 7 with StageHistoryEntry

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.

the class StageServiceIntegrationTest method shouldGetStageHistoryForLastPage.

@Test
public void shouldGetStageHistoryForLastPage() {
    StageHistoryEntry[] stages = createFiveStages();
    StageHistoryPage history = stageService.findStageHistoryPage(stageService.stageById(stages[0].getId()), 3);
    assertThat("Found " + history, history.getStages().get(0), is(stages[1]));
    assertThat("Found " + history, history.getStages().get(1), is(stages[0]));
    assertThat("Found " + history, history.getPagination(), is(Pagination.pageStartingAt(3, 5, 3)));
    assertThat("Found " + history, history.getPagination().getCurrentPage(), is(2));
}
Also used : StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Example 8 with StageHistoryEntry

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.

the class StageSqlMapDao method findStageHistoryPage.

public StageHistoryPage findStageHistoryPage(String pipelineName, String stageName, FuncVarArg<Pagination, Object> function) {
    // IMPORTANT: wire cache clearing on job-state-change for me, the day StageHistoryEntry gets jobs - Sachin & JJ
    String mutex = mutexForStageHistory(pipelineName, stageName);
    readWriteLock.acquireReadLock(mutex);
    try {
        Pagination pagination = function.call();
        String subKey = String.format("%s-%s", pagination.getCurrentPage(), pagination.getPageSize());
        String key = cacheKeyForStageHistories(pipelineName, stageName);
        StageHistoryPage stageHistoryPage = (StageHistoryPage) goCache.get(key, subKey);
        if (stageHistoryPage == null) {
            List<StageHistoryEntry> stageHistoryEntries = findStages(pagination, pipelineName, stageName);
            stageHistoryPage = new StageHistoryPage(stageHistoryEntries, pagination, findImmediateChronologicallyForwardStageHistoryEntry(stageHistoryEntries.get(0)));
            goCache.put(key, subKey, stageHistoryPage);
        }
        return cloner.deepClone(stageHistoryPage);
    } finally {
        readWriteLock.releaseReadLock(mutex);
    }
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)

Example 9 with StageHistoryEntry

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.

the class StageSqlMapDaoTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry.

@Test
void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry() {
    StageIdentifier stageIdentifier = mock(StageIdentifier.class);
    String pipelineName = "some_pipeline_name";
    String stageName = "stage_name";
    long pipelineId = 41l;
    when(stageIdentifier.getPipelineName()).thenReturn(pipelineName);
    when(stageIdentifier.getStageName()).thenReturn(stageName);
    StageHistoryEntry topOfThisPage = mock(StageHistoryEntry.class);
    StageHistoryEntry bottomOfPreviousPage = mock(StageHistoryEntry.class);
    when(topOfThisPage.getId()).thenReturn(pipelineId);
    when(topOfThisPage.getIdentifier()).thenReturn(stageIdentifier);
    HashMap args = new HashMap();
    args.put("pipelineName", pipelineName);
    args.put("stageName", stageName);
    args.put("id", pipelineId);
    args.put("limit", 1);
    when(sqlMapClientTemplate.queryForObject("findStageHistoryEntryBefore", args)).thenReturn(bottomOfPreviousPage);
    StageHistoryEntry actual = stageSqlMapDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfThisPage);
    assertThat(actual, is(bottomOfPreviousPage));
    verify(stageIdentifier).getPipelineName();
    verify(stageIdentifier).getStageName();
    verify(topOfThisPage).getId();
    verify(topOfThisPage).getIdentifier();
    verify(sqlMapClientTemplate).queryForObject("findStageHistoryEntryBefore", args);
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) HashMap(java.util.HashMap) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Example 10 with StageHistoryEntry

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.

the class StageSqlMapDao method findStageHistoryPage.

public StageHistoryPage findStageHistoryPage(String pipelineName, String stageName, Supplier<com.thoughtworks.go.server.util.Pagination> function) {
    // IMPORTANT: wire cache clearing on job-state-change for me, the day StageHistoryEntry gets jobs - Sachin & JJ
    String mutex = mutexForStageHistory(pipelineName, stageName);
    readWriteLock.acquireReadLock(mutex);
    try {
        Pagination pagination = function.get();
        String subKey = format("%s-%s", pagination.getCurrentPage(), pagination.getPageSize());
        String key = cacheKeyForStageHistories(pipelineName, stageName);
        StageHistoryPage stageHistoryPage = (StageHistoryPage) goCache.get(key, subKey);
        if (stageHistoryPage == null) {
            List<StageHistoryEntry> stageHistoryEntries = findStages(pagination, pipelineName, stageName);
            stageHistoryPage = new StageHistoryPage(stageHistoryEntries, pagination, findImmediateChronologicallyForwardStageHistoryEntry(stageHistoryEntries.get(0)));
            goCache.put(key, subKey, stageHistoryPage);
        }
        return cloner.deepClone(stageHistoryPage);
    } finally {
        readWriteLock.releaseReadLock(mutex);
    }
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)

Aggregations

StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)17 Test (org.junit.jupiter.api.Test)14 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)11 Pagination (com.thoughtworks.go.server.util.Pagination)6 Username (com.thoughtworks.go.server.domain.Username)4 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)3 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)3 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 SqlMapClientTemplate (com.thoughtworks.go.server.transaction.SqlMapClientTemplate)2 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 HashMap (java.util.HashMap)1 Supplier (java.util.function.Supplier)1