Пример #1
0
 @Override
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   // start a single cache instance
   ConfigurationBuilder cb = getDefaultStandaloneCacheConfig(true);
   cb.invocationBatching().enable();
   EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(cb);
   cache = new TreeCacheImpl<Object, Object>(cm.getCache());
   tm = cache.getCache().getAdvancedCache().getTransactionManager();
   return cm;
 }
  @Override
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    ConfigurationBuilder cfg = getDefaultStandaloneCacheConfig(true);
    cfg.invocationBatching()
        .enable()
        .loaders()
        .addStore(DummyInMemoryCacheStoreConfigurationBuilder.class)
        .ignoreModifications(true);

    return TestCacheManagerFactory.createCacheManager(cfg);
  }
Пример #3
0
  protected void createCacheManagers() throws Throwable {
    ConfigurationBuilder cb = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true);
    cb.invocationBatching().enable();

    createClusteredCaches(2, "replSync", cb);

    Cache c1 = cache(0, "replSync");
    Cache c2 = cache(1, "replSync");

    cache1 = new TreeCacheImpl<Object, Object>(c1);
    cache2 = new TreeCacheImpl<Object, Object>(c2);
  }
  public void testAtomicMapWithoutBatchSet() {
    ConfigurationBuilder builder = buildConfiguration();
    builder.invocationBatching().disable();
    cacheManager.defineConfiguration("ahm_without_batch", builder.build());
    Cache<String, String> ahmCache = cacheManager.getCache("ahm_without_batch");

    AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(ahmCache, "key");
    assert map.isEmpty();
    map.put("a", "b");
    assert map.get("a").equals("b");

    // now re-retrieve the map and make sure we see the diffs
    assert AtomicMapLookup.getAtomicMap(ahmCache, "key").get("a").equals("b");
  }
  @Test(expectedExceptions = IllegalStateException.class)
  public void testAtomicMapNonTransactionWithoutBatchSet() {
    ConfigurationBuilder builder = buildConfiguration();
    builder.invocationBatching().disable();
    builder.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL);
    cacheManager.defineConfiguration("ahm_no_tx_without_batch", builder.build());
    Cache<String, String> ahmCache = cacheManager.getCache("ahm_no_tx_without_batch");

    AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(ahmCache, "key");
    assert map.isEmpty();
    map.put("a", "b");
    assert map.get("a").equals("b");

    // now re-retrieve the map and make sure we see the diffs
    assert AtomicMapLookup.getAtomicMap(ahmCache, "key").get("a").equals("b");
  }
 protected ConfigurationBuilder buildConfiguration() {
   ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(true);
   builder.invocationBatching().enable();
   builder.transaction().lockingMode(LockingMode.OPTIMISTIC);
   return builder;
 }
  protected void initEmbedded() {
    GlobalConfigurationBuilder gcb = new GlobalConfigurationBuilder();

    boolean clustered = config.getBoolean("clustered", false);
    boolean async = config.getBoolean("async", true);
    boolean allowDuplicateJMXDomains = config.getBoolean("allowDuplicateJMXDomains", true);

    if (clustered) {
      gcb.transport().defaultTransport();
    }
    gcb.globalJmxStatistics().allowDuplicateDomains(allowDuplicateJMXDomains);

    cacheManager = new DefaultCacheManager(gcb.build());
    containerManaged = false;

    logger.debug("Started embedded Infinispan cache container");

    ConfigurationBuilder invalidationConfigBuilder = new ConfigurationBuilder();
    if (clustered) {
      invalidationConfigBuilder
          .clustering()
          .cacheMode(async ? CacheMode.INVALIDATION_ASYNC : CacheMode.INVALIDATION_SYNC);
    }
    Configuration invalidationCacheConfiguration = invalidationConfigBuilder.build();

    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.REALM_CACHE_NAME, invalidationCacheConfiguration);
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.USER_CACHE_NAME, invalidationCacheConfiguration);

    ConfigurationBuilder sessionConfigBuilder = new ConfigurationBuilder();
    if (clustered) {
      String sessionsMode = config.get("sessionsMode", "distributed");
      if (sessionsMode.equalsIgnoreCase("replicated")) {
        sessionConfigBuilder
            .clustering()
            .cacheMode(async ? CacheMode.REPL_ASYNC : CacheMode.REPL_SYNC);
      } else if (sessionsMode.equalsIgnoreCase("distributed")) {
        sessionConfigBuilder
            .clustering()
            .cacheMode(async ? CacheMode.DIST_ASYNC : CacheMode.DIST_SYNC);
      } else {
        throw new RuntimeException("Invalid value for sessionsMode");
      }

      sessionConfigBuilder
          .clustering()
          .hash()
          .numOwners(config.getInt("sessionsOwners", 2))
          .numSegments(config.getInt("sessionsSegments", 60))
          .build();
    }

    Configuration sessionCacheConfiguration = sessionConfigBuilder.build();
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.SESSION_CACHE_NAME, sessionCacheConfiguration);
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.OFFLINE_SESSION_CACHE_NAME, sessionCacheConfiguration);
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.LOGIN_FAILURE_CACHE_NAME, sessionCacheConfiguration);

    ConfigurationBuilder replicationConfigBuilder = new ConfigurationBuilder();
    if (clustered) {
      replicationConfigBuilder
          .clustering()
          .cacheMode(async ? CacheMode.REPL_ASYNC : CacheMode.REPL_SYNC);
    }
    Configuration replicationCacheConfiguration = replicationConfigBuilder.build();
    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.WORK_CACHE_NAME, replicationCacheConfiguration);

    ConfigurationBuilder counterConfigBuilder = new ConfigurationBuilder();
    counterConfigBuilder
        .invocationBatching()
        .enable()
        .transaction()
        .transactionMode(TransactionMode.TRANSACTIONAL);
    counterConfigBuilder
        .transaction()
        .transactionManagerLookup(new DummyTransactionManagerLookup());
    counterConfigBuilder.transaction().lockingMode(LockingMode.PESSIMISTIC);
    Configuration counterCacheConfiguration = counterConfigBuilder.build();

    cacheManager.defineConfiguration(
        InfinispanConnectionProvider.VERSION_CACHE_NAME, counterCacheConfiguration);
  }