Search in sources :

Example 6 with GoCache

use of com.thoughtworks.go.server.cache.GoCache in project gocd by gocd.

the class BaseUrlChangeListenerTest method shouldFlushCacheWhenBaseUrlConfigChangesAndUpdateTheSiteURLAndSecureSiteURLToTheNewValues.

@Test
public void shouldFlushCacheWhenBaseUrlConfigChangesAndUpdateTheSiteURLAndSecureSiteURLToTheNewValues() throws IOException {
    GoCache cache = mock(GoCache.class);
    BaseUrlChangeListener listener = new BaseUrlChangeListener(new ServerSiteUrlConfig(""), new ServerSiteUrlConfig(""), cache);
    CruiseConfig newCruiseConfig = new BasicCruiseConfig();
    newCruiseConfig.setServerConfig(serverConfigWith("http://blah.com", "https://blah.com"));
    listener.onConfigChange(newCruiseConfig);
    listener.onConfigChange(newCruiseConfig);
    verify(cache, times(1)).remove("urls_cache");
}
Also used : GoCache(com.thoughtworks.go.server.cache.GoCache) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ServerSiteUrlConfig(com.thoughtworks.go.domain.ServerSiteUrlConfig) Test(org.junit.Test)

Example 7 with GoCache

use of com.thoughtworks.go.server.cache.GoCache in project gocd by gocd.

the class MaterialRepositoryTest method setUp.

@Before
public void setUp() {
    databaseStrategy = mock(DatabaseStrategy.class);
    sessionFactory = mock(SessionFactory.class);
    goCache = mock(GoCache.class);
    ourCustomCache = new HashMap<>();
    transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    mockHibernateTemplate = mock(HibernateTemplate.class);
    materialConfigConverter = mock(MaterialConfigConverter.class);
    materialExpansionService = mock(MaterialExpansionService.class);
    materialRepository = new MaterialRepository(sessionFactory, goCache, 4242, transactionSynchronizationManager, materialConfigConverter, materialExpansionService, databaseStrategy);
    materialRepository.setHibernateTemplate(mockHibernateTemplate);
    when(goCache.get(anyString())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            return ourCustomCache.get(arguments[0]);
        }
    });
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            return ourCustomCache.put((String) arguments[0], arguments[1]);
        }
    }).when(goCache).put(anyString(), anyObject());
    when(goCache.remove(anyString())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            return ourCustomCache.remove(arguments[0]);
        }
    });
}
Also used : SessionFactory(org.hibernate.SessionFactory) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) MaterialConfigConverter(com.thoughtworks.go.server.service.MaterialConfigConverter) Answer(org.mockito.stubbing.Answer) MaterialExpansionService(com.thoughtworks.go.server.service.MaterialExpansionService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GoCache(com.thoughtworks.go.server.cache.GoCache) DatabaseStrategy(com.thoughtworks.go.server.database.DatabaseStrategy) Before(org.junit.Before)

Example 8 with GoCache

use of com.thoughtworks.go.server.cache.GoCache in project gocd by gocd.

the class StageSqlMapDaoTest method setUp.

@Before
public void setUp() {
    goCache = new StubGoCache(new TestTransactionSynchronizationManager());
    sqlMapClientTemplate = mock(SqlMapClientTemplate.class);
    stageSqlMapDao = new StageSqlMapDao(mock(JobInstanceSqlMapDao.class), new Cache(true, false, false), mock(TransactionTemplate.class), mock(SqlMapClient.class), goCache, mock(TransactionSynchronizationManager.class), mock(SystemEnvironment.class), null);
    stageSqlMapDao.setSqlMapClientTemplate(sqlMapClientTemplate);
    cloner = mock(Cloner.class);
    ReflectionUtil.setField(stageSqlMapDao, "cloner", cloner);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return invocationOnMock.getArguments()[0];
        }
    }).when(cloner).deepClone(anyObject());
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) StubGoCache(com.thoughtworks.go.server.service.StubGoCache) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Matchers.anyObject(org.mockito.Matchers.anyObject) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) GoCache(com.thoughtworks.go.server.cache.GoCache) StubGoCache(com.thoughtworks.go.server.service.StubGoCache) Cache(com.opensymphony.oscache.base.Cache) Cloner(com.rits.cloning.Cloner) Before(org.junit.Before)

Example 9 with GoCache

use of com.thoughtworks.go.server.cache.GoCache in project gocd by gocd.

the class GoConfigServiceTest method setup.

@Before
public void setup() throws Exception {
    new SystemEnvironment().setProperty(SystemEnvironment.ENFORCE_SERVERID_MUTABILITY, "N");
    configRepo = mock(ConfigRepository.class);
    goConfigDao = mock(GoConfigDao.class);
    pipelineRepository = mock(PipelineRepository.class);
    pipelinePauseService = mock(PipelinePauseService.class);
    systemEnvironment = mock(SystemEnvironment.class);
    cruiseConfig = unchangedConfig();
    expectLoad(cruiseConfig);
    this.clock = mock(Clock.class);
    goCache = mock(GoCache.class);
    instanceFactory = mock(InstanceFactory.class);
    userDao = mock(UserDao.class);
    stub(systemEnvironment.optimizeFullConfigSave()).toReturn(false);
    ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    goConfigService = new GoConfigService(goConfigDao, pipelineRepository, this.clock, new GoConfigMigration(configRepo, new TimeProvider(), new ConfigCache(), registry), goCache, configRepo, registry, instanceFactory, mock(CachedGoPartials.class), systemEnvironment);
}
Also used : ConfigRepository(com.thoughtworks.go.service.ConfigRepository) UserDao(com.thoughtworks.go.server.dao.UserDao) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) PipelineRepository(com.thoughtworks.go.server.persistence.PipelineRepository) GoCache(com.thoughtworks.go.server.cache.GoCache) Before(org.junit.Before)

Example 10 with GoCache

use of com.thoughtworks.go.server.cache.GoCache in project gocd by gocd.

the class StageServiceTest method setUp.

@Before
public void setUp() throws Exception {
    stageDao = mock(StageDao.class);
    pipelineDao = mock(PipelineDao.class);
    jobInstanceService = mock(JobInstanceService.class);
    securityService = mock(SecurityService.class);
    pipelineNames = asList(new CaseInsensitiveString("blah-pipeline"));
    user = new Username(new CaseInsensitiveString("poovan"));
    operationResult = new HttpLocalizedOperationResult();
    cruiseConfig = mock(BasicCruiseConfig.class);
    goConfigService = mock(GoConfigService.class);
    changesetService = mock(ChangesetService.class);
    goCache = mock(GoCache.class);
    transactionSynchronizationManager = new TestTransactionSynchronizationManager();
    transactionTemplate = new TestTransactionTemplate(transactionSynchronizationManager);
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) TestTransactionTemplate(com.thoughtworks.go.server.transaction.TestTransactionTemplate) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) GoCache(com.thoughtworks.go.server.cache.GoCache) PipelineDao(com.thoughtworks.go.server.dao.PipelineDao) Before(org.junit.Before)

Aggregations

GoCache (com.thoughtworks.go.server.cache.GoCache)11 Test (org.junit.Test)7 Before (org.junit.Before)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)2 ServerSiteUrlConfig (com.thoughtworks.go.domain.ServerSiteUrlConfig)2 StubGoCache (com.thoughtworks.go.server.service.StubGoCache)2 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 Cache (com.opensymphony.oscache.base.Cache)1 Cloner (com.rits.cloning.Cloner)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)1 PipelineDao (com.thoughtworks.go.server.dao.PipelineDao)1 StageDao (com.thoughtworks.go.server.dao.StageDao)1