flapdoodle-oss / de.flapdoodle.embed.mongo.spring

embedded mongo spring integration
Apache License 2.0
32 stars 7 forks source link

Embedded Mongo Still running when there is an exception #28

Closed rajakumare1 closed 2 months ago

rajakumare1 commented 1 year ago

If there is any exception in the data setup in @BeforeEach, we are seeing the mongd is still running in the background If this populateMockTestCollection() method has an exception, the mongod is running without gracefully shutdown

`@ExtendWith(SpringExtension.class) @ActiveProfiles("test") @SpringBootTest( properties = "de.flapdoodle.mongodb.embedded.version=5.0.12" ) @Import({TestMongoConfiguration.class}) @AutoConfigureDataMongo() @TestInstance(TestInstance.Lifecycle.PER_CLASS) @DirtiesContext class ServiceIntegrationTest {

@Autowired
private TestCollectionRepository testCollectionRepository;

@BeforeEach
void setup() throws IOException {

TestCollection testcollection = populateMockTestCollection(); // If this populateMockTestCollection has an exception, the mongod is running without shutdown testCollectionRepository.insert(testcollection); }

......

} @TestConfiguration

public class TestMongoConfiguration {

@Bean
public MongoDatabaseFactory mongoDbFactory() throws Exception {
    return new SimpleMongoClientDatabaseFactory("mongodb://localhost:27017/db-tests");
}

@Bean
MongoTemplate mongoTemplate(MongoDatabaseFactory factory) {
    return new MongoTemplate(factory);
}

} `

michaelmosmann commented 1 year ago

@rajakumare1 .. hmm.. spring should handle this case.. but i will have a look into that.. maybe something is missing. Maybe this is this @testinstance(TestInstance.Lifecycle.PER_CLASS) and beforeEach .. but this is just a wild guess.

michaelmosmann commented 2 months ago

Should be solved with newer versions of this library..