org.apache.geode.cache.CacheLoader Java Examples

The following examples show how to use org.apache.geode.cache.CacheLoader. 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: InlineCachingRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void doesNotConfigureClientRegionFactoryBeanWithInlineCachingWhenPredicateReturnsFalse() {

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean<>());

	when(this.mockPredicate.test(anyString())).thenReturn(false);

	InlineCachingRegionConfigurer<?, ?> regionConfigurer =
		new InlineCachingRegionConfigurer<>(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, never()).setCacheLoader(any(CacheLoader.class));
	verify(clientRegionFactoryBean, never()).setCacheWriter(any(CacheWriter.class));
	verify(this.mockPredicate, times(2)).test(eq("Example"));
}
 
Example #2
Source File: InlineCachingRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void doesNotConfigurePeerRegionFactoryBeanWithInlineCachingWhenPredicateReturnsFalse() {

	PeerRegionFactoryBean<?, ?> peerRegionFactoryBean = mock(PeerRegionFactoryBean.class);

	when(this.mockPredicate.test(anyString())).thenReturn(false);

	InlineCachingRegionConfigurer<?, ?> regionConfigurer =
		new InlineCachingRegionConfigurer<>(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", peerRegionFactoryBean);

	verify(peerRegionFactoryBean, never()).setCacheLoader(any(CacheLoader.class));
	verify(peerRegionFactoryBean, never()).setCacheWriter(any(CacheWriter.class));
	verify(this.mockPredicate, times(2)).test(eq("Example"));
}
 
Example #3
Source File: EventServerConfig.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Bean("Products")
ReplicatedRegionFactoryBean<Long, Product> createProductRegion(GemFireCache gemFireCache, CacheListener<Long, Product> loggingCacheListener,
															   CacheLoader<Long, Product> productCacheLoader) {
	ReplicatedRegionFactoryBean<Long, Product> replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>();
	replicatedRegionFactoryBean.setCache(gemFireCache);
	replicatedRegionFactoryBean.setRegionName("Products");
	replicatedRegionFactoryBean.setDataPolicy(DataPolicy.REPLICATE);
	replicatedRegionFactoryBean.setCacheLoader(productCacheLoader);
	replicatedRegionFactoryBean.setCacheListeners(new CacheListener[]{loggingCacheListener});
	return replicatedRegionFactoryBean;
}
 
Example #4
Source File: RepositoryCacheLoaderRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void doesNotConfigureClientRegionFactoryBeanWithRepositoryCacheLoaderWhenPredicateReturnsFalse() {

	when(this.mockPredicate.test(anyString())).thenReturn(false);

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean());

	RepositoryCacheLoaderRegionConfigurer regionConfigurer =
		new RepositoryCacheLoaderRegionConfigurer(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, never()).setCacheLoader(any(CacheLoader.class));
	verify(this.mockPredicate, times(1)).test(eq("Example"));
}
 
