• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ClusteringServiceConfigurationBuilder类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder的典型用法代码示例。如果您正苦于以下问题:Java ClusteringServiceConfigurationBuilder类的具体用法?Java ClusteringServiceConfigurationBuilder怎么用?Java ClusteringServiceConfigurationBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ClusteringServiceConfigurationBuilder类属于org.ehcache.clustered.client.config.builders包,在下文中一共展示了ClusteringServiceConfigurationBuilder类的40个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: CacheProvider

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Inject
public CacheProvider(Config config) {
    Objects.requireNonNull(config, Required.CONFIG.toString());
    
    if (config.isClusteredCached()) {
        CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder() 
                .with(ClusteringServiceConfigurationBuilder.cluster(URI.create(config.getCacheClusterUrl())) 
                .autoCreate());

        this.cacheManager = clusteredCacheManagerBuilder.build(true);
    } else {
        this.cacheManager = CacheManagerBuilder.newCacheManagerBuilder().build();
        this.cacheManager.init();
    }

    initApplicationCache();
    initAuthenticationCache();
    initRequestCache();
    initServerEventCache();
    initWebSocketCache();
}
 

开发者ID:svenkubiak,
项目名称:mangooio,
代码行数:22,
代码来源:CacheProvider.java

示例2: setUp

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
  UnitTestConnectionService.add(CLUSTER_URI,
    new UnitTestConnectionService.PassthroughServerBuilder()
      .resource("primary-server-resource", 8, MemoryUnit.MB)
      .resource("secondary-server-resource", 8, MemoryUnit.MB)
      .build());

  cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
    .with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER_URI).autoCreate()
      .defaultServerResource("primary-server-resource")
      .resourcePool("resource-pool-a", 2, MemoryUnit.MB, "secondary-server-resource")
      .resourcePool("resource-pool-b", 4, MemoryUnit.MB))
    .withCache("dedicated-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
      ResourcePoolsBuilder.newResourcePoolsBuilder()
        .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 4, MemoryUnit.MB))))
    .withCache("shared-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
      ResourcePoolsBuilder.newResourcePoolsBuilder()
        .with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool-a"))))
    .build();
  cacheManager.init();

  dedicatedCache = cacheManager.getCache("dedicated-cache", Long.class, String.class);
  sharedCache = cacheManager.getCache("shared-cache", Long.class, String.class);
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:26,
代码来源:ClusteredResourcePoolUpdationTest.java

示例3: clusteredCacheManagerWithServerSideConfigExample

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void clusteredCacheManagerWithServerSideConfigExample() throws Exception {
  // tag::clusteredCacheManagerWithServerSideConfigExample[]
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application")).autoCreate()
              .defaultServerResource("primary-server-resource") // <1>
              .resourcePool("resource-pool-a", 28, MemoryUnit.MB, "secondary-server-resource") // <2>
              .resourcePool("resource-pool-b", 32, MemoryUnit.MB)) // <3>
          .withCache("clustered-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, // <4>
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 32, MemoryUnit.MB)))) // <5>
          .withCache("shared-cache-1", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool-a")))) // <6>
          .withCache("shared-cache-2", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool-a")))); // <7>
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true); // <8>

  cacheManager.close();
  // end::clusteredCacheManagerWithServerSideConfigExample[]
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:24,
代码来源:GettingStarted.java

示例4: clusteredCacheManagerWithDynamicallyAddedCacheExample

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void clusteredCacheManagerWithDynamicallyAddedCacheExample() throws Exception {
  // tag::clusteredCacheManagerWithDynamicallyAddedCacheExample[]
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
          = CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
                  .autoCreate()
                  .defaultServerResource("primary-server-resource")
                  .resourcePool("resource-pool-a", 28, MemoryUnit.MB));
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  try {
    CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
            ResourcePoolsBuilder.newResourcePoolsBuilder()
                    .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB))).build();

    Cache<Long, String> cache = cacheManager.createCache("clustered-cache", config);

  } finally {
    cacheManager.close();
  }
  // end::clusteredCacheManagerWithDynamicallyAddedCacheExample[]
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:25,
代码来源:GettingStarted.java

示例5: testClusteredCacheWithLoaderWriter

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testClusteredCacheWithLoaderWriter() {

  final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
      = CacheManagerBuilder.newCacheManagerBuilder()
      .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
          .autoCreate());
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);

  try {
    CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.newResourcePoolsBuilder()
            .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB)))
        .withLoaderWriter(new TestLoaderWriter())
        .build();

    cacheManager.createCache("test", config);
    fail("IllegalStateException expected");
  } catch (IllegalStateException e){
    assertThat(e.getCause().getMessage(), is("CacheLoaderWriter is not supported with clustered tiers"));
  }
  cacheManager.close();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:24,
代码来源:UnSupportedCombinationsWIthClusteredCacheTest.java

