From b97e4c014a0b8a7a08082bcd8fd5f7d1dec4f5d7 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 13 Sep 2013 15:29:05 +0200 Subject: [PATCH] reset vocbase earlier in requests --- arangod/V8Server/ApplicationV8.cpp | 17 +++++++---- arangod/V8Server/v8-actions.cpp | 6 ++-- js/client/tests/shell-endpoints.js | 46 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/arangod/V8Server/ApplicationV8.cpp b/arangod/V8Server/ApplicationV8.cpp index 23463134e5..e930b312ba 100644 --- a/arangod/V8Server/ApplicationV8.cpp +++ b/arangod/V8Server/ApplicationV8.cpp @@ -291,6 +291,13 @@ ApplicationV8::V8Context* ApplicationV8::enterContext (TRI_vocbase_s* vocbase, context->_locker = new v8::Locker(context->_isolate); context->_isolate->Enter(); context->_context->Enter(); + + // set the current database + v8::HandleScope scope; + TRI_v8_global_t* v8g = (TRI_v8_global_t*) context->_isolate->GetData(); + v8g->_vocbase = vocbase; + v8g->_allowUseDatabase = allowUseDatabase; + LOGGER_TRACE("entering V8 context " << context->_id); context->handleGlobalContextMethods(); @@ -304,12 +311,6 @@ ApplicationV8::V8Context* ApplicationV8::enterContext (TRI_vocbase_s* vocbase, false); } - // set the current database - v8::HandleScope scope; - TRI_v8_global_t* v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData(); - v8g->_vocbase = vocbase; - v8g->_allowUseDatabase = allowUseDatabase; - return context; } @@ -328,6 +329,10 @@ void ApplicationV8::exitContext (V8Context* context) { context->handleGlobalContextMethods(); + TRI_v8_global_t* v8g = (TRI_v8_global_t*) context->_isolate->GetData(); + // set vocbase to 0 + v8g->_vocbase = 0; + context->_context->Exit(); context->_isolate->Exit(); delete context->_locker; diff --git a/arangod/V8Server/v8-actions.cpp b/arangod/V8Server/v8-actions.cpp index afc8b70ba9..46ee4aca84 100644 --- a/arangod/V8Server/v8-actions.cpp +++ b/arangod/V8Server/v8-actions.cpp @@ -109,7 +109,8 @@ class v8_action_t : public TRI_action_t { /// @brief creates callback for a context //////////////////////////////////////////////////////////////////////////////// - void createCallback (v8::Isolate* isolate, v8::Handle callback) { + void createCallback (v8::Isolate* isolate, + v8::Handle callback) { WRITE_LOCKER(_callbacksLock); map< v8::Isolate*, v8::Persistent >::iterator i = _callbacks.find(isolate); @@ -125,7 +126,8 @@ class v8_action_t : public TRI_action_t { /// @brief creates callback for a context //////////////////////////////////////////////////////////////////////////////// - HttpResponse* execute (TRI_vocbase_t* vocbase, HttpRequest* request) { + HttpResponse* execute (TRI_vocbase_t* vocbase, + HttpRequest* request) { ApplicationV8::V8Context* context = GlobalV8Dealer->enterContext(vocbase, false, false); // note: the context might be 0 in case of shut-down diff --git a/js/client/tests/shell-endpoints.js b/js/client/tests/shell-endpoints.js index c6d29e0423..5662ff22e9 100644 --- a/js/client/tests/shell-endpoints.js +++ b/js/client/tests/shell-endpoints.js @@ -89,6 +89,8 @@ function EndpointsSuite () { catch (err) { } } + + arango.reconnect(originalEndpoint, "", "root", ""); }, //////////////////////////////////////////////////////////////////////////////// @@ -96,6 +98,8 @@ function EndpointsSuite () { //////////////////////////////////////////////////////////////////////////////// testListEndpoints : function () { + assertEqual("_system", db._name()); + var i; var base = 30000 + parseInt(Math.random() * 10000, 10); @@ -121,6 +125,8 @@ function EndpointsSuite () { //////////////////////////////////////////////////////////////////////////////// testConfigureEndpoints : function () { + assertEqual("_system", db._name()); + var i; var base = 30000 + parseInt(Math.random() * 10000, 10); @@ -150,6 +156,8 @@ function EndpointsSuite () { //////////////////////////////////////////////////////////////////////////////// testConfigureInvalidEndpoints : function () { + assertEqual("_system", db._name()); + var base = 30000 + parseInt(Math.random() * 10000, 10); try { @@ -185,6 +193,8 @@ function EndpointsSuite () { //////////////////////////////////////////////////////////////////////////////// testRemoveEndpoints : function () { + assertEqual("_system", db._name()); + var i; var base = 30000 + parseInt(Math.random() * 10000, 10); @@ -320,6 +330,42 @@ function EndpointsSuite () { ]; test("tcp://127.0.0.1:" + (base + 4), endpoints); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test non-system +//////////////////////////////////////////////////////////////////////////////// + + testEndpointsNonSystem : function () { + assertEqual("_system", db._name()); + + try { + db._dropDatabase("UnitTestsDatabase0"); + } + catch (err1) { + } + + db._createDatabase("UnitTestsDatabase0"); + db._useDatabase("UnitTestsDatabase0"); + + // _listEndpoints is forbidden + try { + db._listEndpoints(); + fail(); + } + catch (err2) { + assertEqual(ERRORS.ERROR_ARANGO_USE_SYSTEM_DATABASE.code, err2.errorNum) + } + + // _configureEndpoint is forbidden + try { + var base = 30000 + parseInt(Math.random() * 10000, 10); + db._configureEndpoint("tcp://127.0.0.1:" + base, [ ]); + fail(); + } + catch (err3) { + assertEqual(ERRORS.ERROR_ARANGO_USE_SYSTEM_DATABASE.code, err3.errorNum) + } } };