org.apache.tinkerpop.gremlin.driver.Cluster Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.driver.Cluster. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldWorkWithGraphSONV3Serialization() throws Exception {
    final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V3D0).create();
    final Client client = cluster.connect();

    final List<Result> r = client.submit("TinkerFactory.createModern().traversal().V(1)").all().join();
    assertEquals(1, r.size());

    final Vertex v = r.get(0).get(DetachedVertex.class);
    assertEquals(1, v.id());
    assertEquals("person", v.label());

    assertEquals(2, IteratorUtils.count(v.properties()));
    assertEquals("marko", v.value("name"));
    assertEquals(29, Integer.parseInt(v.value("age").toString()));

    cluster.close();
}
 
Example #2
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldExecuteScriptInSession() throws Exception {
    final Cluster cluster = TestClientFactory.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();
}
 
Example #3
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAliasGraphVariables() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();

    try {
        client.submit("g.addVertex(label,'person','name','stephen');").all().get().get(0).getVertex();
        fail("Should have tossed an exception because \"g\" does not have the addVertex method under default config");
    } catch (Exception ex) {
        final Throwable root = ExceptionUtils.getRootCause(ex);
        assertThat(root, instanceOf(ResponseException.class));
        final ResponseException re = (ResponseException) root;
        assertEquals(ResponseStatusCode.SERVER_ERROR_EVALUATION, re.getResponseStatusCode());
    }

    final Client rebound = cluster.connect().alias("graph");
    final Vertex v = rebound.submit("g.addVertex(label,'person','name','jason')").all().get().get(0).getVertex();
    assertEquals("person", v.label());

    cluster.close();
}
 
Example #4
Source File: GremlinServerSslIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEnableSslAndClientCertificateAuthAndFailWithIncorrectKeyStoreType() {
    final Cluster cluster = TestClientFactory.build().enableSsl(true)
            .keyStore(JKS_CLIENT_KEY).keyStorePassword(KEY_PASS).keyStoreType(KEYSTORE_TYPE_PKCS12)
            .trustStore(P12_CLIENT_TRUST).trustStorePassword(KEY_PASS).trustStoreType(TRUSTSTORE_TYPE_PKCS12)
            .create();
    final Client client = cluster.connect();

    try {
        String res = client.submit("'test'").one().getString();
        fail("Should throw exception because incorrect keyStoreType is specified");
    } catch (Exception x) {
        final Throwable root = ExceptionUtils.getRootCause(x);
        assertThat(root, instanceOf(TimeoutException.class));
    } finally {
        cluster.close();
    }
}
 
Example #5
Source File: GremlinServerIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldProvideBetterExceptionForMethodCodeTooLarge() {
    final int numberOfParameters = 4000;
    final Map<String,Object> b = new HashMap<>();

    // generate a script with a ton of bindings usage to generate a "code too large" exception
    String script = "x = 0";
    for (int ix = 0; ix < numberOfParameters; ix++) {
        if (ix > 0 && ix % 100 == 0) {
            script = script + ";" + System.lineSeparator() + "x = x";
        }
        script = script + " + x" + ix;
        b.put("x" + ix, ix);
    }

    final Cluster cluster = TestClientFactory.build().maxContentLength(4096000).create();
    final Client client = cluster.connect();

    try {
        client.submit(script, b).all().get();
        fail("Should have tanked out because of number of parameters used and size of the compile script");
    } catch (Exception ex) {
        assertThat(ex.getMessage(), containsString("The Gremlin statement that was submitted exceeds the maximum compilation size allowed by the JVM"));
    }
}
 
Example #6
Source File: DriverRemoteConnection.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public DriverRemoteConnection(final Configuration conf) {
    final boolean hasClusterConf = IteratorUtils.anyMatch(conf.getKeys(), k -> k.startsWith("clusterConfiguration"));
    if (conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && hasClusterConf)
        throw new IllegalStateException(String.format("A configuration should not contain both '%s' and 'clusterConfiguration'", GREMLIN_REMOTE_DRIVER_CLUSTERFILE));

    remoteTraversalSourceName = conf.getString(GREMLIN_REMOTE_DRIVER_SOURCENAME, DEFAULT_TRAVERSAL_SOURCE);

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

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

    attachElements = false;

    tryCloseCluster = true;
    tryCloseClient = true;
    this.conf = Optional.of(conf);
}
 
