• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Cluster类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Cluster类属于org.apache.tinkerpop.gremlin.driver包,在下文中一共展示了Cluster类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: connect

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入依赖的package包/类
@Override
public Object connect(final List<String> args) throws RemoteException {
    if (args.size() < 1) throw new RemoteException("Expects the location of a configuration file as an argument");

    try {
        this.currentCluster = Cluster.open(args.get(0));
        final boolean useSession = args.size() >= 2 && (args.get(1).equals(TOKEN_SESSION) || args.get(1).equals(TOKEN_SESSION_MANAGED));
        if (useSession) {
            final String sessionName = args.size() == 3 ? args.get(2) : UUID.randomUUID().toString();
            session = Optional.of(sessionName);

            final boolean managed = args.get(1).equals(TOKEN_SESSION_MANAGED);

            this.currentClient = this.currentCluster.connect(sessionName, managed);
        } else {
            this.currentClient = this.currentCluster.connect();
        }
        this.currentClient.init();
        return String.format("Configured %s", this.currentCluster) + getSessionStringSegment();
    } catch (final FileNotFoundException ignored) {
        throw new RemoteException("The 'connect' option must be accompanied by a valid configuration file");
    } catch (final Exception ex) {
        throw new RemoteException("Error during 'connect' - " + ex.getMessage(), ex);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:26,代码来源:DriverRemoteAcceptor.java


示例2: DriverRemoteConnection

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入依赖的package包/类
public DriverRemoteConnection(final Configuration conf) {
    if (conf.containsKey(GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE) && conf.containsKey("clusterConfiguration"))
        throw new IllegalStateException(String.format("A configuration should not contain both '%s' and 'clusterConfiguration'", GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE));

    connectionGraphName = conf.getString(GREMLIN_REMOTE_GRAPH_DRIVER_GRAPHNAME, DEFAULT_GRAPH);

    try {
        final Cluster cluster;
        if (!conf.containsKey(GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE) && !conf.containsKey("clusterConfiguration"))
            cluster = Cluster.open();
        else
            cluster = conf.containsKey(GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE) ?
                    Cluster.open(conf.getString(GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE)) : Cluster.open(conf.subset("clusterConfiguration"));

        client = cluster.connect(Client.Settings.build().unrollTraversers(false).create()).alias(connectionGraphName);
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }

    tryCloseCluster = true;
    this.conf = Optional.of(conf);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:23,代码来源:DriverRemoteConnection.java


示例3: 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,代码来源:GremlinServerAuthOldIntegrateTest.java


示例4: 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


示例5: 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,代码来源:GremlinServerAuthOldIntegrateTest.java


示例6: shouldAuthenticateAndWorkWithVariablesOverJsonSerialization

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入依赖的package包/类
@Test
public void shouldAuthenticateAndWorkWithVariablesOverJsonSerialization() throws Exception {
    final Cluster cluster = Cluster.build().serializer(Serializers.GRAPHSON).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();
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:GremlinServerAuthOldIntegrateTest.java


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


示例8: shouldRollbackOnEvalExceptionForManagedTransaction

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

    final Cluster cluster = Cluster.build().create();
    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:PKUSilvester,项目名称:LiteGraph,代码行数:23,代码来源:GremlinServerSessionIntegrateTest.java


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


示例10: shouldEventuallySucceedAfterMuchFailure

import org.apache.tinkerpop.gremlin.driver.Cluster; //导入依赖的package包/类
@Test
public void shouldEventuallySucceedAfterMuchFailure() throws Exception {
    final Cluster cluster = Cluster.build().addContactPoint("localhost").create();
    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();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:21,代码来源:GremlinDriverIntegrateTest.java


示例11: shouldEventuallySucceedOnSameServer

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

    final Cluster cluster = Cluster.build().addContactPoint("localhost").create();
    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();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:25,代码来源:GremlinDriverIntegrateTest.java


示例12: 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


示例13: shouldFailWithScriptExecutionException

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


示例14: shouldProcessRequestsOutOfOrder

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


示例15: shouldProcessSessionRequestsInOrder

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


示例16: 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


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


示例18: shouldStream

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


示例19: shouldIterate

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


示例20: shouldFailWithBadServerSideSerialization

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HighlightUsagesHandler类代码示例发布时间:2022-05-23
下一篇:
Java ErrorReceiverFilter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap