#539 - Add spring-data-geode-examples module.
This commit is contained in:
committed by
Mark Paluch
parent
08dce4f0f3
commit
fa0021cffb
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.gemfire.mapping.annotation.Region;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A customer used for Lucene examples.
|
||||
*
|
||||
* @author Udo Kohlmeyer
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@Data
|
||||
@Region(name = "Customers")
|
||||
public class Customer implements Serializable {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private EmailAddress emailAddress;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public Customer(Long id, EmailAddress emailAddress, String firstName, String lastName) {
|
||||
this.id = id;
|
||||
this.emailAddress = emailAddress;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface CustomerRepository extends CrudRepository<Customer, Long> {
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Value object to represent email addresses.
|
||||
*
|
||||
* @author Udo Kohlmeyer
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@Data
|
||||
public class EmailAddress implements Serializable {
|
||||
private String value;
|
||||
|
||||
public EmailAddress(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event.server;
|
||||
|
||||
import org.apache.geode.cache.wan.GatewayEventFilter;
|
||||
import org.apache.geode.cache.wan.GatewayQueueEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class EvenNumberedKeyWanEventFilter implements GatewayEventFilter {
|
||||
@Override
|
||||
public boolean beforeEnqueue(GatewayQueueEvent event) {
|
||||
return (Long) event.getKey() % 2 == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean beforeTransmit(GatewayQueueEvent event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterAcknowledgement(GatewayQueueEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event.server;
|
||||
|
||||
import example.springdata.geode.server.wan.event.Customer;
|
||||
import org.apache.geode.cache.EntryEvent;
|
||||
import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class WanEventSubstitutionFilter implements GatewayEventSubstitutionFilter<Long, Customer> {
|
||||
|
||||
@Override
|
||||
public Object getSubstituteValue(EntryEvent<Long, Customer> event) {
|
||||
Customer customer = event.getNewValue();
|
||||
return new Customer(customer.getId(), customer.getEmailAddress(), customer.getFirstName(), customer.getLastName().substring(0, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event.server;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import com.github.javafaker.Internet;
|
||||
import com.github.javafaker.Name;
|
||||
import example.springdata.geode.server.wan.event.Customer;
|
||||
import example.springdata.geode.server.wan.event.CustomerRepository;
|
||||
import example.springdata.geode.server.wan.event.EmailAddress;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = WanServerConfig.class)
|
||||
public class WanServer {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(WanServer.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.build()
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Profile({"default", "SiteA"})
|
||||
public ApplicationRunner siteARunner() {
|
||||
return args -> new Scanner(System.in).nextLine();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Profile("SiteB")
|
||||
public ApplicationRunner siteBRunner(CustomerRepository customerRepository) {
|
||||
return args -> {
|
||||
logger.info("Inserting 300 customers");
|
||||
createCustomers(customerRepository);
|
||||
};
|
||||
}
|
||||
|
||||
private void createCustomers(CustomerRepository repository) {
|
||||
Faker faker = new Faker();
|
||||
Name fakerName = faker.name();
|
||||
Internet fakerInternet = faker.internet();
|
||||
LongStream.range(0, 300).forEach(index ->
|
||||
repository.save(new Customer(index,
|
||||
new EmailAddress(fakerInternet.emailAddress()), fakerName.firstName(), fakerName.lastName())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event.server;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import example.springdata.geode.server.wan.event.Customer;
|
||||
import example.springdata.geode.server.wan.event.CustomerRepository;
|
||||
import example.springdata.geode.server.wan.event.server.siteA.SiteAWanEnabledServerConfig;
|
||||
import example.springdata.geode.server.wan.event.server.siteB.SiteBWanServerConfig;
|
||||
import org.apache.geode.cache.DataPolicy;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.PartitionAttributes;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.cache.wan.GatewaySender;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.gemfire.DiskStoreFactoryBean;
|
||||
import org.springframework.data.gemfire.PartitionAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
||||
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Configuration
|
||||
@EnableGemfireRepositories(basePackageClasses = CustomerRepository.class)
|
||||
@Import({SiteAWanEnabledServerConfig.class, SiteBWanServerConfig.class})
|
||||
public class WanServerConfig {
|
||||
@Bean
|
||||
Faker faker() {
|
||||
return new Faker();
|
||||
}
|
||||
|
||||
@Bean(name = "DiskStore")
|
||||
DiskStoreFactoryBean diskStore(GemFireCache gemFireCache, Faker faker) {
|
||||
final DiskStoreFactoryBean diskStoreFactoryBean = new DiskStoreFactoryBean();
|
||||
final boolean completed = new File("/tmp/" + faker.name().firstName()).mkdirs();
|
||||
final DiskStoreFactoryBean.DiskDir[] diskDirs = {new DiskStoreFactoryBean.DiskDir("/tmp/" + faker.name().firstName())};
|
||||
diskStoreFactoryBean.setDiskDirs(Arrays.asList(diskDirs));
|
||||
diskStoreFactoryBean.setCache(gemFireCache);
|
||||
return diskStoreFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
RegionAttributesFactoryBean<Long, Customer> regionAttributes(PartitionAttributes<Long, Customer> partitionAttributes) {
|
||||
final RegionAttributesFactoryBean<Long, Customer> regionAttributesFactoryBean = new RegionAttributesFactoryBean<>();
|
||||
regionAttributesFactoryBean.setPartitionAttributes(partitionAttributes);
|
||||
return regionAttributesFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
PartitionAttributesFactoryBean<Long, Customer> partitionAttributes() {
|
||||
final PartitionAttributesFactoryBean<Long, Customer> partitionAttributesFactoryBean = new PartitionAttributesFactoryBean<>();
|
||||
partitionAttributesFactoryBean.setTotalNumBuckets(13);
|
||||
partitionAttributesFactoryBean.setRedundantCopies(0);
|
||||
return partitionAttributesFactoryBean;
|
||||
}
|
||||
|
||||
@Bean("Customers")
|
||||
PartitionedRegionFactoryBean<Long, Customer> createCustomerRegion(GemFireCache gemFireCache, RegionAttributes<Long, Customer> regionAttributes, GatewaySender gatewaySender) {
|
||||
final PartitionedRegionFactoryBean<Long, Customer> partitionedRegionFactoryBean = new PartitionedRegionFactoryBean<>();
|
||||
partitionedRegionFactoryBean.setCache(gemFireCache);
|
||||
partitionedRegionFactoryBean.setRegionName("Customers");
|
||||
partitionedRegionFactoryBean.setDataPolicy(DataPolicy.PARTITION);
|
||||
partitionedRegionFactoryBean.setAttributes(regionAttributes);
|
||||
partitionedRegionFactoryBean.setGatewaySenders(new GatewaySender[]{gatewaySender});
|
||||
return partitionedRegionFactoryBean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event.server;
|
||||
|
||||
import org.apache.geode.cache.wan.GatewayTransportFilter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.Adler32;
|
||||
import java.util.zip.CheckedInputStream;
|
||||
import java.util.zip.CheckedOutputStream;
|
||||
|
||||
@Component
|
||||
public class WanTransportEncryptionListener implements GatewayTransportFilter {
|
||||
|
||||
private final Adler32 CHECKER = new Adler32();
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream(InputStream stream) {
|
||||
logger.info("CheckedTransportFilter: Getting input stream");
|
||||
return new CheckedInputStream(stream, CHECKER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream(OutputStream stream) {
|
||||
logger.info("CheckedTransportFilter: Getting output stream");
|
||||
return new CheckedOutputStream(stream, CHECKER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event.server.siteA;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableGemFireProperties;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableLocator;
|
||||
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
|
||||
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
|
||||
|
||||
@Configuration
|
||||
@CacheServerApplication(port = 0, locators = "localhost[10334]", name = "SiteA_Server", logLevel = "error")
|
||||
@Profile({"default", "SiteA"})
|
||||
@EnableLocator
|
||||
@EnableGemFireProperties(distributedSystemId = 1, remoteLocators = "localhost[20334]")
|
||||
public class SiteAWanEnabledServerConfig {
|
||||
@Bean
|
||||
GatewayReceiverFactoryBean createGatewayReceiver(GemFireCache gemFireCache) {
|
||||
final GatewayReceiverFactoryBean gatewayReceiverFactoryBean = new GatewayReceiverFactoryBean((Cache) gemFireCache);
|
||||
gatewayReceiverFactoryBean.setStartPort(15000);
|
||||
gatewayReceiverFactoryBean.setEndPort(15010);
|
||||
gatewayReceiverFactoryBean.setManualStart(false);
|
||||
return gatewayReceiverFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("DiskStore")
|
||||
GatewaySenderFactoryBean createGatewaySender(GemFireCache gemFireCache) {
|
||||
final GatewaySenderFactoryBean gatewaySenderFactoryBean = new GatewaySenderFactoryBean(gemFireCache);
|
||||
gatewaySenderFactoryBean.setBatchSize(15);
|
||||
gatewaySenderFactoryBean.setBatchTimeInterval(1000);
|
||||
gatewaySenderFactoryBean.setRemoteDistributedSystemId(2);
|
||||
gatewaySenderFactoryBean.setPersistent(false);
|
||||
gatewaySenderFactoryBean.setDiskStoreRef("DiskStore");
|
||||
return gatewaySenderFactoryBean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event.server.siteB;
|
||||
|
||||
import example.springdata.geode.server.wan.event.Customer;
|
||||
import example.springdata.geode.server.wan.event.server.EvenNumberedKeyWanEventFilter;
|
||||
import example.springdata.geode.server.wan.event.server.WanEventSubstitutionFilter;
|
||||
import example.springdata.geode.server.wan.event.server.WanTransportEncryptionListener;
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.wan.GatewayEventFilter;
|
||||
import org.apache.geode.cache.wan.GatewayEventSubstitutionFilter;
|
||||
import org.apache.geode.cache.wan.GatewayTransportFilter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableGemFireProperties;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableLocator;
|
||||
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
|
||||
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@Configuration
|
||||
@CacheServerApplication(port = 0, locators = "localhost[20334]", name = "SiteB_Server", logLevel = "error")
|
||||
@Profile("SiteB")
|
||||
@EnableLocator(port = 20334)
|
||||
@EnableGemFireProperties(distributedSystemId = 2, remoteLocators = "localhost[10334]")
|
||||
@Import({EvenNumberedKeyWanEventFilter.class, WanEventSubstitutionFilter.class, WanTransportEncryptionListener.class})
|
||||
public class SiteBWanServerConfig {
|
||||
@Bean
|
||||
GatewayReceiverFactoryBean createGatewayReceiver(GemFireCache gemFireCache) {
|
||||
final GatewayReceiverFactoryBean gatewayReceiverFactoryBean = new GatewayReceiverFactoryBean((Cache) gemFireCache);
|
||||
gatewayReceiverFactoryBean.setStartPort(25000);
|
||||
gatewayReceiverFactoryBean.setEndPort(25010);
|
||||
return gatewayReceiverFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("DiskStore")
|
||||
GatewaySenderFactoryBean createGatewaySender(GemFireCache gemFireCache, GatewayEventFilter gatewayEventFilter,
|
||||
GatewayTransportFilter gatewayTransportFilter, GatewayEventSubstitutionFilter<Long, Customer> gatewayEventSubstitutionFilter) {
|
||||
final GatewaySenderFactoryBean gatewaySenderFactoryBean = new GatewaySenderFactoryBean(gemFireCache);
|
||||
gatewaySenderFactoryBean.setBatchSize(15);
|
||||
gatewaySenderFactoryBean.setBatchTimeInterval(1000);
|
||||
gatewaySenderFactoryBean.setRemoteDistributedSystemId(1);
|
||||
gatewaySenderFactoryBean.setDiskStoreRef("DiskStore");
|
||||
gatewaySenderFactoryBean.setEventFilters(Collections.singletonList(gatewayEventFilter));
|
||||
gatewaySenderFactoryBean.setTransportFilters(Collections.singletonList(gatewayTransportFilter));
|
||||
gatewaySenderFactoryBean.setEventSubstitutionFilter(gatewayEventSubstitutionFilter);
|
||||
gatewaySenderFactoryBean.setPersistent(false);
|
||||
return gatewaySenderFactoryBean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event;
|
||||
|
||||
import example.springdata.geode.server.wan.event.client.WanClientConfig;
|
||||
import example.springdata.geode.server.wan.event.server.WanServer;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = WanClientConfig.class)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
public class WanServerTests extends ForkingClientServerIntegrationTestsSupport {
|
||||
|
||||
@Resource(name = "Customers")
|
||||
private Region<Long, Customer> customers;
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws IOException {
|
||||
startGemFireServer(WanServer.class, "-Dspring.profiles.active=SiteB");
|
||||
startGemFireServer(WanServer.class, "-Dspring.profiles.active=SiteA");
|
||||
System.getProperties().remove("spring.data.gemfire.pool.servers");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void wanReplicationOccursCorrectly() {
|
||||
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> customers.keySetOnServer().size() == 150);
|
||||
assertThat(customers.keySetOnServer().size()).isEqualTo(150);
|
||||
logger.info(customers.keySetOnServer().size() + " entries replicated to siteA");
|
||||
|
||||
customers.getAll(customers.keySetOnServer()).forEach((key, value) -> assertThat(value.getLastName().length()).isEqualTo(1));
|
||||
logger.info("All customers' last names changed to last initial on siteA");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.springdata.geode.server.wan.event.client;
|
||||
|
||||
import example.springdata.geode.server.wan.event.Customer;
|
||||
import example.springdata.geode.server.wan.event.CustomerRepository;
|
||||
import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
|
||||
import org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer;
|
||||
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Spring JavaConfig configuration class to setup a Spring container and infrastructure components.
|
||||
*
|
||||
* @author Udo Kohlmeyer
|
||||
* @author Patrick Johnson
|
||||
*/
|
||||
@Configuration
|
||||
@EnableGemfireRepositories(basePackageClasses = CustomerRepository.class)
|
||||
@ClientCacheApplication(name = "WanClient", logLevel = "error", pingInterval = 5000L, readTimeout = 15000, retryAttempts = 1)
|
||||
public class WanClientConfig {
|
||||
@Bean("Customers")
|
||||
protected ClientRegionFactoryBean<Long, Customer> configureProxyClientCustomerRegion(GemFireCache gemFireCache) {
|
||||
ClientRegionFactoryBean<Long, Customer> clientRegionFactoryBean = new ClientRegionFactoryBean<>();
|
||||
clientRegionFactoryBean.setCache(gemFireCache);
|
||||
clientRegionFactoryBean.setName("Customers");
|
||||
clientRegionFactoryBean.setShortcut(ClientRegionShortcut.PROXY);
|
||||
return clientRegionFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
ClientCacheConfigurer clientCacheServerConfigurer(
|
||||
@Value("${spring.data.geode.locator.host:localhost}") String hostname,
|
||||
@Value("${spring.data.geode.locator.port:10334}") int port) {
|
||||
|
||||
return (beanName, clientCacheFactoryBean) -> clientCacheFactoryBean.setLocators(Collections.singletonList(
|
||||
new ConnectionEndpoint(hostname, port)));
|
||||
}
|
||||
}
|
||||
11
geode/wan/src/test/resources/logback.xml
Normal file
11
geode/wan/src/test/resources/logback.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="error">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user