示例6: testClusteredCacheWithXA

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testClusteredCacheWithXA() throws Exception {
  TransactionManagerServices.getConfiguration().setJournal("null");

  BitronixTransactionManager transactionManager =
      TransactionManagerServices.getTransactionManager();

  PersistentCacheManager persistentCacheManager = null;
  try {
    CacheManagerBuilder.newCacheManagerBuilder()
        .using(new LookupTransactionManagerProviderConfiguration(BitronixTransactionManagerLookup.class))
        .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application")).autoCreate())
        .withCache("xaCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
            ResourcePoolsBuilder.newResourcePoolsBuilder()
                .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB))
            )
                .add(new XAStoreConfiguration("xaCache"))
                .build()
        )
        .build(true);
  } catch (StateTransitionException e) {
    assertThat(e.getCause().getCause().getMessage(), is("Unsupported resource type : interface org.ehcache.clustered.client.config.DedicatedClusteredResourcePool"));
  }

  transactionManager.shutdown();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:27,
代码来源:UnSupportedCombinationsWIthClusteredCacheTest.java

示例7: testCreate

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testCreate() throws Exception {
  CacheConfigurationBuilder<Long, String> configBuilder =
      CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
          ResourcePoolsBuilder.newResourcePoolsBuilder()
              .with(ClusteredResourcePoolBuilder.clusteredShared("primary")));
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService service = new DefaultClusteringService(configuration);

  PersistableResourceService.PersistenceSpaceIdentifier spaceIdentifier = service.getPersistenceSpaceIdentifier("cacheAlias", configBuilder
      .build());
  assertThat(spaceIdentifier, instanceOf(ClusteredCacheIdentifier.class));
  assertThat(((ClusteredCacheIdentifier) spaceIdentifier).getId(), is("cacheAlias"));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:18,
代码来源:DefaultClusteringServiceTest.java

示例8: testStartStopAutoCreate

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testStartStopAutoCreate() throws Exception {
  URI clusterUri = URI.create(CLUSTER_URI_BASE + "my-application");
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(clusterUri)
          .autoCreate()
          .build();
  DefaultClusteringService service = new DefaultClusteringService(configuration);
  assertThat(service.isConnected(), is(false));
  service.start(null);
  assertThat(service.isConnected(), is(true));

  assertThat(UnitTestConnectionService.getConnectionProperties(clusterUri).size(), is(1));
  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));
  ObservableEhcacheActiveEntity activeEntity = activeEntities.get(0);
  assertThat(activeEntity.getDefaultServerResource(), is(nullValue()));
  assertThat(activeEntity.getSharedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getDedicatedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getConnectedClients().size(), is(1));

  service.stop();

  assertThat(activeEntity.getConnectedClients().size(), is(0));
  assertThat(UnitTestConnectionService.getConnectionProperties(clusterUri).size(), is(0));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:27,
代码来源:DefaultClusteringServiceTest.java

示例9: testStartStopNoAutoCreate

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testStartStopNoAutoCreate() throws Exception {
  URI clusterUri = URI.create(CLUSTER_URI_BASE + "my-application");
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(clusterUri)
          .build();
  DefaultClusteringService service = new DefaultClusteringService(configuration);
  try {
    service.start(null);
    fail("Expecting IllegalStateException");
  } catch (IllegalStateException e) {
    assertThat(e.getCause(), is(instanceOf(EntityNotFoundException.class)));
  }

  assertThat(UnitTestConnectionService.getConnectionProperties(clusterUri).size(), is(0));

  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(0));

  service.stop();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:22,
代码来源:DefaultClusteringServiceTest.java

示例10: testStartForMaintenanceAutoStart

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testStartForMaintenanceAutoStart() throws Exception {
  URI clusterUri = URI.create(CLUSTER_URI_BASE + "my-application");
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(clusterUri)
          .autoCreate()
          .build();
  DefaultClusteringService service = new DefaultClusteringService(configuration);
  assertThat(service.isConnected(), is(false));
  service.startForMaintenance(null, MaintainableService.MaintenanceScope.CACHE_MANAGER);
  assertThat(service.isConnected(), is(true));

  assertThat(UnitTestConnectionService.getConnectionProperties(clusterUri).size(), is(1));
  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(0));

  // startForMaintenance does **not** create an ClusterTierManagerActiveEntity

  service.stop();

  assertThat(UnitTestConnectionService.getConnectionProperties(clusterUri).size(), is(0));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:23,
代码来源:DefaultClusteringServiceTest.java

示例11: testStartForMaintenanceInterlock

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testStartForMaintenanceInterlock() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService maintenanceService1 = new DefaultClusteringService(configuration);
  maintenanceService1.startForMaintenance(null, MaintainableService.MaintenanceScope.CACHE_MANAGER);

  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(0));

  DefaultClusteringService maintenanceService2 = new DefaultClusteringService(configuration);
  try {
    maintenanceService2.startForMaintenance(null, MaintainableService.MaintenanceScope.CACHE_MANAGER);
    fail("Expecting IllegalStateException");
  } catch (IllegalStateException e) {
    assertThat(e.getMessage(), containsString(" acquire cluster-wide "));
  }

  maintenanceService1.stop();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:23,
代码来源:DefaultClusteringServiceTest.java

