Java Code Examples for org.ehcache.clustered.client.config.ClusteredResourceType

Following code examples demonstrate how to use org.ehcache.clustered.client.config.ClusteredResourceTypefrom ehcache. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.ehcache.clustered.client.config.ClusteredResourceTypeand various code implementation of this class.

  public void dedicated2Arg() throws Exception {
    ResourcePool pool = ClusteredResourcePoolBuilder.clusteredDedicated(16, MemoryUnit.GB);
    assertThat(pool, is(instanceOf(DedicatedClusteredResourcePool.class)));
    assertThat(pool.getType(), Matchers.<ResourceType>is(ClusteredResourceType.Types.DEDICATED));
    assertThat(pool.isPersistent(), is(true));
    assertThat(((DedicatedClusteredResourcePool)pool).getSize(), is(16L));
    assertThat(((DedicatedClusteredResourcePool)pool).getUnit(), is(MemoryUnit.GB));
    assertThat(((DedicatedClusteredResourcePool)pool).getFromResource(), is(nullValue()));
  } 


  public void dedicated3Arg() throws Exception {
    ResourcePool pool = ClusteredResourcePoolBuilder.clusteredDedicated("resourceId", 16, MemoryUnit.GB);
    assertThat(pool, is(instanceOf(DedicatedClusteredResourcePool.class)));
    assertThat(pool.getType(), Matchers.<ResourceType>is(ClusteredResourceType.Types.DEDICATED));
    assertThat(pool.isPersistent(), is(true));
    assertThat(((DedicatedClusteredResourcePool)pool).getSize(), is(16L));
    assertThat(((DedicatedClusteredResourcePool)pool).getUnit(), is(MemoryUnit.GB));
    assertThat(((DedicatedClusteredResourcePool)pool).getFromResource(), is("resourceId"));
  } 

  public void shared() throws Exception {
    ResourcePool pool = ClusteredResourcePoolBuilder.clusteredShared("resourceId");
    assertThat(pool, is(instanceOf(SharedClusteredResourcePool.class)));
    assertThat(pool.getType(), Matchers.<ResourceType>is(ClusteredResourceType.Types.SHARED));
    assertThat(pool.isPersistent(), is(true));
    assertThat(((SharedClusteredResourcePool)pool).getSharedResourcePool(), is("resourceId"));
  } 

  public void dedicated3ArgFromNull() throws Exception {
    ResourcePool pool = ClusteredResourcePoolBuilder.clusteredDedicated(null, 16, MemoryUnit.GB);
    assertThat(pool, is(instanceOf(DedicatedClusteredResourcePool.class)));
    assertThat(pool.getType(), Matchers.<ResourceType>is(ClusteredResourceType.Types.DEDICATED));
    assertThat(pool.isPersistent(), is(true));
    assertThat(((DedicatedClusteredResourcePool)pool).getSize(), is(16L));
    assertThat(((DedicatedClusteredResourcePool)pool).getUnit(), is(MemoryUnit.GB));
    assertThat(((DedicatedClusteredResourcePool)pool).getFromResource(), is(nullValue()));
  } 

  public void testAuthoritativeRank() {
    ClusteredWriteBehindStore.Provider provider = new ClusteredWriteBehindStore.Provider();
    ServiceLocator serviceLocator = dependencySet().with(mock(ClusteringService.class)).build();
    provider.start(serviceLocator);

    assertThat(provider.rankAuthority(ClusteredResourceType.Types.DEDICATED,
                                      Arrays.asList(cacheLoaderWriterConfiguration, writeBehindConfiguration)),
               is(3));
    assertThat(provider.rankAuthority(ClusteredResourceType.Types.DEDICATED,
                                      Collections.singletonList(writeBehindConfiguration)),
               is(0));
    assertThat(provider.rankAuthority(new ClusteredStoreProviderTest.UnmatchedResourceType(), Arrays.asList(cacheLoaderWriterConfiguration,
                                                                                                            writeBehindConfiguration)),
               is(0));
  } 

  public void testRank() {
    ClusteredWriteBehindStore.Provider provider = new ClusteredWriteBehindStore.Provider();
    ServiceLocator serviceLocator = dependencySet()
      .with(new TieredStore.Provider())
      .with(new OnHeapStore.Provider())
      .with(new OffHeapStore.Provider())
      .with(mock(DiskResourceService.class))
      .with(new OffHeapDiskStore.Provider())
      .with(mock(ClusteringService.class)).build();
    provider.start(serviceLocator);

    assertThat(provider.rank(new HashSet<>(Collections.singletonList(ClusteredResourceType.Types.DEDICATED)),
                             Arrays.asList(cacheLoaderWriterConfiguration, writeBehindConfiguration)), is(3));
    assertThat(provider.rank(new HashSet<>(Collections.singletonList(ClusteredResourceType.Types.DEDICATED)),
                             Collections.singletonList(cacheLoaderWriterConfiguration)), is(0));
    assertThat(provider.rank(new HashSet<>(Collections.singletonList(new ClusteredStoreProviderTest.UnmatchedResourceType())),
                             Arrays.asList(cacheLoaderWriterConfiguration, writeBehindConfiguration)), is(0));
  } 

  public void testRank() {
    ClusteredLoaderWriterStore.Provider provider = new ClusteredLoaderWriterStore.Provider();
    ServiceLocator serviceLocator = dependencySet()
      .with(new TieredStore.Provider())
      .with(new OnHeapStore.Provider())
      .with(new OffHeapStore.Provider())
      .with(mock(DiskResourceService.class))
      .with(new OffHeapDiskStore.Provider())
      .with(mock(ClusteringService.class)).build();
    provider.start(serviceLocator);

    assertThat(provider.rank(new HashSet<>(Collections.singletonList(ClusteredResourceType.Types.DEDICATED)),
                  Collections.singletonList(cacheLoaderWriterConfiguration)), is(2));
    assertThat(provider.rank(new HashSet<>(Collections.singletonList(ClusteredResourceType.Types.DEDICATED)),
                             Collections.emptyList()), is(0));
    assertThat(provider.rank(new HashSet<>(Collections.singletonList(new ClusteredStoreProviderTest.UnmatchedResourceType())),
                             Collections.singletonList(cacheLoaderWriterConfiguration)), is(0));
  } 

  public void testAuthoritativeRank() {
    ClusteredLoaderWriterStore.Provider provider = new ClusteredLoaderWriterStore.Provider();
    ServiceLocator serviceLocator = dependencySet().with(mock(ClusteringService.class)).build();
    provider.start(serviceLocator);

    assertThat(provider.rankAuthority(ClusteredResourceType.Types.DEDICATED,
                                      Collections.singletonList(cacheLoaderWriterConfiguration)),
               is(2));
    assertThat(provider.rankAuthority(ClusteredResourceType.Types.DEDICATED, Collections.emptyList()),
               is(0));
    assertThat(provider.rankAuthority(new ClusteredStoreProviderTest.UnmatchedResourceType(), Collections.singletonList(cacheLoaderWriterConfiguration)),
               is(0));
  } 

  public SharedClusteredResourcePoolImpl(final String sharedResource) {
    super(ClusteredResourceType.Types.SHARED, true);

    if (sharedResource == null) {
      throw new NullPointerException("sharedResource identifier can not be null");
    }
    this.sharedResource = sharedResource;
  } 

Advertisement
Javadoc
Defines the clustered ResourceType.
Advertisement