Example #5
Source File: RepositoryCacheLoaderRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void doesNotConfigurePeerRegionFactoryBeanWithRepositoryCacheLoaderWhenPredicateReturnsFalse() {

	when(this.mockPredicate.test(anyString())).thenReturn(false);

	PeerRegionFactoryBean<?, ?> peerRegionFactoryBean = mock(PeerRegionFactoryBean.class);

	RepositoryCacheLoaderRegionConfigurer regionConfigurer =
		new RepositoryCacheLoaderRegionConfigurer(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", peerRegionFactoryBean);

	verify(peerRegionFactoryBean, never()).setCacheLoader(any(CacheLoader.class));
	verify(this.mockPredicate, times(1)).test(eq("Example"));
}
 
Example #6
Source File: RepositoryCacheLoaderRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 3 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void configuresClientRegionFactoryBeanWithRepositoryCacheLoaderWhenPredicateReturnsTrue() {

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean());

	doAnswer(answer -> {

		CacheLoader cacheLoader = answer.getArgument(0);

		assertThat(cacheLoader).isInstanceOf(RepositoryCacheLoader.class);
		assertThat(((RepositoryCacheLoader) cacheLoader).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(clientRegionFactoryBean).setCacheLoader(isA(CacheLoader.class));

	when(this.mockPredicate.test(anyString())).thenReturn(true);

	RepositoryCacheLoaderRegionConfigurer regionConfigurer =
		new RepositoryCacheLoaderRegionConfigurer(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, times(1))
		.setCacheLoader(isA(RepositoryCacheLoader.class));

	verify(this.mockPredicate, times(1)).test(eq("Example"));
}
 
Example #7
Source File: RepositoryCacheLoaderRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 3 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void configuresPeerRegionFactoryBeanWithRepositoryCacheLoaderWhenPredicateReturnsTrue() {

	PeerRegionFactoryBean<?, ?> peerRegionFactoryBean = mock(PeerRegionFactoryBean.class);

	doAnswer(answer -> {

		CacheLoader cacheLoader = answer.getArgument(0);

		assertThat(cacheLoader).isInstanceOf(RepositoryCacheLoader.class);
		assertThat(((RepositoryCacheLoader) cacheLoader).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(peerRegionFactoryBean).setCacheLoader(isA(CacheLoader.class));

	when(this.mockPredicate.test(anyString())).thenReturn(true);

	RepositoryCacheLoaderRegionConfigurer regionConfigurer =
		new RepositoryCacheLoaderRegionConfigurer(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", peerRegionFactoryBean);

	verify(peerRegionFactoryBean, times(1))
		.setCacheLoader(isA(RepositoryCacheLoader.class));

	verify(this.mockPredicate, times(1)).test(eq("Example"));
}
 
Example #8
Source File: InlineCachingRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 2 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void configureClientRegionFactoryBeanWithInlineCachingWhenPredicateReturnsTrue() {

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean<>());

	doAnswer(answer -> {

		CacheLoader cacheLoader = answer.getArgument(0);

		assertThat(cacheLoader).isInstanceOf(RepositoryCacheLoader.class);
		assertThat(((RepositoryCacheLoader) cacheLoader).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(clientRegionFactoryBean).setCacheLoader(any(CacheLoader.class));

	doAnswer(answer -> {

		CacheWriter cacheWriter = answer.getArgument(0);

		assertThat(cacheWriter).isInstanceOf(RepositoryCacheWriter.class);
		assertThat(((RepositoryCacheWriter) cacheWriter).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(clientRegionFactoryBean).setCacheWriter(any(CacheWriter.class));

	when(this.mockPredicate.test(anyString())).thenReturn(true);

	InlineCachingRegionConfigurer<?, ?> regionConfigurer =
		new InlineCachingRegionConfigurer<>(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, times(1))
		.setCacheLoader(isA(RepositoryCacheLoader.class));

	verify(clientRegionFactoryBean, times(1))
		.setCacheWriter(isA(RepositoryCacheWriter.class));

	verify(this.mockPredicate, times(2)).test(eq("Example"));
}
 
Example #9
Source File: InlineCachingRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 2 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void configurePeerRegionFactoryBeanWithInlineCachingWhenPredicateReturnsFalse() {

	PeerRegionFactoryBean<?, ?> peerRegionFactoryBean = mock(PeerRegionFactoryBean.class);

	doAnswer(answer -> {

		CacheLoader cacheLoader = answer.getArgument(0);

		assertThat(cacheLoader).isInstanceOf(RepositoryCacheLoader.class);
		assertThat(((RepositoryCacheLoader) cacheLoader).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(peerRegionFactoryBean).setCacheLoader(any(CacheLoader.class));

	doAnswer(answer -> {

		CacheWriter cacheWriter = answer.getArgument(0);

		assertThat(cacheWriter).isInstanceOf(RepositoryCacheWriter.class);
		assertThat(((RepositoryCacheWriter) cacheWriter).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(peerRegionFactoryBean).setCacheWriter(any(CacheWriter.class));

	when(this.mockPredicate.test(anyString())).thenReturn(true);

	InlineCachingRegionConfigurer<?, ?> regionConfigurer =
		new InlineCachingRegionConfigurer<>(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", peerRegionFactoryBean);

	verify(peerRegionFactoryBean, times(1))
		.setCacheLoader(isA(RepositoryCacheLoader.class));

	verify(peerRegionFactoryBean, times(1))
		.setCacheWriter(isA(RepositoryCacheWriter.class));

	verify(this.mockPredicate, times(2)).test(eq("Example"));
}