InternalCacheBuilder { public InternalCache create() throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException { synchronized (InternalCacheBuilder.class) { InternalDistributedSystem internalDistributedSystem = findInternalDistributedSystem() .orElseGet(this::createInternalDistributedSystem); return create(internalDistributedSystem); } } InternalCacheBuilder();  InternalCacheBuilder(Properties configProperties);  InternalCacheBuilder(CacheConfig cacheConfig); private  InternalCacheBuilder(Properties configProperties, CacheConfig cacheConfig); @VisibleForTesting  InternalCacheBuilder(Properties configProperties,
      CacheConfig cacheConfig,
      MetricsService.Builder metricsSessionBuilder,
      Supplier<InternalDistributedSystem> singletonSystemSupplier,
      InternalDistributedSystemConstructor internalDistributedSystemConstructor,
      Supplier<InternalCache> singletonCacheSupplier,
      InternalCacheConstructor internalCacheConstructor); InternalCache create(); InternalCache create(InternalDistributedSystem internalDistributedSystem); InternalCacheBuilder set(String name, String value); InternalCacheBuilder setPdxReadSerialized(boolean readSerialized); InternalCacheBuilder setSecurityManager(SecurityManager securityManager); InternalCacheBuilder setPostProcessor(PostProcessor postProcessor); InternalCacheBuilder setPdxSerializer(PdxSerializer serializer); InternalCacheBuilder setPdxDiskStore(String diskStoreName); InternalCacheBuilder setPdxPersistent(boolean isPersistent); InternalCacheBuilder setPdxIgnoreUnreadFields(boolean ignore); InternalCacheBuilder setCacheXMLDescription(String cacheXML); InternalCacheBuilder setIsExistingOk(boolean isExistingOk); InternalCacheBuilder setIsClient(boolean isClient); InternalCacheBuilder setUseAsyncEventListeners(boolean useAsyncEventListeners); InternalCacheBuilder setPoolFactory(PoolFactory poolFactory); InternalCacheBuilder setTypeRegistry(TypeRegistry typeRegistry); InternalCacheBuilder addMeterSubregistry(MeterRegistry subregistry);  }