示例12: testStartForMaintenanceSequence

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testStartForMaintenanceSequence() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService maintenanceService1 = new DefaultClusteringService(configuration);
  maintenanceService1.startForMaintenance(null, MaintainableService.MaintenanceScope.CACHE_MANAGER);
  maintenanceService1.stop();

  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(0));

  DefaultClusteringService maintenanceService2 = new DefaultClusteringService(configuration);
  maintenanceService2.startForMaintenance(null, MaintainableService.MaintenanceScope.CACHE_MANAGER);
  maintenanceService2.stop();

  activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(0));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:21,
代码来源:DefaultClusteringServiceTest.java

示例13: testDestroyCantBeCalledIfStopped

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testDestroyCantBeCalledIfStopped() throws Exception {
  String cacheAlias = "cacheAlias";
  String targetResource = "serverResource2";
  ClusteringServiceConfiguration configuration =
    ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
      .autoCreate()
      .defaultServerResource("defaultResource")
      .build();
  DefaultClusteringService creationService = new DefaultClusteringService(configuration);

  expectedException.expect(IllegalStateException.class);
  expectedException.expectMessage(endsWith(" should be started to call destroy"));

  creationService.destroy(cacheAlias);
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:17,
代码来源:DefaultClusteringServiceTest.java

示例14: content

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
private Runnable content(final CountDownLatch latch) {
  return () -> {
    try {
      CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder()
        .with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER_URI).autoCreate()
          .defaultServerResource("primary-server-resource")
          .resourcePool("resource-pool-a", 32, MemoryUnit.MB)
          .resourcePool("resource-pool-b", 32, MemoryUnit.MB, "secondary-server-resource"))
        .withCache(CACHE_NAME, CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
          ResourcePoolsBuilder.newResourcePoolsBuilder()
            .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 32, MemoryUnit.MB)))
          .add(new ClusteredStoreConfiguration(Consistency.STRONG)));

      latch.countDown();
      try {
        latch.await();
      } catch (InterruptedException e) {
        // continue
      }

      clusteredCacheManagerBuilder.build(true);
    } catch (Throwable t) {
      exception.compareAndSet(null, t); // only keep the first exception
    }
  };
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:27,
代码来源:ClusteredConcurrencyTest.java

示例15: testTerminationBeforeCacheManagerClose

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
/**
 * Tests if {@link CacheManager#close()} blocks if the client/server connection is disconnected.
 */
@Test
public void testTerminationBeforeCacheManagerClose() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
      .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
          .autoCreate()
          .defaultServerResource("primary-server-resource"));
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  cluster.getClusterControl().terminateAllServers();

  new TimeLimitedTask<Void>(2, TimeUnit.SECONDS) {
    @Override
    Void runTask() throws Exception {
      cacheManager.close();
      return null;
    }
  }.run();

  // TODO: Add assertion for successful CacheManager.init() following cluster restart (https://github.com/Terracotta-OSS/galvan/issues/30)
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:26,
代码来源:TerminatedServerTest.java

