@Override
  @SuppressWarnings("unchecked")
  protected void createCacheManagers() throws Throwable {
    // Car is split into 2 shards: one is going to Infinispan Directory with a shared index, the
    // other is
    // going to Ram with a local index
    ConfigurationBuilder cacheCfg = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, false);
    cacheCfg
        .indexing()
        .index(Index.ALL)
        .addIndexedEntity(Car.class)
        .addProperty("hibernate.search.car.sharding_strategy.nbr_of_shards", "2")
        .addProperty("hibernate.search.car.1.directory_provider", "ram")
        .addProperty(
            "hibernate.search.car.0.indexmanager",
            "org.infinispan.query.indexmanager.InfinispanIndexManager")
        .addProperty("error_handler", "org.infinispan.query.helper.StaticTestingErrorHandler")
        .addProperty("lucene_version", "LUCENE_CURRENT");

    List<Cache<Integer, Object>> cacheList = createClusteredCaches(NUM_NODES, cacheCfg);

    waitForClusterToForm(BasicCacheContainer.DEFAULT_CACHE_NAME);

    for (Cache cache : cacheList) {
      caches.add(cache);
    }
  }
  @Override
  protected void createCacheManagers() throws Throwable {
    // todo [anistor] initializing the server-side context in this way is a hack. normally this
    // should use the protobuf metadata registry
    MarshallerRegistration.registerMarshallers(
        SerializationContextHolder.getSerializationContext());

    // initialize client-side serialization context
    MarshallerRegistration.registerMarshallers(ProtoStreamMarshaller.getSerializationContext());

    ConfigurationBuilder builder =
        hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, false));
    builder
        .transaction()
        .indexing()
        .enable()
        .indexLocalOnly(false)
        .addProperty(
            "default.directory_provider", "ram") // todo test with  "infinispan" provider too
        .addProperty("lucene_version", "LUCENE_CURRENT");

    builder.dataContainer().valueEquivalence(AnyEquivalence.getInstance()); // TODO [anistor] hacks!

    createHotRodServers(2, builder);
  }
Exemplo n.º 3
0
  /**
   * Implementation of abstract method processModelNode suitable for distributed cache
   *
   * @param cache
   * @param configuration
   * @param dependencies
   * @return
   */
  @Override
  void processModelNode(
      String containerName,
      ModelNode cache,
      ConfigurationBuilder builder,
      List<Dependency<?>> dependencies) {
    // process the basic clustered configuration
    super.processModelNode(containerName, cache, builder, dependencies);

    // process the additional distributed attributes and elements
    if (cache.hasDefined(ModelKeys.OWNERS)) {
      builder.clustering().hash().numOwners(cache.get(ModelKeys.OWNERS).asInt());
    }
    if (cache.hasDefined(ModelKeys.VIRTUAL_NODES)) {
      builder.clustering().hash().numVirtualNodes(cache.get(ModelKeys.VIRTUAL_NODES).asInt());
    }
    if (cache.hasDefined(ModelKeys.L1_LIFESPAN)) {
      long lifespan = cache.get(ModelKeys.L1_LIFESPAN).asLong();
      if (lifespan > 0) {
        builder.clustering().l1().lifespan(lifespan);
      } else {
        builder.clustering().l1().disable();
      }
    }
  }
  @Override
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    cacheStoreDir = new File(TestingUtil.tmpDirectory(this.getClass()));
    TestingUtil.recursiveFileRemove(cacheStoreDir);

    ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.LOCAL, true, true);
    builder
        .transaction()
        .transactionMode(TransactionMode.TRANSACTIONAL)
        .lockingMode(LockingMode.PESSIMISTIC)
        .transactionManagerLookup(new DummyTransactionManagerLookup())
        .eviction()
        .maxEntries(150)
        .strategy(EvictionStrategy.LIRS)
        .locking()
        .lockAcquisitionTimeout(20000)
        .concurrencyLevel(5000)
        .useLockStriping(false)
        .writeSkewCheck(false)
        .isolationLevel(IsolationLevel.READ_COMMITTED)
        .dataContainer()
        .storeAsBinary()
        .persistence()
        .passivation(passivationEnabled)
        .addSingleFileStore()
        .location(cacheStoreDir.getAbsolutePath())
        .fetchPersistentState(true)
        .ignoreModifications(false)
        .preload(false)
        .purgeOnStartup(false);

    configureConfiguration(builder);

    return TestCacheManagerFactory.createCacheManager(builder);
  }
 @Test
 public void testBuildDiffCacheNameTimestampsRegion() {
   final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
   Properties p = createProperties();
   p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "unrecommended-timestamps");
   InfinispanRegionFactory factory = createRegionFactory(p);
   try {
     EmbeddedCacheManager manager = factory.getCacheManager();
     assertFalse(factory.getDefinedConfigurations().contains("timestamp"));
     assertTrue(factory.getDefinedConfigurations().contains("unrecommended-timestamps"));
     assertTrue(
         factory
             .getTypeOverrides()
             .get("timestamps")
             .getCacheName()
             .equals("unrecommended-timestamps"));
     ConfigurationBuilder builder = new ConfigurationBuilder();
     builder.clustering().stateTransfer().fetchInMemoryState(true);
     builder.clustering().cacheMode(CacheMode.REPL_SYNC);
     manager.defineConfiguration("unrecommended-timestamps", builder.build());
     TimestampsRegionImpl region =
         (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
     AdvancedCache cache = region.getCache();
     Configuration cacheCfg = cache.getCacheConfiguration();
     assertEquals(EvictionStrategy.NONE, cacheCfg.eviction().strategy());
     assertEquals(CacheMode.REPL_SYNC, cacheCfg.clustering().cacheMode());
     assertFalse(cacheCfg.storeAsBinary().enabled());
     assertFalse(cacheCfg.jmxStatistics().enabled());
   } finally {
     factory.stop();
   }
 }
