SGF-15
+ finished parsing support for locators and servers
+ improved schema a bit by adding more up-front validation
This commit is contained in:
costin
2010-09-01 12:04:21 +03:00
parent bdb7a4669e
commit d736c302dd
6 changed files with 96 additions and 29 deletions

View File

@@ -36,6 +36,9 @@ public abstract class TestUtils {
clazz = clazz.getSuperclass();
} while (field == null && !clazz.equals(Object.class));
if (field == null)
throw new IllegalArgumentException("Cannot find field '" + name + "' in the class hierarchy of "
+ target.getClass());
field.setAccessible(true);
return (T) field.get(target);
}

View File

@@ -19,11 +19,15 @@ package org.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.Iterator;
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.TestUtils;
import org.springframework.data.gemfire.client.PoolConnection;
import org.springframework.data.gemfire.client.PoolFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -44,14 +48,32 @@ public class PoolNamespaceTest {
public void testBasicClient() throws Exception {
assertTrue(context.containsBean("gemfire-pool"));
assertEquals(context.getBean("gemfire-pool"), PoolManager.find("gemfire-pool"));
PoolFactoryBean pfb = (PoolFactoryBean) context.getBean("&gemfire-pool");
Collection<PoolConnection> locators = TestUtils.readField("locators", pfb);
assertEquals(1, locators.size());
PoolConnection locator = locators.iterator().next();
assertEquals("localhost", locator.getHost());
assertEquals(40403, locator.getPort());
}
@Test
public void testComplexPool() throws Exception {
assertTrue(context.containsBean("complex"));
PoolFactoryBean pfb = (PoolFactoryBean) context.getBean("&complex");
assertEquals(30, TestUtils.readField("retry-attempts", pfb));
assertEquals(6000, TestUtils.readField("free-connection-timeout", pfb));
assertEquals(5000, TestUtils.readField("ping-interval", pfb));
assertEquals(30, TestUtils.readField("retryAttempts", pfb));
assertEquals(6000, TestUtils.readField("freeConnectionTimeout", pfb));
assertEquals(5000l, TestUtils.readField("pingInterval", pfb));
assertTrue((Boolean) TestUtils.readField("subscriptionEnabled", pfb));
Collection<PoolConnection> servers = TestUtils.readField("servers", pfb);
assertEquals(2, servers.size());
Iterator<PoolConnection> iterator = servers.iterator();
PoolConnection server = iterator.next();
assertEquals("localhost", server.getHost());
assertEquals(40404, server.getPort());
server = iterator.next();
assertEquals("localhost", server.getHost());
assertEquals(40405, server.getPort());
}
}

View File

@@ -3,7 +3,6 @@
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
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
@@ -14,16 +13,13 @@
<gfe:cache />
<gfe:pool/>
<gfe:pool>
<gfe:locator host="localhost" port="40403"/>
</gfe:pool>
<!--
<gfe:locator host="localhost" port="0"/>
-->
<gfe:pool id="complex" free-connection-timeout="6000" retry-attempts="30" ping-interval="5000"/>
<!--
<gfe:server host="localhost" port="0"/>
<gfe:locator host="localhost" port="0"/>
-->
<gfe:pool id="complex" free-connection-timeout="6000" retry-attempts="30" ping-interval="5000" subscription-enabled="true">
<gfe:server host="localhost" port="40404"/>
<gfe:server host="localhost" port="40405"/>
</gfe:pool>
</beans>