@Test public void create_constructsSystem_withGivenProperties_ifNoSystemExists_andNoCacheExists() { InternalDistributedSystemConstructor systemConstructor = constructorOf(constructedSystem()); Properties configProperties = new Properties(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( configProperties, new CacheConfig(), metricsServiceBuilder, nullSingletonSystemSupplier, systemConstructor, nullSingletonCacheSupplier, constructorOf(constructedCache())); internalCacheBuilder .create(); verify(systemConstructor).construct(same(configProperties), any(), any()); }
@Test public void create_passesMetricsServiceBuilderToSystemConstructor_ifNoSystemExists() { InternalDistributedSystemConstructor systemConstructor = constructorOf(constructedSystem()); MetricsService.Builder theMetricsServiceBuilder = mock(MetricsService.Builder.class); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), theMetricsServiceBuilder, nullSingletonSystemSupplier, systemConstructor, nullSingletonCacheSupplier, constructorOf(constructedCache())); internalCacheBuilder.create(); verify(systemConstructor).construct(any(), any(), same(theMetricsServiceBuilder)); }
@Test public void create_returnsConstructedCache_ifNoSystemExists() { InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, nullSingletonSystemSupplier, constructorOf(constructedSystem()), nullSingletonCacheSupplier, constructorOf(constructedCache)); InternalCache result = internalCacheBuilder .create(); assertThat(result).isSameAs(constructedCache); }
@Test public void create_setsConstructedCache_onConstructedSystem_ifNoSystemExists() { InternalDistributedSystem constructedSystem = constructedSystem(); InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, nullSingletonSystemSupplier, constructorOf(constructedSystem), nullSingletonCacheSupplier, constructorOf(constructedCache)); internalCacheBuilder .create(); verify(constructedSystem).setCache(same(constructedCache)); }
@Test public void create_setsConstructedSystem_onConstructedCache_ifNoSystemExists_() { InternalDistributedSystem constructedSystem = constructedSystem(); InternalCache constructedCache = constructedCache(); InternalCacheConstructor cacheConstructor = constructorOf(constructedCache); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, nullSingletonSystemSupplier, constructorOf(constructedSystem), nullSingletonCacheSupplier, cacheConstructor); internalCacheBuilder .create(); verify(cacheConstructor) .construct(anyBoolean(), any(), same(constructedSystem), any(), anyBoolean(), any()); }
@Test public void create_returnsConstructedCache_ifSingletonSystemExists_andNoCacheExists() { InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, supplierOf(singletonSystem()), THROWING_SYSTEM_CONSTRUCTOR, nullSingletonCacheSupplier, constructorOf(constructedCache)); InternalCache result = internalCacheBuilder .create(); assertThat(result).isSameAs(constructedCache); }
@Test public void create_setsSingletonSystem_onConstructedCache_ifSingletonSystemExists_andNoCacheExists() { InternalDistributedSystem singletonSystem = singletonSystem(); InternalCache constructedCache = constructedCache(); InternalCacheConstructor cacheConstructor = constructorOf(constructedCache); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, supplierOf(singletonSystem), THROWING_SYSTEM_CONSTRUCTOR, nullSingletonCacheSupplier, cacheConstructor); internalCacheBuilder .create(); verify(singletonSystem).setCache(same(constructedCache)); }
@Test public void create_setsConstructedCache_onSingletonSystem_ifSingletonSystemExists_andNoCacheExists() { InternalDistributedSystem singletonSystem = singletonSystem(); InternalCache constructedCache = constructedCache(); InternalCacheConstructor cacheConstructor = constructorOf(constructedCache); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, supplierOf(singletonSystem), THROWING_SYSTEM_CONSTRUCTOR, nullSingletonCacheSupplier, cacheConstructor); internalCacheBuilder .create(); verify(cacheConstructor) .construct(anyBoolean(), any(), same(singletonSystem), any(), anyBoolean(), any()); }
@Test public void create_returnsConstructedCache_ifSingletonSystemExists_andSingletonCacheIsClosed() { InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, supplierOf(singletonSystem()), THROWING_SYSTEM_CONSTRUCTOR, supplierOf(cache("singleton", CLOSED)), constructorOf(constructedCache)); InternalCache result = internalCacheBuilder .create(); assertThat(result).isSameAs(constructedCache); }
@Test public void create_setsConstructedCache_onSingletonSystem_ifSingletonSystemExists_andSingletonCacheIsClosed() { InternalDistributedSystem singletonSystem = singletonSystem(); InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, supplierOf(singletonSystem), THROWING_SYSTEM_CONSTRUCTOR, supplierOf(cache("singleton", CLOSED)), constructorOf(constructedCache)); internalCacheBuilder .create(); verify(singletonSystem).setCache(same(constructedCache)); }
@Test public void create_setsSingletonSystem_onConstructedCache_ifSingletonSystemExists_andSingletonCacheIsClosed() { InternalDistributedSystem singletonSystem = singletonSystem(); InternalCacheConstructor cacheConstructor = constructorOf(constructedCache()); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, supplierOf(singletonSystem), THROWING_SYSTEM_CONSTRUCTOR, supplierOf(cache("singleton", CLOSED)), cacheConstructor); internalCacheBuilder .create(); verify(cacheConstructor) .construct(anyBoolean(), any(), same(singletonSystem), any(), anyBoolean(), any()); }
@Test public void create_returnsSingletonCache_ifSingletonCacheIsOpen() { InternalCache singletonCache = cache("singleton", OPEN); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, supplierOf(singletonSystem()), THROWING_SYSTEM_CONSTRUCTOR, supplierOf(singletonCache), THROWING_CACHE_CONSTRUCTOR); InternalCache result = internalCacheBuilder .create(); assertThat(result).isSameAs(singletonCache); }
@Test public void createWithSystem_throwsNullPointerException_ifSystemIsNull() { InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, THROWING_SYSTEM_SUPPLIER, THROWING_SYSTEM_CONSTRUCTOR, THROWING_CACHE_SUPPLIER, THROWING_CACHE_CONSTRUCTOR); Throwable thrown = catchThrowable(() -> internalCacheBuilder .create(null)); assertThat(thrown).isInstanceOf(NullPointerException.class); }
@Test public void createWithSystem_returnsConstructedCache_ifNoCacheExists() { InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, THROWING_SYSTEM_SUPPLIER, THROWING_SYSTEM_CONSTRUCTOR, nullSingletonCacheSupplier, constructorOf(constructedCache)); InternalCache result = internalCacheBuilder .create(systemWithNoCache()); assertThat(result).isSameAs(constructedCache); }
@Test public void createWithSystem_setsConstructedCache_onGivenSystem_ifNoCacheExists() { InternalDistributedSystem givenSystem = systemWithNoCache(); InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, THROWING_SYSTEM_SUPPLIER, THROWING_SYSTEM_CONSTRUCTOR, nullSingletonCacheSupplier, constructorOf(constructedCache)); internalCacheBuilder .create(givenSystem); verify(givenSystem).setCache(same(constructedCache)); }
@Test public void createWithSystem_setsGivenSystem_onConstructedCache_ifNoCacheExists() { InternalDistributedSystem givenSystem = systemWithNoCache(); InternalCacheConstructor cacheConstructor = constructorOf(constructedCache()); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, THROWING_SYSTEM_SUPPLIER, THROWING_SYSTEM_CONSTRUCTOR, nullSingletonCacheSupplier, cacheConstructor); internalCacheBuilder .create(givenSystem); verify(cacheConstructor) .construct(anyBoolean(), any(), same(givenSystem), any(), anyBoolean(), any()); }
@Test public void createWithSystem_returnsConstructedCache_ifSingletonCacheIsClosed() { InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, THROWING_SYSTEM_SUPPLIER, THROWING_SYSTEM_CONSTRUCTOR, supplierOf(cache("singleton", CLOSED)), constructorOf(constructedCache)); InternalCache result = internalCacheBuilder .create(systemWithNoCache()); assertThat(result).isSameAs(constructedCache); }
@Test public void createWithSystem_setsConstructedCache_onGivenSystem_ifSingletonCacheIsClosed() { InternalDistributedSystem givenSystem = systemWithNoCache(); InternalCache constructedCache = constructedCache(); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, THROWING_SYSTEM_SUPPLIER, THROWING_SYSTEM_CONSTRUCTOR, supplierOf(cache("singleton", CLOSED)), constructorOf(constructedCache)); internalCacheBuilder .create(givenSystem); verify(givenSystem).setCache(same(constructedCache)); }
@Test public void createWithSystem_setsGivenSystem_onConstructedCache_ifSingletonCacheIsClosed() { InternalDistributedSystem givenSystem = systemWithNoCache(); InternalCacheConstructor cacheConstructor = constructorOf(constructedCache()); InternalCacheBuilder internalCacheBuilder = new InternalCacheBuilder( new Properties(), new CacheConfig(), metricsServiceBuilder, THROWING_SYSTEM_SUPPLIER, THROWING_SYSTEM_CONSTRUCTOR, supplierOf(cache("singleton", CLOSED)), cacheConstructor); internalCacheBuilder .create(givenSystem); verify(cacheConstructor) .construct(anyBoolean(), any(), same(givenSystem), any(), anyBoolean(), any()); }