Exemplo n.º 6
0
  private void stuConfigurationBuilder() {

    ConfigurationBuilder builder = new ConfigurationBuilder();
    ClusteringConfigurationBuilder clusterBuilder =
        builder.clustering().cacheMode(CacheMode.REPL_SYNC);
    Configuration config = clusterBuilder.build();
  }
 public void testDisabledInterceptorStack() {
   ConfigurationBuilder cfg = new ConfigurationBuilder();
   cfg.storeAsBinary().disable();
   cm.defineConfiguration("a", cfg.build());
   Cache<?, ?> c = cm.getCache("a");
   assert TestingUtil.findInterceptor(c, MarshalledValueInterceptor.class) == null;
 }
Exemplo n.º 8
0
  private void createRemoteValueWrapperInterceptor(ComponentRegistry cr, Configuration cfg) {
    RemoteValueWrapperInterceptor wrapperInterceptor =
        cr.getComponent(RemoteValueWrapperInterceptor.class);
    if (wrapperInterceptor == null) {
      wrapperInterceptor = new RemoteValueWrapperInterceptor();

      // Interceptor registration not needed, core configuration handling
      // already does it for all custom interceptors - UNLESS the InterceptorChain already exists in
      // the component registry!
      AsyncInterceptorChain ic = cr.getComponent(AsyncInterceptorChain.class);

      ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg);
      InterceptorConfigurationBuilder interceptorBuilder =
          builder.customInterceptors().addInterceptor();
      interceptorBuilder.interceptor(wrapperInterceptor);

      if (cfg.invocationBatching().enabled()) {
        if (ic != null) ic.addInterceptorAfter(wrapperInterceptor, BatchingInterceptor.class);
        interceptorBuilder.after(BatchingInterceptor.class);
      } else {
        if (ic != null)
          ic.addInterceptorAfter(wrapperInterceptor, InvocationContextInterceptor.class);
        interceptorBuilder.after(InvocationContextInterceptor.class);
      }
      if (ic != null) {
        cr.registerComponent(wrapperInterceptor, RemoteValueWrapperInterceptor.class);
      }
      cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors());
    }
  }
Exemplo n.º 9
0
 @Override
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   ConfigurationBuilder configuration = getDefaultClusteredCacheConfig(CacheMode.LOCAL, true);
   configuration.transaction().lockingMode(LockingMode.PESSIMISTIC);
   configure(configuration);
   return TestCacheManagerFactory.createCacheManager(configuration);
 }
