Fixes JIRA issues SGF-238, SGF-239 and SGF-240 involving jndi-binding cache settings.

This commit is contained in:
John Blum
2013-12-13 14:59:03 -08:00
parent fb61e19f1e
commit 8dee6f7ab2
7 changed files with 418 additions and 213 deletions

View File

@@ -0,0 +1,117 @@
/*
* 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.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.internal.datasource.ConfigProperty;
/**
* The JndiBindingsPropertyPlaceholderTest class is a test suite of test cases testing the configuration of a GemFire
* Cache JNDI DataSource using property placeholders.
* <p/>
* @author John Blum
* @see org.junit.Test
* @see org.springframework.context.ApplicationContext
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.4.0
* @since 7.0.1 (GemFire)
*/
@ContextConfiguration(locations = "jndi-binding-with-property-placeholders-ns.xml",
initializers = GemfireTestApplicationContextInitializer.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class JndiBindingsPropertyPlaceholderTest {
@Autowired
@SuppressWarnings("unused")
private ApplicationContext context;
protected void assertPropertyValueExists(final String expectedPropertyName, final String expectedPropertyValue,
final List<ConfigProperty> properties) {
for (ConfigProperty property : properties) {
if (expectedPropertyName.equals(property.getName())) {
assertEquals(expectedPropertyValue, property.getValue());
assertEquals(String.class.getName(), property.getType());
return;
}
}
fail(String.format("ConfigProperty with name [%1$s] was not found!", expectedPropertyName));
}
@Test
public void testCacheJndiDataSourceConfiguration() {
CacheFactoryBean factory = context.getBean("&gemfireCache", CacheFactoryBean.class);
List<CacheFactoryBean.JndiDataSource> jndiDataSources = factory.getJndiDataSources();
assertNotNull(jndiDataSources);
assertEquals(1, jndiDataSources.size());
CacheFactoryBean.JndiDataSource dataSource = jndiDataSources.get(0);
assertNotNull(dataSource);
Map<String, String> attributes = dataSource.getAttributes();
assertNotNull(attributes);
assertFalse(attributes.isEmpty());
assertEquals("testDataSource", attributes.get("jndi-name"));
assertEquals("XAPoolDataSource", attributes.get("type"));
assertEquals("60", attributes.get("blocking-timeout-seconds"));
assertEquals("org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource", attributes.get("conn-pooled-datasource-class"));
assertEquals("jdbc:derby:testDataStore;create=true", attributes.get("connection-url"));
assertEquals("180", attributes.get("idle-timeout-seconds"));
assertEquals("10", attributes.get("init-pool-size"));
assertEquals("org.apache.derby.jdbc.EmbeddedDriver", attributes.get("jdbc-driver-class"));
assertEquals("30", attributes.get("login-timeout-seconds"));
assertEquals("org.apache.derby.jdbc.NonExistingManagedConnectionFactoryClass", attributes.get("managed-connection-factory-class"));
assertEquals("50", attributes.get("max-pool-size"));
assertEquals("test123", attributes.get("password"));
assertEquals("XATransaction", attributes.get("transaction-type"));
assertEquals("masterdba", attributes.get("user-name"));
assertEquals("org.apache.derby.jdbc.EmbeddedXADataSource", attributes.get("xa-datasource-class"));
List<ConfigProperty> props = dataSource.getProps();
assertNotNull(props);
assertFalse(props.isEmpty());
assertPropertyValueExists("schemaName", "testSchema", props);
assertPropertyValueExists("databaseName", "testDataStore", props);
assertPropertyValueExists("description", "test", props);
assertPropertyValueExists("email", "masterdba@xcompany.com", props);
assertPropertyValueExists("phone", "501-555-1234", props);
}
}

View File

@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,22 +30,29 @@ import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.internal.datasource.GemFireBasicDataSource;
/**
* @author David Turanski
*
* This test requires a real cache
* <p/>
* @author David Turanski
* @author John Blum
*/
@ContextConfiguration("jndi-binding-ns.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/org/springframework/data/gemfire/config/jndi-binding-ns.xml")
@SuppressWarnings("unused")
public class JndiBindingsTest {
@Autowired ApplicationContext ctx;
@Autowired
private Cache cache;
@Test
public void testJndiBindings() throws Exception {
Cache cache = ctx.getBean("gemfireCache", Cache.class);
assertNotNull(cache.getJNDIContext().lookup("java:/SimpleDataSource"));
GemFireBasicDataSource ds = (GemFireBasicDataSource) cache.getJNDIContext().lookup("java:/SimpleDataSource");
assertEquals("org.apache.derby.jdbc.EmbeddedDriver", ds.getJDBCDriver());
assertEquals(60, ds.getLoginTimeout());
Object dataSourceObject = cache.getJNDIContext().lookup("java:/SimpleDataSource");
assertTrue(dataSourceObject instanceof GemFireBasicDataSource);
GemFireBasicDataSource dataSource = (GemFireBasicDataSource) dataSourceObject;
assertEquals("org.apache.derby.jdbc.EmbeddedDriver", dataSource.getJDBCDriver());
assertEquals(60, dataSource.getLoginTimeout());
}
}

View File

@@ -1,23 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:p="http://www.springframework.org/schema/p" default-lazy-init="true"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
xmlns:gfe="http://www.springframework.org/schema/gemfire"
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/util http://www.springframework.org/schema/util/spring-util.xsd">
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
">
<gfe:cache>
<gfe:jndi-binding type="SimpleDataSource" jndi-name="SimpleDataSource"
jdbc-driver-class="org.apache.derby.jdbc.EmbeddedDriver"
init-pool-size="2" max-pool-size="7" idle-timeout-seconds="40"
blocking-timeout-seconds="40" login-timeout-seconds="60"
conn-pooled-datasource-class="org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource"
xa-datasource-class="org.apache.derby.jdbc.EmbeddedXADataSource"
user-name="mitul" password="83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a"
connection-url="jdbc:derby:newDB;create=true">
<gfe:jndi-binding jndi-name="SimpleDataSource"
type="SimpleDataSource"
blocking-timeout-seconds="40"
conn-pooled-datasource-class="org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource"
connection-url="jdbc:derby:newDB;create=true"
idle-timeout-seconds="40"
init-pool-size="2"
jdbc-driver-class="org.apache.derby.jdbc.EmbeddedDriver"
login-timeout-seconds="60"
max-pool-size="7"
password="83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a"
user-name="mitul"
xa-datasource-class="org.apache.derby.jdbc.EmbeddedXADataSource">
<gfe:jndi-prop key="description">hi</gfe:jndi-prop>
<gfe:jndi-prop key="databaseName">newDB</gfe:jndi-prop>
</gfe:jndi-binding>
</gfe:cache>
</beans>
</beans>

View File

@@ -0,0 +1,63 @@
<?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:properties id="jndi-binding-settings">
<prop key="jndi.binding.name">testDataSource</prop>
<prop key="jndi.binding.type">XAPoolDataSource</prop>
<prop key="jndi.binding.blocking.timeout.seconds">60</prop>
<prop key="jndi.binding.conn.pooled.datasource.class">org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource</prop>
<prop key="jndi.binding.connection.url">jdbc:derby:testDataStore;create=true</prop>
<prop key="jndi.binding.idle.timeout.seconds">180</prop>
<prop key="jndi.binding.init.pool.size">10</prop>
<prop key="jndi.binding.jdbc.driver.class">org.apache.derby.jdbc.EmbeddedDriver</prop>
<prop key="jndi.binding.login.timeout.seconds">30</prop>
<prop key="jndi.binding.managed.connection.factory.class">org.apache.derby.jdbc.NonExistingManagedConnectionFactoryClass</prop>
<prop key="jndi.binding.max.pool.size">50</prop>
<prop key="jndi.binding.password">test123</prop>
<prop key="jndi.binding.transaction.type">XATransaction</prop>
<prop key="jndi.binding.user.name">masterdba</prop>
<prop key="jndi.binding.xa.datasource.class">org.apache.derby.jdbc.EmbeddedXADataSource</prop>
<prop key="jndi.prop.schema.name">testSchema</prop>
<prop key="jndi.prop.database.name">testDataStore</prop>
<prop key="jndi.prop.description">test</prop>
<prop key="jndi.prop.email">masterdba@xcompany.com</prop>
<prop key="jndi.prop.phone">501-555-1234</prop>
</util:properties>
<context:property-placeholder properties-ref="jndi-binding-settings"/>
<gfe:cache lazy-init="true">
<gfe:jndi-binding jndi-name="${jndi.binding.name}"
type="${jndi.binding.type}"
blocking-timeout-seconds="${jndi.binding.blocking.timeout.seconds}"
conn-pooled-datasource-class="${jndi.binding.conn.pooled.datasource.class}"
connection-url="${jndi.binding.connection.url}"
idle-timeout-seconds="${jndi.binding.idle.timeout.seconds}"
init-pool-size="${jndi.binding.init.pool.size}"
jdbc-driver-class="${jndi.binding.jdbc.driver.class}"
login-timeout-seconds="${jndi.binding.login.timeout.seconds}"
managed-connection-factory-class="${jndi.binding.managed.connection.factory.class}"
max-pool-size="${jndi.binding.max.pool.size}"
password="${jndi.binding.password}"
transaction-type="${jndi.binding.transaction.type}"
user-name="${jndi.binding.user.name}"
xa-datasource-class="${jndi.binding.xa.datasource.class}">
<gfe:jndi-prop key="schemaName">${jndi.prop.schema.name}</gfe:jndi-prop>
<gfe:jndi-prop key="databaseName">${jndi.prop.database.name}</gfe:jndi-prop>
<gfe:jndi-prop key="description">${jndi.prop.description}</gfe:jndi-prop>
<gfe:jndi-prop key="email">${jndi.prop.email}</gfe:jndi-prop>
<gfe:jndi-prop key="phone">${jndi.prop.phone}</gfe:jndi-prop>
</gfe:jndi-binding>
</gfe:cache>
</beans>