gomoob / php-embedded-mongo Goto Github PK
View Code? Open in Web Editor NEWStart an embedded Mongo DB server and run your PHPUnit integration tests easily.
License: MIT License
Start an embedded Mongo DB server and run your PHPUnit integration tests easily.
License: MIT License
For now all the JAR files of https://github.com/gomoob/embedded-mongo are versioned in GIT. This should not be done like this.
Instead the PHP library should know where to pull the library from a Maven repository, download it, unzip it in a directory.
When we run the embedded server using the Gomoob phptools
Docker container it first download a Mongo DB distribution and installs it.
It works but because the Docker container used to run tests is ephemeral each time tests are run again the dowload it performed.
We should document how to run the server inside Docker by mapping the directory where the Mongo distribution are downloaded and installed.
When the server starts it displays several logs and redirects them into a log file. It works but it does not allow a developer to quickly know what's going on.
Here are sample logs.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
MONGOD_HOST=ubuntu-VirtualBox
MONGOD_PORT=27017
SERVER_SOCKET_PORT=4309
Download PRODUCTION:Linux:B64 START
Download PRODUCTION:Linux:B64 DownloadSize: 40274671
Download PRODUCTION:Linux:B64 0% 1% 2% 3% 4% 5% 6% 7% 8% 9% 10% 11% 12% 13% 14% 15% 16% 17% 18% 19% 20% 21% 22% 23% 24% 25% 26% 27% 28% 29% 30% 31% 32% 33% 34% 35% 36% 37% 38% 39% 40% 41% 42% 43% 44% 45% 46% 47% 48% 49% 50% 51% 52% 53% 54% 55% 56% 57% 58% 59% 60% 61% 62% 63% 64% 65% 66% 67% 68% 69% 70% 71% 72% 73% 74% 75% 76% 77% 78% 79% 80% 81% 82% 83% 84% 85% 86% 87% 88% 89% 90% 91% 92% 93% 94% 95% 96% 97% 98% 99% 100% Download PRODUCTION:Linux:B64 downloaded with 1638kb/s
Download PRODUCTION:Linux:B64 DONE
Extract /home/ubuntu/.embedmongo/linux/mongodb-linux-x86_64-3.0.5.tgz START
Extract /home/ubuntu/.embedmongo/linux/mongodb-linux-x86_64-3.0.5.tgz extract mongodb-linux-x86_64-3.0.5/bin/mongod
Extract /home/ubuntu/.embedmongo/linux/mongodb-linux-x86_64-3.0.5.tgz noting left
Extract /home/ubuntu/.embedmongo/linux/mongodb-linux-x86_64-3.0.5.tgz DONE
[mongod output]note: noprealloc may hurt performance in many applications
[mongod output] 2015-10-29T06:18:59.262-0400 I STORAGE [DataFileSync] warning: --syncdelay 0 is not recommended and can have strange performance
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] MongoDB starting : pid=9035 port=27017 dbpath=/tmp/embedmongo-db-efe7fc33-d9c2-4321-999d-1106cba0ec5d 64-bit host=ubuntu-VirtualBox
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten]
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] ** We suggest setting it to 'never'
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten]
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] ** We suggest setting it to 'never'
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten]
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 3885 processes, 65536 files. Number of processes should be at least 32768 : 0.5 times number of files.
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten]
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] db version v3.0.5
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] git version: 8bc4ae20708dbb493cb09338d9e7be6698e4a3a3
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] build info: Linux build2.ny.cbi.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] allocator: tcmalloc
[mongod output] 2015-10-29T06:18:59.265-0400 I CONTROL [initandlisten] options: { net: { http: { enabled: false }, port: 27017 }, security: { authorization: "disabled" }, storage: { dbPath: "/tmp/embedmongo-db-efe7fc33-d9c2-4321-999d-1106cba0ec5d", journal: { enabled: false }, mmapv1: { preallocDataFiles: false, smallFiles: true }, syncPeriodSecs: 0.0 } }
[mongod output] 2015-10-29T06:18:59.265-0400 I INDEX [initandlisten] allocating new ns file /tmp/embedmongo-db-efe7fc33-d9c2-4321-999d-1106cba0ec5d/local.ns, filling with zeroes...
[mongod output] 2015-10-29T06:18:59.320-0400 I STORAGE [FileAllocator] allocating new datafile /tmp/embedmongo-db-efe7fc33-d9c2-4321-999d-1106cba0ec5d/local.0, filling with zeroes...
[mongod output] 2015-10-29T06:18:59.320-0400 I STORAGE [FileAllocator] creating directory /tmp/embedmongo-db-efe7fc33-d9c2-4321-999d-1106cba0ec5d/_tmp
[mongod output] 2015-10-29T06:18:59.321-0400 I STORAGE [FileAllocator] done allocating datafile /tmp/embedmongo-db-efe7fc33-d9c2-4321-999d-1106cba0ec5d/local.0, size: 16MB, took 0 secs
[mongod output] 2015-10-29T06:18:59.323-0400 I NETWORK [initandlisten] waiting for connections on port 27017
[mongod output] Waiting for command...
{"command" : "stop"}
Command : stop
2015-10-29T06:18:59.340-0400 I NETWORK [initandlisten] connection accepted from 127.0.0.1:55869 #1 (1 connection now open)
[mongod output] 2015-10-29T06:18:59.341-0400 I COMMAND [conn1] terminating, shutdown command received
[mongod output] 2015-10-29T06:18:59.341-0400 I CONTROL [conn1] now exiting
[mongod output] 2015-10-29T06:18:59.341-0400 I NETWORK [conn1] shutdown: going to close listening sockets...
[mongod output] 2015-10-29T06:18:59.341-0400 I NETWORK [conn1] closing listening socket: 5
[mongod output] 2015-10-29T06:18:59.341-0400 I NETWORK [conn1] closing listening socket: 6
[mongod output] 2015-10-29T06:18:59.341-0400 I NETWORK [conn1] removing socket file: /tmp/mongodb-27017.sock
[mongod output] 2015-10-29T06:18:59.341-0400 I NETWORK [conn1] shutdown: going to flush diaglog...
[mongod output] 2015-10-29T06:18:59.341-0400 I NETWORK [conn1] shutdown: going to close sockets...
[mongod output] 2015-10-29T06:18:59.341-0400 I STORAGE [conn1] shutdown: waiting for fs preallocator...
[mongod output] 2015-10-29T06:18:59.341-0400 I STORAGE [conn1] shutdown: closing all files...
[mongod output] 2015-10-29T06:18:59.341-0400 I STORAGE [conn1] closeAllFiles() finished
[mongod output] 2015-10-29T06:18:59.341-0400 I STORAGE [conn1] shutdown: removing fs lock...
[mongod output]
2015-10-29T06:18:59.341-0400 I CONTROL [conn1] dbexit: rc: 0
[mongod output]
We should be able to display those logs and categorize them (download, mongo start, etc...).
When we start the embedded Mongo server and immedialtly try to communicate with it it fails with a connection error.
MongoConnectionException: Failed to connect to: localhost:27017: Connection refused
This problem seems to be due to the fact we are not waiting for the Mongo distribution to be installed and the Mongo server to be successfully started.
The PHP "driver" should be able to send regular health checks to the Java process to check if the Mongo server is started. If possible it would be better to wait for a signal from the Java program but i'm not sure its possible in PHP.
For now a simple Workaround it to add a sleep
juster after start.
$this->mongoServer = new MongoServer();
$this->mongoServer->start();
sleep(30);
Sometimes we create tests and stops those test with CTRL+C.
The result is that the MongoDB executable installed in C:\User\myuser\AppData\Local\Temp
is not deleted and we encounter the following error at start.
Warning: socket_connect(): unable to connect [10061]: No connection could be made because the target machine actively refused it.
in D:\workspace\myproject\vendor\gomoob\php-embedded-mongo\src\main\php\Gomoob\Embedded\MongoServer.php on line 71
Warning: socket_sendto(): unable to write to socket [10057]: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.
in D:\workspace\myproject\vendor\gomoob\php-embedded-mongo\src\main\php\Gomoob\Embedded\MongoServer.php on line 76
Failed
And also
MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (`serverselectiontryonce` set): [Failed connecting to 'localhost:27017': No connection could be made because the target machine actively refused it.
]
Temporarily to fix the error we can manually delete the extract-*-extractmongod.exe
executable from the OS temporary directory by ideally this should be done automatically.
Thanks
This library is our first one and is dedicated to Mongo, but we could do the same with Memcached, Elasticsearch, Redis, Riak, etc...
To allow quick development of new libraries php-embedded-memcached
, php-embedded-elasticsearch
, php-embedded-redis
, etc... we should create a new common PHP project php-embedded
.
This project would provide a powerful abstract class to drive Java programs, analyze logs, etc...
The library requires Java to be correctly installed and configured because the driver Mongo server is writtent in Java.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.