Search in sources :

Example 21 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.

the class OlapServiceImpl method getCache.

/**
 * Returns a list of catalogs for the current session.
 *
 * <p>The cache is stored in the platform's caches in the region
 * {@link #CATALOG_CACHE_REGION}. It is also segmented by
 * locale, but we only return the correct sub-region according to the
 * session passed as a parameter.
 */
@SuppressWarnings("unchecked")
protected synchronized List<IOlapService.Catalog> getCache(IPentahoSession session) {
    // Create the cache region if necessary.
    final ICacheManager cacheMgr = PentahoSystem.getCacheManager(session);
    final Object cacheKey = makeCacheSubRegionKey(getLocale());
    final Lock writeLock = cacheLock.writeLock();
    try {
        writeLock.lock();
        if (!cacheMgr.cacheEnabled(CATALOG_CACHE_REGION)) {
            // Create the region. This requires write access.
            cacheMgr.addCacheRegion(CATALOG_CACHE_REGION);
        }
        if (cacheMgr.getFromRegionCache(CATALOG_CACHE_REGION, cacheKey) == null) {
            // Create the sub-region. This requires write access.
            cacheMgr.putInRegionCache(CATALOG_CACHE_REGION, cacheKey, new ArrayList<IOlapService.Catalog>());
        }
        return (List<IOlapService.Catalog>) cacheMgr.getFromRegionCache(CATALOG_CACHE_REGION, cacheKey);
    } finally {
        writeLock.unlock();
    }
}
Also used : IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 22 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method tearDown.

public void tearDown() {
    // Clean the cache
    ICacheManager cacheManager = PentahoSystem.getCacheManager(null);
    cacheManager.clearRegionCache(CACHE_NAME);
    super.tearDown();
}
Also used : ICacheManager(org.pentaho.platform.api.engine.ICacheManager)

Example 23 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project data-access by pentaho.

the class AgileHelperTest method setUp.

@Before
public void setUp() throws SQLException, ObjectFactoryException {
    Connection connection = mock(Connection.class);
    DataSource dataSource = mock(DataSource.class);
    when(dataSource.getConnection()).thenReturn(connection);
    final ICacheManager manager = mock(ICacheManager.class);
    when(manager.cacheEnabled(anyString())).thenReturn(true);
    when(manager.getFromRegionCache(anyString(), any())).thenReturn(dataSource);
    pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return manager;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    IApplicationContext context = mock(IApplicationContext.class);
    when(context.getSolutionPath(anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    PentahoSystem.setApplicationContext(context);
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Connection(java.sql.Connection) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) DataSource(javax.sql.DataSource) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Before(org.junit.Before)

Example 24 with ICacheManager

use of org.pentaho.platform.api.engine.ICacheManager in project pentaho-kettle by pentaho.

the class RepositoryFactoryTest method testCachingFactoryConnect.

@Test
public void testCachingFactoryConnect() throws Exception {
    ICacheManager cacheManager = mock(ICacheManager.class);
    PentahoSystem.registerObject(cacheManager);
    IPentahoSession session = new StandaloneSession("joe");
    PentahoSessionHolder.setSession(session);
    // Delegate is just a mock. connect will be a cache miss
    IRepositoryFactory mockFactory = mock(IRepositoryFactory.class);
    IRepositoryFactory.CachingRepositoryFactory cachingRepositoryFactory = new IRepositoryFactory.CachingRepositoryFactory(mockFactory);
    cachingRepositoryFactory.connect("foo");
    verify(mockFactory, times(1)).connect("foo");
    // Test with Cache Hit
    Repository mockRepository = mock(Repository.class);
    when(cacheManager.cacheEnabled(IRepositoryFactory.CachingRepositoryFactory.REGION)).thenReturn(true);
    when(cacheManager.getFromRegionCache(IRepositoryFactory.CachingRepositoryFactory.REGION, "joe")).thenReturn(mockRepository);
    Repository repo = cachingRepositoryFactory.connect("foo");
    assertThat(repo, sameInstance(mockRepository));
}
Also used : Repository(org.pentaho.di.repository.Repository) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Test(org.junit.Test)

Aggregations

ICacheManager (org.pentaho.platform.api.engine.ICacheManager)24 Test (org.junit.Test)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 DataSource (javax.sql.DataSource)2 DataSourcesConfig (mondrian.xmla.DataSourcesConfig)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 Domain (org.pentaho.metadata.model.Domain)2 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)2 MockSessionAwareMetadataDomainRepository (org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1