Merge pull request #5444 from jxblum/polish-data-gemfire-starter-and-sample
* pr/5444: Polish contribution Polish Pivotal GemFire starter and sample
This commit is contained in:
commit
9bfdad7587
|
|
@ -71,7 +71,6 @@
|
||||||
<flyway.version>3.2.1</flyway.version>
|
<flyway.version>3.2.1</flyway.version>
|
||||||
<freemarker.version>2.3.23</freemarker.version>
|
<freemarker.version>2.3.23</freemarker.version>
|
||||||
<elasticsearch.version>2.2.0</elasticsearch.version>
|
<elasticsearch.version>2.2.0</elasticsearch.version>
|
||||||
<gemfire.version>8.2.0</gemfire.version>
|
|
||||||
<glassfish-el.version>3.0.0</glassfish-el.version>
|
<glassfish-el.version>3.0.0</glassfish-el.version>
|
||||||
<gradle.version>1.12</gradle.version>
|
<gradle.version>1.12</gradle.version>
|
||||||
<groovy.version>2.4.6</groovy.version>
|
<groovy.version>2.4.6</groovy.version>
|
||||||
|
|
@ -152,6 +151,7 @@
|
||||||
<spring-security-jwt.version>1.0.3.RELEASE</spring-security-jwt.version>
|
<spring-security-jwt.version>1.0.3.RELEASE</spring-security-jwt.version>
|
||||||
<spring-security-oauth.version>2.0.9.RELEASE</spring-security-oauth.version>
|
<spring-security-oauth.version>2.0.9.RELEASE</spring-security-oauth.version>
|
||||||
<spring-session.version>1.1.0.RELEASE</spring-session.version>
|
<spring-session.version>1.1.0.RELEASE</spring-session.version>
|
||||||
|
<spring-shell.version>1.1.0.RELEASE</spring-shell.version>
|
||||||
<spring-social.version>1.1.4.RELEASE</spring-social.version>
|
<spring-social.version>1.1.4.RELEASE</spring-social.version>
|
||||||
<spring-social-facebook.version>2.0.3.RELEASE</spring-social-facebook.version>
|
<spring-social-facebook.version>2.0.3.RELEASE</spring-social-facebook.version>
|
||||||
<spring-social-linkedin.version>1.0.2.RELEASE</spring-social-linkedin.version>
|
<spring-social-linkedin.version>1.0.2.RELEASE</spring-social-linkedin.version>
|
||||||
|
|
@ -669,17 +669,6 @@
|
||||||
<artifactId>jackson-module-parameter-names</artifactId>
|
<artifactId>jackson-module-parameter-names</artifactId>
|
||||||
<version>${jackson.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.gemstone.gemfire</groupId>
|
|
||||||
<artifactId>gemfire</artifactId>
|
|
||||||
<version>${gemfire.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-gemfire</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||||
<artifactId>caffeine</artifactId>
|
<artifactId>caffeine</artifactId>
|
||||||
|
|
@ -2053,6 +2042,11 @@
|
||||||
<artifactId>spring-session-data-redis</artifactId>
|
<artifactId>spring-session-data-redis</artifactId>
|
||||||
<version>${spring-session.version}</version>
|
<version>${spring-session.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.shell</groupId>
|
||||||
|
<artifactId>spring-shell</artifactId>
|
||||||
|
<version>${spring-shell.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.social</groupId>
|
<groupId>org.springframework.social</groupId>
|
||||||
<artifactId>spring-social-config</artifactId>
|
<artifactId>spring-social-config</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
<version>1.4.0.BUILD-SNAPSHOT</version>
|
<version>1.4.0.BUILD-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-boot-sample-data-gemfire</artifactId>
|
<artifactId>spring-boot-sample-data-gemfire</artifactId>
|
||||||
<name>Spring Boot Data Gemfire Sample</name>
|
<name>Spring Boot Data GemFire Sample</name>
|
||||||
<description>Spring Boot Data Gemfire Sample</description>
|
<description>Spring Boot Data GemFire Sample</description>
|
||||||
<url>http://projects.spring.io/spring-boot/</url>
|
<url>http://projects.spring.io/spring-boot/</url>
|
||||||
<organization>
|
<organization>
|
||||||
<name>Pivotal Software, Inc.</name>
|
<name>Pivotal Software, Inc.</name>
|
||||||
|
|
@ -19,14 +19,23 @@
|
||||||
<main.basedir>${basedir}/../..</main.basedir>
|
<main.basedir>${basedir}/../..</main.basedir>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-gemfire</artifactId>
|
<artifactId>spring-boot-starter-data-gemfire</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.shell</groupId>
|
||||||
|
<artifactId>spring-shell</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 the original author or authors.
|
* Copyright 2012-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,9 +16,21 @@
|
||||||
|
|
||||||
package sample.data.gemfire;
|
package sample.data.gemfire;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import com.gemstone.gemfire.cache.Cache;
|
||||||
|
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||||
|
import sample.data.gemfire.config.SampleDataGemFireProperties;
|
||||||
|
import sample.data.gemfire.domain.Gemstone;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.ImportResource;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||||
|
import org.springframework.data.gemfire.GemfireTransactionManager;
|
||||||
|
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
||||||
|
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||||
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
|
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
|
@ -30,13 +42,76 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
* @author John Blum
|
* @author John Blum
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ImportResource("/spring-data-gemfire-cache.xml")
|
|
||||||
@EnableGemfireRepositories
|
@EnableGemfireRepositories
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
|
@EnableConfigurationProperties(SampleDataGemFireProperties.class)
|
||||||
public class SampleDataGemFireApplication {
|
public class SampleDataGemFireApplication {
|
||||||
|
|
||||||
|
protected static final String GEMSTONES_REGION_NAME = "Gemstones";
|
||||||
|
|
||||||
|
private final SampleDataGemFireProperties applicationProperties;
|
||||||
|
|
||||||
|
public SampleDataGemFireApplication(SampleDataGemFireProperties applicationProperties) {
|
||||||
|
this.applicationProperties = applicationProperties;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(final String[] args) {
|
public static void main(final String[] args) {
|
||||||
SpringApplication.run(SampleDataGemFireApplication.class, args);
|
SpringApplication.run(SampleDataGemFireApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
CacheFactoryBean gemfireCache() {
|
||||||
|
CacheFactoryBean gemfireCache = new CacheFactoryBean();
|
||||||
|
|
||||||
|
gemfireCache.setClose(true);
|
||||||
|
gemfireCache.setProperties(gemfireProperties());
|
||||||
|
|
||||||
|
return gemfireCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Properties gemfireProperties() {
|
||||||
|
Properties gemfireProperties = new Properties();
|
||||||
|
|
||||||
|
gemfireProperties.setProperty("name", SampleDataGemFireApplication.class.getSimpleName());
|
||||||
|
gemfireProperties.setProperty("mcast-port", "0");
|
||||||
|
gemfireProperties.setProperty("locators", "");
|
||||||
|
gemfireProperties.setProperty("log-level", this.applicationProperties.getLogLevel());
|
||||||
|
|
||||||
|
return gemfireProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = GEMSTONES_REGION_NAME)
|
||||||
|
ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion(Cache gemfireCache,
|
||||||
|
RegionAttributes<Long, Gemstone> gemstonesRegionAttributes) {
|
||||||
|
|
||||||
|
ReplicatedRegionFactoryBean<Long, Gemstone> gemstonesRegion =
|
||||||
|
new ReplicatedRegionFactoryBean<Long, Gemstone>();
|
||||||
|
|
||||||
|
gemstonesRegion.setAttributes(gemstonesRegionAttributes);
|
||||||
|
gemstonesRegion.setClose(false);
|
||||||
|
gemstonesRegion.setCache(gemfireCache);
|
||||||
|
gemstonesRegion.setName(GEMSTONES_REGION_NAME);
|
||||||
|
gemstonesRegion.setPersistent(false);
|
||||||
|
|
||||||
|
return gemstonesRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
RegionAttributesFactoryBean gemstonesRegionAttributes() {
|
||||||
|
RegionAttributesFactoryBean gemstonesRegionAttributes =
|
||||||
|
new RegionAttributesFactoryBean();
|
||||||
|
|
||||||
|
gemstonesRegionAttributes.setKeyConstraint(Long.class);
|
||||||
|
gemstonesRegionAttributes.setValueConstraint(Gemstone.class);
|
||||||
|
|
||||||
|
return gemstonesRegionAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
GemfireTransactionManager gemfireTransactionManager(Cache gemfireCache) {
|
||||||
|
return new GemfireTransactionManager(gemfireCache);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2016 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
|
||||||
|
*
|
||||||
|
* http://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 sample.data.gemfire.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration properties for Gemfire sample.
|
||||||
|
*
|
||||||
|
* @author John Blum
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(prefix = "sample.data.gemfire")
|
||||||
|
public class SampleDataGemFireProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caching log level.
|
||||||
|
*/
|
||||||
|
private String logLevel = "config";
|
||||||
|
|
||||||
|
public String getLogLevel() {
|
||||||
|
return this.logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogLevel(String logLevel) {
|
||||||
|
this.logLevel = logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 the original author or authors.
|
* Copyright 2012-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -89,7 +89,7 @@ public class Gemstone implements Serializable {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("{ @type = %1$s, id = %2$d, name = %3$s }",
|
return String.format("{ @type = %1$s, id = %2$d, name = %3$s }",
|
||||||
getClass().getName(), getId(), getName());
|
getClass().getName(), getId(), getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 the original author or authors.
|
* Copyright 2012-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -43,14 +43,15 @@ public class GemstoneServiceImpl implements GemstoneService {
|
||||||
Arrays.asList("ALEXANDRITE", "AQUAMARINE", "DIAMOND", "OPAL", "PEARL", "RUBY",
|
Arrays.asList("ALEXANDRITE", "AQUAMARINE", "DIAMOND", "OPAL", "PEARL", "RUBY",
|
||||||
"SAPPHIRE", "SPINEL", "TOPAZ"));
|
"SAPPHIRE", "SPINEL", "TOPAZ"));
|
||||||
|
|
||||||
@Autowired
|
private final GemstoneRepository gemstoneRepository;
|
||||||
private GemstoneRepository gemstoneRepo;
|
|
||||||
|
public GemstoneServiceImpl(GemstoneRepository gemstoneRepository) {
|
||||||
|
this.gemstoneRepository = gemstoneRepository;
|
||||||
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
Assert.notNull(this.gemstoneRepo,
|
System.out.printf("[%1$s] initialized!%n", getClass().getSimpleName());
|
||||||
"A reference to the 'GemstoneRepository' was not properly configured!");
|
|
||||||
System.out.printf("%1$s initialized!%n", getClass().getSimpleName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -62,7 +63,7 @@ public class GemstoneServiceImpl implements GemstoneService {
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public long count() {
|
public long count() {
|
||||||
return this.gemstoneRepo.count();
|
return this.gemstoneRepository.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -75,8 +76,8 @@ public class GemstoneServiceImpl implements GemstoneService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Gemstone get(final Long id) {
|
public Gemstone get(Long id) {
|
||||||
return this.gemstoneRepo.findOne(id);
|
return this.gemstoneRepository.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -89,8 +90,8 @@ public class GemstoneServiceImpl implements GemstoneService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Gemstone get(final String name) {
|
public Gemstone get(String name) {
|
||||||
return this.gemstoneRepo.findByName(name);
|
return this.gemstoneRepository.findByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -105,7 +106,7 @@ public class GemstoneServiceImpl implements GemstoneService {
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Iterable<Gemstone> list() {
|
public Iterable<Gemstone> list() {
|
||||||
return this.gemstoneRepo.findAll();
|
return this.gemstoneRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -118,32 +119,30 @@ public class GemstoneServiceImpl implements GemstoneService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Gemstone save(final Gemstone gemstone) {
|
public Gemstone save(Gemstone gemstone) {
|
||||||
Assert.notNull(gemstone, "The Gemstone to save must not be null!");
|
Assert.notNull(gemstone, "The Gemstone to save must not be null!");
|
||||||
Assert.notNull(gemstone.getName(), "The name of the Gemstone must be specified!");
|
Assert.notNull(gemstone.getName(), "The name of the Gemstone must be specified!");
|
||||||
|
|
||||||
// NOTE deliberately (naively) validate the Gemstone after mutating data access in
|
// NOTE deliberately (& naively) validate the Gemstone after mutating data access in
|
||||||
// GemFire rather than before
|
// GemFire rather than before to demonstrate transactions in GemFire.
|
||||||
// to demonstrate transactions in GemFire.
|
Gemstone savedGemstone = validate(this.gemstoneRepository.save(gemstone));
|
||||||
Gemstone savedGemstone = validate(this.gemstoneRepo.save(gemstone));
|
|
||||||
|
|
||||||
Assert.state(savedGemstone.equals(get(gemstone.getId())),
|
Assert.state(savedGemstone.equals(get(gemstone.getId())), String.format(
|
||||||
String.format(
|
"Failed to find Gemstone (%1$s) in GemFire's Cache Region 'Gemstones'!",
|
||||||
"Failed to find Gemstone (%1$s) in GemFire's Cache Region 'Gemstones'!",
|
gemstone));
|
||||||
gemstone));
|
|
||||||
|
|
||||||
System.out.printf("Saved Gemstone (%1$s)%n", savedGemstone.getName());
|
System.out.printf("Saved Gemstone [%1$s]%n", savedGemstone.getName());
|
||||||
|
|
||||||
return gemstone;
|
return gemstone;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Gemstone validate(final Gemstone gemstone) {
|
Gemstone validate(Gemstone gemstone) {
|
||||||
if (!APPROVED_GEMS.contains(gemstone.getName().toUpperCase())) {
|
if (!APPROVED_GEMS.contains(gemstone.getName().toUpperCase())) {
|
||||||
// NOTE if the Gemstone is not valid, blow chunks (should cause transaction to
|
// NOTE if the Gemstone is not valid, throw error...
|
||||||
// rollback in GemFire)!
|
// Should cause transaction to rollback in GemFire!
|
||||||
System.err.printf("Illegal Gemstone (%1$s)!%n", gemstone.getName());
|
System.err.printf("Illegal Gemstone [%1$s]!%n", gemstone.getName());
|
||||||
throw new IllegalGemstoneException(
|
throw new IllegalGemstoneException(
|
||||||
String.format("'%1$s' is not a valid Gemstone!", gemstone.getName()));
|
String.format("[%1$s] is not a valid Gemstone!", gemstone.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return gemstone;
|
return gemstone;
|
||||||
|
|
@ -151,21 +150,10 @@ public class GemstoneServiceImpl implements GemstoneService {
|
||||||
|
|
||||||
public static final class IllegalGemstoneException extends IllegalArgumentException {
|
public static final class IllegalGemstoneException extends IllegalArgumentException {
|
||||||
|
|
||||||
public IllegalGemstoneException() {
|
public IllegalGemstoneException(String message) {
|
||||||
}
|
|
||||||
|
|
||||||
public IllegalGemstoneException(final String message) {
|
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IllegalGemstoneException(final Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IllegalGemstoneException(final String message, final Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:gfe="http://www.springframework.org/schema/gemfire" xmlns:util="http://www.springframework.org/schema/util"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="
|
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
|
||||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
|
|
||||||
|
|
||||||
<util:properties id="gemfireCacheConfigurationSettings">
|
|
||||||
<prop key="name">GemstonesSpringGemFireApp</prop>
|
|
||||||
<prop key="log-level">config</prop>
|
|
||||||
<prop key="mcast-port">0</prop>
|
|
||||||
</util:properties>
|
|
||||||
|
|
||||||
<gfe:cache properties-ref="gemfireCacheConfigurationSettings" />
|
|
||||||
|
|
||||||
<gfe:replicated-region id="Gemstones" ignore-jta="true"
|
|
||||||
persistent="false" key-constraint="java.lang.Long"
|
|
||||||
value-constraint="sample.data.gemfire.domain.Gemstone" />
|
|
||||||
|
|
||||||
<gfe:transaction-manager id="transactionManager"
|
|
||||||
copy-on-read="true" />
|
|
||||||
|
|
||||||
</beans>
|
|
||||||
|
|
@ -18,7 +18,6 @@ package sample.data.gemfire;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import sample.data.gemfire.domain.Gemstone;
|
import sample.data.gemfire.domain.Gemstone;
|
||||||
|
|
@ -32,8 +31,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SampleDataGemFireApplicationTests class is a test suite with test cases testing the
|
* Tests for {@link SampleDataGemFireApplication}.
|
||||||
* SampleDataGemFireApplication in Spring Boot.
|
|
||||||
*
|
*
|
||||||
* @author John Blum
|
* @author John Blum
|
||||||
*/
|
*/
|
||||||
|
|
@ -44,15 +42,10 @@ public class SampleDataGemFireApplicationTests {
|
||||||
@Autowired
|
@Autowired
|
||||||
private GemstoneService gemstoneService;
|
private GemstoneService gemstoneService;
|
||||||
|
|
||||||
private final AtomicLong ID_GENERATOR = new AtomicLong(0l);
|
private final AtomicLong idGenerator = new AtomicLong(0L);
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
assertThat(this.gemstoneService).isNotNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGemstonesApp() {
|
public void gemstonesAppServiceEndpoints() {
|
||||||
assertThat(this.gemstoneService.count()).isEqualTo(0);
|
assertThat(this.gemstoneService.count()).isEqualTo(0);
|
||||||
assertThat(this.gemstoneService.list()).isEmpty();
|
assertThat(this.gemstoneService.list()).isEmpty();
|
||||||
|
|
||||||
|
|
@ -60,37 +53,41 @@ public class SampleDataGemFireApplicationTests {
|
||||||
this.gemstoneService.save(createGemstone("Ruby"));
|
this.gemstoneService.save(createGemstone("Ruby"));
|
||||||
|
|
||||||
assertThat(this.gemstoneService.count()).isEqualTo(2);
|
assertThat(this.gemstoneService.count()).isEqualTo(2);
|
||||||
assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby"));
|
assertThat(this.gemstoneService.list()).contains(
|
||||||
|
getGemstones("Diamond", "Ruby"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.gemstoneService.save(createGemstone("Coal"));
|
this.gemstoneService.save(createGemstone("Coal"));
|
||||||
}
|
}
|
||||||
catch (IllegalGemstoneException ex) {
|
catch (IllegalGemstoneException ignore) {
|
||||||
// Expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(this.gemstoneService.count()).isEqualTo(2);
|
assertThat(this.gemstoneService.count()).isEqualTo(2);
|
||||||
assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby"));
|
assertThat(this.gemstoneService.list()).contains(
|
||||||
|
getGemstones("Diamond", "Ruby"));
|
||||||
|
|
||||||
this.gemstoneService.save(createGemstone("Pearl"));
|
this.gemstoneService.save(createGemstone("Pearl"));
|
||||||
this.gemstoneService.save(createGemstone("Sapphire"));
|
this.gemstoneService.save(createGemstone("Sapphire"));
|
||||||
|
|
||||||
assertThat(this.gemstoneService.count()).isEqualTo(4);
|
assertThat(this.gemstoneService.count()).isEqualTo(4);
|
||||||
assertThat(this.gemstoneService.list())
|
assertThat(this.gemstoneService.list()).contains(
|
||||||
.contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.gemstoneService.save(createGemstone("Quartz"));
|
this.gemstoneService.save(createGemstone("Quartz"));
|
||||||
}
|
}
|
||||||
catch (IllegalGemstoneException expected) {
|
catch (IllegalGemstoneException ignore) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(this.gemstoneService.count()).isEqualTo(4);
|
assertThat(this.gemstoneService.count()).isEqualTo(4);
|
||||||
assertThat(this.gemstoneService.list())
|
assertThat(this.gemstoneService.list()).contains(
|
||||||
.contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
||||||
assertThat(this.gemstoneService.get("Diamond"))
|
assertThat(this.gemstoneService.get("Diamond")).isEqualTo(
|
||||||
.isEqualTo(createGemstone("Diamond"));
|
createGemstone("Diamond"));
|
||||||
assertThat(this.gemstoneService.get("Pearl")).isEqualTo(createGemstone("Pearl"));
|
assertThat(this.gemstoneService.get("Pearl")).isEqualTo(
|
||||||
|
createGemstone("Pearl"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Gemstone[] getGemstones(String... names) {
|
private Gemstone[] getGemstones(String... names) {
|
||||||
|
|
@ -102,7 +99,7 @@ public class SampleDataGemFireApplicationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Gemstone createGemstone(String name) {
|
private Gemstone createGemstone(String name) {
|
||||||
return createGemstone(this.ID_GENERATOR.incrementAndGet(), name);
|
return createGemstone(this.idGenerator.incrementAndGet(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Gemstone createGemstone(Long id, String name) {
|
private Gemstone createGemstone(Long id, String name) {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gemstone.gemfire</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>gemfire</artifactId>
|
<artifactId>spring-data-gemfire</artifactId>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>commons-logging</groupId>
|
<groupId>commons-logging</groupId>
|
||||||
|
|
@ -33,14 +33,6 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-gemfire</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjweaver</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
provides: gemfire,spring-data-gemfire
|
provides: spring-data-gemfire
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue