org.apache.geode.cache.CacheWriter Java Examples

The following examples show how to use org.apache.geode.cache.CacheWriter. 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("Customers")
ReplicatedRegionFactoryBean<Long, Customer> createCustomerRegion(GemFireCache gemFireCache,
																 CacheWriter<Long, Customer> customerCacheWriter,
																 CacheListener<Long, Customer> loggingCacheListener) {
	ReplicatedRegionFactoryBean<Long, Customer> replicatedRegionFactoryBean = new ReplicatedRegionFactoryBean<>();
	replicatedRegionFactoryBean.setCache(gemFireCache);
	replicatedRegionFactoryBean.setRegionName("Customers");
	replicatedRegionFactoryBean.setDataPolicy(DataPolicy.REPLICATE);
	replicatedRegionFactoryBean.setCacheListeners(new CacheListener[]{loggingCacheListener});
	replicatedRegionFactoryBean.setCacheWriter(customerCacheWriter);
	return replicatedRegionFactoryBean;
}
 
Example #4
Source File: RepositoryCacheWriterRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void doesNotConfigureClientRegionFactoryBeanWithRepositoryCacheWriterWhenPredicateReturnsFalse() {

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

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

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

	regionConfigurer.configure("Example", clientRegionFactoryBean);

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

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

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

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

	regionConfigurer.configure("Example", peerRegionFactoryBean);

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

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

	doAnswer(answer -> {

		CacheWriter cacheWriter = answer.getArgument(0);

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

		return null;

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

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

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

	regionConfigurer.configure("Example", clientRegionFactoryBean);

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

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

	PeerRegionFactoryBean<?, ?> peerRegionFactoryBean = mock(PeerRegionFactoryBean.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(isA(CacheWriter.class));

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

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

	regionConfigurer.configure("Example", peerRegionFactoryBean);

	verify(peerRegionFactoryBean, times(1))
		.setCacheWriter(isA(RepositoryCacheWriter.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"));
}