Search in sources :

Example 1 with OSQLNonBlockingQuery

use of com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery in project orientdb by orientechnologies.

the class GraphNonBlockingQueryRemote method testNonBlockingClose.

@Test
public void testNonBlockingClose() throws ExecutionException, InterruptedException {
    OrientGraph database = new OrientGraph("remote:localhost:3064/" + GraphNonBlockingQueryRemote.class.getSimpleName());
    database.createVertexType("Prod").createProperty("something", OType.STRING);
    for (int i = 0; i < 21; i++) {
        OrientVertex vertex = database.addVertex("class:Prod");
        vertex.setProperty("something", "value");
        vertex.save();
    }
    database.commit();
    final CountDownLatch ended = new CountDownLatch(21);
    try {
        OSQLNonBlockingQuery<Object> test = new OSQLNonBlockingQuery<Object>("select * from Prod ", new OCommandResultListener() {

            int resultCount = 0;

            @Override
            public boolean result(Object iRecord) {
                resultCount++;
                ODocument odoc = ((ODocument) iRecord);
                for (String name : odoc.fieldNames()) {
                    // <----------- PROBLEM
                    assertEquals("something", name);
                }
                ended.countDown();
                return resultCount > 20 ? false : true;
            }

            @Override
            public void end() {
                ended.countDown();
            }

            @Override
            public Object getResult() {
                return resultCount;
            }
        });
        database.command(test).execute();
        assertTrue(ended.await(10, TimeUnit.SECONDS));
    } finally {
        database.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLNonBlockingQuery(com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery) OCommandResultListener(com.orientechnologies.orient.core.command.OCommandResultListener) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) CountDownLatch(java.util.concurrent.CountDownLatch) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OrientGraphRemoteTest(com.tinkerpop.blueprints.impls.orient.OrientGraphRemoteTest) Test(org.junit.Test)

Aggregations

OCommandResultListener (com.orientechnologies.orient.core.command.OCommandResultListener)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OSQLNonBlockingQuery (com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery)1 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)1 OrientGraphRemoteTest (com.tinkerpop.blueprints.impls.orient.OrientGraphRemoteTest)1 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1