コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: sbiaudet/cs-threads
        public void Should_Be_Able_To_Create_A_RandomID()
        {
            ThreadId i = ThreadId.FromRandom(Variant.Raw, 16);

            Assert.NotNull(i);
            Assert.Equal(18, i.Bytes.Length);
            Assert.True(i.IsDefined);
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: sbiaudet/cs-threads
        public void Should_Be_Able_To_Round_Trip_To_And_From_Bytes()
        {
            ThreadId i = ThreadId.FromRandom(Variant.Raw, 16);

            byte[]   b = i.Bytes;
            ThreadId n = ThreadId.FromBytes(b);

            Assert.Equal(n, i);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new store on the remote node.
        /// </summary>
        /// <param name="threadId">The ID of the database.</param>
        /// <param name="name"></param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns></returns>
        public async Task <ThreadId> NewDBAsync(ThreadId threadId, string name = null, CancellationToken cancellationToken = default)
        {
            ThreadId dbId = threadId ?? ThreadId.FromRandom();

            NewDBRequest request = new()
            {
                DbID = ByteString.CopyFrom(dbId.Bytes)
            };

            if (!string.IsNullOrEmpty(name))
            {
                _threadContext.WithThreadName(name);
                request.Name = name;
            }

            await _apiClient.NewDBAsync(request, headers : _threadContext.WithThread(dbId.ToString()).Metadata, cancellationToken : cancellationToken);

            return(dbId);
        }