示例16: testTerminationBeforeCacheManagerCloseWithCaches

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
@Ignore("Need to decide if we close cache entity in a daemon thread")
public void testTerminationBeforeCacheManagerCloseWithCaches() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
                  .autoCreate()
                  .defaultServerResource("primary-server-resource"))
          .withCache("simple-cache",
              CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
                  ResourcePoolsBuilder.newResourcePoolsBuilder()
                      .with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  cluster.getClusterControl().terminateAllServers();

  new TimeLimitedTask<Void>(5, TimeUnit.SECONDS) {
    @Override
    Void runTask() throws Exception {
      cacheManager.close();
      return null;
    }
  }.run();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:26,
代码来源:TerminatedServerTest.java

示例17: testTerminationBeforeCacheManagerRetrieve

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testTerminationBeforeCacheManagerRetrieve() throws Exception {
  // Close all servers
  cluster.getClusterControl().terminateAllServers();

  // Try to retrieve an entity (that doesn't exist but I don't care... the server is not running anyway
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
                  .timeouts(TimeoutsBuilder.timeouts().connection(Duration.ofSeconds(1))) // Need a connection timeout shorter than the TimeLimitedTask timeout
                  .expecting()
                  .defaultServerResource("primary-server-resource"));
  final PersistentCacheManager cacheManagerExisting = clusteredCacheManagerBuilder.build(false);

  // Base test time limit on observed TRANSPORT_HANDSHAKE_SYNACK_TIMEOUT; might not have been set in time to be effective
  long synackTimeout = TimeUnit.MILLISECONDS.toSeconds(ClientMessageTransport.TRANSPORT_HANDSHAKE_SYNACK_TIMEOUT);
  assertExceptionOccurred(StateTransitionException.class,
    new TimeLimitedTask<Void>(3 + synackTimeout, TimeUnit.SECONDS) {
      @Override
      Void runTask() {
        cacheManagerExisting.init();
        return null;
      }
    })
    .withRootCauseInstanceOf(TimeoutException.class);
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:27,
代码来源:TerminatedServerTest.java

示例18: testTerminationBeforeCacheCreate

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
@Ignore("Multi entity means this is now a blocking operation")
public void testTerminationBeforeCacheCreate() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
                  .autoCreate()
                  .defaultServerResource("primary-server-resource"));
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  cluster.getClusterControl().terminateAllServers();

  assertExceptionOccurred(IllegalStateException.class,
    new TimeLimitedTask<Cache<Long, String>>(5, TimeUnit.SECONDS) {
      @Override
      Cache<Long, String> runTask() throws Exception {
        return cacheManager.createCache("simple-cache",
            CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
                ResourcePoolsBuilder.newResourcePoolsBuilder()
                    .with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
      }
    })
    .withRootCauseInstanceOf(TimeoutException.class);
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:26,
代码来源:TerminatedServerTest.java

示例19: testTerminationBeforeCacheRemove

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
@Ignore("Need to decide if we close cache entity in a daemon thread")
public void testTerminationBeforeCacheRemove() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
                  .autoCreate()
                  .defaultServerResource("primary-server-resource"))
          .withCache("simple-cache",
              CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
                  ResourcePoolsBuilder.newResourcePoolsBuilder()
                      .with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  cluster.getClusterControl().terminateAllServers();

  new TimeLimitedTask<Void>(5, TimeUnit.SECONDS) {
    @Override
    Void runTask() throws Exception {
      // CacheManager.removeCache silently "fails" when a timeout is recognized
      cacheManager.removeCache("simple-cache");
      return null;
    }
  }.run();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:27,
代码来源:TerminatedServerTest.java

示例20: startServers

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Before
public void startServers() throws Exception {
  CLUSTER.getClusterControl().startAllServers();
  CLUSTER.getClusterControl().waitForActive();
  CLUSTER.getClusterControl().waitForRunningPassivesInStandby();
  final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
      = CacheManagerBuilder.newCacheManagerBuilder()
      .with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER.getConnectionURI().resolve("/crud-cm-replication"))
          .autoCreate()
          .defaultServerResource("primary-server-resource"));
  CACHE_MANAGER1 = clusteredCacheManagerBuilder.build(true);
  CACHE_MANAGER2 = clusteredCacheManagerBuilder.build(true);
  CacheConfiguration<Long, BlobValue> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, BlobValue.class,
      ResourcePoolsBuilder.newResourcePoolsBuilder().heap(500, EntryUnit.ENTRIES)
          .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 4, MemoryUnit.MB)))
      .add(ClusteredStoreConfigurationBuilder.withConsistency(cacheConsistency))
      .build();

  CACHE1 = CACHE_MANAGER1.createCache("clustered-cache", config);
  CACHE2 = CACHE_MANAGER2.createCache("clustered-cache", config);
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:22,
代码来源:BasicClusteredCacheOpsReplicationWithMultipleClientsTest.java

示例21: startServers

点赞 3

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Before
public void startServers() throws Exception {
  CLUSTER.getClusterControl().startAllServers();
  CLUSTER.getClusterControl().waitForActive();
  CLUSTER.getClusterControl().waitForRunningPassivesInStandby();
  final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
      = CacheManagerBuilder.newCacheManagerBuilder()
      .with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER.getConnectionURI().resolve("/cm-replication"))
          .timeouts(TimeoutsBuilder.timeouts() // we need to give some time for the failover to occur
              .read(Duration.ofMinutes(1))
              .write(Duration.ofMinutes(1)))
          .autoCreate()
          .defaultServerResource("primary-server-resource"));
  CACHE_MANAGER = clusteredCacheManagerBuilder.build(true);
  CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
      ResourcePoolsBuilder.newResourcePoolsBuilder().heap(100, EntryUnit.ENTRIES)
          .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 4, MemoryUnit.MB)))
      .add(ClusteredStoreConfigurationBuilder.withConsistency(cacheConsistency))
      .build();

  CACHE1 = CACHE_MANAGER.createCache("clustered-cache", config);
  CACHE2 = CACHE_MANAGER.createCache("another-cache", config);
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:24,
代码来源:BasicClusteredCacheOpsReplicationTest.java

示例22: createClusteredCacheManager

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
private CacheManager createClusteredCacheManager() {
    JHipsterProperties.Cache.Ehcache.Cluster clusterProperties = properties.getCache().getEhcache().getCluster();
    URI clusterUri = clusterProperties.getUri();
    boolean autoCreate = clusterProperties.isAutoCreate();
    long clusteredCacheSize = clusterProperties.getSizeInMb();
    Consistency consistency = clusterProperties.getConsistency();

    long heapCacheSize = properties.getCache().getEhcache().getSize();
    long ttl = properties.getCache().getEhcache().getTimeToLiveSeconds();

    ClusteringServiceConfigurationBuilder clusteringServiceConfigurationBuilder = ClusteringServiceConfigurationBuilder.cluster(clusterUri);
    ServerSideConfigurationBuilder serverSideConfigurationBuilder = (autoCreate ? clusteringServiceConfigurationBuilder.autoCreate() : clusteringServiceConfigurationBuilder.expecting())
        .defaultServerResource("primary-server-resource");

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
        .newCacheConfigurationBuilder(Object.class, Object.class, ResourcePoolsBuilder
            .newResourcePoolsBuilder()
            .heap(heapCacheSize)
            .with(ClusteredResourcePoolBuilder.clusteredDedicated(clusteredCacheSize, MemoryUnit.MB)))
        .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
        .add(new ClusteredStoreConfiguration(consistency)).build();

    Map<String, org.ehcache.config.CacheConfiguration<?, ?>> caches = createCacheConfigurations(cacheConfiguration);

    EhcacheCachingProvider provider = getCachingProvider();
    DefaultConfiguration configuration = new DefaultConfiguration(caches, provider.getDefaultClassLoader(), serverSideConfigurationBuilder.build());
    return provider.getCacheManager(provider.getDefaultURI(), configuration);
}
 

