@After public void tearDown() { testDocumentTx.activateOnCurrentThread(); testDocumentTx.drop(); baseDocumentTx.activateOnCurrentThread(); baseDocumentTx.drop(); OFileUtils.deleteRecursively(buildDir); Assert.assertFalse(buildDir.exists()); }
@Override public Void call() throws Exception { baseDB.open("admin", "admin"); testDB.open("admin", "admin"); try { while (true) { long id = idGen.getAndIncrement(); long ts = System.currentTimeMillis(); ODatabaseRecordThreadLocal.INSTANCE.set(baseDB); ODocument doc = new ODocument(); doc.field("ts", ts); doc.save(); baseDB .command( new OCommandSQL( "insert into index:mi (key, rid) values (" + id + ", " + doc.getIdentity() + ")")) .execute(); ODatabaseRecordThreadLocal.INSTANCE.set(testDB); doc = new ODocument(); doc.field("ts", ts); doc.save(); testDB .command( new OCommandSQL( "insert into index:mi (key, rid) values (" + id + ", " + doc.getIdentity() + ")")) .execute(); } } finally { baseDB.activateOnCurrentThread(); baseDB.close(); testDB.activateOnCurrentThread(); testDB.close(); } }
@Test public void testLiveInsert() { OLiveCommandExecutorSQLFactory.init(); ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:OLiveQueryTest"); db.activateOnCurrentThread(); db.create(); db.registerHook(new OLiveQueryHook(db)); try { db.getMetadata().getSchema().createClass("test"); db.getMetadata().getSchema().createClass("test2"); MyLiveQueryListener listener = new MyLiveQueryListener(); db.query(new OLiveQuery<ODocument>("live select from test", listener)); db.command(new OCommandSQL("insert into test set name = 'foo', surname = 'bar'")).execute(); db.command(new OCommandSQL("insert into test set name = 'foo', surname = 'baz'")).execute(); db.command(new OCommandSQL("insert into test2 set name = 'foo'")); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Assert.assertEquals(listener.ops.size(), 2); for (ORecordOperation doc : listener.ops) { Assert.assertEquals(doc.type, ORecordOperation.CREATED); Assert.assertEquals(((ODocument) doc.record).field("name"), "foo"); } } finally { db.drop(); } }
@Before public void prepareDatabase() throws Exception { String dbUrl = "memory:test"; ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl); String username = "******"; String password = "******"; if (db.exists()) { db.activateOnCurrentThread(); db.open(username, password); db.drop(); } db.create(); createSchemaDB(db); if (!new File("./src/test/resources/file.pdf").exists()) OLogManager.instance() .warn( this, "TEST IS NOT RUNNING UNDER distributed folder, attachment will be not loaded!"); loadDB(db, 20); Properties info = new Properties(); info.put("user", username); info.put("password", password); conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:" + dbUrl, info); }
@Test public void testExceptionManagement() { // issue #5244 OLiveCommandExecutorSQLFactory.init(); ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:ONonBlockingQueryTest"); db.activateOnCurrentThread(); db.create(); db.getMetadata().getSchema().createClass("test"); MyResultListener listener = new MyResultListener(); try { db.command(new OCommandSQL("insert into test set name = 'foo', surname = 'bar'")).execute(); db.query(new OSQLNonBlockingQuery<Object>("select from test bla blu", listener)); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Assert.assertEquals(listener.finished, true); listener = new MyResultListener(); db.query(new OSQLNonBlockingQuery<Object>("select from test", listener)); } finally { db.close(); } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Assert.assertEquals(listener.numResults, 1); }