DATADOC-133 changed non-string attributes to xsd:string to support configuration using property placeholder; upgraded to Mongo Java driver 2.5.3
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
<name>Spring Data MongoDB Support</name>
|
||||
|
||||
<properties>
|
||||
<mongo.version>2.4</mongo.version>
|
||||
<mongo.version>2.5.3</mongo.version>
|
||||
<querydsl.version>2.2.0-beta4</querydsl.version>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ The Mongo Replica set database addresses
|
||||
The name of the mongo definition (by default "mongo").]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="port" type="xsd:positiveInteger" use="optional">
|
||||
<xsd:attribute name="port" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The port to connect to MongoDB server. Default is 27017
|
||||
@@ -236,7 +236,7 @@ The name of the Mongo object that determines what server to monitor. (by default
|
||||
|
||||
|
||||
<xsd:complexType name="optionsType">
|
||||
<xsd:attribute name="connectionsPerHost" type="xsd:positiveInteger">
|
||||
<xsd:attribute name="connectionsPerHost" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The number of connections allowed per host. Will block if run out. Default is 10. System property MONGO.POOLSIZE can override
|
||||
@@ -252,28 +252,28 @@ then 50 threads can block more than that and an exception will be thrown.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="maxWaitTime" type="xsd:positiveInteger">
|
||||
<xsd:attribute name="maxWaitTime" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The max wait time of a blocking thread for a connection. Default is 12000 ms (2 minutes)
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="connectTimeout" type="xsd:positiveInteger">
|
||||
<xsd:attribute name="connectTimeout" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The connect timeout in milliseconds. 0 is default and infinite.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="socketTimeout" type="xsd:positiveInteger">
|
||||
<xsd:attribute name="socketTimeout" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The socket timeout. 0 is default and infinite.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="autoConnectRetry" type="xsd:boolean">
|
||||
<xsd:attribute name="autoConnectRetry" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This controls whether or not on a connect, the system retries automatically. Default is false.
|
||||
|
||||
@@ -28,6 +28,9 @@ import org.springframework.data.document.mongodb.MongoFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoOptions;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class MongoNamespaceTests {
|
||||
@@ -35,9 +38,10 @@ public class MongoNamespaceTests {
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@Test
|
||||
public void testMongoSingleton() throws Exception {
|
||||
assertTrue(ctx.containsBean("mongo"));
|
||||
MongoFactoryBean mfb = (MongoFactoryBean) ctx.getBean("&mongo");
|
||||
assertTrue(ctx.containsBean("noAttrMongo"));
|
||||
MongoFactoryBean mfb = (MongoFactoryBean) ctx.getBean("&noAttrMongo");
|
||||
assertNull(readField("host", mfb));
|
||||
assertNull(readField("port", mfb));
|
||||
}
|
||||
@@ -52,6 +56,22 @@ public class MongoNamespaceTests {
|
||||
assertEquals(new Integer(27017), port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMongoSingletonWithPropertyPlaceHolders() throws Exception {
|
||||
assertTrue(ctx.containsBean("mongo"));
|
||||
MongoFactoryBean mfb = (MongoFactoryBean) ctx.getBean("&mongo");
|
||||
String host = readField("host", mfb);
|
||||
Integer port = readField("port", mfb);
|
||||
assertEquals("127.0.0.1", host);
|
||||
assertEquals(new Integer(27017), port);
|
||||
Mongo mongo = mfb.getObject();
|
||||
MongoOptions mongoOpts = mongo.getMongoOptions();
|
||||
assertEquals(8, mongoOpts.connectionsPerHost);
|
||||
assertEquals(1000, mongoOpts.connectTimeout);
|
||||
assertEquals(1500, mongoOpts.maxWaitTime);
|
||||
assertEquals(false, mongoOpts.autoConnectRetry);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public static <T> T readField(String name, Object target) throws Exception {
|
||||
Field field = null;
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
<?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:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:property-placeholder location="classpath:/org/springframework/data/document/mongodb/config/mongo.properties"/>
|
||||
|
||||
<mongo:mongo host="localhost" port="27017">
|
||||
<mongo:options connectionsPerHost="5"/>
|
||||
<mongo:mongo host="${mongo.host}" port="${mongo.port}">
|
||||
<mongo:options
|
||||
connectionsPerHost="${mongo.connectionsPerHost}"
|
||||
connectTimeout="${mongo.connectTimeout}"
|
||||
maxWaitTime="${mongo.maxWaitTime}"
|
||||
autoConnectRetry="${mongo.autoConnectRetry}"/>
|
||||
</mongo:mongo>
|
||||
|
||||
<mongo:mongo id="defaultMongo" host="localhost" port="27017"/>
|
||||
|
||||
<mongo:mongo id="noAttrMongo"/>
|
||||
|
||||
<mongo:mapping-converter>
|
||||
<mongo:custom-converters>
|
||||
<mongo:converter ref="readConverter"/>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
mongo.host=127.0.0.1
|
||||
mongo.port=27017
|
||||
mongo.connectionsPerHost=8
|
||||
mongo.connectTimeout=1000
|
||||
mongo.maxWaitTime=1500
|
||||
mongo.autoConnectRetry=false
|
||||
Reference in New Issue
Block a user