开发者ID:ehcache,
项目名称:ehcache3-samples,
代码行数:29,
代码来源:CacheConfiguration.java

示例23: clusteredCacheManagerExample

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void clusteredCacheManagerExample() throws Exception {
  // tag::clusteredCacheManagerExample[]
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder() // <1>
          .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application")) // <2>
              .autoCreate()); // <3>
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true); // <4>

  cacheManager.close(); // <5>
  // end::clusteredCacheManagerExample[]
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:13,
代码来源:GettingStarted.java

示例24: explicitConsistencyConfiguration

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void explicitConsistencyConfiguration() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
          = CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
                  .autoCreate()
                  .defaultServerResource("primary-server-resource")
                  .resourcePool("resource-pool-a", 32, MemoryUnit.MB));
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  try {
    // tag::clusteredCacheConsistency[]
    CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
            ResourcePoolsBuilder.newResourcePoolsBuilder()
                    .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB)))
        .add(ClusteredStoreConfigurationBuilder.withConsistency(Consistency.STRONG)) // <1>
        .build();

    Cache<Long, String> cache = cacheManager.createCache("clustered-cache", config);
    cache.put(42L, "All you need to know!"); // <2>

    // end::clusteredCacheConsistency[]
  } finally {
    cacheManager.close();
  }
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:28,
代码来源:GettingStarted.java

示例25: clusteredCacheTieredExample

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void clusteredCacheTieredExample() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
      = CacheManagerBuilder.newCacheManagerBuilder()
      .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
          .autoCreate()
          .defaultServerResource("primary-server-resource")
          .resourcePool("resource-pool-a", 32, MemoryUnit.MB));
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  try {
    // tag::clusteredCacheTieredExample[]
    CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.newResourcePoolsBuilder()
            .heap(2, MemoryUnit.MB) // <1>
            .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB))) // <2>
        .add(ClusteredStoreConfigurationBuilder.withConsistency(Consistency.STRONG))
        .build();

    Cache<Long, String> cache = cacheManager.createCache("clustered-cache-tiered", config);
    cache.put(42L, "All you need to know!");

    // end::clusteredCacheTieredExample[]
  } finally {
    cacheManager.close();
  }
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:29,
代码来源:GettingStarted.java

示例26: clusteredCacheManagerLifecycleExamples

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void clusteredCacheManagerLifecycleExamples() throws Exception {
  // tag::clusteredCacheManagerLifecycle[]
  CacheManagerBuilder<PersistentCacheManager> autoCreate = CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
              .autoCreate() // <1>
              .resourcePool("resource-pool", 32, MemoryUnit.MB, "primary-server-resource"))
          .withCache("clustered-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool"))));

  CacheManagerBuilder<PersistentCacheManager> expecting = CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
              .expecting() // <2>
              .resourcePool("resource-pool", 32, MemoryUnit.MB, "primary-server-resource"))
          .withCache("clustered-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool"))));

  CacheManagerBuilder<PersistentCacheManager> configless = CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application")))
              // <3>
          .withCache("clustered-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool"))));
  // end::clusteredCacheManagerLifecycle[]

  autoCreate.build(true).close();
  expecting.build(true).close();
  configless.build(true).close();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:32,
代码来源:GettingStarted.java

示例27: testClusteredCacheWithEventListeners

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testClusteredCacheWithEventListeners() {

  CacheEventListenerConfigurationBuilder cacheEventListenerConfiguration = CacheEventListenerConfigurationBuilder
      .newEventListenerConfiguration(new TestEventListener(), EventType.CREATED, EventType.UPDATED) // <1>
      .unordered().asynchronous(); // <2>

  final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder
      = CacheManagerBuilder.newCacheManagerBuilder()
      .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
          .autoCreate());
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);

  try {
    CacheConfiguration<Long, String> config = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.newResourcePoolsBuilder()
            .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 8, MemoryUnit.MB)))
        .add(cacheEventListenerConfiguration)
        .build();

    cacheManager.createCache("test", config);
    fail("IllegalStateException expected");
  } catch (IllegalStateException e){
    assertThat(e.getCause().getMessage(), is("CacheEventListener is not supported with clustered tiers"));
  }
  cacheManager.close();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:28,
代码来源:UnSupportedCombinationsWIthClusteredCacheTest.java

