public void Should_Make_Rpc_Call_When_Using_Analytics_Source()
        {
            var coreStatements = new List <SimpleStatement>();

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatements.Add(stmt), null, stmt =>
            {
                if (stmt is SimpleStatement st && st.QueryString.StartsWith("CALL "))
                {
                    var rowMock = new Mock <Row>();
                    rowMock
                    .Setup(r => r.GetValue <IDictionary <string, string> >(It.Is <string>(c => c == "result")))
                    .Returns(new Dictionary <string, string> {
                        { "location", "1.2.3.4:8888" }
                    });
                    var rows = new[]
                    {
                        rowMock.Object
                    };
                    var mock = new Mock <RowSet>();
                    mock
                    .Setup(r => r.GetEnumerator()).Returns(() => ((IEnumerable <Row>)rows).GetEnumerator());
                    return(mock.Object);
                }
                return(new RowSet());
            });
        public void ExecuteGraph_Should_Build_Payload_With_Statement_Properties()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(
                stmt => coreStatement = stmt,
                new GraphOptions()
                .SetName("name1")
                .SetSource("My source!")
                .SetReadConsistencyLevel(ConsistencyLevel.LocalQuorum)
                .SetWriteConsistencyLevel(ConsistencyLevel.EachQuorum));
            var session = _cluster.Connect();

            session.ExecuteGraph(new SimpleGraphStatement("g.V()")
                                 .SetGraphLanguage("my-lang")
                                 .SetReadTimeoutMillis(5555)
                                 .SetSystemQuery()
                                 .SetGraphReadConsistencyLevel(ConsistencyLevel.Two)
                                 .SetGraphSource("Statement source"));
            Assert.NotNull(coreStatement);
            Assert.NotNull(coreStatement.OutgoingPayload);
            Assert.That(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-source"]), Is.EqualTo("Statement source"));
            //is a sistem query
            Assert.False(coreStatement.OutgoingPayload.ContainsKey("graph-name"));
            Assert.AreEqual(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-read-consistency"]), "TWO");
            Assert.AreEqual(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-write-consistency"]), "EACH_QUORUM");
            Assert.AreEqual(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-language"]), "my-lang");
            Assert.That(coreStatement.OutgoingPayload["request-timeout"], Is.EqualTo(ExecuteGraphTests.ToBuffer(5555)));
        }
        public void ExecuteGraph_Should_Build_Payload_With_GraphOptions()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(
                stmt => coreStatement = stmt,
                new GraphOptions()
                .SetName("name1")
                .SetSource("My source!")
                .SetReadTimeoutMillis(22222)
                .SetReadConsistencyLevel(ConsistencyLevel.LocalQuorum)
                .SetWriteConsistencyLevel(ConsistencyLevel.EachQuorum));
            var session = _cluster.Connect();

            session.ExecuteGraph(new SimpleGraphStatement("g.V()"));
            Assert.NotNull(coreStatement);
            Assert.NotNull(coreStatement.OutgoingPayload);
            Assert.That(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-source"]), Is.EqualTo("My source!"));
            Assert.AreEqual(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-name"]), "name1");
            Assert.AreEqual(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-read-consistency"]), "LOCAL_QUORUM");
            Assert.AreEqual(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-write-consistency"]), "EACH_QUORUM");
            //default
            Assert.AreEqual(Encoding.UTF8.GetString(coreStatement.OutgoingPayload["graph-language"]), "gremlin-groovy");
            Assert.That(coreStatement.OutgoingPayload["request-timeout"], Is.EqualTo(ExecuteGraphTests.ToBuffer(22222)));
        }
        public void ExecuteGraph_Should_Wrap_RowSet()
        {
            var rowMock1 = new Mock <Row>();

            rowMock1.Setup(r => r.GetValue <string>(It.Is <string>(n => n == "gremlin"))).Returns("{\"result\": 100}");
            var rowMock2 = new Mock <Row>();

            rowMock2.Setup(r => r.GetValue <string>(It.Is <string>(n => n == "gremlin"))).Returns("{\"result\": 101}");
            IEnumerable <Row> rows = new[]
            {
                rowMock1.Object,
                rowMock2.Object
            };
            var rsMock = new Mock <RowSet>();

            rsMock.Setup(r => r.GetEnumerator()).Returns(() => rows.GetEnumerator());

            _cluster = ExecuteGraphTests.GetCluster(stmt => { }, null, rsMock.Object);
            var session = _cluster.Connect();
            var rsGraph = session.ExecuteGraph(new SimpleGraphStatement("g.V()"));

            Assert.NotNull(rsGraph);
            var resultArray = rsGraph.ToArray();

            Assert.AreEqual(2, resultArray.Length);
            CollectionAssert.AreEqual(new[] { 100, 101 }, resultArray.Select(g => g.ToInt32()));
        }
        public void ExecuteGraph_Should_Call_ExecuteAsync_With_ConsistencyLevel_Set()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt);
            var session = _cluster.Connect();
            const ConsistencyLevel consistency = ConsistencyLevel.Three;

            session.ExecuteGraph(new SimpleGraphStatement("g.V()").SetConsistencyLevel(consistency));
            Assert.NotNull(coreStatement);
            Assert.AreEqual(coreStatement.ConsistencyLevel, consistency);
            Assert.Null(coreStatement.Timestamp);
        }
        public void ExecuteGraph_Should_Call_ExecuteAsync_With_Timestamp_Set()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt);
            var session   = _cluster.Connect();
            var timestamp = DateTimeOffset.Now;

            session.ExecuteGraph(new SimpleGraphStatement("g.V()").SetTimestamp(timestamp));
            Assert.NotNull(coreStatement);
            Assert.Null(coreStatement.ConsistencyLevel);
            Assert.AreEqual(coreStatement.Timestamp, timestamp);
        }
        public void ExecuteGraph_Should_Call_ExecuteAsync_With_SimpleStatement()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt);
            var session = _cluster.Connect();

            session.ExecuteGraph(new SimpleGraphStatement("g.V()"));
            Assert.NotNull(coreStatement);
            Assert.Null(coreStatement.Timestamp);
            Assert.Null(coreStatement.ConsistencyLevel);
            Assert.AreEqual("g.V()", coreStatement.QueryString);
        }
        public void ExecuteGraph_Should_Allow_IpAddress_As_Parameters()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt);
            var session = _cluster.Connect();
            var value   = IPAddress.Parse("192.168.1.100");

            session.ExecuteGraph(new SimpleGraphStatement("g.V(vertexId)", new { value }));
            Assert.NotNull(coreStatement);
            Assert.AreEqual(1, coreStatement.QueryValues.Length);
            Assert.AreEqual("{\"value\":\"" + value + "\"}", coreStatement.QueryValues[0]);
        }
        public void ExecuteGraph_Should_Allow_BigInteger_As_Parameters()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt);
            var session = _cluster.Connect();
            var value   = BigInteger.Parse("1234567890123456789123456789");

            session.ExecuteGraph(new SimpleGraphStatement("g.V(vertexId)", new { value }));
            Assert.NotNull(coreStatement);
            Assert.AreEqual(1, coreStatement.QueryValues.Length);
            Assert.AreEqual("{\"value\":" + value + "}", coreStatement.QueryValues[0]);
        }
