Ejemplo n.º 1
0
  private void doTest(boolean strict) {
    EmbeddedCacheManager cm1 = null, cm2 = null;
    try {
      Configuration c = new Configuration();
      c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
      GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault();
      gc.setStrictPeerToPeer(strict);

      cm1 = TestCacheManagerFactory.createCacheManager(gc, c);
      cm2 = TestCacheManagerFactory.createCacheManager(gc, c);

      cm1.getCache();
      cm2.getCache();

      cm1.getCache().put("k", "v");
      assert "v".equals(cm1.getCache().get("k"));
      assert "v".equals(cm2.getCache().get("k"));

      cm1.defineConfiguration("newCache", c);

      if (strict) {
        try {
          cm1.getCache("newCache").put("k", "v");
          assert false : "Should have failed!";
        } catch (CacheException e) {
          assert e.getCause() instanceof NamedCacheNotFoundException;
        }
      } else {
        cm1.getCache("newCache").put("k", "v");
        assert "v".equals(cm1.getCache("newCache").get("k"));
      }
    } finally {
      TestingUtil.killCacheManagers(cm1, cm2);
    }
  }
 @Override
 protected EmbeddedCacheManager addClusterEnabledCacheManager(Configuration deConfiguration) {
   int index = cacheManagers.size();
   String rack;
   String machine;
   switch (index) {
     case 0:
       {
         rack = "r0";
         machine = "m0";
         break;
       }
     case 1:
       {
         rack = "r0";
         machine = "m1";
         break;
       }
     case 2:
       {
         rack = "r1";
         machine = "m0";
         break;
       }
     case 3:
       {
         rack = "r2";
         machine = "m0";
         break;
       }
     case 4:
       {
         rack = "r2";
         machine = "m0";
         break;
       }
     default:
       {
         throw new RuntimeException("Bad!");
       }
   }
   GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault();
   gc.setRackId(rack);
   gc.setMachineId(machine);
   EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(gc, deConfiguration);
   cacheManagers.add(cm);
   return cm;
 }
Ejemplo n.º 3
0
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault();
    gc.setAsyncTransportExecutorFactoryClass(WTE.class.getName());
    cacheManager = TestCacheManagerFactory.createCacheManager(gc);

    cacheManager.defineConfiguration(LOCAL_CACHE_NAME, getBaseCfg());

    cacheManager.defineConfiguration(REPL_SYNC_CACHE_NAME, getClusteredCfg(REPL_SYNC, false));
    cacheManager.defineConfiguration(REPL_ASYNC_CACHE_NAME, getClusteredCfg(REPL_ASYNC, false));
    cacheManager.defineConfiguration(DIST_SYNC_CACHE_NAME, getClusteredCfg(DIST_SYNC, false));
    cacheManager.defineConfiguration(DIST_ASYNC_CACHE_NAME, getClusteredCfg(DIST_ASYNC, false));
    cacheManager.defineConfiguration(DIST_SYNC_L1_CACHE_NAME, getClusteredCfg(DIST_SYNC, true));
    cacheManager.defineConfiguration(DIST_ASYNC_L1_CACHE_NAME, getClusteredCfg(DIST_ASYNC, true));

    return cacheManager;
  }
  protected EmbeddedCacheManager createCacheManager() throws Exception {
    GlobalConfiguration globalConfiguration = GlobalConfiguration.getNonClusteredDefault();
    globalConfiguration.setExposeGlobalJmxStatistics(true);
    globalConfiguration.setMBeanServerLookup(PerThreadMBeanServerLookup.class.getName());
    globalConfiguration.setJmxDomain(JMX_DOMAIN);
    cacheManager = TestCacheManagerFactory.createCacheManagerEnforceJmxDomain(globalConfiguration);

    Configuration configuration = getDefaultClusteredConfig(Configuration.CacheMode.LOCAL);
    configuration.setExposeJmxStatistics(true);
    cacheManager.defineConfiguration("test", configuration);
    cache = cacheManager.getCache("test");
    advanced = cache.getAdvancedCache();
    mgmtInterceptor = getCacheObjectName(JMX_DOMAIN, "test(local)", "Statistics");

    threadMBeanServer = PerThreadMBeanServerLookup.getThreadMBeanServer();
    return cacheManager;
  }
