@Test
  public void getDistributedCacheManager() throws Exception {
    ReplicationConfig config = new ReplicationConfig();
    ReplicationGranularity granularity = ReplicationGranularity.SESSION;
    config.setReplicationGranularity(granularity);
    Configuration configuration = new Configuration();
    configuration.fluent().invocationBatching();

    when(this.sessionCacheSource.getCache(same(this.registry), same(this.manager)))
        .thenReturn(this.cache);
    when(this.cache.getAdvancedCache()).thenReturn(this.cache);
    when(this.cache.with(same(DistributedCacheManagerFactory.class.getClassLoader())))
        .thenReturn(this.cache);
    when(this.cache.getConfiguration()).thenReturn(configuration);
    when(this.lockManagerSource.getLockManager(same(this.cache))).thenReturn(null);
    when(this.cache.getTransactionManager()).thenReturn(new BatchModeTransactionManager());

    when(this.marshallerFactory.createMarshaller(this.manager)).thenReturn(this.marshaller);
    when(this.manager.getReplicationConfig()).thenReturn(config);
    when(this.storageFactory.createStorage(granularity, this.marshaller)).thenReturn(this.storage);

    when(this.cache.getAdvancedCache()).thenReturn(this.cache);

    org.jboss.as.clustering.web.DistributedCacheManager<?> result =
        this.factory.getDistributedCacheManager(this.registry, this.manager);

    assertNotNull(result);
    assertTrue(result instanceof DistributedCacheManager);
  }
  private void verifyDependencies(
      String cacheName, ServiceName sessionCacheServiceName, ServiceName jvmRouteCacheServiceName) {
    ReplicationConfig config = new ReplicationConfig();
    config.setCacheName(cacheName);
    JBossWebMetaData metaData = new JBossWebMetaData();
    metaData.setReplicationConfig(config);

    Collection<ServiceName> dependencies = this.factory.getDependencies(metaData);

    assertEquals(2, dependencies.size());
    assertTrue(dependencies.contains(sessionCacheServiceName));
    assertTrue(dependencies.contains(jvmRouteCacheServiceName));
  }
Example #3
0
  public static JBossWebMetaData createWebMetaData(
      ReplicationGranularity granularity,
      ReplicationTrigger trigger,
      int maxSessions,
      boolean passivation,
      int maxIdle,
      int minIdle,
      boolean batchMode,
      int maxUnreplicated) {
    JBossWebMetaData webMetaData = new JBossWebMetaData();
    webMetaData.setDistributable(new EmptyMetaData());
    webMetaData.setMaxActiveSessions(new Integer(maxSessions));
    PassivationConfig pcfg = new PassivationConfig();
    pcfg.setUseSessionPassivation(Boolean.valueOf(passivation));
    pcfg.setPassivationMaxIdleTime(new Integer(maxIdle));
    pcfg.setPassivationMinIdleTime(new Integer(minIdle));
    webMetaData.setPassivationConfig(pcfg);
    ReplicationConfig repCfg = new ReplicationConfig();
    repCfg.setReplicationGranularity(granularity);
    repCfg.setReplicationTrigger(trigger);
    repCfg.setReplicationFieldBatchMode(Boolean.valueOf(batchMode));
    repCfg.setMaxUnreplicatedInterval(Integer.valueOf(maxUnreplicated));
    repCfg.setSnapshotMode(SnapshotMode.INSTANT);
    webMetaData.setReplicationConfig(repCfg);

    return webMetaData;
  }