当前位置: 首页>>代码示例>>Java>>正文


Java Cluster.connect方法代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.driver.Cluster.connect方法的典型用法代码示例。如果您正苦于以下问题:Java Cluster.connect方法的具体用法?Java Cluster.connect怎么用?Java Cluster.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tinkerpop.gremlin.driver.Cluster的用法示例。


在下文中一共展示了Cluster.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldWaitForAllResultsToArrive

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的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();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:GremlinDriverIntegrateTest.java

示例2: shouldFailAuthenticateWithPlainTextNoCredentials

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldFailAuthenticateWithPlainTextNoCredentials() 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 provide credentials");
    } catch(Exception ex) {
        final Throwable root = ExceptionUtils.getRootCause(ex);
        assertEquals(GSSException.class, root.getClass());

        // removed this assert as the text of the message changes based on kerberos config - stupid kerberos
        // assertThat(root.getMessage(), startsWith("Invalid name provided"));
    } finally {
        cluster.close();
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:19,代码来源:GremlinServerAuthOldIntegrateTest.java

示例3: shouldRequireAliasedGraphVariablesInStrictTransactionMode

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldRequireAliasedGraphVariablesInStrictTransactionMode() throws Exception {
    final Cluster cluster = Cluster.build().create();
    final Client client = cluster.connect();

    try {
        client.submit("1+1").all().get();
        fail("Should have tossed an exception because strict mode is on and no aliasing was performed");
    } catch (Exception ex) {
        final Throwable root = ExceptionUtils.getRootCause(ex);
        assertThat(root, instanceOf(ResponseException.class));
        final ResponseException re = (ResponseException) root;
        assertEquals(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS, re.getResponseStatusCode());
    }

    cluster.close();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:GremlinDriverIntegrateTest.java

示例4: 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();
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:23,代码来源:GremlinServerIntegrateTest.java

示例5: shouldCloseSession

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的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));
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:21,代码来源:GremlinDriverIntegrateTest.java

示例6: shouldExecuteScriptsInMultipleSession

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的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();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:24,代码来源:GremlinDriverIntegrateTest.java

示例7: shouldUseInterpreterMode

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldUseInterpreterMode() throws Exception {
    final Cluster cluster = Cluster.open();
    final Client client = cluster.connect(name.getMethodName());

    client.submit("def subtractAway(x,y){x-y};[]").all().get();
    client.submit("multiplyIt = { x,y -> x * y};[]").all().get();

    assertEquals(2, client.submit("x = 1 + 1").all().get().get(0).getInt());
    assertEquals(3, client.submit("int y = x + 1").all().get().get(0).getInt());
    assertEquals(5, client.submit("def z = x + y").all().get().get(0).getInt());

    final Map<String,Object> m = new HashMap<>();
    m.put("x", 10);
    assertEquals(-5, client.submit("z - x", m).all().get().get(0).getInt());
    assertEquals(15, client.submit("addItUp(x,z)", m).all().get().get(0).getInt());
    assertEquals(5, client.submit("subtractAway(x,z)", m).all().get().get(0).getInt());
    assertEquals(50, client.submit("multiplyIt(x,z)", m).all().get().get(0).getInt());

    cluster.close();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:22,代码来源:GremlinServerIntegrateTest.java

示例8: 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();
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:GremlinServerAuthIntegrateTest.java

示例9: shouldReturnNiceMessageFromOpSelector

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldReturnNiceMessageFromOpSelector() {
    final Cluster cluster = Cluster.build().create();
    final Client client = cluster.connect();

    try {
        final Map m = new HashMap<>();
        m.put(null, "a null key will force a throw of OpProcessorException in message validation");
        client.submit("1+1", m).all().get();
        fail("Should throw an exception.");
    } catch (Exception re) {
        final Throwable root = ExceptionUtils.getRootCause(re);
        assertEquals("The [eval] message is using one or more invalid binding keys - they must be of type String and cannot be null", root.getMessage());
    } finally {
        cluster.close();
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:GremlinDriverIntegrateTest.java

示例10: 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();
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:GremlinServerAuthIntegrateTest.java

示例11: shouldFailWithBadClientSideSerialization

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的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();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:23,代码来源:GremlinDriverIntegrateTest.java

示例12: shouldAuthenticateWithQop

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldAuthenticateWithQop() throws Exception {
    final String oldQop = System.getProperty("javax.security.sasl.qop", "");
    System.setProperty("javax.security.sasl.qop", "auth-conf");
    final Cluster cluster = TestClientFactory.build().jaasEntry(TESTCONSOLE)
            .protocol(kdcServer.serverPrincipalName).addContactPoint(kdcServer.hostname).create();
    final Client client = cluster.connect();
    try {
        assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
        assertEquals(3, client.submit("1+2").all().get().get(0).getInt());
        assertEquals(4, client.submit("1+3").all().get().get(0).getInt());
    } finally {
        cluster.close();
        System.setProperty("javax.security.sasl.qop", oldQop);
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:17,代码来源:GremlinServerAuthKrb5IntegrateTest.java

示例13: shouldRollbackOnEvalExceptionForManagedTransaction

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldRollbackOnEvalExceptionForManagedTransaction() throws Exception {
    assumeNeo4jIsPresent();

    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect(name.getMethodName(), true);

    try {
        client.submit("graph.addVertex(); throw new Exception('no worky')").all().get();
        fail("Should have tossed the manually generated exception");
    } catch (Exception ex) {
        final Throwable root = ExceptionUtils.getRootCause(ex);
        ex.printStackTrace();
        assertEquals("no worky", root.getMessage());

        // just force a commit here of "something" in case there is something lingering
        client.submit("graph.addVertex(); graph.tx().commit()").all().get();
    }

    // the transaction is managed so a rollback should have executed
    assertEquals(1, client.submit("g.V().count()").all().get().get(0).getInt());
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:23,代码来源:GremlinServerSessionIntegrateTest.java

示例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();
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:18,代码来源:GremlinDriverIntegrateTest.java

示例15: 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();
      }
  }
 
开发者ID:apache,项目名称:tinkerpop,代码行数:18,代码来源:GremlinServerIntegrateTest.java


注:本文中的org.apache.tinkerpop.gremlin.driver.Cluster.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。