示例28: testHandlesResourceType

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testHandlesResourceType() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService service = new DefaultClusteringService(configuration);

  assertThat(service.handlesResourceType(DISK), is(false));
  assertThat(service.handlesResourceType(HEAP), is(false));
  assertThat(service.handlesResourceType(OFFHEAP), is(false));
  assertThat(service.handlesResourceType(DEDICATED), is(true));
  assertThat(service.handlesResourceType(SHARED), is(true));
  assertThat(service.handlesResourceType(new ClusteredResourceType<ClusteredResourcePool>() {
    @Override
    public Class<ClusteredResourcePool> getResourcePoolClass() {
      throw new UnsupportedOperationException(".getResourcePoolClass not implemented");
    }

    @Override
    public boolean isPersistable() {
      throw new UnsupportedOperationException(".isPersistable not implemented");
    }

    @Override
    public boolean requiresSerialization() {
      throw new UnsupportedOperationException(".requiresSerialization not implemented");
    }

    @Override
    public int getTierHeight() {
      throw new UnsupportedOperationException(".getTierHeight not implemented");
    }
  }), is(false));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:36,
代码来源:DefaultClusteringServiceTest.java

示例29: testGetPersistenceSpaceIdentifier

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testGetPersistenceSpaceIdentifier() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService service = new DefaultClusteringService(configuration);

  PersistableResourceService.PersistenceSpaceIdentifier spaceIdentifier = service.getPersistenceSpaceIdentifier("cacheAlias", null);
  assertThat(spaceIdentifier, is(instanceOf(ClusteredCacheIdentifier.class)));
  assertThat(((ClusteredCacheIdentifier)spaceIdentifier).getId(), is("cacheAlias"));
  assertThat(service.getPersistenceSpaceIdentifier("cacheAlias", null), sameInstance(spaceIdentifier));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:14,
代码来源:DefaultClusteringServiceTest.java

示例30: testStartStopAutoCreateTwiceA

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
/**
 * Ensures a second client specifying auto-create can start {@link DefaultClusteringService} while the
 * creator is still connected.
 */
@Test
public void testStartStopAutoCreateTwiceA() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService firstService = new DefaultClusteringService(configuration);
  firstService.start(null);

  DefaultClusteringService secondService = new DefaultClusteringService(configuration);
  secondService.start(null);

  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));
  ObservableEhcacheActiveEntity activeEntity = activeEntities.get(0);
  assertThat(activeEntity.getDefaultServerResource(), is(nullValue()));
  assertThat(activeEntity.getSharedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getDedicatedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getConnectedClients().size(), is(2));

  firstService.stop();
  assertThat(activeEntity.getConnectedClients().size(), is(1));

  secondService.stop();
  assertThat(activeEntity.getConnectedClients().size(), is(0));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:31,
代码来源:DefaultClusteringServiceTest.java

示例31: testStartStopAutoCreateTwiceB

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
/**
 * Ensures a second client specifying auto-create can start {@link DefaultClusteringService} while the
 * creator is not connected.
 */
@Test
public void testStartStopAutoCreateTwiceB() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService firstService = new DefaultClusteringService(configuration);
  firstService.start(null);
  firstService.stop();

  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));

  DefaultClusteringService secondService = new DefaultClusteringService(configuration);
  secondService.start(null);

  activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));
  ObservableEhcacheActiveEntity activeEntity = activeEntities.get(0);
  assertThat(activeEntity.getDefaultServerResource(), is(nullValue()));
  assertThat(activeEntity.getSharedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getDedicatedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getConnectedClients().size(), is(1));

  secondService.stop();
  assertThat(activeEntity.getConnectedClients().size(), is(0));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:32,
代码来源:DefaultClusteringServiceTest.java

示例32: testStartForMaintenanceOtherAutoCreate

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testStartForMaintenanceOtherAutoCreate() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService createService = new DefaultClusteringService(configuration);
  createService.start(null);

  DefaultClusteringService maintenanceService = new DefaultClusteringService(configuration);
  try {
    maintenanceService.startForMaintenance(null, MaintainableService.MaintenanceScope.CACHE_MANAGER);
    fail("Expecting IllegalStateException");
  } catch (IllegalStateException e) {
    // Expected
  }

  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));
  ObservableEhcacheActiveEntity activeEntity = activeEntities.get(0);
  assertThat(activeEntity.getDefaultServerResource(), is(nullValue()));
  assertThat(activeEntity.getSharedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getDedicatedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getConnectedClients().size(), is(1));

  createService.stop();
  assertThat(activeEntity.getConnectedClients().size(), is(0));

  maintenanceService.stop();
  assertThat(activeEntity.getConnectedClients().size(), is(0));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:32,
代码来源:DefaultClusteringServiceTest.java

示例33: testStartForMaintenanceOtherCreated

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testStartForMaintenanceOtherCreated() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .build();
  DefaultClusteringService createService = new DefaultClusteringService(configuration);
  createService.start(null);
  createService.stop();

  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));
  ObservableEhcacheActiveEntity activeEntity = activeEntities.get(0);

  assertThat(activeEntity.getConnectedClients().size(), is(0));

  DefaultClusteringService maintenanceService = new DefaultClusteringService(configuration);
  maintenanceService.startForMaintenance(null, MaintainableService.MaintenanceScope.CACHE_MANAGER);

  activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));
  activeEntity = activeEntities.get(0);
  assertThat(activeEntity.getDefaultServerResource(), is(nullValue()));
  assertThat(activeEntity.getSharedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getDedicatedResourcePoolIds(), is(Matchers.<String>empty()));

  // startForMaintenance does **not** establish a link with the ClusterTierManagerActiveEntity
  assertThat(activeEntity.getConnectedClients().size(), is(0));

  maintenanceService.stop();
  assertThat(activeEntity.getConnectedClients().size(), is(0));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:33,
