SGF-408 - Provide support in the SDG XML namespace to load a pre-defined data set using GemFire Snapshot Service for development and testing purposes.
Renamed the <gfe-data:snapshot-service> element 'suppress-init-import' attribute to 'suppress-import-on-init'. Fixed up the JSONRegionAdviceTest class test case failures due to changes in the ..repository.sample.Person application domain object class. (cherry picked from commit d9245f343050182f570a0ea1bf629f03258667b1) Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
@@ -49,7 +49,7 @@ class SnapshotServiceParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
ParsingUtils.setCacheReference(element, builder);
|
||||
ParsingUtils.setRegionReference(element, builder);
|
||||
ParsingUtils.setPropertyValue(element, builder, "suppress-init-import");
|
||||
ParsingUtils.setPropertyValue(element, builder, "suppress-import-on-init");
|
||||
builder.addPropertyValue("exports", parseExports(element, parserContext));
|
||||
builder.addPropertyValue("imports", parseImports(element, parserContext));
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ import com.gemstone.gemfire.cache.snapshot.SnapshotOptions;
|
||||
* @see org.springframework.beans.factory.FactoryBean
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
* @see org.springframework.context.ApplicationListener
|
||||
* @see SnapshotServiceFactoryBean.SnapshotServiceAdapter
|
||||
* @see org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.SnapshotServiceAdapter
|
||||
* @see com.gemstone.gemfire.cache.snapshot.CacheSnapshotService
|
||||
* @see com.gemstone.gemfire.cache.snapshot.RegionSnapshotService
|
||||
* @since 1.7.0
|
||||
@@ -75,7 +75,7 @@ public class SnapshotServiceFactoryBean<K, V> implements FactoryBean<SnapshotSer
|
||||
|
||||
protected static final SnapshotMetadata[] EMPTY_ARRAY = new SnapshotMetadata[0];
|
||||
|
||||
private Boolean suppressInitImport;
|
||||
private Boolean suppressImportOnInit;
|
||||
|
||||
private Cache cache;
|
||||
|
||||
@@ -195,22 +195,22 @@ public class SnapshotServiceFactoryBean<K, V> implements FactoryBean<SnapshotSer
|
||||
/**
|
||||
* Sets a boolean condition to indicate whether importing on initialization should be suppressed.
|
||||
*
|
||||
* @param suppressInitImport a Boolean value to indicate whether importing on initialization should be suppressed.
|
||||
* @see #isSuppressInitImport()
|
||||
* @param suppressImportOnInit a Boolean value to indicate whether importing on initialization should be suppressed.
|
||||
* @see #getSuppressImportOnInit()
|
||||
*/
|
||||
public void setSuppressInitImport(Boolean suppressInitImport) {
|
||||
this.suppressInitImport = suppressInitImport;
|
||||
public void setSuppressImportOnInit(Boolean suppressImportOnInit) {
|
||||
this.suppressImportOnInit = suppressImportOnInit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether importing on initialization should be suppressed.
|
||||
*
|
||||
* @return a boolean value indicating whether import on initialization should be suppressed.
|
||||
* @see #setSuppressInitImport(Boolean)
|
||||
* @see #setSuppressImportOnInit(Boolean)
|
||||
* @see #afterPropertiesSet()
|
||||
*/
|
||||
protected boolean isSuppressInitImport() {
|
||||
return Boolean.TRUE.equals(suppressInitImport);
|
||||
protected boolean getSuppressImportOnInit() {
|
||||
return Boolean.TRUE.equals(suppressImportOnInit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,7 +262,7 @@ public class SnapshotServiceFactoryBean<K, V> implements FactoryBean<SnapshotSer
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
snapshotServiceAdapter = create();
|
||||
|
||||
if (!isSuppressInitImport()) {
|
||||
if (!getSuppressImportOnInit()) {
|
||||
snapshotServiceAdapter.doImport(getImports());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ ID of the GemFire [Cache|Region] SnapshotService bean in the Spring context.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="suppress-init-import" type="xsd:string" default="false">
|
||||
<xsd:attribute name="suppress-import-on-init" type="xsd:string" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Determines whether imports are suppressed on initialization of the GemFire Snapshot Service.
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.io.Serializable;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.gemfire.mapping.Region;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.gemstone.gemfire.management.internal.cli.util.spring.ObjectUtils;
|
||||
|
||||
/**
|
||||
@@ -30,6 +31,7 @@ import com.gemstone.gemfire.management.internal.cli.util.spring.ObjectUtils;
|
||||
* @see java.io.Serializable
|
||||
*/
|
||||
@Region("simple")
|
||||
@JsonIgnoreProperties("name")
|
||||
public class Person implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 508843183613325255L;
|
||||
@@ -48,6 +50,15 @@ public class Person implements Serializable {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Person's address.
|
||||
*
|
||||
* @return the Address of the Person.
|
||||
*/
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier (ID) of this Person.
|
||||
*
|
||||
@@ -58,14 +69,18 @@ public class Person implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the firstname
|
||||
* Gets this Person's first name.
|
||||
*
|
||||
* @return the first name of this Person.
|
||||
*/
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lastname
|
||||
* Gets this Person's last name.
|
||||
*
|
||||
* @return the last name of this Person.
|
||||
*/
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
|
||||
@@ -259,20 +259,20 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetSuppressInitImportSuccessfully() {
|
||||
assertThat(factoryBean.isSuppressInitImport(), is(false));
|
||||
public void setAndGetSuppressImportOnInitSuccessfully() {
|
||||
assertThat(factoryBean.getSuppressImportOnInit(), is(false));
|
||||
|
||||
factoryBean.setSuppressInitImport(true);
|
||||
factoryBean.setSuppressImportOnInit(true);
|
||||
|
||||
assertThat(factoryBean.isSuppressInitImport(), is(true));
|
||||
assertThat(factoryBean.getSuppressImportOnInit(), is(true));
|
||||
|
||||
factoryBean.setSuppressInitImport(false);
|
||||
factoryBean.setSuppressImportOnInit(false);
|
||||
|
||||
assertThat(factoryBean.isSuppressInitImport(), is(false));
|
||||
assertThat(factoryBean.getSuppressImportOnInit(), is(false));
|
||||
|
||||
factoryBean.setSuppressInitImport(null);
|
||||
factoryBean.setSuppressImportOnInit(null);
|
||||
|
||||
assertThat(factoryBean.isSuppressInitImport(), is(false));
|
||||
assertThat(factoryBean.getSuppressImportOnInit(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -311,10 +311,10 @@ public class SnapshotServiceFactoryBeanTest {
|
||||
}
|
||||
};
|
||||
|
||||
factoryBean.setSuppressInitImport(true);
|
||||
factoryBean.setSuppressImportOnInit(true);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(factoryBean.isSuppressInitImport(), is(true));
|
||||
assertThat(factoryBean.getSuppressImportOnInit(), is(true));
|
||||
|
||||
verify(mockSnapshotService, never()).doImport(any(SnapshotMetadata[].class));
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import static org.junit.Assert.assertEquals;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -31,16 +30,21 @@ import org.springframework.data.gemfire.repository.sample.Person;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.query.SelectResults;
|
||||
|
||||
/**
|
||||
* JSONRegionAdviceTest is a test suite of test cases testing SDG's support for storing and retrieving JSON data
|
||||
* in GemFire Cache Regions (un)marshalled using Jackson.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "unused" })
|
||||
public class JSONRegionAdviceTest {
|
||||
|
||||
// TODO figure out why auto-proxying the Region for JSON support prevents the GemfireTemplate from being "auto-wired",
|
||||
@@ -49,7 +53,6 @@ public class JSONRegionAdviceTest {
|
||||
@Autowired
|
||||
private GemfireOperations template;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Resource(name = "jsonRegion")
|
||||
private Region jsonRegion;
|
||||
|
||||
@@ -58,6 +61,15 @@ public class JSONRegionAdviceTest {
|
||||
jsonRegion.clear();
|
||||
}
|
||||
|
||||
protected static String toJson(Object bean) {
|
||||
try {
|
||||
return new ObjectMapper().writeValueAsString(bean);
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException(String.format("Failed to convert object (%1$s) into JSON", bean), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutString() {
|
||||
String json = "{\"hello\":\"world\"}";
|
||||
@@ -68,8 +80,6 @@ public class JSONRegionAdviceTest {
|
||||
|
||||
jsonRegion.create("key2", json);
|
||||
|
||||
System.out.println(jsonRegion.get("key"));
|
||||
|
||||
assertEquals(json, jsonRegion.get("key"));
|
||||
}
|
||||
|
||||
@@ -79,47 +89,47 @@ public class JSONRegionAdviceTest {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("key1", "{\"hello1\":\"world1\"}");
|
||||
map.put("key2", "{\"hello2\":\"world2\"}");
|
||||
|
||||
jsonRegion.putAll(map);
|
||||
List<String> keys = Arrays.asList("key1", "key2");
|
||||
Map<String, String> results = jsonRegion.getAll(keys);
|
||||
|
||||
Map<String, String> results = jsonRegion.getAll(Arrays.asList("key1", "key2"));
|
||||
|
||||
assertEquals("{\"hello1\":\"world1\"}", results.get("key1"));
|
||||
assertEquals("{\"hello2\":\"world2\"}", results.get("key2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectToJSon() throws IOException {
|
||||
Person dave = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", dave);
|
||||
String json = (String) jsonRegion.get("dave");
|
||||
assertEquals(json, "{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}", json);
|
||||
Object result = jsonRegion.put("dave", dave);
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}", result);
|
||||
Person daveTuranski = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", daveTuranski);
|
||||
String json = String.valueOf(jsonRegion.get("dave"));
|
||||
assertEquals(json, toJson(daveTuranski), json);
|
||||
Object result = jsonRegion.put("dave", daveTuranski);
|
||||
assertEquals(toJson(daveTuranski), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateFindUnique() {
|
||||
Person dave = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", dave);
|
||||
String json = (String) template.findUnique("SELECT * FROM /jsonRegion WHERE firstname=$1", "Dave");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}", json);
|
||||
Person daveTuranski = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", daveTuranski);
|
||||
String json = template.findUnique("SELECT * FROM /jsonRegion WHERE firstname=$1", "Dave");
|
||||
assertEquals(toJson(daveTuranski), json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateFind() {
|
||||
Person dave = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", dave);
|
||||
Person daveTuranski = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", daveTuranski);
|
||||
SelectResults<String> results = template.find("SELECT * FROM /jsonRegion WHERE firstname=$1", "Dave");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",
|
||||
results.iterator().next());
|
||||
assertEquals(toJson(daveTuranski), results.iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateQuery() {
|
||||
Person dave = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", dave);
|
||||
Person daveTuranski = new Person(1L, "Dave", "Turanski");
|
||||
jsonRegion.put("dave", daveTuranski);
|
||||
SelectResults<String> results = template.query("firstname='Dave'");
|
||||
assertEquals("{\"id\":1,\"firstname\":\"Dave\",\"lastname\":\"Turanski\",\"address\":null}",
|
||||
results.iterator().next());
|
||||
assertEquals(toJson(daveTuranski), results.iterator().next());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,17 +51,17 @@
|
||||
<gfe-data:export-snapshot location="gemfire/snapshots/nonHandyNonDoePeople.snapshot" filter-ref="nonHandyNonDoeSnapshotFilter"/>
|
||||
</gfe-data:snapshot-service>
|
||||
|
||||
<gfe-data:snapshot-service id="doeSnapshotService" region-ref="Doe" suppress-init-import="true">
|
||||
<gfe-data:snapshot-service id="doeSnapshotService" region-ref="Doe" suppress-import-on-init="true">
|
||||
<gfe-data:import-snapshot location="gemfire/snapshots/people.snapshot">
|
||||
<bean class="org.springframework.data.gemfire.snapshot.SnapshotApplicationEventTriggeredImportsExportsIntegrationTest.LastNameSnapshotFilter" c:lastName="Doe"/>
|
||||
</gfe-data:import-snapshot>
|
||||
</gfe-data:snapshot-service>
|
||||
|
||||
<gfe-data:snapshot-service id="everyoneElseSnapshotService" region-ref="EveryoneElse" suppress-init-import="true">
|
||||
<gfe-data:snapshot-service id="everyoneElseSnapshotService" region-ref="EveryoneElse" suppress-import-on-init="true">
|
||||
<gfe-data:import-snapshot location="gemfire/snapshots/nonHandyNonDoePeople.snapshot"/>
|
||||
</gfe-data:snapshot-service>
|
||||
|
||||
<gfe-data:snapshot-service id="handySnapshotService" region-ref="Handy" suppress-init-import="true">
|
||||
<gfe-data:snapshot-service id="handySnapshotService" region-ref="Handy" suppress-import-on-init="true">
|
||||
<gfe-data:import-snapshot location="gemfire/snapshots/people.snapshot">
|
||||
<bean class="org.springframework.data.gemfire.snapshot.SnapshotApplicationEventTriggeredImportsExportsIntegrationTest.LastNameSnapshotFilter" c:lastName="Handy"/>
|
||||
</gfe-data:import-snapshot>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">JSONRegionAdviceTest</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="log-level">config</prop>
|
||||
<prop key="log-level">warning</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
|
||||
Reference in New Issue
Block a user