public static GlobalConfigurationBuilder defaultClusteredBuilder() {
    GlobalConfigurationBuilder builder = new GlobalConfigurationBuilder();
    builder
        .transport()
        .transport(new JGroupsTransport())
        .asyncTransportExecutor()
        .addProperty("threadNamePrefix", "asyncTransportThread");

    return builder;
  }
  public static List createTopologyAwareCacheNodes(
      int numberOfNodes,
      CacheMode cacheMode,
      boolean transactional,
      boolean indexLocalOnly,
      boolean isRamDirectoryProvider) {
    List caches = new ArrayList();

    ConfigurationBuilder builder =
        AbstractCacheTest.getDefaultClusteredCacheConfig(cacheMode, transactional);

    builder.indexing().enable().indexLocalOnly(indexLocalOnly);

    if (isRamDirectoryProvider) {
      builder
          .indexing()
          .addProperty("default.directory_provider", "ram")
          .addProperty("lucene_version", "LUCENE_CURRENT");
    } else {
      builder
          .indexing()
          .addProperty(
              "hibernate.search.default.indexmanager",
              "org.infinispan.query.indexmanager.InfinispanIndexManager")
          .addProperty("default.directory_provider", "infinispan")
          .addProperty("hibernate.search.default.exclusive_index_use", "false")
          .addProperty("lucene_version", "LUCENE_36");
      if (cacheMode.isClustered()) {
        builder.clustering().stateTransfer().fetchInMemoryState(true);
      }
    }

    for (int i = 0; i < numberOfNodes; i++) {
      GlobalConfigurationBuilder globalConfigurationBuilder =
          GlobalConfigurationBuilder.defaultClusteredBuilder();
      globalConfigurationBuilder.transport().machineId("a" + i).rackId("b" + i).siteId("test" + i);

      EmbeddedCacheManager cm1 =
          TestCacheManagerFactory.createClusteredCacheManager(globalConfigurationBuilder, builder);

      caches.add(cm1.getCache());
    }

    return caches;
  }
  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);
  }
 @Test(expectedExceptions = CacheConfigurationException.class)
 public void testClusterNameNull() {
   GlobalConfigurationBuilder gc = new GlobalConfigurationBuilder();
   gc.transport().clusterName(null).build();
 }