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:
@@ -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