Exemplo n.º 10
0
 /**
  * Create the default configuration.
  *
  * @return the default cache configuration.
  */
 protected ConfigurationBuilder createDefaultConfigurationBuilder() {
   ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
   configurationBuilder.transaction().transactionMode(TransactionMode.TRANSACTIONAL);
   configurationBuilder.transaction().transactionManagerLookup(transactionManagerLookupInstance());
   configurationBuilder.transaction().lockingMode(LockingMode.PESSIMISTIC);
   return configurationBuilder;
 }
 @Override
 protected ConfigurationBuilder createCacheConfigBuilder() {
   ConfigurationBuilder c = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true);
   c.clustering().hash().numOwners(100).numSegments(4).l1().disable();
   c.transaction().transactionProtocol(TransactionProtocol.TOTAL_ORDER).recovery().disable();
   return c;
 }
  @Override
  protected void createCacheManagers() throws Throwable {
    ConfigurationBuilder defaultConfiguration =
        getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, false);
    defaultConfiguration.clustering().stateTransfer().fetchInMemoryState(true);
    createClusteredCaches(2, defaultConfiguration);

    ConfigurationBuilder cfg = initialCacheConfiguration();
    cfg.clustering()
        .stateTransfer()
        .fetchInMemoryState(true)
        .indexing()
        .index(Index.LOCAL)
        .addIndexedEntity(getModelFactory().getUserImplClass())
        .addIndexedEntity(getModelFactory().getAccountImplClass())
        .addIndexedEntity(getModelFactory().getTransactionImplClass())
        .addProperty(
            "default.indexmanager", "org.infinispan.query.indexmanager.InfinispanIndexManager")
        .addProperty("lucene_version", "LUCENE_CURRENT");

    manager(0).defineConfiguration(TEST_CACHE_NAME, cfg.build());
    manager(1).defineConfiguration(TEST_CACHE_NAME, cfg.build());
    cache1 = manager(0).getCache(TEST_CACHE_NAME);
    cache2 = manager(1).getCache(TEST_CACHE_NAME);
  }
Exemplo n.º 13
0
 @Override
 protected ConfigurationBuilder getCacheConfig() {
   ConfigurationBuilder builder =
       hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, false));
   builder.clustering().hash().numOwners(1);
   return builder;
 }
  @Override
  protected void createCacheManagers() throws Throwable {
    ConfigurationBuilder cfgBuilder =
        hotRodCacheConfiguration(getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, false));
    cfgBuilder
        .indexing()
        .index(Index.ALL)
        .addProperty("default.directory_provider", "ram")
        .addProperty("lucene_version", "LUCENE_CURRENT");

    createHotRodServers(NUM_NODES, cfgBuilder);

    waitForClusterToForm();

    remoteCache = client(0).getCache();

    // initialize server-side serialization context
    RemoteCache<String, String> metadataCache =
        client(0).getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
    metadataCache.put(
        "sample_bank_account/bank.proto",
        Util.read(
            Util.getResourceAsStream(
                "/sample_bank_account/bank.proto", getClass().getClassLoader())));
    assertFalse(metadataCache.containsKey(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX));

    // initialize client-side serialization context
    MarshallerRegistration.registerMarshallers(
        ProtoStreamMarshaller.getSerializationContext(client(0)));
  }
