Fixes JIRA issues SGF-249 involving property placeholder values on Disk Store bean definition attributes, and specifically the compaction-threshold attribute, in the SDG XML namespace.
This commit is contained in:
@@ -24,40 +24,42 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
import com.gemstone.gemfire.cache.DiskStoreFactory;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
|
||||
/**
|
||||
* FactoryBean for creating a DiskStore
|
||||
* FactoryBean for creating a GemFire DiskStore.
|
||||
* <p/>
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.BeanNameAware
|
||||
* @see org.springframework.beans.factory.FactoryBean
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, InitializingBean, BeanNameAware {
|
||||
|
||||
private DiskStoreFactory diskStoreFactory;
|
||||
|
||||
private Boolean allowForceCompaction;
|
||||
private Boolean autoCompact;
|
||||
|
||||
private Boolean allowForceCompaction;
|
||||
|
||||
private Integer maxOplogSize;
|
||||
|
||||
private Integer timeInterval;
|
||||
|
||||
private Integer queueSize;
|
||||
|
||||
private Integer compactionThreshold;
|
||||
|
||||
private Integer writeBufferSize;
|
||||
private DiskStore diskStore;
|
||||
|
||||
private GemFireCache cache;
|
||||
|
||||
private String name;
|
||||
private Integer compactionThreshold;
|
||||
private Integer maxOplogSize;
|
||||
private Integer queueSize;
|
||||
private Integer timeInterval;
|
||||
private Integer writeBufferSize;
|
||||
|
||||
private List<DiskDir> diskDirs;
|
||||
|
||||
private DiskStore diskStore;
|
||||
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public DiskStore getObject() throws Exception {
|
||||
@@ -76,7 +78,9 @@ public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, Initializin
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(cache, "Cache property must be set");
|
||||
Assert.state(cache != null, String.format("A reference to the GemFire Cache must be set for Disk Store '%1$s'.",
|
||||
getName()));
|
||||
|
||||
diskStoreFactory = cache.createDiskStoreFactory();
|
||||
|
||||
if (allowForceCompaction != null) {
|
||||
@@ -104,52 +108,32 @@ public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, Initializin
|
||||
if (!CollectionUtils.isEmpty(diskDirs)) {
|
||||
File[] diskDirFiles = new File[diskDirs.size()];
|
||||
int[] diskDirSizes = new int[diskDirs.size()];
|
||||
|
||||
for (int i = 0; i < diskDirs.size(); i++) {
|
||||
DiskDir diskDir = diskDirs.get(i);
|
||||
diskDirFiles[i] = new File(diskDir.location);
|
||||
diskDirSizes[i] = diskDir.maxSize == null ? DiskStoreFactory.DEFAULT_DISK_DIR_SIZE : diskDir.maxSize;
|
||||
}
|
||||
|
||||
diskStoreFactory.setDiskDirsAndSizes(diskDirFiles, diskDirSizes);
|
||||
}
|
||||
|
||||
diskStore = diskStoreFactory.create(name == null ? DiskStoreFactory.DEFAULT_DISK_STORE_NAME : name);
|
||||
Assert.notNull(diskStore);
|
||||
|
||||
diskStore = diskStoreFactory.create(getName());
|
||||
|
||||
Assert.notNull(diskStore, String.format("The DiskStore with name '%1$s' failed to be created successfully.",
|
||||
diskStore.getName()));
|
||||
}
|
||||
|
||||
public void setCache(GemFireCache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public void setAutoCompact(Boolean autoCompact) {
|
||||
this.autoCompact = autoCompact;
|
||||
}
|
||||
|
||||
public void setAllowForceCompaction(Boolean allowForceCompaction) {
|
||||
this.allowForceCompaction = allowForceCompaction;
|
||||
}
|
||||
|
||||
public void setMaxOplogSize(Integer maxOplogSize) {
|
||||
this.maxOplogSize = maxOplogSize;
|
||||
}
|
||||
|
||||
public void setTimeInterval(Integer timeInterval) {
|
||||
this.timeInterval = timeInterval;
|
||||
}
|
||||
|
||||
public void setQueueSize(Integer queueSize) {
|
||||
this.queueSize = queueSize;
|
||||
}
|
||||
|
||||
public void setCompactionThreshold(Integer compactionThreshold) {
|
||||
this.compactionThreshold = compactionThreshold;
|
||||
}
|
||||
|
||||
public void setWriteBufferSize(Integer writeBufferSize) {
|
||||
this.writeBufferSize = writeBufferSize;
|
||||
}
|
||||
|
||||
public void setDiskDirs(List<DiskDir> diskDirs) {
|
||||
this.diskDirs = diskDirs;
|
||||
public void setAutoCompact(Boolean autoCompact) {
|
||||
this.autoCompact = autoCompact;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -157,10 +141,44 @@ public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, Initializin
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static class DiskDir {
|
||||
final String location;
|
||||
public void setCompactionThreshold(Integer compactionThreshold) {
|
||||
validateCompactionThreshold(compactionThreshold);
|
||||
this.compactionThreshold = compactionThreshold;
|
||||
}
|
||||
|
||||
protected void validateCompactionThreshold(final Integer compactionThreshold) {
|
||||
Assert.isTrue(compactionThreshold == null || (compactionThreshold >= 0 && compactionThreshold <= 100),
|
||||
String.format("The DiskStore's (%1$s) compaction threshold (%2$d) must be an integer value between 0 and 100 inclusive.",
|
||||
this.name, compactionThreshold));
|
||||
}
|
||||
|
||||
public void setDiskDirs(List<DiskDir> diskDirs) {
|
||||
this.diskDirs = diskDirs;
|
||||
}
|
||||
|
||||
public void setMaxOplogSize(Integer maxOplogSize) {
|
||||
this.maxOplogSize = maxOplogSize;
|
||||
}
|
||||
|
||||
public void setQueueSize(Integer queueSize) {
|
||||
this.queueSize = queueSize;
|
||||
}
|
||||
|
||||
public void setTimeInterval(Integer timeInterval) {
|
||||
this.timeInterval = timeInterval;
|
||||
}
|
||||
|
||||
public void setWriteBufferSize(Integer writeBufferSize) {
|
||||
this.writeBufferSize = writeBufferSize;
|
||||
}
|
||||
|
||||
/* package-private */ final String getName() {
|
||||
return (StringUtils.hasText(name) ? name : DiskStoreFactory.DEFAULT_DISK_STORE_NAME);
|
||||
}
|
||||
|
||||
public static class DiskDir {
|
||||
final Integer maxSize;
|
||||
final String location;
|
||||
|
||||
public DiskDir(String location, int maxSize) {
|
||||
this.location = location;
|
||||
@@ -172,4 +190,5 @@ public class DiskStoreFactoryBean implements FactoryBean<DiskStore>, Initializin
|
||||
this.maxSize = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,11 +29,13 @@ import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <disk-store> definitions.
|
||||
* Parser for <disk-store> bean definitions.
|
||||
* <p/>
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
public class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return DiskStoreFactoryBean.class;
|
||||
@@ -42,29 +44,37 @@ public class DiskStoreParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
|
||||
builder.setLazyInit(false);
|
||||
|
||||
ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache");
|
||||
ParsingUtils.setPropertyValue(element, builder, "auto-compact");
|
||||
ParsingUtils.setPropertyValue(element, builder, "allow-force-compaction");
|
||||
ParsingUtils.setPropertyValue(element, builder, "max-oplog-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "time-interval");
|
||||
ParsingUtils.setPropertyValue(element, builder, "queue-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "auto-compact");
|
||||
ParsingUtils.setPropertyValue(element, builder, "compaction-threshold");
|
||||
ParsingUtils.setPropertyValue(element, builder, "max-oplog-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "queue-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "time-interval");
|
||||
ParsingUtils.setPropertyValue(element, builder, "write-buffer-size");
|
||||
|
||||
List<Element> diskDirElements = DomUtils.getChildElementsByTagName(element, "disk-dir");
|
||||
|
||||
if (!CollectionUtils.isEmpty(diskDirElements)) {
|
||||
ManagedList<AbstractBeanDefinition> diskDirs = new ManagedList<AbstractBeanDefinition>();
|
||||
|
||||
for (Element diskDirElement : diskDirElements) {
|
||||
BeanDefinitionBuilder diskDirBuilder = BeanDefinitionBuilder.genericBeanDefinition(DiskDir.class);
|
||||
|
||||
diskDirBuilder.addConstructorArgValue(diskDirElement.getAttribute("location"));
|
||||
|
||||
if (diskDirElement.hasAttribute("max-size")) {
|
||||
diskDirBuilder.addConstructorArgValue(diskDirElement.getAttribute("max-size"));
|
||||
}
|
||||
|
||||
diskDirs.add(diskDirBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
builder.addPropertyValue("diskDirs", diskDirs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1557,16 +1557,14 @@ The maximum size (in megabytes) of data stored in each directory. Default value
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="auto-compact" type="xsd:string"
|
||||
default="true">
|
||||
<xsd:attribute name="auto-compact" type="xsd:string" default="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether or not the operation logs are automatically compacted or not. Default is true.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="max-oplog-size" type="xsd:string"
|
||||
default="1024">
|
||||
<xsd:attribute name="max-oplog-size" type="xsd:string" default="1024">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Sets the maximum size in megabytes a single oplog (operation log) is allowed to be. When an oplog is created this
|
||||
@@ -1574,8 +1572,7 @@ amount of file space will be immediately reserved.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="time-interval" type="xsd:string"
|
||||
default="1000">
|
||||
<xsd:attribute name="time-interval" type="xsd:string" default="1000">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Sets the number of milliseconds that can elapse before unwritten data is written to disk.
|
||||
@@ -1583,8 +1580,7 @@ It is considered only for asynchronous writing.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="queue-size" type="xsd:string"
|
||||
default="0">
|
||||
<xsd:attribute name="queue-size" type="xsd:string" default="0">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The maximum number of operations that can be asynchronously queued. Once this many pending async operations have been
|
||||
@@ -1593,32 +1589,24 @@ Considered only for asynchronous writing.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="compaction-threshold" default="50">
|
||||
<xsd:attribute name="compaction-threshold" type="xsd:string" default="50">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Sets the threshold at which an oplog will become compactable. Until it reaches this threshold the oplog will not be compacted.
|
||||
The threshold is a percentage in the range 0..100. When the amount of garbage in an oplog exceeds this percentage then when a
|
||||
compaction is done this garbage will be cleaned up freeing up disk space. Garbage is created by entry destroys,
|
||||
compaction is done and this garbage will be cleaned up freeing up disk space. Garbage is created by entry destroys,
|
||||
entry updates, and region destroys.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:short">
|
||||
<xsd:minInclusive value="0" />
|
||||
<xsd:maxInclusive value="100" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="allow-force-compaction" type="xsd:string"
|
||||
default="false">
|
||||
<xsd:attribute name="allow-force-compaction" type="xsd:string" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether forced compaction is allowed for regions using this disk store
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="write-buffer-size" type="xsd:string"
|
||||
default="32768">
|
||||
<xsd:attribute name="write-buffer-size" type="xsd:string" default="32768">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates the write buffer size in bytes
|
||||
@@ -1636,8 +1624,7 @@ Indicates the write buffer size in bytes
|
||||
The name of the disk store bean definition. This is also used as the disk store name]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="cache-ref" type="xsd:string" use="optional"
|
||||
default="gemfireCache">
|
||||
<xsd:attribute name="cache-ref" type="xsd:string" use="optional" default="gemfireCache">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the bean defining the GemFire cache (by default 'gemfireCache').
|
||||
|
||||
@@ -1548,16 +1548,14 @@ The maximum size (in megabytes) of data stored in each directory. Default value
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="auto-compact" type="xsd:string"
|
||||
default="true">
|
||||
<xsd:attribute name="auto-compact" type="xsd:string" default="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether or not the operation logs are automatically compacted or not. Default is true.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="max-oplog-size" type="xsd:string"
|
||||
default="1024">
|
||||
<xsd:attribute name="max-oplog-size" type="xsd:string" default="1024">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Sets the maximum size in megabytes a single oplog (operation log) is allowed to be. When an oplog is created this
|
||||
@@ -1565,8 +1563,7 @@ amount of file space will be immediately reserved.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="time-interval" type="xsd:string"
|
||||
default="1000">
|
||||
<xsd:attribute name="time-interval" type="xsd:string" default="1000">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Sets the number of milliseconds that can elapse before unwritten data is written to disk.
|
||||
@@ -1574,8 +1571,7 @@ It is considered only for asynchronous writing.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="queue-size" type="xsd:string"
|
||||
default="0">
|
||||
<xsd:attribute name="queue-size" type="xsd:string" default="0">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The maximum number of operations that can be asynchronously queued. Once this many pending async operations have been
|
||||
@@ -1584,32 +1580,24 @@ Considered only for asynchronous writing.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="compaction-threshold" default="50">
|
||||
<xsd:attribute name="compaction-threshold" type="xsd:string" default="50">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Sets the threshold at which an oplog will become compactable. Until it reaches this threshold the oplog will not be compacted.
|
||||
The threshold is a percentage in the range 0..100. When the amount of garbage in an oplog exceeds this percentage then when a
|
||||
compaction is done this garbage will be cleaned up freeing up disk space. Garbage is created by entry destroys,
|
||||
compaction is done and this garbage will be cleaned up freeing up disk space. Garbage is created by entry destroys,
|
||||
entry updates, and region destroys.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:short">
|
||||
<xsd:minInclusive value="0" />
|
||||
<xsd:maxInclusive value="100" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="allow-force-compaction" type="xsd:string"
|
||||
default="false">
|
||||
<xsd:attribute name="allow-force-compaction" type="xsd:string" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether forced compaction is allowed for regions using this disk store
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="write-buffer-size" type="xsd:string"
|
||||
default="32768">
|
||||
<xsd:attribute name="write-buffer-size" type="xsd:string" default="32768">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates the write buffer size in bytes
|
||||
@@ -1627,8 +1615,7 @@ Indicates the write buffer size in bytes
|
||||
The name of the disk store bean definition. This is also used as the disk store name]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="cache-ref" type="xsd:string" use="optional"
|
||||
default="gemfireCache">
|
||||
<xsd:attribute name="cache-ref" type="xsd:string" use="optional" default="gemfireCache">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the bean defining the GemFire cache (by default 'gemfireCache').
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.DiskStore;
|
||||
|
||||
/**
|
||||
* The DiskStoreBeanUsingPropertyPlaceholdersIntegrationTest class is a test suite of integration tests testing the use
|
||||
* of Spring PropertyPlaceholders to configure and initialize a Disk Store bean's properties using property placeholders
|
||||
* in the SDG XML namespace <disk-store> bean definition attributes.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.DiskStoreFactoryBean
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @see com.gemstone.gemfire.cache.DiskStore
|
||||
* @link https://jira.springsource.org/browse/SGF-249
|
||||
* @since 1.3.4
|
||||
*/
|
||||
@ContextConfiguration(locations = "diskstore-using-propertyplaceholders-config.xml",
|
||||
initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class DiskStoreBeanUsingPropertyPlaceholdersIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private DiskStore testDataStore;
|
||||
|
||||
@Resource(name="diskStoreConfiguration")
|
||||
private Map<String, Object> diskStoreConfiguration;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object getExpectedValue(final String propertyPlaceholderName) {
|
||||
return diskStoreConfiguration.get(propertyPlaceholderName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiskStoreBeanWithPropertyPlaceholderConfiguration() {
|
||||
System.out.printf("Disk Store Configuration: %1$s%n", diskStoreConfiguration);
|
||||
assertNotNull("The Disk Store was not configured and initialized!", testDataStore);
|
||||
assertEquals(getExpectedValue("allowForceCompaction"), testDataStore.getAllowForceCompaction());
|
||||
assertEquals(getExpectedValue("autoCompact"), testDataStore.getAutoCompact());
|
||||
assertEquals(getExpectedValue("compactionThreshold"), testDataStore.getCompactionThreshold());
|
||||
assertEquals(getExpectedValue("maxOplogSize"), testDataStore.getMaxOplogSize());
|
||||
assertEquals("TestDataStore", testDataStore.getName());
|
||||
assertEquals(getExpectedValue("queueSize"), testDataStore.getQueueSize());
|
||||
assertEquals(getExpectedValue("timeInterval"), testDataStore.getTimeInterval());
|
||||
assertEquals(getExpectedValue("writeBufferSize"), testDataStore.getWriteBufferSize());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* The DiskStoreFactoryBeanTest class is a test suite of test cases testing the contract and functionality of the
|
||||
* DiskStoreFactoryBean class.
|
||||
* <p/>
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.DiskStoreFactoryBean
|
||||
* @since 1.3.4
|
||||
*/
|
||||
public class DiskStoreFactoryBeanTest {
|
||||
|
||||
private final DiskStoreFactoryBean factoryBean = new DiskStoreFactoryBean();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
factoryBean.setBeanName("testDiskStore");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCompactionThresholdWhenNull() {
|
||||
factoryBean.validateCompactionThreshold(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCompactionThresholdWhenValid() {
|
||||
factoryBean.validateCompactionThreshold(0);
|
||||
factoryBean.validateCompactionThreshold(50);
|
||||
factoryBean.validateCompactionThreshold(100);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testValidateCompactionThresholdWhenLessThan0() {
|
||||
try {
|
||||
factoryBean.validateCompactionThreshold(-1);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals(String.format("The DiskStore's (%1$s) compaction threshold (%2$d) must be an integer value between 0 and 100 inclusive.",
|
||||
factoryBean.getName(), -1), expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testValidateCompactionThresholdWhenGreaterThan100() {
|
||||
try {
|
||||
factoryBean.validateCompactionThreshold(101);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals(String.format("The DiskStore's (%1$s) compaction threshold (%2$d) must be an integer value between 0 and 100 inclusive.",
|
||||
factoryBean.getName(), 101), expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCompactionThreshold() {
|
||||
factoryBean.setCompactionThreshold(75);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetCompactionThreadWithIllegalArgument() {
|
||||
try {
|
||||
factoryBean.setCompactionThreshold(200);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals(String.format(
|
||||
"The DiskStore's (%1$s) compaction threshold (%2$d) must be an integer value between 0 and 100 inclusive.",
|
||||
factoryBean.getName(), 200), expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testAfterPropertiesSetWithNoCacheReference() throws Exception {
|
||||
try {
|
||||
factoryBean.afterPropertiesSet();
|
||||
}
|
||||
catch (IllegalStateException expected) {
|
||||
assertEquals("A reference to the GemFire Cache must be set for Disk Store 'testDiskStore'.", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
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/context http://www.springframework.org/schema/context/spring-context.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:map id="diskStoreConfiguration" key-type="java.lang.String">
|
||||
<entry key="allowForceCompaction" value-type="java.lang.Boolean" value="false"/>
|
||||
<entry key="autoCompact" value-type="java.lang.Boolean" value="true"/>
|
||||
<entry key="compactionThreshold" value-type="java.lang.Integer" value="75"/>
|
||||
<entry key="maxOplogSize" value-type="java.lang.Long" value="16384"/>
|
||||
<entry key="queueSize" value-type="java.lang.Integer" value="8192"/>
|
||||
<entry key="timeInterval" value-type="java.lang.Long" value="5000"/>
|
||||
<entry key="writeBufferSize" value-type="java.lang.Integer" value="65536"/>
|
||||
</util:map>
|
||||
|
||||
<context:property-placeholder properties-ref="diskStoreConfiguration"/>
|
||||
|
||||
<gfe:cache/>
|
||||
|
||||
<gfe:disk-store id="TestDataStore"
|
||||
allow-force-compaction="${allowForceCompaction}"
|
||||
auto-compact="${autoCompact}"
|
||||
compaction-threshold="${compactionThreshold}"
|
||||
max-oplog-size="${maxOplogSize}"
|
||||
queue-size="${queueSize}"
|
||||
time-interval="${timeInterval}"
|
||||
write-buffer-size="${writeBufferSize}">
|
||||
</gfe:disk-store>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user