de.bwaldvogel.mongo.backend.memory.MemoryBackend Java Examples

The following examples show how to use de.bwaldvogel.mongo.backend.memory.MemoryBackend. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From elepy with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    MongoServer mongoServer = new MongoServer(new MemoryBackend());

    InetSocketAddress serverAddress = mongoServer.bind();

    MongoClient client = new MongoClient(new ServerAddress(serverAddress));

    final var elepyInstance = new Elepy()
            .addConfiguration(MongoConfiguration.of(client, "example", "bucket"))
            .withPort(7331)
            .addModelPackage("com.elepy.tests.devfrontend")
            .addExtension((http, elepy) -> {
                http.before(context -> {
                    context.response().header("Access-Control-Allow-Headers", "*");
                    context.request().addPermissions(Permissions.SUPER_USER);
                });
            })
            .addExtension(new FrontendLoader());
    elepyInstance.start();

}
 
Example #2
Source File: MongoContext.java    From immutables with Apache License 2.0 6 votes vote down vote up
public static MongoContext create() {
  final String uri = System.getProperty("mongo");
  final Closer closer = Closer.create();
  if (uri != null) {
    // remote mongo server
    return new MongoContext(new MongoClient(new MongoClientURI(uri)), closer);
  }

  final MongoServer server = new MongoServer(new MemoryBackend());
  closer.register(new Closeable() {
    @Override
    public void close() throws IOException {
      server.shutdownNow();
    }
  });

  final MongoClient client = new MongoClient(new ServerAddress(server.bind()));
  final MongoContext context = new MongoContext(client, closer);
  return context;
}
 
Example #3
Source File: MongoInstance.java    From immutables with Apache License 2.0 6 votes vote down vote up
static MongoInstance create() {
  final String uri = System.getProperty("mongo");


  if (uri != null) {
    // connect to remote mongo server
    return new MongoInstance(MongoClients.create(uri));
  }

  final MongoServer server = new MongoServer(new MemoryBackend());
  final InetSocketAddress address = server.bind();
  final Closer closer = Closer.create();
  closer.register(server::shutdownNow);

  final MongoClient client = MongoClients.create(String.format("mongodb://127.0.0.1:%d", address.getPort()));
  return new MongoInstance(client, closer);
}
 
Example #4
Source File: FakeMongoConfiguration.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
@Bean(destroyMethod = "close")
public MongoClient mongoClient() {
    MemoryBackend backend = new MemoryBackend();
    MongoServer server = new MongoServer(backend);
    // bind on a random local port
    InetSocketAddress serverAddress = server.bind();
    return new MongoClient(new ServerAddress(serverAddress));
}
 
Example #5
Source File: TestMongoConfig.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
private void startLocalMongoServer(ModuleContext context) {
    synchronized (TestMongoConfig.class) {
        // in test env, config is initialized in order and within same thread, so no threading issue
        if (localMongoAddress == null) {
            var server = new MongoServer(new MemoryBackend());
            localMongoAddress = server.bind();
            context.shutdownHook.add(ShutdownHook.STAGE_7, timeout -> server.shutdown());
        }
    }
}
 
Example #6
Source File: RepositoryTestsConfiguration.java    From microcks with Apache License 2.0 5 votes vote down vote up
@Override
public MongoClient mongoClient() {
   // Replacing fongo by mongo-java-server, according to
   // https://github.com/fakemongo/fongo/issues/337
   //return new Fongo("mongo-test").getMongo();

   // Create a server and bind on a random local port
   server = new MongoServer(new MemoryBackend());
   InetSocketAddress serverAddress = server.bind();
   //client = new MongoClient(new ServerAddress(serverAddress));
   client = MongoClients.create("mongodb://localhost:" + serverAddress.getPort());
   return client;
}
 
Example #7
Source File: Engine.java    From clouditor with Apache License 2.0 4 votes vote down vote up
public void initDB() {
  if (this.dbInMemory) {
    var server = new MongoServer(new MemoryBackend());

    var address = server.bind();

    LOGGER.info("Starting database purely in-memory...");

    this.dbHost = address.getHostName();
    this.dbPort = address.getPort();

    Runtime.getRuntime().addShutdownHook(new Thread(server::shutdown));
  }

  PersistenceManager.getInstance().init(this.dbName, this.dbHost, this.dbPort);
}
 
Example #8
Source File: InMemoryClientFactory.java    From elepy with Apache License 2.0 3 votes vote down vote up
public static MongoClient createInMemoryClient() {
    MongoServer mongoServer = new MongoServer(new MemoryBackend());

    InetSocketAddress serverAddress = mongoServer.bind();
    return new MongoClient(new ServerAddress(serverAddress));

}
 
Example #9
Source File: MongoFunctionalityTest.java    From elepy with Apache License 2.0 3 votes vote down vote up
@Override
public void configureElepy(Elepy elepy) {
    mongoServer = new MongoServer(new MemoryBackend());

    InetSocketAddress serverAddress = mongoServer.bind();

    MongoClient client = new MongoClient(new ServerAddress(serverAddress));

    elepy.addConfiguration(MongoConfiguration.of(client, "test", "bucket"));
}
 
Example #10
Source File: MongoFileServiceTest.java    From elepy with Apache License 2.0 3 votes vote down vote up
@BeforeAll
public void setUp() {
    mongoServer = new MongoServer(new MemoryBackend());

    InetSocketAddress serverAddress = mongoServer.bind();

    client = new MongoClient(new ServerAddress(serverAddress));
    super.setUp();

}
 
Example #11
Source File: BaseFongo.java    From elepy with Apache License 2.0 3 votes vote down vote up
public void setUp() throws Exception {
    mongoServer = new MongoServer(new MemoryBackend());

    InetSocketAddress serverAddress = mongoServer.bind();

    client = new MongoClient(new ServerAddress(serverAddress));
}
 
Example #12
Source File: MongoSystemTest.java    From elepy with Apache License 2.0 3 votes vote down vote up
@Override
public void configureElepy(Elepy elepy) {

    mongoServer = new MongoServer(new MemoryBackend());

    InetSocketAddress serverAddress = mongoServer.bind();

    MongoClient client = new MongoClient(new ServerAddress(serverAddress));
    elepy.addConfiguration(MongoConfiguration.of(client, "test", "bucket"));
}
 
Example #13
Source File: MongoStack.java    From elepy with Apache License 2.0 3 votes vote down vote up
@Override
public void configureElepy(Elepy elepy) {

    mongoServer = new MongoServer(new MemoryBackend());

    InetSocketAddress serverAddress = mongoServer.bind();

    MongoClient client = new MongoClient(new ServerAddress(serverAddress));
    elepy.addConfiguration(MongoConfiguration.of(client, "test", "bucket"));
}