本文整理汇总了Java中org.apache.tinkerpop.gremlin.driver.ResultSet类的典型用法代码示例。如果您正苦于以下问题:Java ResultSet类的具体用法?Java ResultSet怎么用?Java ResultSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResultSet类属于org.apache.tinkerpop.gremlin.driver包,在下文中一共展示了ResultSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interpret
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Override
public InterpreterResult interpret(String gremlin, InterpreterContext interpreterContext) {
logger.info("execute gremlin traversal {}", gremlin);
try {
ResultSet results = client.submit(gremlin);
JsonArray array = results.stream()
.map(result -> new JsonPrimitive(results.toString()))
.collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
//TODO extract ResultSet
//Case MessageSerializer
return new InterpreterResult(InterpreterResult.Code.SUCCESS, array.toString());
} catch (RuntimeException e) {
return new InterpreterResult(InterpreterResult.Code.ERROR, e.getMessage());
}
}
示例2: shouldFailWithBadClientSideSerialization
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldFailWithBadClientSideSerialization() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("java.awt.Color.RED");
try {
results.all().join();
fail("Should have thrown exception over bad serialization");
} catch (Exception ex) {
final Throwable inner = ExceptionUtils.getRootCause(ex);
assertTrue(inner instanceof RuntimeException);
assertThat(inner.getMessage(), startsWith("Encountered unregistered class ID:"));
}
// should not die completely just because we had a bad serialization error. that kind of stuff happens
// from time to time, especially in the console if you're just exploring.
assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
cluster.close();
}
示例3: shouldFailWithScriptExecutionException
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldFailWithScriptExecutionException() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("1/0");
try {
results.all().join();
fail("Should have thrown exception over bad serialization");
} catch (Exception ex) {
final Throwable inner = ExceptionUtils.getRootCause(ex);
assertTrue(inner instanceof ResponseException);
assertThat(inner.getMessage(), endsWith("Division by zero"));
}
// should not die completely just because we had a bad serialization error. that kind of stuff happens
// from time to time, especially in the console if you're just exploring.
assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
cluster.close();
}
示例4: shouldProcessRequestsOutOfOrder
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldProcessRequestsOutOfOrder() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet rsFive = client.submit("Thread.sleep(5000);'five'");
final ResultSet rsZero = client.submit("'zero'");
final CompletableFuture<List<Result>> futureFive = rsFive.all();
final CompletableFuture<List<Result>> futureZero = rsZero.all();
final long start = System.nanoTime();
assertFalse(futureFive.isDone());
assertEquals("zero", futureZero.get().get(0).getString());
logger.info("Eval of 'zero' complete: " + TimeUtil.millisSince(start));
assertFalse(futureFive.isDone());
assertEquals("five", futureFive.get(10, TimeUnit.SECONDS).get(0).getString());
logger.info("Eval of 'five' complete: " + TimeUtil.millisSince(start));
}
示例5: shouldProcessSessionRequestsInOrder
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldProcessSessionRequestsInOrder() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect(name.getMethodName());
final ResultSet rsFive = client.submit("Thread.sleep(5000);'five'");
final ResultSet rsZero = client.submit("'zero'");
final CompletableFuture<List<Result>> futureFive = rsFive.all();
final CompletableFuture<List<Result>> futureZero = rsZero.all();
final AtomicBoolean hit = new AtomicBoolean(false);
while (!futureFive.isDone()) {
// futureZero can't finish before futureFive - racy business here?
assertThat(futureZero.isDone(), is(false));
hit.set(true);
}
// should have entered the loop at least once and thus proven that futureZero didn't return ahead of
// futureFive
assertThat(hit.get(), is(true));
assertEquals("zero", futureZero.get().get(0).getString());
assertEquals("five", futureFive.get(10, TimeUnit.SECONDS).get(0).getString());
}
示例6: shouldWaitForAllResultsToArrive
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldWaitForAllResultsToArrive() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final AtomicInteger checked = new AtomicInteger(0);
final ResultSet results = client.submit("[1,2,3,4,5,6,7,8,9]");
while (!results.allItemsAvailable()) {
assertTrue(results.getAvailableItemCount() < 10);
checked.incrementAndGet();
Thread.sleep(100);
}
assertTrue(checked.get() > 0);
assertEquals(9, results.getAvailableItemCount());
cluster.close();
}
示例7: shouldWorkOverNioTransport
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldWorkOverNioTransport() throws Exception {
final Cluster cluster = Cluster.build().channelizer(Channelizer.NioChannelizer.class.getName()).create();
final Client client = cluster.connect();
final AtomicInteger checked = new AtomicInteger(0);
final ResultSet results = client.submit("[1,2,3,4,5,6,7,8,9]");
while (!results.allItemsAvailable()) {
assertTrue(results.getAvailableItemCount() < 10);
checked.incrementAndGet();
Thread.sleep(100);
}
assertTrue(checked.get() > 0);
assertEquals(9, results.getAvailableItemCount());
cluster.close();
}
示例8: shouldStream
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldStream() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("[1,2,3,4,5,6,7,8,9]");
final AtomicInteger counter = new AtomicInteger(0);
results.stream().map(i -> i.get(Integer.class) * 2).forEach(i -> assertEquals(counter.incrementAndGet() * 2, Integer.parseInt(i.toString())));
assertEquals(9, counter.get());
assertThat(results.allItemsAvailable(), is(true));
// cant stream it again
assertThat(results.stream().iterator().hasNext(), is(false));
cluster.close();
}
示例9: shouldIterate
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldIterate() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("[1,2,3,4,5,6,7,8,9]");
final Iterator<Result> itty = results.iterator();
final AtomicInteger counter = new AtomicInteger(0);
while (itty.hasNext()) {
counter.incrementAndGet();
assertEquals(counter.get(), itty.next().getInt());
}
assertEquals(9, counter.get());
assertThat(results.allItemsAvailable(), is(true));
// can't stream it again
assertThat(results.iterator().hasNext(), is(false));
cluster.close();
}
示例10: shouldFailWithBadServerSideSerialization
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldFailWithBadServerSideSerialization() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("TinkerGraph.open().variables()");
try {
results.all().join();
fail();
} catch (Exception ex) {
final Throwable inner = ExceptionUtils.getRootCause(ex);
assertTrue(inner instanceof ResponseException);
assertEquals(ResponseStatusCode.SERVER_ERROR_SERIALIZATION, ((ResponseException) inner).getResponseStatusCode());
}
// should not die completely just because we had a bad serialization error. that kind of stuff happens
// from time to time, especially in the console if you're just exploring.
assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
cluster.close();
}
示例11: shouldSerializeToStringWhenRequested
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldSerializeToStringWhenRequested() throws Exception {
final Map<String, Object> m = new HashMap<>();
m.put("serializeResultToString", true);
final GryoMessageSerializerV1d0 serializer = new GryoMessageSerializerV1d0();
serializer.configure(m, null);
final Cluster cluster = Cluster.build().serializer(serializer).create();
final Client client = cluster.connect();
final ResultSet resultSet = client.submit("TinkerFactory.createClassic()");
final List<Result> results = resultSet.all().join();
assertEquals(1, results.size());
assertEquals("tinkergraph[vertices:6 edges:6]", results.get(0).getString());
cluster.close();
}
示例12: shouldHandleRequestSentThatNeverReturns
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
@org.junit.Ignore("Can't seem to make this test pass consistently")
public void shouldHandleRequestSentThatNeverReturns() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("Thread.sleep(10000); 'should-not-ever-get-back-coz-we-killed-the-server'");
stopServer();
// give the server a chance to kill everything
Thread.sleep(1000);
try {
results.all().get(10000, TimeUnit.MILLISECONDS);
fail("Server was stopped before the request could execute");
} catch (TimeoutException toe) {
fail("Should not have tossed a TimeOutException getting the result");
} catch (Exception ex) {
final Throwable cause = ExceptionUtils.getCause(ex);
assertThat(cause.getMessage(), containsString("rejected from java.util.concurrent.ThreadPoolExecutor"));
}
cluster.close();
}
示例13: shouldExecuteScriptInSession
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldExecuteScriptInSession() throws Exception {
final Cluster cluster = Cluster.build().create();
final Client client = cluster.connect(name.getMethodName());
final ResultSet results1 = client.submit("x = [1,2,3,4,5,6,7,8,9]");
assertEquals(9, results1.all().get().size());
final ResultSet results2 = client.submit("x[0]+1");
assertEquals(2, results2.all().get().get(0).getInt());
final ResultSet results3 = client.submit("x[1]+2");
assertEquals(4, results3.all().get().get(0).getInt());
cluster.close();
}
示例14: shouldCloseSession
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldCloseSession() throws Exception {
final Cluster cluster = Cluster.build().create();
final Client client = cluster.connect(name.getMethodName());
final ResultSet results1 = client.submit("x = [1,2,3,4,5,6,7,8,9]");
assertEquals(9, results1.all().get().size());
final ResultSet results2 = client.submit("x[0]+1");
assertEquals(2, results2.all().get().get(0).getInt());
client.close();
try {
client.submit("x[0]+1");
fail("Should have thrown an exception because the connection is closed");
} catch (Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
assertThat(root, instanceOf(ConnectionException.class));
}
}
示例15: shouldExecuteScriptsInMultipleSession
import org.apache.tinkerpop.gremlin.driver.ResultSet; //导入依赖的package包/类
@Test
public void shouldExecuteScriptsInMultipleSession() throws Exception {
final Cluster cluster = Cluster.build().create();
final Client client1 = cluster.connect(name.getMethodName() + "1");
final Client client2 = cluster.connect(name.getMethodName() + "2");
final Client client3 = cluster.connect(name.getMethodName() + "3");
final ResultSet results11 = client1.submit("x = 1");
final ResultSet results21 = client2.submit("x = 2");
final ResultSet results31 = client3.submit("x = 3");
assertEquals(1, results11.all().get().get(0).getInt());
assertEquals(2, results21.all().get().get(0).getInt());
assertEquals(3, results31.all().get().get(0).getInt());
final ResultSet results12 = client1.submit("x + 100");
final ResultSet results22 = client2.submit("x * 2");
final ResultSet results32 = client3.submit("x * 10");
assertEquals(101, results12.all().get().get(0).getInt());
assertEquals(4, results22.all().get().get(0).getInt());
assertEquals(30, results32.all().get().get(0).getInt());
cluster.close();
}