/// <summary>
        /// Submits a request message as an asynchronous operation where only a single result gets returned.
        /// </summary>
        /// <remarks>If multiple results are received from Gremlin Server, then only the first gets returned. Use <see cref="SubmitAsync{T}"/> instead when you expect a collection of results.</remarks>
        /// <typeparam name="T">The type of the expected result.</typeparam>
        /// <param name="gremlinClient">The <see cref="IGremlinClient"/> that submits the request.</param>
        /// <param name="requestMessage">The <see cref="ScriptRequestMessage"/> to send.</param>
        /// <returns>A single result received from the Gremlin Server.</returns>
        /// <exception cref="Exceptions.ResponseException">Thrown when a response is received from Gremlin Server that indicates that an error occurred.</exception>
        public static async Task <T> SubmitWithSingleResultAsync <T>(this IGremlinClient gremlinClient,
                                                                     ScriptRequestMessage requestMessage)
        {
            var resultCollection = await gremlinClient.SubmitAsync <T>(requestMessage).ConfigureAwait(false);

            return(resultCollection.FirstOrDefault());
        }
Esempio n. 2
0
        public void RequestIdsShouldBeUnique()
        {
            var firstMsg  = new ScriptRequestMessage();
            var secondMsg = new ScriptRequestMessage();

            Assert.NotEqual(firstMsg.RequestId, secondMsg.RequestId);
        }
Esempio n. 3
0
        public async Task ResponseBatchesShouldBeReassembled()
        {
            const int batchSize      = 2;
            var       expectedResult = new List <int> {
                1, 2, 3, 4, 5
            };
            var requestScript = $"{nameof(expectedResult)}";
            var bindings      = new Dictionary <string, object> {
                { nameof(expectedResult), expectedResult }
            };
            var requestMessage = new ScriptRequestMessage
            {
                Arguments =
                    new ScriptRequestArguments
                {
                    BatchSize     = batchSize,
                    GremlinScript = requestScript,
                    Bindings      = bindings
                }
            };
            var gremlinServer = new GremlinServer(TestHost, TestPort);

            using (var gremlinClient = new GremlinClient(gremlinServer))
            {
                var response = await gremlinClient.SubmitAsync <int>(requestMessage);

                Assert.Equal(expectedResult, response);
            }
        }
        /// <summary>
        /// Submits a request message that consists of a script with bindings as an asynchronous operation.
        /// </summary>
        /// <typeparam name="T">The type of the expected results.</typeparam>
        /// <param name="gremlinClient">The <see cref="IGremlinClient"/> that submits the request.</param>
        /// <param name="requestScript">The Gremlin request script to send.</param>
        /// <param name="bindings">Bindings for parameters used in the requestScript.</param>
        /// <returns>An enumerable collection of the data returned from the server.</returns>
        /// <exception cref="Exceptions.ResponseException">Thrown when a response is received from Gremlin Server that indicates that an error occurred.</exception>
        public static async Task <IEnumerable <T> > SubmitAsync <T>(this IGremlinClient gremlinClient, string requestScript,
                                                                    Dictionary <string, object> bindings = null)
        {
            var requestMessage = new ScriptRequestMessage
            {
                Arguments = new ScriptRequestArguments {
                    GremlinScript = requestScript, Bindings = bindings
                }
            };

            return(await gremlinClient.SubmitAsync <T>(requestMessage).ConfigureAwait(false));
        }
Esempio n. 5
0
        public async Task AliasForTraversalSourceShouldBeUsed()
        {
            var gremlinServer = new GremlinServer(TestHost, TestPort);

            using (var gremlinClient = new GremlinClient(gremlinServer))
            {
                var aliasTraversalSource = "g2";
                var aliases = new Dictionary <string, string> {
                    { aliasTraversalSource, "g" }
                };
                var gremlinScript = $"{aliasTraversalSource}.V().count()";
                var requestMsg    = new ScriptRequestMessage
                {
                    Arguments = new ScriptRequestArguments {
                        Aliases = aliases, GremlinScript = gremlinScript
                    }
                };

                var result = await gremlinClient.SubmitWithSingleResultAsync <bool>(requestMsg);

                Assert.NotNull(result);
            }
        }
 /// <summary>
 /// Submits a request message as an asynchronous operation without returning the result received from the Gremlin Server.
 /// </summary>
 /// <param name="gremlinClient">The <see cref="IGremlinClient"/> that submits the request.</param>
 /// <param name="requestMessage">The <see cref="ScriptRequestMessage"/> to send.</param>
 /// <returns>The task object representing the asynchronous operation.</returns>
 /// <exception cref="Exceptions.ResponseException">Thrown when a response is received from Gremlin Server that indicates that an error occurred.</exception>
 public static async Task SubmitAsync(this IGremlinClient gremlinClient, ScriptRequestMessage requestMessage)
 {
     await gremlinClient.SubmitAsync <object>(requestMessage).ConfigureAwait(false);
 }
Esempio n. 7
0
 /// <inheritdoc />
 public async Task <IEnumerable <T> > SubmitAsync <T>(ScriptRequestMessage requestMessage)
 {
     using (var connection = await _connectionPool.GetAvailableConnectionAsync().ConfigureAwait(false))
         return(await connection.SubmitAsync <T>(requestMessage).ConfigureAwait(false));
 }
Esempio n. 8
0
 public async Task <IEnumerable <T> > SubmitAsync <T>(ScriptRequestMessage requestMessage)
 {
     return(await _realConnection.SubmitAsync <T>(requestMessage).ConfigureAwait(false));
 }
Esempio n. 9
0
        public async Task <IEnumerable <T> > SubmitAsync <T>(ScriptRequestMessage requestMessage)
        {
            await SendAsync(requestMessage).ConfigureAwait(false);

            return(await ReceiveAsync <T>().ConfigureAwait(false));
        }