Ejemplo n.º 5
0
 private static EmbeddedCacheManager createCacheManagerProgramatically() {
   return new DefaultCacheManager(
       GlobalConfiguration.getClusteredDefault()
           .fluent()
           .transport()
           .addProperty("configurationFile", "jgroups.xml")
           .build(),
       new Configuration().fluent().clustering().mode(REPL_SYNC).build());
 }
 @Override
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   Configuration cfg = new Configuration();
   cfg.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
   cfg.setUseReplQueue(true);
   cfg.setReplQueueClass(TestReplQueueClass.class.getName());
   EmbeddedCacheManager ecm =
       TestCacheManagerFactory.createCacheManager(GlobalConfiguration.getClusteredDefault(), cfg);
   return ecm;
 }
  @Before
  public void beforeTest() {
    File dbDir = new File("target/bdb");
    TestUtil.delete(dbDir);

    GlobalConfiguration global = new GlobalConfiguration();
    global =
        global.fluent().serialization().addAdvancedExternalizer(Schematic.externalizers()).build();

    BdbjeCacheStoreConfig berkleyConfig = new BdbjeCacheStoreConfig();
    berkleyConfig.setLocation(dbDir.getAbsolutePath());
    Configuration c = new Configuration();
    c =
        c.fluent()
            .invocationBatching()
            .transaction()
            .transactionManagerLookup(new DummyTransactionManagerLookup())
            .loaders()
            .addCacheLoader(berkleyConfig)
            .build();
    cm = TestCacheManagerFactory.createCacheManager(global, c, true);
    // Now create the SchematicDb ...
    db = Schematic.get(cm, "documents");
  }