Example #7
Source File: GremlinServerIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGarbageCollectPhantomButNotHard() throws Exception {
    final Cluster cluster = TestClientFactory.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();
    }
}
 
Example #8
Source File: GremlinServerSslIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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 = TestClientFactory.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();
    }
}
 
Example #9
Source File: OpenCypherGremlinDatabase.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
public OpenCypherGremlinDatabase(OpenCypherGremlinConfiguration configuration) {
    String host = configuration.getHost();
    Integer port = configuration.getPort();
    String username = configuration.getUser();
    String password = configuration.getPassword();

    String url = String.format("gremlin://%s:%s", host, port);
    URI uri = URI.create(url);

    cluster = Cluster.build()
            .addContactPoint(uri.getHost())
            .credentials(username, password)
            .serializer(configuration.getSerializer())
            .enableSsl(configuration.getSSL())
            .port(uri.getPort())
            .create();

    flavor = configuration.getFlavor();

    converter = new OpenCypherGremlinValueConverter();
}
 
Example #10
Source File: ConcurrencyConfig.java    From amazon-neptune-tools with Apache License 2.0 6 votes vote down vote up
Cluster.Builder applyTo(Cluster.Builder clusterBuilder){
    if (concurrency == 1){
        return clusterBuilder;
    }

    int minPoolSize = max(concurrency, 2);
    int maxPoolSize =  max(concurrency, 8);
    int minSimultaneousUsage = 1;
    int maxSimultaneousUsage = 1;
    int minInProcess = 1;
    int maxInProcess = 1;

    return clusterBuilder.
            minConnectionPoolSize(minPoolSize).
            maxConnectionPoolSize(maxPoolSize).
            minSimultaneousUsagePerConnection(minSimultaneousUsage).
            maxSimultaneousUsagePerConnection(maxSimultaneousUsage).
            minInProcessPerConnection(minInProcess).
            maxInProcessPerConnection(maxInProcess);
}
 
Example #11
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldExecuteInSessionAndSessionlessWithoutOpeningTransaction() throws Exception {
    assumeNeo4jIsPresent();

    final Cluster cluster = TestClientFactory.open();
    final Client sessionClient = cluster.connect(name.getMethodName());
    final Client sessionlessClient = cluster.connect();

    //open transaction in session, then add vertex and commit
    sessionClient.submit("g.tx().open()").all().get();
    final Vertex vertexBeforeTx = sessionClient.submit("v=g.addV(\"person\").property(\"name\",\"stephen\").next()").all().get().get(0).getVertex();
    assertEquals("person", vertexBeforeTx.label());
    sessionClient.submit("g.tx().commit()").all().get();

    // check that session transaction is closed
    final boolean isOpen = sessionClient.submit("g.tx().isOpen()").all().get().get(0).getBoolean();
    assertTrue("Transaction should be closed", !isOpen);

    //run a sessionless read
    sessionlessClient.submit("g.V()").all().get();

    // check that session transaction is still closed
    final boolean isOpenAfterSessionless = sessionClient.submit("g.tx().isOpen()").all().get().get(0).getBoolean();
    assertTrue("Transaction should stil be closed", !isOpenAfterSessionless);

}
 
Example #12
Source File: GremlinServerSslIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEnableSslAndFailIfProtocolsDontMatch() {
    final Cluster cluster = TestClientFactory.build().enableSsl(true).keyStore(JKS_SERVER_KEY).keyStorePassword(KEY_PASS)
            .sslSkipCertValidation(true).sslEnabledProtocols(Arrays.asList("TLSv1.2")).create();
    final Client client = cluster.connect();

    try {
        client.submit("'test'").one();
        fail("Should throw exception because ssl client requires TLSv1.2 whereas server supports only TLSv1.1");
    } catch (Exception x) {
        final Throwable root = ExceptionUtils.getRootCause(x);
        assertThat(root, instanceOf(TimeoutException.class));
    } finally {
        cluster.close();
    }
}
 
