Search in sources :

Example 11 with SessionCachingMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method testStoreDomain.

public void testStoreDomain() throws Exception {
    // $NON-NLS-1$
    final String ID = "1";
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
    repo.storeDomain(getTestDomain(ID), false);
    // No cache values when storing a domain
    assertEquals(0, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // Cache one domain
    repo.getDomain(ID);
    // Storing a domain under a different session should wipe out all cached domains with the same id
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "2"));
    try {
        repo.storeDomain(getTestDomain(ID), false);
        // $NON-NLS-1$
        fail("Should have thrown a " + DomainAlreadyExistsException.class.getSimpleName());
    } catch (DomainAlreadyExistsException ex) {
    // expected
    }
    repo.storeDomain(getTestDomain(ID), true);
    // Storing a domain under a different session should wipe out all cached domains with the same id
    assertEquals(0, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    assertEquals(1, repo.getDomainIds().size());
    repo.getDomain(ID);
    assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // Storing a domain should only wipe out the cached domains with the same id
    // $NON-NLS-1$
    repo.storeDomain(getTestDomain("2"), false);
    assertEquals(2, repo.getDomainIds().size());
    assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException)

Example 12 with SessionCachingMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method testReloadDomains.

public void testReloadDomains() throws Exception {
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    // $NON-NLS-1$
    mock.setPersistedDomains(getTestDomain("1"));
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1234-5678-90"));
    // Cache should be empty
    assertEquals(0, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    assertEquals(0, repo.getDomainIds().size());
    repo.reloadDomains();
    // $NON-NLS-1$
    assertEquals(1, mock.getInvocationCount("reloadDomains"));
    assertEquals(1, repo.getDomainIds().size());
    // Cache should only have the domain ids
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository)

Example 13 with SessionCachingMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method testGetDomainIds.

/**
 * Getting the domain ids should always hit the delegate and not cache any objects
 */
public void testGetDomainIds() throws Exception {
    // $NON-NLS-1$
    final String ID = "1";
    // $NON-NLS-1$
    final String ID2 = "2";
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1234-5678-90"));
    Set<String> ids = repo.getDomainIds();
    assertEquals(0, ids.size());
    // $NON-NLS-1$
    assertEquals(1, mock.getInvocationCount("getDomainIds"));
    repo.storeDomain(getTestDomain(ID), false);
    assertEquals(0, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    ids = repo.getDomainIds();
    assertEquals(1, ids.size());
    // $NON-NLS-1$
    assertEquals(2, mock.getInvocationCount("getDomainIds"));
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository)

Example 14 with SessionCachingMetadataDomainRepository

use of org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryIT method testCannotCreateCache.

public void testCannotCreateCache() throws Exception {
    SimpleObjectFactory factory = new SimpleObjectFactory();
    // $NON-NLS-1$
    factory.defineObject("ICacheManager", MockDisabledCacheManager.class.getName());
    // Swap in an object factory with a cache manager that doesn't allow creating new caches
    Set<IPentahoObjectFactory> facts = ((AggregateObjectFactory) PentahoSystem.getObjectFactory()).getFactories();
    PentahoSystem.clearObjectFactory();
    PentahoSystem.registerObjectFactory(factory);
    try {
        try {
            new SessionCachingMetadataDomainRepository(new MockSessionAwareMetadataDomainRepository());
            // $NON-NLS-1$
            fail("Should not be able to create a Session Caching Repository without an enabled cache");
        } catch (IllegalStateException ex) {
            // $NON-NLS-1$
            assertTrue(ex.getMessage().contains("cannot be initialized"));
        // expected
        }
    } finally {
        // Replace the original object factory so the rest of the tests work
        PentahoSystem.clearObjectFactory();
        for (IPentahoObjectFactory fact : facts) {
            PentahoSystem.registerObjectFactory(fact);
        }
    }
}
Also used : SimpleObjectFactory(org.pentaho.test.platform.engine.core.SimpleObjectFactory) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory)

Aggregations

SessionCachingMetadataDomainRepository (org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository)14 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)11 Domain (org.pentaho.metadata.model.Domain)5 EnumSet (java.util.EnumSet)1 LogicalModel (org.pentaho.metadata.model.LogicalModel)1 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)1 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IAclNodeHelper (org.pentaho.platform.api.repository2.unified.IAclNodeHelper)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 AggregateObjectFactory (org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory)1 SimpleObjectFactory (org.pentaho.test.platform.engine.core.SimpleObjectFactory)1