org.springframework.data.gemfire.CacheFactoryBean Java Examples
The following examples show how to use
org.springframework.data.gemfire.CacheFactoryBean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemberNameConfiguration.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
private void configureMemberName(Environment environment, CacheFactoryBean cacheFactoryBean) { getMemberName() .filter(memberName -> namePropertiesNotPresent(environment)) .ifPresent(memberName -> cacheFactoryBean.getProperties().setProperty(GEMFIRE_NAME_PROPERTY, memberName)); }
Example #2
Source File: CacheNameAutoConfiguration.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
private void configureCacheName(Environment environment, CacheFactoryBean cacheFactoryBean) { String springApplicationName = resolveSpringApplicationName(environment); if (StringUtils.hasText(springApplicationName)) { setGemFireName(cacheFactoryBean, springApplicationName); } }
Example #3
Source File: GroupsConfiguration.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
private void configureGroups(CacheFactoryBean cacheFactoryBean) { getGroups().ifPresent(groups -> cacheFactoryBean.getProperties() .setProperty(GEMFIRE_GROUPS_PROPERTY, StringUtils.arrayToCommaDelimitedString(groups))); }
Example #4
Source File: EnvironmentSourcedGemFirePropertiesAutoConfiguration.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
protected void configureGemFireProperties(@NonNull ConfigurableEnvironment environment, @NonNull CacheFactoryBean cache) { Assert.notNull(environment, "Environment must not be null"); Assert.notNull(cache, "CacheFactoryBean must not be null"); MutablePropertySources propertySources = environment.getPropertySources(); if (propertySources != null) { Set<String> gemfirePropertyNames = propertySources.stream() .filter(EnumerablePropertySource.class::isInstance) .map(EnumerablePropertySource.class::cast) .map(EnumerablePropertySource::getPropertyNames) .map(propertyNamesArray -> ArrayUtils.nullSafeArray(propertyNamesArray, String.class)) .flatMap(Arrays::stream) .filter(this::isGemFireDotPrefixedProperty) .filter(this::isValidGemFireProperty) .collect(Collectors.toSet()); Properties gemfireProperties = cache.getProperties(); gemfirePropertyNames.stream() .filter(gemfirePropertyName -> isNotSet(gemfireProperties, gemfirePropertyName)) .filter(this::isValidGemFireProperty) .forEach(gemfirePropertyName -> { String propertyName = normalizeGemFirePropertyName(gemfirePropertyName); String propertyValue = environment.getProperty(gemfirePropertyName); if (StringUtils.hasText(propertyValue)) { gemfireProperties.setProperty(propertyName, propertyValue); } else { getLogger().warn("Apache Geode Property [{}] was not set", propertyName); } }); cache.setProperties(gemfireProperties); } }
Example #5
Source File: CacheNameAutoConfiguration.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
private void setGemFireName(CacheFactoryBean cacheFactoryBean, String gemfireName) { cacheFactoryBean.getProperties().setProperty(GEMFIRE_NAME_PROPERTY, gemfireName); }
Example #6
Source File: GemFirePropertiesFromEnvironmentAutoConfigurationUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Test public void clientCacheGemFirePropertiesConfigurerCallsConfigureGemFireProperties() { ClientCacheFactoryBean mockClientCacheFactoryBean = mock(ClientCacheFactoryBean.class); ConfigurableEnvironment mockEnvironment = mock(ConfigurableEnvironment.class); doNothing().when(this.configuration) .configureGemFireProperties(any(ConfigurableEnvironment.class), any(CacheFactoryBean.class)); ClientCacheConfigurer clientCacheConfigurer = this.configuration.clientCacheGemFirePropertiesConfigurer(mockEnvironment); assertThat(clientCacheConfigurer).isNotNull(); clientCacheConfigurer.configure("MockCacheBeanName", mockClientCacheFactoryBean); verify(this.configuration, times(1)) .configureGemFireProperties(eq(mockEnvironment), eq(mockClientCacheFactoryBean)); }
Example #7
Source File: GemFirePropertiesFromEnvironmentAutoConfigurationUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Test public void peerCacheGemFirePropertiesConfigurerCallsConfigureGemFireProperties() { CacheFactoryBean mockPeerCacheFactoryBean = mock(CacheFactoryBean.class); ConfigurableEnvironment mockEnvironment = mock(ConfigurableEnvironment.class); doNothing().when(this.configuration) .configureGemFireProperties(any(ConfigurableEnvironment.class), any(CacheFactoryBean.class)); PeerCacheConfigurer peerCacheConfigurer = this.configuration.peerCacheGemFirePropertiesConfigurer(mockEnvironment); assertThat(peerCacheConfigurer).isNotNull(); peerCacheConfigurer.configure("MockCacheBeanName", mockPeerCacheFactoryBean); verify(this.configuration, times(1)) .configureGemFireProperties(eq(mockEnvironment), eq(mockPeerCacheFactoryBean)); }
Example #8
Source File: GemFirePropertiesFromEnvironmentAutoConfigurationUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Test public void configuresGemFirePropertiesCorrectlyAndSafely() { Map<String, Object> gemfirePropertiesOne = MapBuilder.<String, Object>newMapBuilder() .put("gemfire.cache-xml-file", "/path/to/cache.xml") .put("gemfire.name", "TestName") .put("gemfire.non-existing-property", "TEST") .put("geode.enforce-unique-host", "true") .put("enable-time-statistics", "true") .put("junk.test-property", "MOCK") .build(); Map<String, Object> gemfirePropertiesTwo = MapBuilder.<String, Object>newMapBuilder() .put("gemfire.groups", "MockGroup,TestGroup") .put("gemfire.mcast-port", " ") .put("gemfire.remote-locators", "hellbox[666]") .put("mock-property", "MOCK") .put(" ", "BLANK") .put("", "EMPTY") .build(); CacheFactoryBean mockCacheFactoryBean = mock(CacheFactoryBean.class); ConfigurableEnvironment mockEnvironment = mock(ConfigurableEnvironment.class); EnumerablePropertySource<?> emptyEnumerablePropertySource = mock(EnumerablePropertySource.class); Logger mockLogger = mock(Logger.class); MutablePropertySources propertySources = new MutablePropertySources(); PropertySource<?> nonEnumerablePropertySource = mock(PropertySource.class); propertySources.addFirst(new MapPropertySource("gemfirePropertiesOne", gemfirePropertiesOne)); propertySources.addLast(new MapPropertySource("gemfirePropertiesTwo", gemfirePropertiesTwo)); propertySources.addLast(emptyEnumerablePropertySource); propertySources.addLast(nonEnumerablePropertySource); when(mockEnvironment.getPropertySources()).thenReturn(propertySources); Properties actualGemFireProperties = new Properties(); actualGemFireProperties.setProperty("remote-locators", "skullbox[12345]"); doAnswer(invocation -> actualGemFireProperties).when(mockCacheFactoryBean).getProperties(); doAnswer(invocation -> { Properties gemfireProperties = invocation.getArgument(0); actualGemFireProperties.putAll(gemfireProperties); return null; }).when(mockCacheFactoryBean).setProperties(any(Properties.class)); doReturn(mockLogger).when(this.configuration).getLogger(); doAnswer(invocation -> { String propertyName = invocation.getArgument(0); return gemfirePropertiesOne.getOrDefault(propertyName, gemfirePropertiesTwo.getOrDefault(propertyName, null)); }).when(mockEnvironment).getProperty(anyString()); this.configuration.configureGemFireProperties(mockEnvironment, mockCacheFactoryBean); assertThat(actualGemFireProperties).isNotNull(); assertThat(actualGemFireProperties).hasSize(4); assertThat(actualGemFireProperties).containsKeys("cache-xml-file", "name", "groups"); assertThat(actualGemFireProperties.getProperty("cache-xml-file")).isEqualTo("/path/to/cache.xml"); assertThat(actualGemFireProperties.getProperty("name")).isEqualTo("TestName"); assertThat(actualGemFireProperties.getProperty("groups")).isEqualTo("MockGroup,TestGroup"); assertThat(actualGemFireProperties.getProperty("remote-locators")).isEqualTo("skullbox[12345]"); verify(mockLogger, times(1)) .warn(eq("[gemfire.non-existing-property] is not a valid Apache Geode property")); verify(mockLogger, times(1)) .warn(eq("Apache Geode Property [{}] was not set"), eq("mcast-port")); }
Example #9
Source File: GemFirePropertiesFromEnvironmentAutoConfigurationUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Override protected void configureGemFireProperties(@NonNull ConfigurableEnvironment environment, @NonNull CacheFactoryBean bean) { super.configureGemFireProperties(environment, bean); }
Example #10
Source File: GemfireCacheConfig.java From spring4-sandbox with Apache License 2.0 | 4 votes |
@Bean CacheFactoryBean cacheFactoryBean() { return new CacheFactoryBean(); }