Skip to content

Instantly share code, notes, and snippets.

@a-peyrard
Created April 19, 2015 18:01
Show Gist options
  • Save a-peyrard/aee7e47f3bc7bd9546a8 to your computer and use it in GitHub Desktop.
Save a-peyrard/aee7e47f3bc7bd9546a8 to your computer and use it in GitHub Desktop.
test for restx's issue #193
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