How to query an embedded DB?

39 views
Skip to first unread message

Marvin Froeder

unread,
Sep 6, 2015, 12:16:21 AM9/6/15
to OrientDB
I'm starting an in-memory embedded server to run some "unit" tests.

server = OServerMain.create();
server
.startup(configuration);
server
.activate();


And the I query it by using:
try (ODatabaseDocumentTx db = new ODatabaseDocumentTx(server.getStorageURL("test"));) {
 db
.open("root", "1234");
 
return db.query(query, args);
}


And this give me the following error:
com.orientechnologies.orient.core.exception.OSecurityAccessException: User or password not valid for database: 'test'
 at com
.orientechnologies.orient.core.metadata.security.OSecurityShared.authenticate(OSecurityShared.java:173)
 at com
.orientechnologies.orient.core.metadata.security.OSecurityProxy.authenticate(OSecurityProxy.java:87)
 at com
.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:265)
 at io
.sonarcloud.orientdb.EmbeddedOrientDB.query(EmbeddedOrientDB.java:91)
 at io
.sonarcloud.github.routes.RecordRouteBuilderTest.testSendMatchingMessage(RecordRouteBuilderTest.java:82)
 at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java
.lang.reflect.Method.invoke(Method.java:497)
 at org
.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
 at org
.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at org
.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
 at org
.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 at org
.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
 at org
.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
 at org
.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
 at org
.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
 at org
.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
 at org
.junit.rules.RunRules.evaluate(RunRules.java:20)
 at org
.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
 at org
.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
 at org
.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
 at org
.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
 at org
.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
 at org
.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
 at org
.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
 at org
.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
 at org
.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
 at org
.junit.runners.ParentRunner.run(ParentRunner.java:363)
 at org
.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
 at org
.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org
.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
 at org
.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
 at org
.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
 at org
.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
 
Suppressed: com.orientechnologies.orient.core.exception.ODatabaseException: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db);
 at com
.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal.get(ODatabaseRecordThreadLocal.java:51)
 at com
.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.checkIfActive(ODatabaseDocumentTx.java:3131)
 at com
.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.close(ODatabaseDocumentTx.java:1129)
 at io
.sonarcloud.orientdb.EmbeddedOrientDB.query(EmbeddedOrientDB.java:93)
 
... 31 more


How can I solve this?

xvik

unread,
Sep 6, 2015, 3:39:11 AM9/6/15
to OrientDB
I suppose you are trying to connect with user from server configuration, but server users and database users are different. 
Try admin/admin - the default user created for each new database.
http://orientdb.com/docs/last/Database-Security.html#users

воскресенье, 6 сентября 2015 г., 10:16:21 UTC+6 пользователь Marvin Froeder написал:
...

xvik

unread,
Sep 6, 2015, 3:48:14 AM9/6/15
to OrientDB
By the way, you don't need the embedded server for unit tests: you can simply create new in-memory db and work with it

ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:test");
db.create();
db.open("admin", "admin");

The behavior of in-memory database is the same as remote connection in many cases (not all ofc), but usually its enough for tests  

воскресенье, 6 сентября 2015 г., 13:39:11 UTC+6 пользователь xvik написал:

Marvin Froeder

unread,
Sep 6, 2015, 6:09:02 AM9/6/15
to orient-...@googlegroups.com
On my tests I need to access document API over HTTP.

Now I just wanna assert if all is fine making some queries..  That is why I instantiate a server.

admin/1234 is the user I set for my tests.... it work like a charm for http.

Any other idea?

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/Lqfnrgk2l6Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marvin Froeder

unread,
Sep 6, 2015, 6:17:57 AM9/6/15
to orient-...@googlegroups.com
What I'm trying to create is a junit rule, this is the initial effort for ti

xvik

unread,
Sep 6, 2015, 6:22:22 AM9/6/15
to OrientDB, vel...@gmail.com
But in the first post you are using "root/1234" and not "admin/1234".
In any case error is pretty clear: user credentials are not good.

And one more moment: please check that server.getStorageUrl() returns remote url.
I briefly look the code and most likely it will return plocal url, which is not desired for you.

воскресенье, 6 сентября 2015 г., 16:09:02 UTC+6 пользователь Marvin Froeder написал:

Marvin Froeder

unread,
Sep 6, 2015, 6:25:13 AM9/6/15
to xvik, OrientDB
Sorry, mean to say root/1234

And on the http request I use Basic cm9vdDoxMjM0 (which is also root:1234 and works like a charm)

xvik

unread,
Sep 6, 2015, 6:27:06 AM9/6/15
to OrientDB, vel...@gmail.com
According to your gist, you create embedded server with root/1234 user.
But its a server user! You can't use this user to connect to database!
To access your just created test database you need to use default admin/admin user.

воскресенье, 6 сентября 2015 г., 16:17:57 UTC+6 пользователь Marvin Froeder написал:

Marvin Froeder

unread,
Sep 6, 2015, 6:32:12 AM9/6/15
to xvik, OrientDB
Ok, that was the problem. I though was the same.

Thanks man
Reply all
Reply to author
Forward
0 new messages