Пример #1
0
        private async Task <uint?> GetCidAsync(string fullyQualifiedName, bool sendAsBody)
        {
            using var rootSpan = RootSpan(OuterRequestSpans.ServiceSpan.Internal.GetCid);
            using var getCid   = new GetCid
                  {
                      Opaque = SequenceGenerator.GetNext(),
                      Span   = rootSpan,
                  };

            if (sendAsBody)
            {
                getCid.Content = fullyQualifiedName;
            }
            else
            {
                getCid.Key = fullyQualifiedName;
            }

            _operationConfigurator.Configure(getCid, new GetOptions().Transcoder(_rawStringTranscoder));
            await _bucket.RetryAsync(getCid).ConfigureAwait(false);

            var resultWithValue = getCid.GetValueAsUint();

            return(resultWithValue);
        }
Пример #2
0
        internal static async Task <uint?> GetCid(this IConnection connection, string name, ITypeTranscoder transcoder)
        {
            var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >();

            using var getCid = new GetCid
                  {
                      Key        = name,
                      Transcoder = transcoder,
                      Opaque     = SequenceGenerator.GetNext(),
                      Content    = null,
                      Completed  = s =>
                      {
                          completionSource.TrySetResult(s.ExtractData());
                          return(completionSource.Task);
                      }
                  };
            await getCid.SendAsync(connection).ConfigureAwait(false);

            var gitCidBytes = await completionSource.Task.ConfigureAwait(false);

            await getCid.ReadAsync(gitCidBytes).ConfigureAwait(false);

            var resultWithValue = getCid.GetResultWithValue();

            return(resultWithValue.Content);
        }
Пример #3
0
        private async Task <uint?> GetCidAsync(string fullyQualifiedName, bool sendAsBody, bool retryIfFailure)
        {
            using var rootSpan = RootSpan(OuterRequestSpans.ServiceSpan.Internal.GetCid);
            using var getCid   = new GetCid
                  {
                      Opaque = SequenceGenerator.GetNext(),
                      Span   = rootSpan,
                  };

            if (sendAsBody)
            {
                getCid.Content = fullyQualifiedName;
            }
            else
            {
                getCid.Key = fullyQualifiedName;
            }

            var options = new GetOptions();

            _operationConfigurator.Configure(getCid, options.Transcoder(_rawStringTranscoder));
            using var ctp = CreateRetryTimeoutCancellationTokenSource(options, getCid);
            if (retryIfFailure)
            {
                await _bucket.RetryAsync(getCid, ctp.TokenPair).ConfigureAwait(false);
            }
            else
            {
                await _bucket.SendAsync(getCid, ctp.TokenPair).ConfigureAwait(false);
            }

            var resultWithValue = getCid.GetValueAsUint();

            return(resultWithValue);
        }
        public void Test_GetWithValue()
        {
            var packet = new byte[]
            {
                129, 187, 0, 0, 12, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 45, 0,
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 0, 0, 0, 34
            };

            var response = MemoryPool <byte> .Shared.RentAndSlice(packet.Length);

            packet.AsMemory(0, packet.Length).CopyTo(response.Memory);
            var op = new GetCid();

            op.Read(response);

            var result = op.GetResultWithValue();

            Assert.True(result.Content.HasValue);
            Assert.Equal(85u, result.Content.Value);
        }
Пример #5
0
        public void Test_GetCid_GetValue_Throws_NotImplementedException()
        {
            var packet = new byte[]
            {
                0x18, 0xbb, 0x03, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x1a,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x17
            };

            var response = MemoryPool <byte> .Shared.RentAndSlice(packet.Length);

            packet.AsMemory(0, packet.Length).CopyTo(response.Memory);
            var op = new GetCid()
            {
                Transcoder = new LegacyTranscoder()
            };

            op.Read(response);

            Assert.Throws <NotImplementedException>(() => op.GetValue());
        }
Пример #6
0
        public void Test_GetWithValue()
        {
            var packet = new byte[]
            {
                0x18, 0xbb, 0x03, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x1a,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x17
            };

            var response = MemoryPool <byte> .Shared.RentAndSlice(packet.Length);

            packet.AsMemory(0, packet.Length).CopyTo(response.Memory);
            var op = new GetCid()
            {
                Transcoder = new LegacyTranscoder()
            };

            op.Read(response);

            var result = op.GetResultWithValue();

            Assert.True(result.Content.HasValue);
            Assert.Equal(0x17u, result.Content.Value);
        }