iainporter / oauth2-provider

Implementation of an oauth2 provider
Apache License 2.0
225 stars 182 forks source link

MongoDB indexes break tests #14

Open chartrand22 opened 9 years ago

chartrand22 commented 9 years ago

If you add this to User.java for example :

@CompoundIndexes(value=@CompoundIndex(name="email_idx", def="{'emailAddress':1}", unique=true)) public class User extends BaseEntity implements UserDetails {

This breaks the MongoDbConfigurationTest tests with this error , it looks like Mongo is not running ?

Caused by: com.mongodb.MongoServerSelectionException: Unable to connect to any server that matches AnyServerSelector{} at com.mongodb.BaseCluster.getServer(BaseCluster.java:80) at com.mongodb.DBTCPConnector.getServer(DBTCPConnector.java:666) at com.mongodb.DBTCPConnector.access$300(DBTCPConnector.java:42) at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:511) at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:459) at com.mongodb.DBTCPConnector.getPrimaryPort(DBTCPConnector.java:417) at com.mongodb.DBCollectionImpl.createIndex(DBCollectionImpl.java:337) at com.mongodb.DBCollection.createIndex(DBCollection.java:564) at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.createIndex(MongoPersistentEntityIndexCreator.java:135) .... .....

iainporter commented 9 years ago

Sorry, have not had time to look at this yet. It will be a problem for testing if you use the index annotations.

The options are:

  1. Fix the tests to use mocks. That will be a problem for the functional tests that rely on an embedded MongoDB instance
  2. Manage the indexes through command line interface (mongo) to the database. This is not too dissimilar to how you might fine tune a SQL Server instance
  3. Use the Spring Mongo Template to programmatically handle indexing (http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo-template.index-and-collections).

I might get some time later in the week to give it more thought.