From ff3061d4ce4c9885c3f4601aefb81c7ad1767a6e Mon Sep 17 00:00:00 2001 From: Hannes Magnusson Date: Wed, 9 Sep 2015 11:40:03 -0700 Subject: [PATCH 01/10] Don't provide server_id when we have none --- php_phongo.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index bc2628e0b..cff0f7d19 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -726,7 +726,9 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, const p return false; } - cursor->hint = server_id; + if (server_id > 0) { + cursor->hint = server_id; + } if (!mongoc_cursor_next(cursor, &doc)) { bson_error_t error; @@ -757,7 +759,9 @@ int phongo_execute_command(mongoc_client_t *client, const char *db, const bson_t cursor = mongoc_client_command(client, db, MONGOC_QUERY_NONE, 0, 1, 0, command, NULL, read_preference); - cursor->hint = server_id; + if (server_id > 0) { + cursor->hint = server_id; + } if (!mongoc_cursor_next(cursor, &doc)) { bson_error_t error; From 4d6157fb78462ee011758651837e318eed8af8d3 Mon Sep 17 00:00:00 2001 From: Hannes Magnusson Date: Wed, 9 Sep 2015 11:43:48 -0700 Subject: [PATCH 02/10] $readPreferences should not be sent to standalone server --- tests/readPreference/bug0146.phpt | 40 ++++--------------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/tests/readPreference/bug0146.phpt b/tests/readPreference/bug0146.phpt index e29c95e25..6503ac06f 100644 --- a/tests/readPreference/bug0146.phpt +++ b/tests/readPreference/bug0146.phpt @@ -104,20 +104,12 @@ object(MongoDB\Driver\Cursor)#%d (%d) { ["has_fields"]=> bool(false) ["query"]=> - object(stdClass)#%d (2) { + object(stdClass)#%d (%d) { ["$query"]=> object(stdClass)#%d (%d) { ["my"]=> string(5) "query" } - ["$readPreference"]=> - object(stdClass)#%d (%d) { - ["mode"]=> - string(16) "primaryPreferred" - ["tags"]=> - array(0) { - } - } } ["fields"]=> object(stdClass)#%d (0) { @@ -168,20 +160,12 @@ object(MongoDB\Driver\Cursor)#%d (%d) { ["has_fields"]=> bool(false) ["query"]=> - object(stdClass)#%d (2) { + object(stdClass)#%d (%d) { ["$query"]=> object(stdClass)#%d (%d) { ["my"]=> string(5) "query" } - ["$readPreference"]=> - object(stdClass)#%d (%d) { - ["mode"]=> - string(9) "secondary" - ["tags"]=> - array(0) { - } - } } ["fields"]=> object(stdClass)#%d (0) { @@ -232,20 +216,12 @@ object(MongoDB\Driver\Cursor)#%d (%d) { ["has_fields"]=> bool(false) ["query"]=> - object(stdClass)#%d (2) { + object(stdClass)#%d (%d) { ["$query"]=> object(stdClass)#%d (%d) { ["my"]=> string(5) "query" } - ["$readPreference"]=> - object(stdClass)#%d (%d) { - ["mode"]=> - string(18) "secondaryPreferred" - ["tags"]=> - array(0) { - } - } } ["fields"]=> object(stdClass)#%d (0) { @@ -296,20 +272,12 @@ object(MongoDB\Driver\Cursor)#%d (%d) { ["has_fields"]=> bool(false) ["query"]=> - object(stdClass)#%d (2) { + object(stdClass)#%d (%d) { ["$query"]=> object(stdClass)#%d (%d) { ["my"]=> string(5) "query" } - ["$readPreference"]=> - object(stdClass)#%d (%d) { - ["mode"]=> - string(7) "nearest" - ["tags"]=> - array(0) { - } - } } ["fields"]=> object(stdClass)#%d (0) { From 3a91948e552fc8934b4a19f27644f01427baeb4b Mon Sep 17 00:00:00 2001 From: Hannes Magnusson Date: Fri, 11 Sep 2015 14:35:12 -0700 Subject: [PATCH 03/10] PHPC-415: SSL/TLS already set-up for this stream When closing a stream we can't free the base_stream, only our stream. Which also means, when destroying a stream we may not always have a wrapping stream --- php_phongo.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index cff0f7d19..7383a8fdf 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -825,7 +825,11 @@ void phongo_stream_destroy(mongoc_stream_t *stream_wrap) /* {{{ */ { php_phongo_stream_socket *base_stream = (php_phongo_stream_socket *)stream_wrap; - MONGOC_DEBUG("Not destroying RSRC#%d", base_stream->stream->rsrc_id); + if (base_stream->stream) { + MONGOC_DEBUG("Not destroying RSRC#%d", base_stream->stream->rsrc_id); + } else { + MONGOC_DEBUG("Wrapped stream already destroyed"); + } /* * DON'T DO ANYTHING TO THE INTERNAL base_stream->stream * The stream should not be closed during normal dtor -- as we want it to @@ -855,7 +859,14 @@ int phongo_stream_close(mongoc_stream_t *stream_wrap) /* {{{ */ php_phongo_stream_socket *base_stream = (php_phongo_stream_socket *)stream_wrap; MONGOC_DEBUG("Closing RSRC#%d", base_stream->stream->rsrc_id); - phongo_stream_destroy(stream_wrap); + if (base_stream->stream) { + TSRMLS_FETCH_FROM_CTX(base_stream->tsrm_ls); + + MONGOC_DEBUG("Destroying RSRC#%d", base_stream->stream->rsrc_id); + php_stream_free(base_stream->stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR); + base_stream->stream = NULL; + } + return 0; } /* }}} */ From f4200872b97dbb03fa38ecdf3f6dd4443539e0ec Mon Sep 17 00:00:00 2001 From: Hannes Magnusson Date: Fri, 11 Sep 2015 14:34:37 -0700 Subject: [PATCH 04/10] PHPC-415: Add testcase --- tests/connect/standalone-x509-error-0001.phpt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/connect/standalone-x509-error-0001.phpt diff --git a/tests/connect/standalone-x509-error-0001.phpt b/tests/connect/standalone-x509-error-0001.phpt new file mode 100644 index 000000000..8a0bd77aa --- /dev/null +++ b/tests/connect/standalone-x509-error-0001.phpt @@ -0,0 +1,49 @@ +--TEST-- +Connect to MongoDB with using X509 retrieving username from certificate #002 +--SKIPIF-- + +--FILE-- +insert(array("very" => "important")); + $manager->executeBulkWrite(NS, $bulk); + echo "Connected\n"; + } catch(Exception $e) { + echo get_class($e), ": ", $e->getMessage(), "\n"; + } + return $manager; + +} +$SSL_DIR = realpath(__DIR__ . "/" . "./../../scripts/ssl/"); + +$opts = array( + "peer_name" => "server", + "verify_peer" => true, + "verify_peer_name" => true, + "allow_self_signed" => false, + "cafile" => $SSL_DIR . "/ca.pem", /* Defaults to openssl.cafile */ + "capath" => $SSL_DIR, /* Defaults to openssl.capath */ + "local_cert" => $SSL_DIR . "/src/libmongoc/tests/certificates/client.pem", +); +$parsed = parse_url(STANDALONE_X509); +$dsn = sprintf("mongodb://username@%s:%d/%s?ssl=true&authMechanism=MONGODB-X509", $parsed["host"], $parsed["port"], DATABASE_NAME); + + +$m1 = connect($dsn, $opts); +$m2 = connect($dsn, $opts); + +echo "Both should have failed with auth failure - without reusing previous stream\n"; +?> +===DONE=== + +--EXPECTF-- +MongoDB\Driver\Exception\AuthenticationException: auth failed +MongoDB\Driver\Exception\AuthenticationException: auth failed +Both should have failed with auth failure - without reusing previous stream +===DONE=== From 356ced1e94114c51fbb2e17ca581bf3cb1ac53e8 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 2 Oct 2015 13:42:41 -0400 Subject: [PATCH 05/10] Bump libbson and libmongoc submodules to 1.2.0-rc0 --- src/libbson | 2 +- src/libmongoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libbson b/src/libbson index 3420d4d25..7afe7e989 160000 --- a/src/libbson +++ b/src/libbson @@ -1 +1 @@ -Subproject commit 3420d4d2579941f509db8daff91ecb0cfb7daff9 +Subproject commit 7afe7e98969889c442f780eda45172d33a1d9e8e diff --git a/src/libmongoc b/src/libmongoc index 3eaf73ed8..c45526094 160000 --- a/src/libmongoc +++ b/src/libmongoc @@ -1 +1 @@ -Subproject commit 3eaf73ed8a88340584a203520ee9ad98fd1b89d3 +Subproject commit c45526094073e13f2c391c8057fa39e77d20b6b4 From 5732362b8bae747ec56e8be97d069ecd1e4e1c2e Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 2 Oct 2015 13:55:20 -0400 Subject: [PATCH 06/10] PHPC-436: Handle new writeConcernErrors array in mongoc_write_result_t --- php_phongo.c | 35 +++++++++++++++++++---------------- src/MongoDB/WriteResult.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index 7383a8fdf..7ea3b89b5 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -512,9 +512,10 @@ php_phongo_writeresult_t *phongo_writeresult_init(zval *return_value, mongoc_wri SCP(nRemoved); SCP(nUpserted); - bson_copy_to(&write_result->upserted, &writeresult->write_result.upserted); - bson_copy_to(&write_result->writeConcernError, &writeresult->write_result.writeConcernError); - bson_copy_to(&write_result->writeErrors, &writeresult->write_result.writeErrors); + bson_copy_to(&write_result->upserted, &writeresult->write_result.upserted); + SCP(n_writeConcernErrors); + bson_copy_to(&write_result->writeConcernErrors, &writeresult->write_result.writeConcernErrors); + bson_copy_to(&write_result->writeErrors, &writeresult->write_result.writeErrors); SCP(upsert_append_count); #undef SCP @@ -684,10 +685,7 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, mongoc /* The Write failed */ if (!success) { /* The Command itself failed */ - if ( - bson_empty0(&writeresult->write_result.writeErrors) - && bson_empty0(&writeresult->write_result.writeConcernError) - ) { + if (bson_empty0(&writeresult->write_result.writeErrors) && bson_empty0(&writeresult->write_result.writeConcernErrors)) { /* FIXME: Maybe we can look at write_result.error and not pass error at all? */ phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC); } else { @@ -2022,25 +2020,30 @@ bool php_phongo_writeresult_get_write_errors(php_phongo_writeresult_t *writeresu } return false; } /* }}} */ + bool php_phongo_writeresult_get_writeconcern_error(php_phongo_writeresult_t *writeresult, bson_error_t *error) /* {{{ */ { const char *err = NULL; uint32_t code = 0; + bson_iter_t iter; + bson_iter_t citer; - if (!bson_empty0(&writeresult->write_result.writeConcernError)) { - bson_iter_t iter; - - if (bson_iter_init_find(&iter, &writeresult->write_result.writeConcernError, "code") && BSON_ITER_HOLDS_INT32(&iter)) { - code = bson_iter_int32(&iter); - } - if (bson_iter_init_find(&iter, &writeresult->write_result.writeConcernError, "errmsg") && BSON_ITER_HOLDS_UTF8(&iter)) { - err = bson_iter_utf8(&iter, NULL); + if (!bson_empty0 (&writeresult->write_result.writeConcernErrors) && + bson_iter_init (&iter, &writeresult->write_result.writeConcernErrors) && + bson_iter_next (&iter) && + BSON_ITER_HOLDS_DOCUMENT (&iter) && + bson_iter_recurse (&iter, &citer)) { + while (bson_iter_next (&citer)) { + if (BSON_ITER_IS_KEY (&citer, "errmsg")) { + err = bson_iter_utf8 (&citer, NULL); + } else if (BSON_ITER_IS_KEY (&citer, "code")) { + code = bson_iter_int32 (&citer); + } } bson_set_error(error, PHONGO_ERROR_WRITECONCERN_FAILED, code, "%s", err); return true; } - return false; } /* }}} */ zval* php_phongo_throw_write_errors(php_phongo_writeresult_t *wr TSRMLS_DC) /* {{{ */ diff --git a/src/MongoDB/WriteResult.c b/src/MongoDB/WriteResult.c index 73e37c992..6e65a52c7 100644 --- a/src/MongoDB/WriteResult.c +++ b/src/MongoDB/WriteResult.c @@ -250,10 +250,33 @@ PHP_METHOD(WriteResult, getWriteConcernError) } - if (!bson_empty0(&intern->write_result.writeConcernError)) { - object_init_ex(return_value, php_phongo_writeconcernerror_ce); - if (!phongo_writeconcernerror_init(return_value, &intern->write_result.writeConcernError TSRMLS_CC)) { - zval_ptr_dtor(&return_value); + if (!bson_empty0(&intern->write_result.writeConcernErrors)) { + bson_iter_t iter; + + bson_iter_init(&iter, &intern->write_result.writeConcernErrors); + + while (bson_iter_next(&iter)) { + bson_t cbson; + uint32_t len; + const uint8_t *data; + + if (!BSON_ITER_HOLDS_DOCUMENT(&iter)) { + continue; + } + + bson_iter_document(&iter, &len, &data); + + if (!bson_init_static(&cbson, data, len)) { + continue; + } + + object_init_ex(return_value, php_phongo_writeconcernerror_ce); + + if (!phongo_writeconcernerror_init(return_value, &cbson TSRMLS_CC)) { + zval_ptr_dtor(&return_value); + } + + return; } } } From 98887ff579fd5aa6765bb2bf9548bac41f6d470d Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 2 Oct 2015 14:19:34 -0400 Subject: [PATCH 07/10] PHPC-438: Debug handler should display null for no WC error --- src/MongoDB/WriteResult.c | 18 +++++++++++++++--- .../replicaset/writeresult-getserver-002.phpt | 3 +-- tests/server/server-executeBulkWrite-001.phpt | 3 +-- .../writeresult-isacknowledged-001.phpt | 3 +-- .../writeresult-isacknowledged-002.phpt | 3 +-- .../writeresult-isacknowledged-003.phpt | 3 +-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/MongoDB/WriteResult.c b/src/MongoDB/WriteResult.c index 6e65a52c7..8f4e8a91e 100644 --- a/src/MongoDB/WriteResult.c +++ b/src/MongoDB/WriteResult.c @@ -452,6 +452,7 @@ HashTable *php_phongo_writeresult_get_debug_info(zval *object, int *is_temp TSRM php_phongo_writeresult_t *intern; zval retval = zval_used_for_init; php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER; + bson_iter_t iter; intern = (php_phongo_writeresult_t *)zend_object_store_get_object(object TSRMLS_CC); *is_temp = 1; @@ -479,10 +480,21 @@ HashTable *php_phongo_writeresult_get_debug_info(zval *object, int *is_temp TSRM bson_to_zval(bson_get_data(&intern->write_result.writeErrors), intern->write_result.writeErrors.len, &state); add_assoc_zval_ex(&retval, ZEND_STRS("writeErrors"), state.zchild); + if (!bson_empty0(&intern->write_result.writeConcernErrors) && + bson_iter_init(&iter, &intern->write_result.writeConcernErrors) && + bson_iter_next(&iter) && + BSON_ITER_HOLDS_DOCUMENT(&iter)) { + uint32_t len; + const uint8_t *data; - MAKE_STD_ZVAL(state.zchild); - bson_to_zval(bson_get_data(&intern->write_result.writeConcernError), intern->write_result.writeConcernError.len, &state); - add_assoc_zval_ex(&retval, ZEND_STRS("writeConcernError"), state.zchild); + bson_iter_document(&iter, &len, &data); + + MAKE_STD_ZVAL(state.zchild); + bson_to_zval(data, len, &state); + add_assoc_zval_ex(&retval, ZEND_STRS("writeConcernError"), state.zchild); + } else { + add_assoc_null_ex(&retval, ZEND_STRS("writeConcernError")); + } if (intern->write_concern) { zval *write_concern = NULL; diff --git a/tests/replicaset/writeresult-getserver-002.phpt b/tests/replicaset/writeresult-getserver-002.phpt index a94fea942..f278b19ed 100644 --- a/tests/replicaset/writeresult-getserver-002.phpt +++ b/tests/replicaset/writeresult-getserver-002.phpt @@ -77,8 +77,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) { array(0) { } ["writeConcernError"]=> - array(0) { - } + NULL ["writeConcern"]=> array(%d) { ["w"]=> diff --git a/tests/server/server-executeBulkWrite-001.phpt b/tests/server/server-executeBulkWrite-001.phpt index 5ca856eee..54070b128 100644 --- a/tests/server/server-executeBulkWrite-001.phpt +++ b/tests/server/server-executeBulkWrite-001.phpt @@ -67,8 +67,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) { array(0) { } ["writeConcernError"]=> - array(0) { - } + NULL ["writeConcern"]=> array(%d) { ["w"]=> diff --git a/tests/standalone/writeresult-isacknowledged-001.phpt b/tests/standalone/writeresult-isacknowledged-001.phpt index a0a65acb8..cc1de48c0 100644 --- a/tests/standalone/writeresult-isacknowledged-001.phpt +++ b/tests/standalone/writeresult-isacknowledged-001.phpt @@ -36,8 +36,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) { array(0) { } ["writeConcernError"]=> - array(0) { - } + NULL ["writeConcern"]=> array(%d) { ["w"]=> diff --git a/tests/standalone/writeresult-isacknowledged-002.phpt b/tests/standalone/writeresult-isacknowledged-002.phpt index c296ad084..5bf9ef704 100644 --- a/tests/standalone/writeresult-isacknowledged-002.phpt +++ b/tests/standalone/writeresult-isacknowledged-002.phpt @@ -38,8 +38,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) { array(0) { } ["writeConcernError"]=> - array(0) { - } + NULL ["writeConcern"]=> array(%d) { ["w"]=> diff --git a/tests/standalone/writeresult-isacknowledged-003.phpt b/tests/standalone/writeresult-isacknowledged-003.phpt index 74c29aa2c..fee9d6506 100644 --- a/tests/standalone/writeresult-isacknowledged-003.phpt +++ b/tests/standalone/writeresult-isacknowledged-003.phpt @@ -36,8 +36,7 @@ object(MongoDB\Driver\WriteResult)#%d (%d) { array(0) { } ["writeConcernError"]=> - array(0) { - } + NULL ["writeConcern"]=> array(%d) { ["w"]=> From 82507965a7d0b053760d108c8b465769f32a4765 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 2 Oct 2015 14:28:15 -0400 Subject: [PATCH 08/10] Update filenames for libmongoc and libbson version functions --- config.m4 | 3 ++- config.w32 | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config.m4 b/config.m4 index 8ddb5e960..55b96c791 100644 --- a/config.m4 +++ b/config.m4 @@ -217,7 +217,7 @@ if test "$MONGODB" != "no"; then bson-timegm.c \ bson-utf8.c \ bson-value.c \ - bson-version.c \ + bson-version-functions.c \ bson-writer.c "; MONGOC_SOURCES="\ @@ -265,6 +265,7 @@ if test "$MONGODB" != "no"; then mongoc-topology-description.c \ mongoc-uri.c \ mongoc-util.c \ + mongoc-version-functions.c \ mongoc-write-command.c \ mongoc-write-concern.c "; diff --git a/config.w32 b/config.w32 index 92a2b4847..1d49f2335 100644 --- a/config.w32 +++ b/config.w32 @@ -13,8 +13,8 @@ if (PHP_MONGODB != "no") { ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "Exception.c LogicException.c RuntimeException.c UnexpectedValueException.c InvalidArgumentException.c ConnectionException.c AuthenticationException.c SSLConnectionException.c DuplicateKeyException.c ExecutionTimeoutException.c ConnectionTimeoutException.c WriteException.c WriteConcernException.c BulkWriteException.c", "mongodb"); ADD_SOURCES(configure_module_dirname + "/src/contrib/", "php-ssl.c", "mongodb"); ADD_SOURCES(configure_module_dirname + "/src/libbson/src/yajl", "yajl_version.c yajl.c yajl_encode.c yajl_lex.c yajl_parser.c yajl_buf.c yajl_tree.c yajl_alloc.c yajl_gen.c", "mongodb"); - ADD_SOURCES(configure_module_dirname + "/src/libbson/src/bson", "bcon.c bson.c bson-atomic.c bson-clock.c bson-context.c bson-error.c bson-iter.c bson-iso8601.c bson-json.c bson-keys.c bson-md5.c bson-memory.c bson-oid.c bson-reader.c bson-string.c bson-timegm.c bson-utf8.c bson-value.c bson-version.c bson-writer.c", "mongodb"); - ADD_SOURCES(configure_module_dirname + "/src/libmongoc/src/mongoc", "mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-b64.c mongoc-client.c mongoc-client-pool.c mongoc-cluster.c mongoc-collection.c mongoc-counters.c mongoc-cursor.c mongoc-cursor-array.c mongoc-cursor-transform.c mongoc-cursor-cursorid.c mongoc-database.c mongoc-init.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-page.c mongoc-gridfs-file-list.c mongoc-host-list.c mongoc-index.c mongoc-list.c mongoc-log.c mongoc-matcher-op.c mongoc-matcher.c mongoc-opcode.c mongoc-queue.c mongoc-read-prefs.c mongoc-rpc.c mongoc-set.c mongoc-server-description.c mongoc-socket.c mongoc-stream.c mongoc-stream-buffered.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-socket.c mongoc-topology.c mongoc-topology-scanner.c mongoc-topology-description.c mongoc-uri.c mongoc-util.c mongoc-write-command.c mongoc-write-concern.c", "mongodb"); + ADD_SOURCES(configure_module_dirname + "/src/libbson/src/bson", "bcon.c bson.c bson-atomic.c bson-clock.c bson-context.c bson-error.c bson-iter.c bson-iso8601.c bson-json.c bson-keys.c bson-md5.c bson-memory.c bson-oid.c bson-reader.c bson-string.c bson-timegm.c bson-utf8.c bson-value.c bson-version-functions.c bson-writer.c", "mongodb"); + ADD_SOURCES(configure_module_dirname + "/src/libmongoc/src/mongoc", "mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-b64.c mongoc-client.c mongoc-client-pool.c mongoc-cluster.c mongoc-collection.c mongoc-counters.c mongoc-cursor.c mongoc-cursor-array.c mongoc-cursor-transform.c mongoc-cursor-cursorid.c mongoc-database.c mongoc-init.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-page.c mongoc-gridfs-file-list.c mongoc-host-list.c mongoc-index.c mongoc-list.c mongoc-log.c mongoc-matcher-op.c mongoc-matcher.c mongoc-opcode.c mongoc-queue.c mongoc-read-prefs.c mongoc-rpc.c mongoc-set.c mongoc-server-description.c mongoc-socket.c mongoc-stream.c mongoc-stream-buffered.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-socket.c mongoc-topology.c mongoc-topology-scanner.c mongoc-topology-description.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-concern.c", "mongodb"); ADD_SOURCES(configure_module_dirname + "/src/libmongoc/src/mongoc", "mongoc-rand.c mongoc-scram.c mongoc-stream-tls.c mongoc-ssl.c", "mongodb"); ADD_SOURCES(configure_module_dirname + "/src/libmongoc/src/mongoc", "mongoc-sasl.c", "mongodb"); From 51a9ad7ef4b2a57489f5d9f9e26bbc3100835450 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 2 Oct 2015 17:39:42 -0400 Subject: [PATCH 09/10] PHPC-409: $readPreference is no longer sent to non-mongos nodes Fixed by CDRIVER-704 --- tests/server/server-executeCommand-002.phpt | 8 -------- tests/server/server-executeQuery-005.phpt | 8 -------- 2 files changed, 16 deletions(-) diff --git a/tests/server/server-executeCommand-002.phpt b/tests/server/server-executeCommand-002.phpt index 3b4a8dfe4..c4fc5003f 100644 --- a/tests/server/server-executeCommand-002.phpt +++ b/tests/server/server-executeCommand-002.phpt @@ -63,14 +63,6 @@ object(stdClass)#%d (%d) { } } } - ["$readPreference"]=> - object(stdClass)#%d (%d) { - ["mode"]=> - string(9) "secondary" - ["tags"]=> - array(0) { - } - } } Set profile level to 0 successfully: yes ===DONE=== diff --git a/tests/server/server-executeQuery-005.phpt b/tests/server/server-executeQuery-005.phpt index a03a4309a..006d075cb 100644 --- a/tests/server/server-executeQuery-005.phpt +++ b/tests/server/server-executeQuery-005.phpt @@ -55,14 +55,6 @@ object(stdClass)#%d (%d) { ["x"]=> int(1) } - ["$readPreference"]=> - object(stdClass)#%d (%d) { - ["mode"]=> - string(9) "secondary" - ["tags"]=> - array(0) { - } - } } Set profile level to 0 successfully: yes ===DONE=== From 31661a383dce3104d2e0c1a12ac02ef1576d7ebe Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 5 Oct 2015 15:16:23 -0400 Subject: [PATCH 10/10] Test write and WC error extraction for single write methods --- .../manager-executeDelete_error-001.phpt | 23 ++++++++++++++++++ .../manager-executeDelete_error-002.phpt | 24 +++++++++++++++++++ .../manager-executeInsert_error-001.phpt | 21 ++++++++++++++++ .../manager-executeInsert_error-002.phpt | 22 +++++++++++++++++ .../manager-executeUpdate_error-001.phpt | 23 ++++++++++++++++++ .../manager-executeUpdate_error-002.phpt | 24 +++++++++++++++++++ 6 files changed, 137 insertions(+) create mode 100644 tests/manager/manager-executeDelete_error-001.phpt create mode 100644 tests/manager/manager-executeDelete_error-002.phpt create mode 100644 tests/manager/manager-executeInsert_error-001.phpt create mode 100644 tests/manager/manager-executeInsert_error-002.phpt create mode 100644 tests/manager/manager-executeUpdate_error-001.phpt create mode 100644 tests/manager/manager-executeUpdate_error-002.phpt diff --git a/tests/manager/manager-executeDelete_error-001.phpt b/tests/manager/manager-executeDelete_error-001.phpt new file mode 100644 index 000000000..115d4c3d4 --- /dev/null +++ b/tests/manager/manager-executeDelete_error-001.phpt @@ -0,0 +1,23 @@ +--TEST-- +MongoDB\Driver\Manager::executeDelete() write error +--SKIPIF-- + +--FILE-- +executeInsert(NS, ['x' => 1]); + +echo throws(function() use ($manager) { + $manager->executeDelete(NS, ['$foo' => 1], ['limit' => 1]); +}, 'MongoDB\Driver\Exception\WriteException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\WriteException +unknown top level operator: $foo +===DONE=== diff --git a/tests/manager/manager-executeDelete_error-002.phpt b/tests/manager/manager-executeDelete_error-002.phpt new file mode 100644 index 000000000..0c7028e6e --- /dev/null +++ b/tests/manager/manager-executeDelete_error-002.phpt @@ -0,0 +1,24 @@ +--TEST-- +MongoDB\Driver\Manager::executeDelete() write concern error +--SKIPIF-- + + +--FILE-- +executeInsert(NS, ['x' => 1]); + +echo throws(function() use ($manager) { + $manager->executeDelete(NS, ['x' => 1], ['limit' => 1], new MongoDB\Driver\WriteConcern(30)); +}, 'MongoDB\Driver\Exception\WriteConcernException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\WriteConcernException +Not enough data-bearing nodes +===DONE=== diff --git a/tests/manager/manager-executeInsert_error-001.phpt b/tests/manager/manager-executeInsert_error-001.phpt new file mode 100644 index 000000000..4aabe9852 --- /dev/null +++ b/tests/manager/manager-executeInsert_error-001.phpt @@ -0,0 +1,21 @@ +--TEST-- +MongoDB\Driver\Manager::executeInsert() write error +--SKIPIF-- + +--FILE-- +executeInsert(NS, ['$foo' => 1]); +}, 'MongoDB\Driver\Exception\WriteException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\WriteException +Document can't have $ prefixed field names: $foo +===DONE=== diff --git a/tests/manager/manager-executeInsert_error-002.phpt b/tests/manager/manager-executeInsert_error-002.phpt new file mode 100644 index 000000000..f27ed5029 --- /dev/null +++ b/tests/manager/manager-executeInsert_error-002.phpt @@ -0,0 +1,22 @@ +--TEST-- +MongoDB\Driver\Manager::executeInsert() write concern error +--SKIPIF-- + + +--FILE-- +executeInsert(NS, ['x' => 1], new MongoDB\Driver\WriteConcern(30)); +}, 'MongoDB\Driver\Exception\WriteConcernException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\WriteConcernException +Not enough data-bearing nodes +===DONE=== diff --git a/tests/manager/manager-executeUpdate_error-001.phpt b/tests/manager/manager-executeUpdate_error-001.phpt new file mode 100644 index 000000000..b4a3fd8f1 --- /dev/null +++ b/tests/manager/manager-executeUpdate_error-001.phpt @@ -0,0 +1,23 @@ +--TEST-- +MongoDB\Driver\Manager::executeUpdate() write error +--SKIPIF-- + +--FILE-- +executeInsert(NS, ['x' => 1]); + +echo throws(function() use ($manager) { + $manager->executeUpdate(NS, ['x' => 1], ['$foo' => 1]); +}, 'MongoDB\Driver\Exception\WriteException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\WriteException +Unknown modifier: $foo +===DONE=== diff --git a/tests/manager/manager-executeUpdate_error-002.phpt b/tests/manager/manager-executeUpdate_error-002.phpt new file mode 100644 index 000000000..bbf9a1b6b --- /dev/null +++ b/tests/manager/manager-executeUpdate_error-002.phpt @@ -0,0 +1,24 @@ +--TEST-- +MongoDB\Driver\Manager::executeUpdate() write concern error +--SKIPIF-- + + +--FILE-- +executeInsert(NS, ['x' => 1]); + +echo throws(function() use ($manager) { + $manager->executeUpdate(NS, ['x' => 1], ['$inc' => ['x' => 1]], [], new MongoDB\Driver\WriteConcern(30)); +}, 'MongoDB\Driver\Exception\WriteConcernException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\WriteConcernException +Not enough data-bearing nodes +===DONE===