Created
April 19, 2015 18:01
-
-
Save a-peyrard/aee7e47f3bc7bd9546a8 to your computer and use it in GitHub Desktop.
test for restx's issue #193
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.teutinc.teutssampleapp.mongo; | |
import static org.assertj.core.api.Assertions.assertThat; | |
import static restx.factory.Factory.LocalMachines.overrideComponents; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import de.flapdoodle.embed.mongo.distribution.Version; | |
import restx.factory.Factory; | |
import restx.factory.Name; | |
import restx.jongo.JongoCollection; | |
import restx.jongo.specs.tests.MongoEmbedRule; | |
/** | |
* @author apeyrard | |
*/ | |
public class MongoClientTest { | |
@Rule | |
public MongoEmbedRule mongo = new MongoEmbedRule(Version.Main.PRODUCTION); | |
@Test | |
public void should_close_mongo_client() { | |
overrideComponents().set("mongo.db", "tests"); | |
final int maxLoop = 10000; | |
for (int i = 0; i < maxLoop; i++) { | |
try (Factory factory = Factory.newInstance()) { | |
JongoCollection sample = factory.getComponent(Name.of(JongoCollection.class, "sample")); | |
// dumb insertion | |
sample.get().save(new Something(i)); | |
} | |
} | |
try (Factory factory = Factory.newInstance()) { | |
JongoCollection sample = factory.getComponent(Name.of(JongoCollection.class, "sample")); | |
assertThat(sample.get().count()).isEqualTo(maxLoop); | |
} | |
} | |
static class Something { | |
private int index; | |
public Something() {} | |
public Something(int index) { | |
this.index = index; | |
} | |
public int getIndex() { | |
return index; | |
} | |
public Something setIndex(int index) { | |
this.index = index; | |
return this; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment