use of com.thoughtworks.go.domain.materials.git.GitMaterialInstance in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldCachePipelineInstancesTriggeredOutOfMaterialRevision.
@Test
public void shouldCachePipelineInstancesTriggeredOutOfMaterialRevision() throws Exception {
GitMaterialInstance materialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight");
List<PipelineIdentifier> results = Arrays.asList(new PipelineIdentifier("p1", 1));
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance.getFingerprint(), "r1");
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), anyString())).thenReturn(results);
assertThat(goCache.get(cacheKey), is(Matchers.nullValue()));
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance, "r1");
// Query second time should return from cache
pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1".toUpperCase(), materialInstance, "r1");
assertThat(goCache.get(cacheKey), is(actual));
verify(mockTemplate, times(1)).queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), anyString());
}
use of com.thoughtworks.go.domain.materials.git.GitMaterialInstance in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldCacheEmptyPipelineInstancesTriggeredOutOfMaterialRevision.
@Test
public void shouldCacheEmptyPipelineInstancesTriggeredOutOfMaterialRevision() throws Exception {
GitMaterialInstance materialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight");
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance.getFingerprint(), "r1");
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), anyString())).thenReturn(new ArrayList());
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance, "r1");
assertThat(actual, hasSize(0));
assertThat(goCache.get(cacheKey), is(actual));
}
use of com.thoughtworks.go.domain.materials.git.GitMaterialInstance in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision.
@Test
public void shouldInvalidateCacheOfPipelineInstancesTriggeredWithMaterialRevision() throws Exception {
GitMaterialInstance materialInstance = new GitMaterialInstance("url", "branch", "submodule", "flyweight");
String cacheKey = pipelineDao.cacheKeyForPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance.getFingerprint(), "r1");
List<PipelineIdentifier> result = Arrays.asList(new PipelineIdentifier("p1", 1, "1"));
when(mockTemplate.queryForList(eq("pipelineInstancesTriggeredOffOfMaterialRevision"), anyString())).thenReturn(result);
List<PipelineIdentifier> actual = pipelineDao.getPipelineInstancesTriggeredWithDependencyMaterial("p1", materialInstance, "r1");
assertThat(actual, hasSize(1));
assertThat((List<PipelineIdentifier>) goCache.get(cacheKey), hasSize(1));
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(new GitMaterial("url", "branch"), new Modification("user", "comment", "email", new Date(), "r1")));
Pipeline pipeline = new Pipeline("p1", BuildCause.createWithModifications(materialRevisions, ""));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((TransactionSynchronizationAdapter) invocation.getArguments()[0]).afterCommit();
return null;
}
}).when(transactionSynchronizationManager).registerSynchronization(any(TransactionSynchronization.class));
when(transactionTemplate.execute(any(TransactionCallback.class))).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((TransactionCallback) invocation.getArguments()[0]).doInTransaction(new SimpleTransactionStatus());
return null;
}
});
pipelineDao.save(pipeline);
assertThat(goCache.get(cacheKey), is(Matchers.nullValue()));
}
use of com.thoughtworks.go.domain.materials.git.GitMaterialInstance in project gocd by gocd.
the class ValueStreamMapServiceTest method shouldGetPipelineDependencyGraphForAPipelineWithDiamondDependency_VSMForMaterial.
@Test
public void shouldGetPipelineDependencyGraphForAPipelineWithDiamondDependency_VSMForMaterial() {
/*
* |----> P1----->
* g |_> p3
* | |
* ---- > P2----->
*
* */
GitMaterial gitMaterial = new GitMaterial("git");
MaterialConfig gitConfig = gitMaterial.config();
GitMaterialInstance gitMaterialInstance = new GitMaterialInstance("git", "master", "submodule", "flyweight");
BuildCause p3buildCause = createBuildCause(asList("p1", "p2"), new ArrayList<>());
BuildCause p2buildCause = createBuildCause(new ArrayList<>(), asList(gitMaterial));
Modification gitModification = p2buildCause.getMaterialRevisions().getRevisions().get(0).getModifications().get(0);
String gitRevision = gitModification.getRevision();
BuildCause p1buildCause = createBuildCause(new ArrayList<>(), asList(gitMaterial));
when(pipelineService.buildCauseFor("p3", 1)).thenReturn(p3buildCause);
when(pipelineService.buildCauseFor("p2", 1)).thenReturn(p2buildCause);
when(pipelineService.buildCauseFor("p1", 1)).thenReturn(p1buildCause);
PipelineConfig p1Config = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(gitConfig));
PipelineConfig p2Config = PipelineConfigMother.pipelineConfig("p2", new MaterialConfigs(gitConfig));
PipelineConfig p3Config = PipelineConfigMother.pipelineConfig("p3", new MaterialConfigs(new DependencyMaterialConfig(p1Config.name(), p1Config.getFirstStageConfig().name()), new DependencyMaterialConfig(p2Config.name(), p2Config.getFirstStageConfig().name())));
PipelineConfigs pipelineConfigs = new BasicPipelineConfigs("g1", new Authorization(), p1Config, p2Config, p3Config);
CruiseConfig cruiseConfig = new BasicCruiseConfig(pipelineConfigs);
when(goConfigService.groups()).thenReturn(new PipelineGroups(pipelineConfigs));
when(materialRepository.findMaterialInstance(gitConfig)).thenReturn(gitMaterialInstance);
when(materialRepository.findModificationWithRevision(gitMaterial, gitRevision)).thenReturn(gitModification);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap(gitMaterial.getFingerprint(), gitRevision, user, result);
List<List<Node>> nodesAtEachLevel = graph.getNodesAtEachLevel();
assertThat(graph.getCurrentPipeline(), is(nullValue()));
assertThat(graph.getCurrentMaterial().getId(), is(gitMaterial.getFingerprint()));
assertThat(nodesAtEachLevel.size(), is(3));
List<Node> firstLevel = nodesAtEachLevel.get(0);
assertThat(firstLevel.size(), is(1));
assertNode(0, firstLevel.get(0), gitMaterial.getDisplayName(), gitMaterial.getFingerprint(), 0, "p1", "p2");
assertDepth(graph, firstLevel.get(0).getId(), 1);
List<Node> secondLevel = nodesAtEachLevel.get(1);
assertThat(secondLevel.size(), is(2));
assertNode(1, secondLevel.get(0), "p1", "p1", 0, "p3");
assertDepth(graph, secondLevel.get(0).getId(), 1);
assertNode(1, secondLevel.get(1), "p2", "p2", 0, "p3");
assertDepth(graph, secondLevel.get(1).getId(), 2);
List<Node> thirdLevel = nodesAtEachLevel.get(2);
assertThat(thirdLevel.size(), is(1));
assertNode(2, thirdLevel.get(0), "p3", "p3", 0);
assertDepth(graph, thirdLevel.get(0).getId(), 1);
}
Aggregations