代码来源:DefaultClusteringServiceTest.java

示例34: testBasicConfiguration

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testBasicConfiguration() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
          .autoCreate()
          .defaultServerResource("defaultResource")
          .resourcePool("sharedPrimary", 2, MemoryUnit.MB, "serverResource1")
          .resourcePool("sharedSecondary", 2, MemoryUnit.MB, "serverResource2")
          .resourcePool("sharedTertiary", 4, MemoryUnit.MB)
          .build();
  DefaultClusteringService createService = new DefaultClusteringService(configuration);
  createService.start(null);

  List<ObservableEhcacheActiveEntity> activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));
  ObservableEhcacheActiveEntity activeEntity = activeEntities.get(0);
  assertThat(activeEntity.getDefaultServerResource(), is("defaultResource"));
  assertThat(activeEntity.getSharedResourcePoolIds(), containsInAnyOrder("sharedPrimary", "sharedSecondary", "sharedTertiary"));
  assertThat(activeEntity.getDedicatedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getConnectedClients().size(), is(1));
  assertThat(activeEntity.getStores(), is(Matchers.<String>empty()));

  createService.stop();

  activeEntities = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntities.size(), is(1));
  activeEntity = activeEntities.get(0);
  assertThat(activeEntity.getDefaultServerResource(), is("defaultResource"));
  assertThat(activeEntity.getSharedResourcePoolIds(), containsInAnyOrder("sharedPrimary", "sharedSecondary", "sharedTertiary"));
  assertThat(activeEntity.getDedicatedResourcePoolIds(), is(Matchers.<String>empty()));
  assertThat(activeEntity.getConnectedClients().size(), is(0));
  assertThat(activeEntity.getStores(), is(Matchers.<String>empty()));
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:34,
代码来源:DefaultClusteringServiceTest.java