Exemplo n.º 15
0
  @Override
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    final ConfigurationBuilder builder = getDefaultStandaloneCacheConfig(true);
    builder
        .indexing()
        .index(Index.LOCAL)
        .addIndexedEntity(TestEntity.class)
        .addProperty("default.directory_provider", "ram")
        .addProperty("lucene_version", "LUCENE_CURRENT")
        .security()
        .authorization()
        .enable()
        .role("admin")
        .role("query")
        .role("noquery");
    return Subject.doAs(
        ADMIN,
        new PrivilegedAction<EmbeddedCacheManager>() {

          @Override
          public EmbeddedCacheManager run() {
            EmbeddedCacheManager ecm =
                TestCacheManagerFactory.createCacheManager(getSecureGlobalConfiguration(), builder);
            ecm.getCache();
            return ecm;
          }
        });
  }
  public void testCorrectShutdown() {
    CacheContainer cc = null;

    try {
      ConfigurationBuilder cfg = new ConfigurationBuilder();
      cfg.transaction()
          .transactionMode(TransactionMode.TRANSACTIONAL)
          .indexing()
          .index(Index.ALL)
          .addProperty("default.directory_provider", "ram")
          .addProperty("lucene_version", "LUCENE_CURRENT");
      cc = TestCacheManagerFactory.createCacheManager(cfg);
      Cache<?, ?> cache = cc.getCache();
      SearchFactoryIntegrator sfi =
          TestingUtil.extractComponent(cache, SearchFactoryIntegrator.class);

      assert !sfi.isStopped();

      cc.stop();

      assert sfi.isStopped();
    } finally {
      // proper cleanup for exceptional execution
      TestingUtil.killCacheManagers(cc);
    }
  }
  private ConfigurationBuilder getCB() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.clustering()
        .cacheMode(CacheMode.DIST_SYNC)
        .sync()
        .replTimeout(60000)
        .stateTransfer()
        .timeout(180000)
        .fetchInMemoryState(true)
        .hash()
        .numOwners(1);

    // transactions

    cb.transaction()
        .transactionMode(TransactionMode.TRANSACTIONAL)
        .lockingMode(LockingMode.PESSIMISTIC)
        .syncCommitPhase(true)
        .syncRollbackPhase(true);

    // cb.transaction().transactionMode(TransactionMode.NON_TRANSACTIONAL);

    cb.loaders().passivation(false).preload(true).shared(true);
    // Make it really shared by adding the test's name as store name
    cb.loaders()
        .addStore(DummyInMemoryCacheStoreConfigurationBuilder.class)
        .storeName(getClass().getSimpleName())
        .async()
        .disable();
    return cb;
  }
  @Override
  protected void afterSitesCreated() {
    super.afterSitesCreated();

    ConfigurationBuilder builder = newConfiguration();
    builder.sites().addBackup().site(siteName(2)).strategy(BackupConfiguration.BackupStrategy.SYNC);
    defineInSite(site(0), CacheType.BACKUP_TO_SITE_2.name(), builder.build());
    defineInSite(site(2), CacheType.BACKUP_TO_SITE_2.name(), newConfiguration().build());

    builder = newConfiguration();
    builder.sites().addBackup().site(siteName(1)).strategy(BackupConfiguration.BackupStrategy.SYNC);
    builder.sites().addBackup().site(siteName(2)).strategy(BackupConfiguration.BackupStrategy.SYNC);
    defineInSite(site(0), CacheType.BACKUP_TO_SITE_1_AND_2.name(), builder.build());
    defineInSite(site(1), CacheType.BACKUP_TO_SITE_1_AND_2.name(), newConfiguration().build());
    defineInSite(site(2), CacheType.BACKUP_TO_SITE_1_AND_2.name(), newConfiguration().build());

    defineInSite(site(0), CacheType.NO_BACKUP.name(), newConfiguration().build());

    // wait for caches in primary cluster
    site(0).waitForClusterToForm(null);
    site(0).waitForClusterToForm(CacheType.BACKUP_TO_SITE_1_AND_2.name());
    site(0).waitForClusterToForm(CacheType.BACKUP_TO_SITE_1_AND_2.name());
    site(0).waitForClusterToForm(CacheType.BACKUP_TO_SITE_2.name());

    // wait for caches in backup site 1
    site(1).waitForClusterToForm(null);
    site(1).waitForClusterToForm(CacheType.BACKUP_TO_SITE_1_AND_2.name());

    // wait for caches in backup site 2
    site(2).waitForClusterToForm(CacheType.BACKUP_TO_SITE_1_AND_2.name());
    site(2).waitForClusterToForm(CacheType.BACKUP_TO_SITE_2.name());
  }
 protected ConfigurationBuilder getConfig() {
   ConfigurationBuilder dcc = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true);
   dcc.transaction().locking().writeSkewCheck(true);
   dcc.transaction().locking().isolationLevel(IsolationLevel.REPEATABLE_READ);
   dcc.transaction().versioning().enable().scheme(VersioningScheme.SIMPLE);
   return dcc;
 }
