Package org.pentaho.platform.plugin.services.metadata

Examples of org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository$CacheKey


    super.tearDown();
  }

  public void testCreate_no_delegate() throws Exception {
    try {
      new SessionCachingMetadataDomainRepository( null );
      fail( "Should not be able to create a Session Caching Repository without a base implementation (delegate)" ); //$NON-NLS-1$
    } catch ( NullPointerException ex ) {
      // expected
    }
  }
View Full Code Here


    Set<IPentahoObjectFactory> facts = ( (AggregateObjectFactory) PentahoSystem.getObjectFactory() ).getFactories();
    PentahoSystem.clearObjectFactory();
    PentahoSystem.registerObjectFactory( factory );
    try {
      try {
        new SessionCachingMetadataDomainRepository( new MockSessionAwareMetadataDomainRepository() );
        fail( "Should not be able to create a Session Caching Repository without an enabled cache" ); //$NON-NLS-1$
      } catch ( IllegalStateException ex ) {
        assertTrue( ex.getMessage().contains( "cannot be initialized" ) ); //$NON-NLS-1$
        // expected
      }
View Full Code Here

    final String SESSION_ID = "1234-5678-90"; //$NON-NLS-1$
    final String ID = "1"; //$NON-NLS-1$
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    mock.storeDomain( getTestDomain( ID ), false );

    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", SESSION_ID ) ); //$NON-NLS-1$

    assertEquals( 0, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$
    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 ) );
    assertEquals( 1, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$
    // Cache should contain a domain for this session
    assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );

    d = repo.getDomain( ID );
    // Make sure cache was hit and delegate was not called
    assertEquals( 1, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$

    // Cache should contain a domain for this session
    assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
View Full Code Here

    final String SESSION_ID = null;
    final String ID = "1"; //$NON-NLS-1$
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    mock.storeDomain( getTestDomain( ID ), false );

    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", SESSION_ID ) ); //$NON-NLS-1$

    Domain domain = repo.getDomain( ID );
    // Description will equal the id when no description is provided (null session)
    assertEquals( ID, domain.getDescription( TEST_LOCALE ) );
  }
View Full Code Here

    final String SESSION_ID2 = "5678"; //$NON-NLS-1$
    final String ID = "1"; //$NON-NLS-1$
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    mock.storeDomain( getTestDomain( ID ), false );

    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", SESSION_ID1 ) ); //$NON-NLS-1$

    assertEquals( 0, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$
    Domain d = repo.getDomain( ID );
    assertEquals( ID, d.getId() );
    assertEquals( SESSION_ID1, d.getDescription( TEST_LOCALE ) );
    assertEquals( 1, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$
    // 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
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", SESSION_ID2 ) ); //$NON-NLS-1$

    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
    assertEquals( 2, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$
    // 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
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "1" ) ); //$NON-NLS-1$ //$NON-NLS-2$

    // Check for domains available for this session
    assertEquals( 1, repo.getDomainIds().size() );
  }
View Full Code Here

   */
  public void testGetDomainIds() throws Exception {
    final String ID = "1"; //$NON-NLS-1$
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();

    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "1234-5678-90" ) ); //$NON-NLS-1$ //$NON-NLS-2$

    Set<String> ids = repo.getDomainIds();
    assertEquals( 0, ids.size() );
    assertEquals( 1, mock.getInvocationCount( "getDomainIds" ) ); //$NON-NLS-1$

    repo.storeDomain( getTestDomain( ID ), false );
    assertEquals( 0, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );

    ids = repo.getDomainIds();
    assertEquals( 1, ids.size() );
    assertEquals( 2, mock.getInvocationCount( "getDomainIds" ) ); //$NON-NLS-1$
    assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );

    ids = repo.getDomainIds();
    assertEquals( 2, mock.getInvocationCount( "getDomainIds" ) ); //$NON-NLS-1$
    assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
  }
View Full Code Here

   */
  public void testGetDomainIds_differentSessions() throws Exception {
    final String ID = "1"; //$NON-NLS-1$
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();

    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "1" ) ); //$NON-NLS-1$ //$NON-NLS-2$

    Set<String> ids = repo.getDomainIds();
    assertEquals( 0, ids.size() );
    assertEquals( 1, mock.getInvocationCount( "getDomainIds" ) ); //$NON-NLS-1$

    repo.storeDomain( getTestDomain( ID ), false );

    ids = repo.getDomainIds();
    assertEquals( 1, ids.size() );
    assertEquals( 2, mock.getInvocationCount( "getDomainIds" ) ); //$NON-NLS-1$

    // Switch the session
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "2" ) ); //$NON-NLS-1$ //$NON-NLS-2$

    // Make sure the domain id is returned
    ids = repo.getDomainIds();
    assertEquals( 1, ids.size() );
    assertEquals( 3, mock.getInvocationCount( "getDomainIds" ) ); //$NON-NLS-1$
  }
View Full Code Here

  public void testReloadDomains() throws Exception {
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    mock.setPersistedDomains( getTestDomain( "1" ) ); //$NON-NLS-1$

    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "1234-5678-90" ) ); //$NON-NLS-1$ //$NON-NLS-2$

    // Cache should be empty
    assertEquals( 0, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );

    assertEquals( 0, repo.getDomainIds().size() );

    repo.reloadDomains();
    assertEquals( 1, mock.getInvocationCount( "reloadDomains" ) ); //$NON-NLS-1$
    assertEquals( 1, repo.getDomainIds().size() );

    // Cache should only have the domain ids
    assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
  }
View Full Code Here

  public void testFlushDomains() throws Exception {
    final String ID = "1"; //$NON-NLS-1$
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();

    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "1" ) ); //$NON-NLS-1$ //$NON-NLS-2$
    repo.storeDomain( getTestDomain( ID ), false );

    repo.getDomain( ID );
    assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );

    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "2" ) ); //$NON-NLS-1$ //$NON-NLS-2$
    repo.getDomain( ID );
    assertEquals( 2, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );

    assertEquals( 1, repo.getDomainIds().size() );

    repo.flushDomains();
    assertEquals( 1, mock.getInvocationCount( "flushDomains" ) ); //$NON-NLS-1$
    assertEquals( 0, repo.getDomainIds().size() );
    assertEquals( 0, mock.getDomainIds().size() );
    assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
  }
View Full Code Here

    final String ID2 = "2"; //$NON-NLS-1$
    MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
    mock.storeDomain( getTestDomain( ID1 ), false );
    mock.storeDomain( getTestDomain( ID2 ), false );

    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "1" ) ); //$NON-NLS-1$ //$NON-NLS-2$

    Domain domainFromSession1 = repo.getDomain( ID1 );
    assertNotNull( domainFromSession1 );
    assertEquals( 1, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$

    PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "2" ) ); //$NON-NLS-1$ //$NON-NLS-2$

    Domain domainFromSession2 = repo.getDomain( ID1 );
    assertNotNull( domainFromSession2 );
    assertEquals( 2, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$

    assertEquals( 2, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );

    repo.removeDomain( ID1 );
    assertEquals( 0, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );

    // Calling getDomain() now should increment the call count to the delegate
    repo.getDomain( ID2 );
    assertEquals( 3, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$

    // There should now only be one in the cache
    assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
  }
View Full Code Here

TOP

Related Classes of org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository$CacheKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.