本文整理汇总了Java中org.apache.tinkerpop.gremlin.driver.Cluster.close方法的典型用法代码示例。如果您正苦于以下问题:Java Cluster.close方法的具体用法?Java Cluster.close怎么用?Java Cluster.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tinkerpop.gremlin.driver.Cluster
的用法示例。
在下文中一共展示了Cluster.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldFailIfSslEnabledOnServerButNotClient
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldFailIfSslEnabledOnServerButNotClient() throws Exception {
final Cluster cluster = Cluster.build().create();
final Client client = cluster.connect();
try {
client.submit("1+1").all().get();
fail("This should not succeed as the client did not enable SSL");
} catch(Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
assertEquals(TimeoutException.class, root.getClass());
assertThat(root.getMessage(), startsWith("Timed out while waiting for an available host"));
} finally {
cluster.close();
}
}
示例2: shouldFailAuthenticateWithPlainTextBadPassword
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldFailAuthenticateWithPlainTextBadPassword() throws Exception {
final Cluster cluster = Cluster.build().credentials("stephen", "bad").create();
final Client client = cluster.connect();
try {
client.submit("1+1").all().get();
fail("This should not succeed as the client did not provide valid credentials");
} catch(Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
assertEquals(ResponseException.class, root.getClass());
assertEquals("Username and/or password are incorrect", root.getMessage());
} finally {
cluster.close();
}
}
示例3: shouldAuthenticateAndWorkWithVariablesOverGraphSONSerialization
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldAuthenticateAndWorkWithVariablesOverGraphSONSerialization() throws Exception {
final Cluster cluster = Cluster.build().serializer(Serializers.GRAPHSON_V1D0).credentials("stephen", "password").create();
final Client client = cluster.connect(name.getMethodName());
try {
Map vertex = (Map) client.submit("v=graph.addVertex('name', 'stephen')").all().get().get(0).getObject();
Map<String, List<Map>> properties = (Map) vertex.get("properties");
assertEquals("stephen", properties.get("name").get(0).get("value"));
final Map vpName = (Map)client.submit("v.property('name')").all().get().get(0).getObject();
assertEquals("stephen", vpName.get("value"));
} finally {
cluster.close();
}
}
示例4: shouldWorkOverNioTransport
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的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();
}
示例5: shouldEnableSslWithSslContextProgrammaticallySpecified
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldEnableSslWithSslContextProgrammaticallySpecified() throws Exception {
// just for testing - this is not good for production use
final SslContextBuilder builder = SslContextBuilder.forClient();
builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
builder.sslProvider(SslProvider.JDK);
final Cluster cluster = Cluster.build().enableSsl(true).sslContext(builder.build()).create();
final Client client = cluster.connect();
try {
// this should return "nothing" - there should be no exception
assertEquals("test", client.submit("'test'").one().getString());
} finally {
cluster.close();
}
}
示例6: shouldEventuallySucceedAfterChannelLevelError
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldEventuallySucceedAfterChannelLevelError() throws Exception {
final Cluster cluster = Cluster.build().addContactPoint("localhost")
.reconnectIntialDelay(500)
.reconnectInterval(500)
.maxContentLength(1024).create();
final Client client = cluster.connect();
try {
client.submit("def x = '';(0..<1024).each{x = x + '$it'};x").all().get();
fail("Request should have failed because it exceeded the max content length allowed");
} catch (Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
assertThat(root.getMessage(), containsString("Max frame length of 1024 has been exceeded."));
}
assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
cluster.close();
}
示例7: shouldGarbageCollectPhantomButNotHard
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldGarbageCollectPhantomButNotHard() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
assertEquals(2, client.submit("addItUp(1,1)").all().join().get(0).getInt());
assertEquals(0, client.submit("def subtract(x,y){x-y};subtract(1,1)").all().join().get(0).getInt());
assertEquals(0, client.submit("subtract(1,1)").all().join().get(0).getInt());
final Map<String, Object> bindings = new HashMap<>();
bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_PHANTOM);
assertEquals(4, client.submit("def multiply(x,y){x*y};multiply(2,2)", bindings).all().join().get(0).getInt());
try {
client.submit("multiply(2,2)").all().join().get(0).getInt();
fail("Should throw an exception since reference is phantom.");
} catch (RuntimeException ignored) {
} finally {
cluster.close();
}
}
示例8: shouldUseSimpleSandbox
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldUseSimpleSandbox() throws Exception {
final Cluster cluster = TestClientFactory.open();
final Client client = cluster.connect();
assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
try {
// this should return "nothing" - there should be no exception
client.submit("java.lang.System.exit(0)").all().get();
fail("The above should not have executed in any successful way as sandboxing is enabled");
} catch (Exception ex) {
assertThat(ex.getCause().getMessage(), containsString("[Static type checking] - Not authorized to call this method: java.lang.System#exit(int)"));
} finally {
cluster.close();
}
}
示例9: shouldEnableSslAndClientCertificateAuthAndFailWithoutTrustedClientCert
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldEnableSslAndClientCertificateAuthAndFailWithoutTrustedClientCert() {
final Cluster cluster = TestClientFactory.build().enableSsl(true)
.keyCertChainFile(CLIENT_CRT).keyFile(CLIENT_KEY)
.keyPassword(KEY_PASS).trustCertificateChainFile(SERVER_CRT).create();
final Client client = cluster.connect();
try {
client.submit("'test'").one();
fail("Should throw exception because ssl client auth is enabled on the server but does not trust client's cert");
} catch(Exception x) {
final Throwable root = ExceptionUtils.getRootCause(x);
assertThat(root, instanceOf(TimeoutException.class));
} finally {
cluster.close();
}
}
示例10: shouldEventuallySucceedAfterMuchFailure
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldEventuallySucceedAfterMuchFailure() throws Exception {
final Cluster cluster = TestClientFactory.open();
final Client client = cluster.connect();
// tested independently to 10000 iterations but for speed, bumped back to 1000
IntStream.range(0,1000).forEach(i -> {
try {
client.submit("1 + 9 9").all().join().get(0).getInt();
fail("Should not have gone through due to syntax error");
} catch (Exception ex) {
final Throwable root = ExceptionUtils.getRootCause(ex);
assertThat(root, instanceOf(ResponseException.class));
}
});
assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
cluster.close();
}
示例11: shouldEventuallySucceedOnSameServer
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldEventuallySucceedOnSameServer() throws Exception {
stopServer();
final Cluster cluster = TestClientFactory.open();
final Client client = cluster.connect();
try {
client.submit("1+1").all().join().get(0).getInt();
fail("Should not have gone through because the server is not running");
} catch (Exception i) {
final Throwable root = ExceptionUtils.getRootCause(i);
assertThat(root, instanceOf(TimeoutException.class));
}
startServer();
// default reconnect time is 1 second so wait some extra time to be sure it has time to try to bring it
// back to life
TimeUnit.SECONDS.sleep(3);
assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
cluster.close();
}
示例12: shouldWaitForAllResultsToArrive
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldWaitForAllResultsToArrive() throws Exception {
final Cluster cluster = TestClientFactory.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();
}
示例13: shouldFailWithBadServerSideSerialization
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldFailWithBadServerSideSerialization() throws Exception {
final Cluster cluster = TestClientFactory.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();
}
示例14: shouldSerializeToStringWhenRequestedGryoV3
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldSerializeToStringWhenRequestedGryoV3() throws Exception {
final Map<String, Object> m = new HashMap<>();
m.put("serializeResultToString", true);
final GryoMessageSerializerV3d0 serializer = new GryoMessageSerializerV3d0();
serializer.configure(m, null);
final Cluster cluster = TestClientFactory.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();
}
示例15: shouldIterate
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldIterate() throws Exception {
final Cluster cluster = TestClientFactory.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();
}