Exemplo n.º 20
0
 private HotRodServer addHotRodServer() {
   EmbeddedCacheManager cm = addClusterEnabledCacheManager(defaultBuilder);
   cm.defineConfiguration(DIST_ONE_CACHE_NAME, distOneBuilder.build());
   cm.defineConfiguration(DIST_TWO_CACHE_NAME, distTwoBuilder.build());
   HotRodServer server = HotRodClientTestingUtil.startHotRodServer(cm);
   addr2hrServer.put(new InetSocketAddress(server.getHost(), server.getPort()), server);
   return server;
 }
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   ConfigurationBuilder c = getDefaultStandaloneCacheConfig(true);
   c.indexing()
       .enable()
       .addProperty("hibernate.search.default.directory_provider", "ram")
       .addProperty("hibernate.search.lucene_version", "LUCENE_CURRENT");
   return TestCacheManagerFactory.createCacheManager(c);
 }
Exemplo n.º 22
0
 @Test
 public void testDummyTMGetCache() {
   ConfigurationBuilder cb = new ConfigurationBuilder();
   cb.transaction()
       .use1PcForAutoCommitTransactions(true)
       .transactionManagerLookup(new DummyTransactionManagerLookup());
   DefaultCacheManager cm = new DefaultCacheManager(cb.build());
   cm.getCache();
 }
 @Override
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   ConfigurationBuilder cfg = getDefaultStandaloneCacheConfig(false);
   cfg.indexing()
       .index(Index.ALL)
       .addProperty("default.directory_provider", "ram")
       .addProperty("error_handler", "org.infinispan.query.helper.StaticTestingErrorHandler");
   return TestCacheManagerFactory.createCacheManager(cfg);
 }
 @Override
 protected void createCacheManagers() throws Throwable {
   dccc = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true, true);
   dccc.transaction().transactionManagerLookup(new DummyTransactionManagerLookup());
   dccc.clustering().hash().l1().disable().locking().lockAcquisitionTimeout(1000l);
   dccc.clustering().stateTransfer().fetchInMemoryState(true);
   createCluster(dccc, 2);
   waitForClusterToForm();
 }
Exemplo n.º 25
0
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   ConfigurationBuilder cfg = getDefaultStandaloneCacheConfig(true);
   cfg.indexing()
       .index(Index.ALL)
       .addIndexedEntity(Car.class)
       .addProperty("default.directory_provider", "ram")
       .addProperty("lucene_version", "LUCENE_CURRENT");
   return TestCacheManagerFactory.createCacheManager(cfg);
 }
 private static ConfigurationBuilder createConfigurationBuilder() {
   ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, false);
   builder.clustering().stateTransfer().fetchInMemoryState(true);
   builder.clustering().hash().groups().enabled(true);
   builder.clustering().hash().numOwners(2);
   builder.clustering().hash().numSegments(1);
   builder.clustering().hash().consistentHashFactory(new CustomConsistentHashFactory());
   return builder;
 }
 private Configuration buildConfiguration(boolean tx) {
   ConfigurationBuilder cb = getDefaultClusteredCacheConfig(CacheMode.REPL_ASYNC, tx);
   cb.clustering().async().useReplQueue(true).replQueueInterval(100).replQueueMaxElements(3);
   // These are the default:
   // .asyncMarshalling(false)
   // .stateTransfer().fetchInMemoryState(true)
   // .locking().useLockStriping(false);
   return cb.build();
 }
 protected ConfigurationBuilder getConfigurationBuilder() {
   ConfigurationBuilder cfgBuilder = new ConfigurationBuilder();
   cfgBuilder
       .indexing()
       .index(Index.ALL)
       .addProperty("default.directory_provider", "ram")
       .addProperty("lucene_version", "LUCENE_CURRENT");
   return cfgBuilder;
 }
 @Override
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   ConfigurationBuilder cfg = getDefaultStandaloneCacheConfig(true);
   cfg.indexing()
       .index(Index.ALL)
       .addProperty("default.directory_provider", "filesystem")
       .addProperty("default.indexBase", indexDirectory)
       .addProperty("lucene_version", "LUCENE_CURRENT");
   return TestCacheManagerFactory.createCacheManager(cfg);
 }
Exemplo n.º 30
0
 @Override
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   // start a single cache instance
   ConfigurationBuilder c = getDefaultStandaloneCacheConfig(true);
   c.storeAsBinary().enable();
   EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(false);
   cm.defineConfiguration("lazy-cache-test", c.build());
   cache = cm.getCache("lazy-cache-test");
   return cm;
 }