Example #13
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSendUserAgentBytecode() {
    final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V3D0).create();
    final Client client = Mockito.spy(cluster.connect().alias("g"));
    Mockito.when(client.alias("g")).thenReturn(client);
    GraphTraversalSource g = AnonymousTraversalSource.traversal().withRemote(DriverRemoteConnection.using(client));
    g.with(Tokens.ARGS_USER_AGENT, "test").V().iterate();
    cluster.close();
    ArgumentCaptor<RequestOptions> requestOptionsCaptor = ArgumentCaptor.forClass(RequestOptions.class);
    verify(client).submitAsync(Mockito.any(Bytecode.class), requestOptionsCaptor.capture());
    RequestOptions requestOptions = requestOptionsCaptor.getValue();
    assertEquals("test", requestOptions.getUserAgent().get());

    ArgumentCaptor<RequestMessage> requestMessageCaptor = ArgumentCaptor.forClass(RequestMessage.class);
    verify(client).submitAsync(requestMessageCaptor.capture());
    RequestMessage requestMessage = requestMessageCaptor.getValue();
    assertEquals("test", requestMessage.getArgs().getOrDefault(Tokens.ARGS_USER_AGENT, null));
}
 
Example #14
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRequireAliasedGraphVariablesInStrictTransactionMode() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    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();
}
 
Example #15
Source File: GremlinServerAuthIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailIfSslEnabledOnServerButNotClient() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    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();
    }
}
 
Example #16
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAliasGraphVariablesInSession() throws Exception {
    final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRYO_V3D0).create();
    final Client client = cluster.connect(name.getMethodName());

    try {
        client.submit("g.addVertex('name','stephen');").all().get().get(0).getVertex();
        fail("Should have tossed an exception because \"g\" does not have the addVertex method under default config");
    } catch (Exception ex) {
        final Throwable root = ExceptionUtils.getRootCause(ex);
        assertThat(root, instanceOf(ResponseException.class));
        final ResponseException re = (ResponseException) root;
        assertEquals(ResponseStatusCode.SERVER_ERROR_EVALUATION, re.getResponseStatusCode());
    }

    final Client aliased = client.alias("graph");
    assertEquals("jason", aliased.submit("n='jason'").all().get().get(0).getString());
    final Vertex v = aliased.submit("g.addVertex('name',n)").all().get().get(0).getVertex();
    assertEquals("jason", v.value("name"));

    cluster.close();
}
 
Example #17
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldWorkWithGraphSONV2Serialization() throws Exception {
    final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V2D0).create();
    final Client client = cluster.connect();

    final List<Result> r = client.submit("TinkerFactory.createModern().traversal().V(1)").all().join();
    assertEquals(1, r.size());

    final Vertex v = r.get(0).get(DetachedVertex.class);
    assertEquals(1, v.id());
    assertEquals("person", v.label());

    assertEquals(2, IteratorUtils.count(v.properties()));
    assertEquals("marko", v.value("name"));
    assertEquals(29, Integer.parseInt(v.value("age").toString()));

    cluster.close();
}
 
Example #18
Source File: GremlinServerIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUseInterpreterMode() throws Exception {
    final Cluster cluster = TestClientFactory.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();
}
 
Example #19
Source File: GremlinServerAuditLogIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAuditLogWithAllowAllAuthenticator() throws Exception {

    final Cluster cluster = TestClientFactory.build().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();
    }

    // wait for logger to flush - (don't think there is a way to detect this)
    stopServer();
    Thread.sleep(1000);

    // WebSocketChannelizer does not add SaslAuthenticationHandler for AllowAllAuthenticator,
    // so no authenticated user log line available
    assertTrue(recordingAppender.logMatchesAny(AUDIT_LOGGER_NAME, INFO, "User with address .*? requested: 1\\+1"));
    assertTrue(recordingAppender.logMatchesAny(AUDIT_LOGGER_NAME, INFO, "User with address .*? requested: 1\\+2"));
    assertTrue(recordingAppender.logMatchesAny(AUDIT_LOGGER_NAME, INFO, "User with address .*? requested: 1\\+3"));
}
 