示例35: testStartNoAutoCreateThenAutoCreate

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testStartNoAutoCreateThenAutoCreate() throws Exception {
  ClusteringServiceConfiguration creationConfigBad =
  ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
      .expecting()
      .defaultServerResource("defaultResource")
      .resourcePool("sharedPrimary", 2, MemoryUnit.MB, "serverResource1")
      .resourcePool("sharedSecondary", 2, MemoryUnit.MB, "serverResource2")
      .resourcePool("sharedTertiary", 4, MemoryUnit.MB)
      .build();
  DefaultClusteringService creationServiceBad = new DefaultClusteringService(creationConfigBad);

  try {
    creationServiceBad.start(null);
    fail("Expecting IllegalStateException");
  } catch (IllegalStateException e) {
    // Expected
  }

  List<ObservableEhcacheActiveEntity> activeEntitiesBad = observableEhcacheServerEntityService.getServedActiveEntities();
  assertThat(activeEntitiesBad.size(), is(0));

  ClusteringServiceConfiguration creationConfigGood =
  ClusteringServiceConfigurationBuilder.cluster(URI.create(CLUSTER_URI_BASE + "my-application"))
      .autoCreate()
      .defaultServerResource("defaultResource")
      .resourcePool("sharedPrimary", 2, MemoryUnit.MB, "serverResource1")
      .resourcePool("sharedSecondary", 2, MemoryUnit.MB, "serverResource2")
      .resourcePool("sharedTertiary", 4, MemoryUnit.MB)
      .build();
  DefaultClusteringService creationServiceGood = new DefaultClusteringService(creationConfigGood);

  creationServiceGood.start(null);
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:35,
代码来源:DefaultClusteringServiceTest.java

示例36: testClusteredStateRepositoryReplication

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testClusteredStateRepositoryReplication() throws Exception {
  ClusteringServiceConfiguration configuration =
      ClusteringServiceConfigurationBuilder.cluster(URI.create(STRIPE_URI))
          .autoCreate()
          .build();

  ClusteringService service = new ClusteringServiceFactory().create(configuration);

  service.start(null);

  BaseCacheConfiguration<Long, String> config = new BaseCacheConfiguration<>(Long.class, String.class, noAdvice(), null, noExpiration(),
    newResourcePoolsBuilder().with(clusteredDedicated("test", 2, org.ehcache.config.units.MemoryUnit.MB)).build());
  ClusteringService.ClusteredCacheIdentifier spaceIdentifier = (ClusteringService.ClusteredCacheIdentifier) service.getPersistenceSpaceIdentifier("test",
    config);

  ServerStoreProxy serverStoreProxy = service.getServerStoreProxy(spaceIdentifier, new StoreConfigurationImpl<>(config, 1, null, null), Consistency.STRONG, mock(ServerCallback.class));

  SimpleClusterTierClientEntity clientEntity = getEntity(serverStoreProxy);

  ClusterStateRepository stateRepository = new ClusterStateRepository(spaceIdentifier, "test", clientEntity);

  StateHolder<String, String> testHolder = stateRepository.getPersistentStateHolder("testHolder", String.class, String.class);
  testHolder.putIfAbsent("One", "One");
  testHolder.putIfAbsent("Two", "Two");

  clusterControl.terminateActive();
  clusterControl.waitForActive();

  assertThat(testHolder.get("One"), is("One"));
  assertThat(testHolder.get("Two"), is("Two"));

  service.stop();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:35,
代码来源:ClusterStateRepositoryReplicationTest.java

示例37: testTerminationBeforeCacheManagerDestroyCache

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
@Ignore("In multi entity, destroy cache is a blocking operation")
public void testTerminationBeforeCacheManagerDestroyCache() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
                  .autoCreate()
                  .defaultServerResource("primary-server-resource"))
          .withCache("simple-cache",
              CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
                  ResourcePoolsBuilder.newResourcePoolsBuilder()
                      .with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  final Cache<Long, String> cache = cacheManager.getCache("simple-cache", Long.class, String.class);
  cache.put(1L, "un");
  cache.put(2L, "deux");
  cache.put(3L, "trois");

  cacheManager.removeCache("simple-cache");

  cluster.getClusterControl().terminateAllServers();

  assertExceptionOccurred(CachePersistenceException.class,
    new TimeLimitedTask<Void>(5, TimeUnit.SECONDS) {
      @Override
      Void runTask() throws Exception {
        cacheManager.destroyCache("simple-cache");
        return null;
      }
    })
    .withRootCauseInstanceOf(TimeoutException.class);
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:35,
代码来源:TerminatedServerTest.java

示例38: testTerminationThenGet

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testTerminationThenGet() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
              .timeouts(TimeoutsBuilder.timeouts().read(Duration.of(1, ChronoUnit.SECONDS)).build())
              .autoCreate()
              .defaultServerResource("primary-server-resource"))
      .withCache("simple-cache",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  final Cache<Long, String> cache = cacheManager.getCache("simple-cache", Long.class, String.class);
  cache.put(1L, "un");
  cache.put(2L, "deux");
  cache.put(3L, "trois");

  assertThat(cache.get(2L)).isNotNull();

  cluster.getClusterControl().terminateAllServers();

  String value = new TimeLimitedTask<String>(5, TimeUnit.SECONDS) {
    @Override
    String runTask() throws Exception {
      return cache.get(2L);
    }
  }.run();

  assertThat(value).isNull();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:34,
代码来源:TerminatedServerTest.java

示例39: testTerminationThenContainsKey

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Test
public void testTerminationThenContainsKey() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
              .timeouts(TimeoutsBuilder.timeouts().read(Duration.of(1, ChronoUnit.SECONDS)).build())
              .autoCreate()
              .defaultServerResource("primary-server-resource"))
      .withCache("simple-cache",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  final Cache<Long, String> cache = cacheManager.getCache("simple-cache", Long.class, String.class);
  cache.put(1L, "un");
  cache.put(2L, "deux");
  cache.put(3L, "trois");

  assertThat(cache.containsKey(2L)).isTrue();

  cluster.getClusterControl().terminateAllServers();

  boolean value = new TimeLimitedTask<Boolean>(5, TimeUnit.SECONDS) {
    @Override
    Boolean runTask() throws Exception {
      return cache.containsKey(2L);
    }
  }.run();

  assertThat(value).isFalse();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:34,
代码来源:TerminatedServerTest.java

示例40: testTerminationThenIterator

点赞 2

import org.ehcache.clustered.client.config.builders.ClusteringServiceConfigurationBuilder; //导入依赖的package包/类
@Ignore("ClusteredStore.iterator() is not implemented")
@Test
public void testTerminationThenIterator() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      CacheManagerBuilder.newCacheManagerBuilder()
          .with(ClusteringServiceConfigurationBuilder.cluster(cluster.getConnectionURI().resolve("/MyCacheManagerName"))
            .timeouts(TimeoutsBuilder.timeouts().read(Duration.of(1, ChronoUnit.SECONDS)).build())
              .autoCreate()
              .defaultServerResource("primary-server-resource"))
      .withCache("simple-cache",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              ResourcePoolsBuilder.newResourcePoolsBuilder()
                  .with(ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB))));
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(false);
  cacheManager.init();

  final Cache<Long, String> cache = cacheManager.getCache("simple-cache", Long.class, String.class);
  cache.put(1L, "un");
  cache.put(2L, "deux");
  cache.put(3L, "trois");

  cluster.getClusterControl().terminateAllServers();

  Iterator<Cache.Entry<Long, String>> value = new TimeLimitedTask<Iterator<Cache.Entry<Long,String>>>(5, TimeUnit.SECONDS) {
    @Override
    Iterator<Cache.Entry<Long, String>> runTask() throws Exception {
      return cache.iterator();
    }
  }.run();

  assertThat(value.hasNext()).isFalse();
}
 

开发者ID:ehcache,
项目名称:ehcache3,
代码行数:33,
代码来源:TerminatedServerTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)