Ejemplo n.º 8
0
  public static EmbeddedCacheManager createCacheContainer(
      boolean local, String passivationDir, boolean totalReplication, boolean purgeCacheLoader)
      throws Exception {
    Configuration.CacheMode mode =
        local ? CacheMode.LOCAL : (totalReplication ? CacheMode.REPL_SYNC : CacheMode.DIST_SYNC);
    GlobalConfiguration global = defaults.getGlobalConfiguration().clone();
    FluentGlobalConfiguration.TransportConfig transport = global.fluent().transport();
    if (mode.isClustered()) {
      transport
          .transportClass(JGroupsTransport.class)
          .addProperty("configurationFile", "jgroups-udp.xml");
    } else {
      transport.transportClass(null);
    }
    transport
        .clusterName("test-session")
        .strictPeerToPeer(false)
        .globalJmxStatistics()
        .jmxDomain("org.infinispan")
        .cacheManagerName("container" + containerIndex++)
        .allowDuplicateDomains(true);

    Configuration config = defaults.getDefaultConfiguration(mode).clone();
    FluentConfiguration fluent = config.fluent();
    fluent
        .syncCommitPhase(true)
        .syncRollbackPhase(true)
        .invocationBatching()
        .locking()
        .isolationLevel(IsolationLevel.REPEATABLE_READ)
        .transaction()
        .useSynchronization(false);

    if (passivationDir != null) {
      fluent
          .loaders()
          .passivation(true)
          .preload(!purgeCacheLoader)
          .addCacheLoader(
              new FileCacheStoreConfig()
                  .location(passivationDir)
                  .fetchPersistentState(mode.isReplicated())
                  .purgeOnStartup(purgeCacheLoader));
    }

    final EmbeddedCacheManager sessionContainer = new DefaultCacheManager(global, config, false);

    if (!mode.isDistributed()) {
      return sessionContainer;
    }
    // Otherwise, we need a separate cache manager for address -> jvm route mapping
    global = global.clone();
    global
        .fluent()
        .transport()
        .clusterName("test-jvmroute")
        .globalJmxStatistics()
        .cacheManagerName("container" + containerIndex++);

    config = defaults.getDefaultConfiguration(Configuration.CacheMode.REPL_SYNC).clone();
    config
        .fluent()
        .syncCommitPhase(true)
        .syncRollbackPhase(true)
        .invocationBatching()
        .locking()
        .isolationLevel(IsolationLevel.REPEATABLE_READ)
        .transaction()
        .useSynchronization(false);

    final EmbeddedCacheManager jvmRouteContainer = new DefaultCacheManager(global, config, false);

    return new EmbeddedCacheManager() {
      @Override
      public <K, V> Cache<K, V> getCache() {
        return sessionContainer.getCache();
      }

      @Override
      public <K, V> Cache<K, V> getCache(String cacheName) {
        return cacheName.equals(JVM_ROUTE_CACHE_NAME)
            ? jvmRouteContainer.<K, V>getCache()
            : sessionContainer.<K, V>getCache(cacheName);
      }

      @Override
      public void start() {
        jvmRouteContainer.start();
        try {
          sessionContainer.start();
        } catch (RuntimeException e) {
          jvmRouteContainer.stop();
          throw e;
        }
      }

      @Override
      public void stop() {
        try {
          sessionContainer.stop();
        } catch (Exception e) {
          log.warn(e.getMessage(), e);
        }
        jvmRouteContainer.stop();
      }

      @Override
      public void addListener(Object listener) {
        sessionContainer.addListener(listener);
      }

      @Override
      public void removeListener(Object listener) {
        sessionContainer.removeListener(listener);
      }

      @Override
      public Set<Object> getListeners() {
        return sessionContainer.getListeners();
      }

      @Override
      public Configuration defineConfiguration(
          String cacheName, Configuration configurationOverride) {
        return sessionContainer.defineConfiguration(cacheName, configurationOverride);
      }

      @Override
      public Configuration defineConfiguration(
          String cacheName, String templateCacheName, Configuration configurationOverride) {
        return sessionContainer.defineConfiguration(
            cacheName, templateCacheName, configurationOverride);
      }

      @Override
      public String getClusterName() {
        return sessionContainer.getClusterName();
      }

      @Override
      public List<Address> getMembers() {
        return sessionContainer.getMembers();
      }

      @Override
      public Address getAddress() {
        return sessionContainer.getAddress();
      }

      @Override
      public boolean isCoordinator() {
        return sessionContainer.isCoordinator();
      }

      @Override
      public ComponentStatus getStatus() {
        return sessionContainer.getStatus();
      }

      @Override
      public GlobalConfiguration getGlobalConfiguration() {
        return sessionContainer.getGlobalConfiguration();
      }

      @Override
      public Configuration getDefaultConfiguration() {
        return sessionContainer.getDefaultConfiguration();
      }

      @Override
      public Set<String> getCacheNames() {
        return sessionContainer.getCacheNames();
      }

      @Override
      public Address getCoordinator() {
        return sessionContainer.getCoordinator();
      }

      @Override
      public boolean isRunning(String cacheName) {
        return cacheName.equals(JVM_ROUTE_CACHE_NAME)
            ? jvmRouteContainer.isDefaultRunning()
            : sessionContainer.isRunning(cacheName);
      }

      @Override
      public boolean isDefaultRunning() {
        return sessionContainer.isDefaultRunning();
      }

      @Override
      public boolean cacheExists(String name) {
        return name.equals(JVM_ROUTE_CACHE_NAME)
            ? jvmRouteContainer.cacheExists(CacheContainer.DEFAULT_CACHE_NAME)
            : sessionContainer.cacheExists(name);
      }

      @Override
      public <K, V> Cache<K, V> getCache(String name, boolean start) {
        return name.equals(JVM_ROUTE_CACHE_NAME)
            ? jvmRouteContainer.<K, V>getCache(CacheContainer.DEFAULT_CACHE_NAME, start)
            : sessionContainer.<K, V>getCache(name, start);
      }

      @Override
      public void removeCache(String name) {
        if (name.equals(JVM_ROUTE_CACHE_NAME)) {
          jvmRouteContainer.removeCache(CacheContainer.DEFAULT_CACHE_NAME);
        } else {
          sessionContainer.removeCache(name);
        }
      }
    };
  }