Esempio n. 10
0
        public void ExecuteGraph_Should_Build_Payload_With_Default_Values()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt);
            var session = _cluster.Connect();

            session.ExecuteGraph(new SimpleGraphStatement("g.V()"));
            Assert.NotNull(coreStatement);
            Assert.NotNull(coreStatement.OutgoingPayload);
            //The default graph payload
            Assert.AreEqual(2, coreStatement.OutgoingPayload.Count);
            CollectionAssert.AreEqual(new[] { "graph-language", "graph-source" }, coreStatement.OutgoingPayload.Keys);
        }
Esempio n. 11
0
        public void ExecuteGraph_Should_Allow_GraphNode_As_Parameters()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt);
            var          session      = _cluster.Connect();
            const string expectedJson =
                "{\"member_id\":123,\"community_id\":586910,\"~label\":\"vertex\",\"group_id\":2}";
            var id = new GraphNode("{\"result\":" + expectedJson + "}");

            session.ExecuteGraph(new SimpleGraphStatement("g.V(vertexId)", new { vertexId = id }));
            Assert.NotNull(coreStatement);
            Assert.AreEqual(1, coreStatement.QueryValues.Length);
            Assert.AreEqual("{\"vertexId\":" + expectedJson + "}", coreStatement.QueryValues[0]);
        }
Esempio n. 12
0
        public void ExecuteGraph_Should_Call_ExecuteAsync_With_ReadTimeout_Set_From_Statement()
        {
            const int       defaultReadTimeout = 15000;
            SimpleStatement coreStatement      = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt, new GraphOptions().SetReadTimeoutMillis(defaultReadTimeout));
            var       session     = _cluster.Connect();
            const int readTimeout = 6000;

            session.ExecuteGraph(new SimpleGraphStatement("g.V()").SetReadTimeoutMillis(readTimeout));
            Assert.NotNull(coreStatement);
            Assert.AreEqual(readTimeout, coreStatement.ReadTimeoutMillis);
            Assert.True(coreStatement.OutgoingPayload.ContainsKey("request-timeout"));
            Assert.That(coreStatement.OutgoingPayload["request-timeout"], Is.EqualTo(ExecuteGraphTests.ToBuffer(readTimeout)));
        }
Esempio n. 13
0
        public void ExecuteGraph_Should_Call_ExecuteAsync_With_Dictionary_Parameters_Set()
        {
            SimpleStatement coreStatement = null;

            _cluster = ExecuteGraphTests.GetCluster(stmt => coreStatement = stmt);
            var session    = _cluster.Connect();
            var parameters = new Dictionary <string, object>
            {
                { "myName", "is what" }
            };

            session.ExecuteGraph(new SimpleGraphStatement(parameters, "g.V().has('name', myName)"));
            Assert.NotNull(coreStatement);
            Assert.AreEqual("g.V().has('name', myName)", coreStatement.QueryString);
            //A single parameter with the key/values json stringified
            Assert.AreEqual(new object[] { "{\"myName\":\"is what\"}" }, coreStatement.QueryValues);
        }