コード例 #1
0
 @Test
 public void testUsingReadPreference() throws Exception {
   this.template.execute(
       "readPref",
       new CollectionCallback<Object>() {
         public Object doInCollection(DBCollection collection)
             throws MongoException, DataAccessException {
           assertThat(collection.getOptions(), is(0));
           assertThat(collection.getDB().getOptions(), is(0));
           return null;
         }
       });
   MongoTemplate slaveTemplate = new MongoTemplate(factory);
   slaveTemplate.setReadPreference(ReadPreference.SECONDARY);
   slaveTemplate.execute(
       "readPref",
       new CollectionCallback<Object>() {
         public Object doInCollection(DBCollection collection)
             throws MongoException, DataAccessException {
           assertThat(collection.getReadPreference(), is(ReadPreference.SECONDARY));
           assertThat(collection.getDB().getOptions(), is(0));
           return null;
         }
       });
 }