Example #20
Source File: GremlinServerAuthKrb5IntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to force the logger to flush fully or at least wait until it does.
 */
private void assertFailedLogin() throws Exception {
    final Cluster cluster = TestClientFactory.build().jaasEntry(TESTCONSOLE)
            .protocol(kdcServer.serverPrincipalName).addContactPoint(kdcServer.hostname).create();
    final Client client = cluster.connect();
    try {
        client.submit("1+1").all().get();
        fail("The kerberos config is a bust so this request should fail");
    } catch (Exception ex) {
        final ResponseException re = (ResponseException) ex.getCause();
        assertEquals(ResponseStatusCode.SERVER_ERROR, re.getResponseStatusCode());
        assertEquals("Authenticator is not ready to handle requests", re.getMessage());
    } finally {
        cluster.close();
    }
}
 
Example #21
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSerializeToStringWhenRequestedGryoV1() 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 = 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();
}
 
Example #22
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldExecuteScriptsInMultipleSession() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    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();
}
 
Example #23
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #24
Source File: GremlinServerIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReceiveFailureOnBadGraphSONSerialization() throws Exception {
    final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V3D0).create();
    final Client client = cluster.connect();

    try {
        client.submit("class C { def C getC(){return this}}; new C()").all().join();
        fail("Should throw an exception.");
    } catch (RuntimeException re) {
        final Throwable root = ExceptionUtils.getRootCause(re);
        assertThat(root.getMessage(), CoreMatchers.startsWith("Error during serialization: Direct self-reference leading to cycle (through reference chain:"));

        // validate that we can still send messages to the server
        assertEquals(2, client.submit("1+1").all().join().get(0).getInt());
    } finally {
        cluster.close();
    }
}
 
Example #25
Source File: GremlinServerSslIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEnableSslAndFailIfCiphersDontMatch() {
    final Cluster cluster = TestClientFactory.build().enableSsl(true).keyStore(JKS_SERVER_KEY).keyStorePassword(KEY_PASS)
            .sslSkipCertValidation(true).sslCipherSuites(Arrays.asList("SSL_RSA_WITH_RC4_128_SHA")).create();
    final Client client = cluster.connect();

    try {
        client.submit("'test'").one();
        fail("Should throw exception because ssl client requires TLSv1.2 whereas server supports only TLSv1.1");
    } catch (Exception x) {
        final Throwable root = ExceptionUtils.getRootCause(x);
        assertThat(root, instanceOf(TimeoutException.class));
    } finally {
        cluster.close();
    }
}
 
Example #26
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailWithBadClientSideSerialization() throws Exception {
    final Cluster cluster = TestClientFactory.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);
        assertThat(inner, instanceOf(ResponseException.class));
        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();
}
 
Example #27
Source File: GremlinServerIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #28
Source File: GremlinServerSslIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEnableSslAndClientCertificateAuthWithDifferentStoreType() {
    final Cluster cluster = TestClientFactory.build().enableSsl(true)
            .keyStore(JKS_CLIENT_KEY).keyStorePassword(KEY_PASS).keyStoreType(KEYSTORE_TYPE_JKS)
            .trustStore(P12_CLIENT_TRUST).trustStorePassword(KEY_PASS).trustStoreType(TRUSTSTORE_TYPE_PKCS12)
            .create();
    final Client client = cluster.connect();

    try {
        assertEquals("test", client.submit("'test'").one().getString());
    } finally {
        cluster.close();
    }

    final Cluster cluster2 = TestClientFactory.build().enableSsl(true)
            .keyStore(P12_CLIENT_KEY).keyStorePassword(KEY_PASS).keyStoreType(KEYSTORE_TYPE_PKCS12)
            .trustStore(JKS_CLIENT_TRUST).trustStorePassword(KEY_PASS).trustStoreType(TRUSTSTORE_TYPE_JKS)
            .create();
    final Client client2 = cluster2.connect();

    try {
        assertEquals("test", client2.submit("'test'").one().getString());
    } finally {
        cluster2.close();
    }
}
 
Example #29
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #30
Source File: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldStream() 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 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();
}