use of com.orientechnologies.orient.core.db.record.ORecordOperation in project orientdb by orientechnologies.
the class LiveQueryTest method checkLiveQuery1.
@Test(enabled = false)
public void checkLiveQuery1() throws IOException, InterruptedException {
final String className1 = "LiveQueryTest1_1";
final String className2 = "LiveQueryTest1_2";
database.getMetadata().getSchema().createClass(className1);
database.getMetadata().getSchema().createClass(className2);
MyLiveQueryListener listener = new MyLiveQueryListener();
OResultSet<ODocument> tokens = database.query(new OLiveQuery<ODocument>("live select from " + className1, listener));
Assert.assertEquals(tokens.size(), 1);
ODocument tokenDoc = tokens.get(0);
int token = tokenDoc.field("token");
Assert.assertNotNull(token);
database.command(new OCommandSQL("insert into " + className1 + " set name = 'foo', surname = 'bar'")).execute();
database.command(new OCommandSQL("insert into " + className1 + " set name = 'foo', surname = 'baz'")).execute();
database.command(new OCommandSQL("insert into " + className2 + " set name = 'foo'"));
latch.await(1, TimeUnit.MINUTES);
database.command(new OCommandSQL("live unsubscribe " + token)).execute();
database.command(new OCommandSQL("insert into " + className1 + " set name = 'foo', surname = 'bax'")).execute();
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");
}
unLatch.await(1, TimeUnit.MINUTES);
Assert.assertEquals(listener.unsubscribe, token);
}
use of com.orientechnologies.orient.core.db.record.ORecordOperation in project orientdb by orientechnologies.
the class SQLLiveSelectTest method liveQueryTestTX.
@Test
public void liveQueryTestTX() throws InterruptedException {
int TOTAL_OPS = 6;
final CountDownLatch latch = new CountDownLatch(TOTAL_OPS);
final List<ORecordOperation> ops = Collections.synchronizedList(new ArrayList());
OResultSet<ODocument> tokens = database.query(new OLiveQuery<Object>("live select from LiveClassTx", new OLiveResultListener() {
@Override
public void onLiveResult(int iLiveToken, ORecordOperation iOp) throws OException {
ops.add(iOp);
latch.countDown();
}
@Override
public void onError(int iLiveToken) {
}
@Override
public void onUnsubscribe(int iLiveToken) {
}
}));
Assert.assertEquals(tokens.size(), 1);
ODocument tokenDoc = tokens.get(0);
Integer token = tokenDoc.field("token");
Assert.assertNotNull(token);
database.begin();
database.command(new OCommandSQL("insert into LiveClassTx set name = 'foo', surname = 'bar'")).execute();
database.command(new OCommandSQL("insert into LiveClassTx set name = 'foo', surname = 'baz'")).execute();
database.command(new OCommandSQL("insert into LiveClassTx set name = 'foo'")).execute();
database.commit();
database.begin();
database.command(new OCommandSQL("update LiveClassTx set name = 'updated'")).execute();
database.commit();
latch.await();
Assert.assertEquals(ops.size(), TOTAL_OPS);
for (ORecordOperation doc : ops) {
if (doc.type == ORecordOperation.CREATED) {
Assert.assertEquals(((ODocument) doc.record).field("name"), "foo");
} else if (doc.type == ORecordOperation.UPDATED) {
Assert.assertEquals(((ODocument) doc.record).field("name"), "updated");
} else {
Assert.fail();
}
}
}
Aggregations