1
0
Fork 0

reset vocbase earlier in requests

This commit is contained in:
Jan Steemann 2013-09-13 15:29:05 +02:00
parent 64741f8a8d
commit b97e4c014a
3 changed files with 61 additions and 8 deletions

View File

@ -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;

View File

@ -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<v8::Function> callback) {
void createCallback (v8::Isolate* isolate,
v8::Handle<v8::Function> callback) {
WRITE_LOCKER(_callbacksLock);
map< v8::Isolate*, v8::Persistent<v8::Function> >::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

View File

@ -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)
}
}
};