Skip to content

Commit

Permalink
fixed minor bug on non blocking query result, issue #6267
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman authored and luigidellaquila committed Jul 2, 2016
1 parent efb4c07 commit 52c49a9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class OSQLNonBlockingQuery<T extends Object> extends OSQLQuery<T> implements OCommandRequestAsynch {
private static final long serialVersionUID = 1L;

public static class ONonBlockingQueryFuture implements Future, List<Future> {
public class ONonBlockingQueryFuture implements Future, List<Future> {

protected volatile boolean finished = false;

Expand All @@ -72,15 +72,15 @@ public synchronized Object get() throws InterruptedException, ExecutionException
while (!finished) {
wait();
}
return null;
return OSQLNonBlockingQuery.this.getResultListener().getResult();
}

@Override
public synchronized Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
while (!finished) {
wait();
}
return null;
return OSQLNonBlockingQuery.this.getResultListener().getResult();
}

@Override
Expand All @@ -100,7 +100,23 @@ public boolean contains(Object o) {

@Override
public Iterator<Future> iterator() {
throw new UnsupportedOperationException("Trying to iterate over a non-blocking query result");
return new Iterator<Future>() {

@Override
public boolean hasNext() {
return false;
}

@Override
public Future next() {
return null;
}

@Override
public void remove() {
throw new UnsupportedOperationException("Unsuppored remove on non blocking query result");
}
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.orientechnologies.orient.graph;

import com.orientechnologies.orient.core.command.OCommandResultListener;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import org.junit.Test;

import java.util.concurrent.ExecutionException;


/**
* Created by tglman on 01/07/16.
*/
public class GraphNonBlockingQuery {

@Test
public void testNonBlockingClose() throws ExecutionException, InterruptedException {
OrientGraph database = new OrientGraph("memory:" + GraphNonBlockingQuery.class.getSimpleName());
database.createVertexType("Prod").createProperty("something", OType.STRING);
for (int i = 0; i < 21; i++) {
OrientVertex vertex = database.addVertex(null);
vertex.setProperty("something", "value");
vertex.save();
}
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);
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
System.out.println(db);
for (String name : odoc.fieldNames()) { // <----------- PROBLEM
System.out.println("Name:" + name);
}

System.out.println("callback " + resultCount + " invoked");
return resultCount > 20 ? false : true;
}

@Override
public void end() {
}

@Override
public Object getResult() {
return true;
}
});

database.command(test).execute();
System.out.println("query executed");
} finally {
System.out.println("Original" + database);
database.shutdown();
}
}

}

0 comments on commit 52c49a9

Please sign in to comment.