Search in sources :

Example 1 with SessionCachingMetadataDomainRepository

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

the class SessionCachingMetadataDomainRepositoryIT method testGetDomain_differentSessions.

public void testGetDomain_differentSessions() throws Exception {
    // $NON-NLS-1$
    final String SESSION_ID1 = "1234";
    // $NON-NLS-1$
    final String SESSION_ID2 = "5678";
    // $NON-NLS-1$
    final String ID = "1";
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    mock.storeDomain(getTestDomain(ID), false);
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    // $NON-NLS-1$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", SESSION_ID1));
    // $NON-NLS-1$
    assertEquals(0, mock.getInvocationCount("getDomain"));
    Domain d = repo.getDomain(ID);
    assertEquals(ID, d.getId());
    assertEquals(SESSION_ID1, d.getDescription(TEST_LOCALE));
    // $NON-NLS-1$
    assertEquals(1, mock.getInvocationCount("getDomain"));
    // Cache should contain a domain for this session
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // Get the same domain from a different session
    // $NON-NLS-1$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", SESSION_ID2));
    d = repo.getDomain(ID);
    // Make sure we got a new, session-specific, domain
    assertEquals(SESSION_ID2, d.getDescription(TEST_LOCALE));
    // Make sure cache was missed and delegate was called
    // $NON-NLS-1$
    assertEquals(2, mock.getInvocationCount("getDomain"));
    // We should now have two objects in the cache (1 domain per session)
    assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // Domains in current session
    assertEquals(1, repo.getDomainIds().size());
    // Switch back to original session
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "1"));
    // Check for domains available for this session
    assertEquals(1, repo.getDomainIds().size());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) Domain(org.pentaho.metadata.model.Domain)

Example 2 with SessionCachingMetadataDomainRepository

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

the class SessionCachingMetadataDomainRepositoryIT method testRemoveModel.

public void testRemoveModel() throws Exception {
    // $NON-NLS-1$
    final String ID1 = "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", "1"));
    Domain domain = getTestDomain(ID1);
    LogicalModel model = new LogicalModel();
    // $NON-NLS-1$
    model.setId("test");
    domain.addLogicalModel(model);
    repo.storeDomain(domain, false);
    repo.storeDomain(getTestDomain(ID2), false);
    repo.getDomain(ID1);
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    repo.getDomain(ID2);
    assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "2"));
    repo.getDomain(ID1);
    assertEquals(3, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // $NON-NLS-1$
    repo.removeModel(ID1, "test");
    // Removing a model should remove all domains with that same id, leaving others intact
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // $NON-NLS-1$
    assertEquals(1, mock.getInvocationCount("removeModel"));
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) Domain(org.pentaho.metadata.model.Domain)

Example 3 with SessionCachingMetadataDomainRepository

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

the class SessionCachingMetadataDomainRepositoryIT method testGetDomain.

public void testGetDomain() throws Exception {
    // $NON-NLS-1$
    final String SESSION_ID = "1234-5678-90";
    // $NON-NLS-1$
    final String ID = "1";
    // $NON-NLS-1$
    final String ID2 = "2";
    IAclNodeHelper aclNodeHelper = mock(IAclNodeHelper.class);
    when(aclNodeHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
    MockAclAwareMetadataDomainRepository mock = new MockAclAwareMetadataDomainRepository(aclNodeHelper, null);
    mock.storeDomain(getTestDomain(ID), false);
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    // $NON-NLS-1$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", SESSION_ID));
    // $NON-NLS-1$
    assertEquals(0, mock.getInvocationCount("getDomain"));
    Domain d = repo.getDomain(ID);
    assertEquals(ID, d.getId());
    // Make sure the domain we got back has our session embedded in it (tests mock repository)
    assertEquals(SESSION_ID, d.getDescription(TEST_LOCALE));
    // $NON-NLS-1$
    assertEquals(1, mock.getInvocationCount("getDomain"));
    // Cache should contain a domain for this session
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    repo.getDomain(ID);
    // Make sure cache was hit and delegate was not called
    // $NON-NLS-1$
    assertEquals(1, mock.getInvocationCount("getDomain"));
    // Cache should contain a domain for this session
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    mock.storeDomain(getTestDomain(ID2), false);
    repo.getDomain(ID2);
    // Cache should contain tow domains for this session
    assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
    // Block access to domain ID2. Cache should be cleared for this domain
    when(aclNodeHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(false);
    repo.getDomain(ID2);
    // Make sure cache was hit and delegate was not called
    // $NON-NLS-1$
    assertEquals(2, mock.getInvocationCount("getDomain"));
    // Cache should contain a domain for this session
    assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) EnumSet(java.util.EnumSet) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Domain(org.pentaho.metadata.model.Domain)

Example 4 with SessionCachingMetadataDomainRepository

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

the class SessionCachingMetadataDomainRepositoryIT method testHasAccess.

public void testHasAccess() throws Exception {
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    // Only thing to do here is make sure the return value is the same; cache shouldn't do anything here
    assertEquals(mock.hasAccess(0, null), repo.hasAccess(0, null));
    // $NON-NLS-1$
    assertEquals(2, mock.getInvocationCount("hasAccess"));
}
Also used : SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository)

Example 5 with SessionCachingMetadataDomainRepository

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

the class SessionCachingMetadataDomainRepositoryIT method testGetDomainIds_differentSessions.

/**
 * Make sure all domain ids are returned in all sessions
 */
public void testGetDomainIds_differentSessions() 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"));
    Set<String> ids = repo.getDomainIds();
    assertEquals(0, ids.size());
    // $NON-NLS-1$
    assertEquals(1, mock.getInvocationCount("getDomainIds"));
    repo.storeDomain(getTestDomain(ID), false);
    ids = repo.getDomainIds();
    assertEquals(1, ids.size());
    // $NON-NLS-1$
    assertEquals(2, mock.getInvocationCount("getDomainIds"));
    // Switch the session
    // $NON-NLS-1$ //$NON-NLS-2$
    PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", "2"));
    // Make sure the domain id is returned
    ids = repo.getDomainIds();
    assertEquals(1, ids.size());
    // $NON-NLS-1$
    assertEquals(3, mock.getInvocationCount("getDomainIds"));
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository)

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