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

The following examples show how to use org.apache.tinkerpop.gremlin.driver.Client. 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 Project: tinkerpop   Author: apache   File: DriverRemoteConnection.java    License: 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 #2
Source Project: tinkerpop   Author: apache   File: GremlinServerAuthKrb5IntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #3
Source Project: tinkerpop   Author: apache   File: GremlinServerSslIntegrateTest.java    License: 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 #4
Source Project: tinkerpop   Author: apache   File: GremlinServerSslIntegrateTest.java    License: 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 Project: tinkerpop   Author: apache   File: GremlinServerSessionIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #6
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReportErrorWhenRequestCantBeSerialized() throws Exception {
    final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V3D0).create();
    final Client client = cluster.connect().alias("g");

    try {
        final Map<String,Object> params = new HashMap<>();
        params.put("r", Color.RED);
        client.submit("r", params).all().get();
        fail("Should have thrown exception over bad serialization");
    } catch (Exception ex) {
        final Throwable inner = ExceptionUtils.getRootCause(ex);
        assertThat(inner, instanceOf(ResponseException.class));
        assertEquals(ResponseStatusCode.REQUEST_ERROR_SERIALIZATION, ((ResponseException) inner).getResponseStatusCode());
        assertTrue(ex.getMessage().contains("An error occurred during serialization of this request"));
    }

    // 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 #7
Source Project: tinkerpop   Author: apache   File: GremlinServerSslIntegrateTest.java    License: 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 #8
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #9
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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 #10
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldProcessRequestsOutOfOrder() throws Exception {
    final Cluster cluster = TestClientFactory.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));
}
 
Example #11
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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 #12
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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();
}
 
Example #13
Source Project: tinkerpop   Author: apache   File: GremlinServerIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReceiveFailureOnBadGryoSerialization() throws Exception {
    final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRYO_V1D0).create();
    final Client client = cluster.connect();

    try {
        client.submit("java.awt.Color.RED").all().join();
        fail("Should throw an exception.");
    } catch (RuntimeException re) {
        final Throwable root = ExceptionUtils.getRootCause(re);
        assertThat(root.getMessage(), CoreMatchers.startsWith("Error during serialization: Class is not registered: java.awt.Color"));

        // 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 #14
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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 #15
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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 #16
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #17
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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 Project: tinkerpop   Author: apache   File: GremlinServerAuditLogIntegrateTest.java    License: 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 #19
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailClientSideWithTooLargeAResponse() {
    final Cluster cluster = TestClientFactory.build().maxContentLength(1).create();
    final Client client = cluster.connect();

    try {
        final String fatty = IntStream.range(0, 100).mapToObj(String::valueOf).collect(Collectors.joining());
        client.submit("'" + fatty + "'").all().get();
        fail("Should throw an exception.");
    } catch (Exception re) {
        final Throwable root = ExceptionUtils.getRootCause(re);
        assertTrue(root.getMessage().equals("Max frame length of 1 has been exceeded."));
    } finally {
        cluster.close();
    }
}
 
Example #20
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnNiceMessageFromOpSelector() {
    final Cluster cluster = TestClientFactory.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();
    }
}
 
Example #21
Source Project: tinkerpop   Author: apache   File: GremlinServerSslIntegrateTest.java    License: 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 #22
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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 #23
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldExecuteSessionlessScriptOnTransactionalGraph() throws Exception {
    assumeNeo4jIsPresent();

    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();

    // this line is important because it tests GraphTraversal which has a certain transactional path
    final Vertex vertexRequest1 = client.submit("g.addV().property(\"name\",\"stephen\")").all().get().get(0).getVertex();

    final Vertex vertexRequest2 = client.submit("graph.vertices().next()").all().get().get(0).getVertex();
    assertEquals(vertexRequest1.id(), vertexRequest2.id());

    // this line is important because it tests the other transactional path
    client.submit("graph.addVertex(\"name\",\"marko\")").all().get().get(0).getVertex();

    assertEquals(2, client.submit("g.V().count()").all().get().get(0).getLong());

    cluster.close();
}
 
Example #24
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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 #25
Source Project: tinkerpop   Author: apache   File: GremlinServerIntegrateTest.java    License: 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 #26
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAliasGraphVariablesInStrictTransactionMode() throws Exception {
    assumeNeo4jIsPresent();

    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();

    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.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS, re.getResponseStatusCode());
    }

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

    cluster.close();
}
 
Example #27
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: 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 #28
Source Project: tinkerpop   Author: apache   File: GremlinServerIntegrateTest.java    License: 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 #29
Source Project: tinkerpop   Author: apache   File: GremlinServerSslIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEnableSslAndClientCertificateAuthAndFailWithoutCert() {
    final Cluster cluster = TestClientFactory.build().enableSsl(true).keyStore(JKS_SERVER_KEY).keyStorePassword(KEY_PASS)
            .keyStoreType(KEYSTORE_TYPE_JKS).sslSkipCertValidation(true).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 client does not have a cert");
    } catch (Exception x) {
        final Throwable root = ExceptionUtils.getRootCause(x);
        assertThat(root, instanceOf(TimeoutException.class));
    } finally {
        cluster.close();
    }
}
 
Example #30
Source Project: tinkerpop   Author: apache   File: GremlinDriverIntegrateTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAliasTraversalSourceVariablesInSession() throws Exception {
    final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRYO_V3D0).create();
    final Client client = cluster.connect(name.getMethodName());

    try {
        client.submit("g.addV().property('name','stephen')").all().get().get(0).getVertex();
        fail("Should have tossed an exception because \"g\" is readonly in this context");
    } 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 clientAliased = client.alias("g1");
    assertEquals("jason", clientAliased.submit("n='jason'").all().get().get(0).getString());
    final Vertex v = clientAliased.submit("g.addV().property('name',n)").all().get().get(0).getVertex();
    assertEquals("jason", v.value("name"));

    cluster.close();
}