• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Tcp.TcpPackage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中EventStore.Core.Services.Transport.Tcp.TcpPackage的典型用法代码示例。如果您正苦于以下问题:C# TcpPackage类的具体用法?C# TcpPackage怎么用?C# TcpPackage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TcpPackage类属于EventStore.Core.Services.Transport.Tcp命名空间,在下文中一共展示了TcpPackage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: when_handling_trusted_write_on_internal_service

        public void when_handling_trusted_write_on_internal_service()
        {
            ManualResetEvent waiter = new ManualResetEvent(false);
            ClientMessage.WriteEvents publishedWrite = null;
            var evnt = new Event(Guid.NewGuid(), "TestEventType", true, new byte[] { }, new byte[] { });
            var write = new TcpClientMessageDto.WriteEvents(
                Guid.NewGuid().ToString(),
                ExpectedVersion.Any,
                new[] { new TcpClientMessageDto.NewEvent(evnt.EventId.ToByteArray(), evnt.EventType, evnt.IsJson ? 1 : 0, 0, evnt.Data, evnt.Metadata) },
                false);

            var package = new TcpPackage(TcpCommand.WriteEvents, Guid.NewGuid(), write.Serialize());
            var dummyConnection = new DummyTcpConnection();
            var publisher = InMemoryBus.CreateTest();

            publisher.Subscribe(new AdHocHandler<ClientMessage.WriteEvents>(x => {
                publishedWrite = x;
                waiter.Set();
            }));

            var tcpConnectionManager = new TcpConnectionManager(
                Guid.NewGuid().ToString(), TcpServiceType.Internal, new ClientTcpDispatcher(),
                publisher, dummyConnection, publisher, new InternalAuthenticationProvider(new Core.Helpers.IODispatcher(publisher, new NoopEnvelope()), new StubPasswordHashAlgorithm(), 1),
                TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), (man, err) => { });

            tcpConnectionManager.ProcessPackage(package);

            if (!waiter.WaitOne(TimeSpan.FromSeconds(5)))
            {
                throw new Exception("Timed out waiting for events.");
            }
            Assert.AreEqual(evnt.EventId, publishedWrite.Events.First().EventId, "Expected the published write to be the event that was sent through the tcp connection manager to be the event {0} but got {1}", evnt.EventId, publishedWrite.Events.First().EventId);
        }
开发者ID:SzymonPobiega,项目名称:EventStore,代码行数:33,代码来源:TcpConnectionManagerTests.cs


示例2: Execute

        public bool Execute(CommandProcessorContext context, string[] args)
        {
            context.IsAsync();

            var package = new TcpPackage(TcpCommand.Ping, Guid.NewGuid(), null);
            context.Log.Info("[{0}:{1}]: PING...", context.Client.Options.Ip, context.Client.Options.TcpPort);

            var connection = context.Client.CreateTcpConnection(
                context,
                (conn, pkg) =>
                {
                    if (pkg.Command != TcpCommand.Pong)
                    {
                        context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
                        return;
                    }
                    context.Log.Info("[{0}:{1}]: PONG!", context.Client.Options.Ip, context.Client.Options.TcpPort);
                    conn.Close();
                    context.Success();
                },
                null,
                (typedConnection, error) =>
                    {
                        if (error == SocketError.Success)
                            context.Success();
                        else
                            context.Fail();
                    });
            connection.EnqueueSend(package.AsByteArray());
            context.WaitForCompletion();
            return true;
        }
开发者ID:jpierson,项目名称:EventStore,代码行数:32,代码来源:PingProcessor.cs


示例3: Execute

        public bool Execute(CommandProcessorContext context, string[] args)
        {
            context.IsAsync();

            context.Client.CreateTcpConnection(
                context,
                connectionEstablished: conn =>
                {
                    var package = new TcpPackage(TcpCommand.Ping, Guid.NewGuid(), null);
                    context.Log.Info("[{0}:{1}]: PING...", context.Client.Options.Ip, context.Client.Options.TcpPort);
                    conn.EnqueueSend(package.AsByteArray());
                },
                handlePackage: (conn, pkg) =>
                {
                    if (pkg.Command != TcpCommand.Pong)
                    {
                        context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
                        return;
                    }
                    context.Log.Info("[{0}:{1}]: PONG!", context.Client.Options.Ip, context.Client.Options.TcpPort);
                    context.Success();
                    conn.Close();
                },
                connectionClosed: (typedConnection, error) => context.Fail(reason: "Connection was closed prematurely."));
            context.WaitForCompletion();
            return true;
        }
开发者ID:danieldeb,项目名称:EventStore,代码行数:27,代码来源:PingProcessor.cs


示例4: PingFloodWaiting

        private void PingFloodWaiting(CommandProcessorContext context, int clientsCnt, long requestsCnt)
        {
            context.IsAsync();

            var clients = new List<TcpTypedConnection<byte[]>>();
            var threads = new List<Thread>();
            var doneEvent = new ManualResetEventSlim(false);
            var clientsDone = 0;
            long all = 0;
            for (int i = 0; i < clientsCnt; i++)
            {
                var autoResetEvent = new AutoResetEvent(false);
                var client = context.Client.CreateTcpConnection(
                    context,
                    (_, __) =>
                    {
                        Interlocked.Increment(ref all);
                        autoResetEvent.Set();
                    },
                    connectionClosed: (conn, err) => context.Fail(reason: "Connection was closed prematurely."));
                clients.Add(client);

                var count = requestsCnt / clientsCnt + ((i == clientsCnt - 1) ? requestsCnt % clientsCnt : 0);
                threads.Add(new Thread(() =>
                {
                    for (int j = 0; j < count; ++j)
                    {
                        var package = new TcpPackage(TcpCommand.Ping, Guid.NewGuid(), null);
                        client.EnqueueSend(package.AsByteArray());
                        autoResetEvent.WaitOne();
                    }
                    if (Interlocked.Increment(ref clientsDone) == clientsCnt)
                    {
                        context.Success();
                        doneEvent.Set();
                    }
                }) { IsBackground = true });
            }

            var sw = Stopwatch.StartNew();
            threads.ForEach(thread => thread.Start());
            doneEvent.Wait();
            sw.Stop();
            clients.ForEach(x => x.Close());

            var reqPerSec = (all + 0.0)/sw.ElapsedMilliseconds*1000;
            context.Log.Info("{0} requests completed in {1}ms ({2:0.00} reqs per sec).", all, sw.ElapsedMilliseconds, reqPerSec);
            PerfUtils.LogData(Keyword,
                              PerfUtils.Row(PerfUtils.Col("clientsCnt", clientsCnt),
                                            PerfUtils.Col("requestsCnt", requestsCnt),
                                            PerfUtils.Col("ElapsedMilliseconds", sw.ElapsedMilliseconds)));
            PerfUtils.LogTeamCityGraphData(string.Format("{0}-{1}-{2}-reqPerSec", Keyword, clientsCnt, requestsCnt), (int) reqPerSec);
            PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword), (int) Math.Round(sw.Elapsed.TotalMilliseconds/all));

            if (Interlocked.Read(ref all) == requestsCnt)
                context.Success();
            else
                context.Fail();
        }
开发者ID:czcz1024,项目名称:EventStore,代码行数:59,代码来源:PingFloodWaitingProcessor.cs


示例5: UnwrapPing

 private static Message UnwrapPing(TcpPackage package, IEnvelope envelope)
 {
     var data = new byte[package.Data.Count];
     Buffer.BlockCopy(package.Data.Array, package.Data.Offset, data, 0, package.Data.Count);
     var pongMessage = new TcpMessage.PongMessage(package.CorrelationId, data);
     envelope.ReplyWith(pongMessage);
     return pongMessage;
 }
开发者ID:adbrowne,项目名称:EventStore,代码行数:8,代码来源:ClientTcpDispatcher.cs


示例6: UnwrapCommitAck

 private static StorageMessage.CommitAck UnwrapCommitAck(TcpPackage package, IEnvelope envelope)
 {
     var dto = package.Data.Deserialize<ReplicationMessageDto.CommitAck>();
     return new StorageMessage.CommitAck(package.CorrelationId,
                                         dto.LogPosition,
                                         dto.TransactionPosition,
                                         dto.FirstEventNumber,
                                         dto.LastEventNumber);
 }
开发者ID:danieldeb,项目名称:EventStore,代码行数:9,代码来源:InternalTcpDispatcher.cs


示例7: Execute

        public bool Execute(CommandProcessorContext context, string[] args)
        {
            var eventStreamId = "test-stream";
            var expectedVersion = ExpectedVersion.Any;

            if (args.Length > 0)
            {
                if (args.Length > 2)
                    return false;
                eventStreamId = args[0];
                if (args.Length == 2)
                    expectedVersion = args[1].Trim().ToUpper() == "ANY" ? ExpectedVersion.Any : int.Parse(args[1]);
            }

            context.IsAsync();
            var sw = new Stopwatch();
            context.Client.CreateTcpConnection(
                context,
                connectionEstablished: conn =>
                {
                    context.Log.Info("[{0}, L{1}]: Trying to delete event stream '{2}'...", conn.RemoteEndPoint, conn.LocalEndPoint, eventStreamId);
                    var corrid = Guid.NewGuid();
                    var deleteDto = new TcpClientMessageDto.DeleteStream(eventStreamId, expectedVersion, false);
                    var package = new TcpPackage(TcpCommand.DeleteStream, corrid, deleteDto.Serialize()).AsByteArray();
                    sw.Start();
                    conn.EnqueueSend(package);
                },
                handlePackage: (conn, pkg) =>
                {
                    sw.Stop();
                    context.Log.Info("Delete request took: {0}.", sw.Elapsed);

                    if (pkg.Command != TcpCommand.DeleteStreamCompleted)
                    {
                        context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
                        return;
                    }

                    var dto = pkg.Data.Deserialize<TcpClientMessageDto.DeleteStreamCompleted>();
                    if (dto.Result == TcpClientMessageDto.OperationResult.Success)
                    {
                        context.Log.Info("DELETED event stream {0}.", eventStreamId);
                        PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword), (int)sw.ElapsedMilliseconds);
                        context.Success();
                    }
                    else
                    {
                        context.Log.Info("DELETION FAILED for event stream {0}: {1} ({2}).", eventStreamId, dto.Message, dto.Result);
                        context.Fail();
                    }
                    conn.Close();
                },
                connectionClosed:(connection, error) => context.Fail(reason: "Connection was closed prematurely."));

            context.WaitForCompletion();
            return true;
        }
开发者ID:jjvdangelo,项目名称:EventStore,代码行数:57,代码来源:DeleteProcessor.cs


示例8: not_authorized_with_empty_data_should_serialize_and_deserialize_correctly

        public void not_authorized_with_empty_data_should_serialize_and_deserialize_correctly()
        {
            var corrId = Guid.NewGuid();
            var refPkg = new TcpPackage(TcpCommand.BadRequest, TcpFlags.None, corrId, null, null, new byte[0]);
            var bytes = refPkg.AsArraySegment();

            var pkg = TcpPackage.FromArraySegment(bytes);
            Assert.AreEqual(TcpCommand.BadRequest, pkg.Command);
            Assert.AreEqual(TcpFlags.None, pkg.Flags);
            Assert.AreEqual(corrId, pkg.CorrelationId);
            Assert.AreEqual(null, pkg.Login);
            Assert.AreEqual(null, pkg.Password);

            Assert.AreEqual(0, pkg.Data.Count);
        }
开发者ID:danieldeb,项目名称:EventStore,代码行数:15,代码来源:core_tcp_package.cs


示例9: UnwrapReplicaSubscriptionRequest

 private ReplicationMessage.ReplicaSubscriptionRequest UnwrapReplicaSubscriptionRequest(TcpPackage package, IEnvelope envelope, TcpConnectionManager connection)
 {
     var dto = package.Data.Deserialize<ReplicationMessageDto.SubscribeReplica>();
     var vnodeTcpEndPoint = new IPEndPoint(new IPAddress(dto.Ip), dto.Port);
     var lastEpochs = dto.LastEpochs.Safe().Select(x => new Epoch(x.EpochPosition, x.EpochNumber, new Guid(x.EpochId))).ToArray();
     return new ReplicationMessage.ReplicaSubscriptionRequest(package.CorrelationId,
                                                              envelope, 
                                                              connection,
                                                              dto.LogPosition,
                                                              new Guid(dto.ChunkId), 
                                                              lastEpochs,
                                                              vnodeTcpEndPoint,
                                                              new Guid(dto.MasterId), 
                                                              new Guid(dto.SubscriptionId), 
                                                              dto.IsPromotable);
 }
开发者ID:danieldeb,项目名称:EventStore,代码行数:16,代码来源:InternalTcpDispatcher.cs


示例10: UnwrapWriteEvents

        private static ClientMessage.WriteEvents UnwrapWriteEvents(TcpPackage package, IEnvelope envelope,
                                                                   IPrincipal user, string login, string password)
        {
            var dto = package.Data.Deserialize<TcpClientMessageDto.WriteEvents>();
            if (dto == null) return null;
            
            var events = new Event[dto.Events == null ? 0 : dto.Events.Length];
            for (int i = 0; i < events.Length; ++i)
            {
// ReSharper disable PossibleNullReferenceException
                var e = dto.Events[i];
// ReSharper restore PossibleNullReferenceException
                events[i] = new Event(new Guid(e.EventId), e.EventType, e.DataContentType == 1, e.Data, e.Metadata);
            }
            return new ClientMessage.WriteEvents(Guid.NewGuid(), package.CorrelationId, envelope, dto.RequireMaster,
                                                 dto.EventStreamId, dto.ExpectedVersion, events, user, login, password);
        }
开发者ID:adbrowne,项目名称:EventStore,代码行数:17,代码来源:ClientTcpDispatcher.cs


示例11: when_handling_trusted_write_on_external_service

        public void when_handling_trusted_write_on_external_service()
        {
            var package = new TcpPackage(TcpCommand.WriteEvents, TcpFlags.TrustedWrite, Guid.NewGuid(), null, null, new byte[] { });

            var dummyConnection = new DummyTcpConnection();

            var tcpConnectionManager = new TcpConnectionManager(
                Guid.NewGuid().ToString(), TcpServiceType.External, new ClientTcpDispatcher(),
                InMemoryBus.CreateTest(), dummyConnection, InMemoryBus.CreateTest(), new InternalAuthenticationProvider(new Core.Helpers.IODispatcher(InMemoryBus.CreateTest(), new NoopEnvelope()), new StubPasswordHashAlgorithm(), 1),
                TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10), (man, err) => { });

            tcpConnectionManager.ProcessPackage(package);

            var data = dummyConnection.ReceivedData.Last();
            var receivedPackage = TcpPackage.FromArraySegment(data);
           
            Assert.AreEqual(receivedPackage.Command, TcpCommand.BadRequest, "Expected Bad Request but got {0}", receivedPackage.Command);
        }
开发者ID:SzymonPobiega,项目名称:EventStore,代码行数:18,代码来源:TcpConnectionManagerTests.cs


示例12: authorized_with_data_should_serialize_and_deserialize_correctly

        public void authorized_with_data_should_serialize_and_deserialize_correctly()
        {
            var corrId = Guid.NewGuid();
            var refPkg = new TcpPackage(TcpCommand.BadRequest, TcpFlags.Authenticated, corrId, "login", "pa$$", new byte[] { 1, 2, 3 });
            var bytes = refPkg.AsArraySegment();

            var pkg = TcpPackage.FromArraySegment(bytes);
            Assert.AreEqual(TcpCommand.BadRequest, pkg.Command);
            Assert.AreEqual(TcpFlags.Authenticated, pkg.Flags);
            Assert.AreEqual(corrId, pkg.CorrelationId);
            Assert.AreEqual("login", pkg.Login);
            Assert.AreEqual("pa$$", pkg.Password);

            Assert.AreEqual(3, pkg.Data.Count);
            Assert.AreEqual(1, pkg.Data.Array[pkg.Data.Offset + 0]);
            Assert.AreEqual(2, pkg.Data.Array[pkg.Data.Offset + 1]);
            Assert.AreEqual(3, pkg.Data.Array[pkg.Data.Offset + 2]);
        }
开发者ID:danieldeb,项目名称:EventStore,代码行数:18,代码来源:core_tcp_package.cs


示例13: Execute

        public bool Execute(CommandProcessorContext context, string[] args)
        {
            var package = new TcpPackage(TcpCommand.ScavengeDatabase, Guid.NewGuid(), null);
            context.Log.Info("Sending SCAVENGE request...");

            var connection = context.Client.CreateTcpConnection(
                context,
                (conn, pkg) => { },
                null,
                (typedConnection, error) =>
                {
                    if (error == SocketError.Success)
                        context.Success();
                    else
                        context.Fail();
                });
            connection.EnqueueSend(package.AsByteArray());
            connection.Close("OK");
            return true;
        }
开发者ID:thinkbeforecoding,项目名称:EventStore,代码行数:20,代码来源:ScavengeProcessor.cs


示例14: UnwrapReadStreamEventsForward

 private static ClientMessage.ReadStreamEventsForward UnwrapReadStreamEventsForward(TcpPackage package,
                                                                                    IEnvelope envelope,
                                                                                    TcpConnectionManager connection)
 {
     var dto = package.Data.Deserialize<TcpClientMessageDto.ReadStreamEventsForward>();
     if (dto == null) return null;
     return new ClientMessage.ReadStreamEventsForward(package.CorrelationId,
                                                      envelope,
                                                      dto.EventStreamId,
                                                      dto.StartIndex,
                                                      dto.MaxCount,
                                                      dto.ResolveLinkTos);
 }
开发者ID:robashton,项目名称:EventStore,代码行数:13,代码来源:ClientTcpDispatcher.cs


示例15: UnwrapTransactionStart

 private static ClientMessage.TransactionStart UnwrapTransactionStart(TcpPackage package, IEnvelope envelope)
 {
     var dto = package.Data.Deserialize<TcpClientMessageDto.TransactionStart>();
     if (dto == null) return null;
     return new ClientMessage.TransactionStart(package.CorrelationId, envelope, dto.AllowForwarding, dto.EventStreamId, dto.ExpectedVersion);
 }
开发者ID:robashton,项目名称:EventStore,代码行数:6,代码来源:ClientTcpDispatcher.cs


示例16: UnwrapReadAllEventsForward

 private static ClientMessage.ReadAllEventsForward UnwrapReadAllEventsForward(TcpPackage package, IEnvelope envelope, TcpConnectionManager connection)
 {
     var dto = package.Data.Deserialize<TcpClientMessageDto.ReadAllEventsForward>();
     if (dto == null) return null;
     return new ClientMessage.ReadAllEventsForward(package.CorrelationId,
                                                   envelope,
                                                   dto.CommitPosition,
                                                   dto.PreparePosition,
                                                   dto.MaxCount,
                                                   dto.ResolveLinkTos);
 }
开发者ID:robashton,项目名称:EventStore,代码行数:11,代码来源:ClientTcpDispatcher.cs


示例17: UnwrapReadEvents

 private static ClientMessage.ReadEvent UnwrapReadEvents(TcpPackage package, IEnvelope envelope)
 {
     var dto = package.Data.Deserialize<TcpClientMessageDto.ReadEvent>();
     if (dto == null) return null;
     return new ClientMessage.ReadEvent(package.CorrelationId, envelope, dto.EventStreamId, dto.EventNumber, dto.ResolveLinkTos);
 }
开发者ID:robashton,项目名称:EventStore,代码行数:6,代码来源:ClientTcpDispatcher.cs


示例18: Execute

        public bool Execute(CommandProcessorContext context, string[] args)
        {
            var eventStreamId = "test-stream";
            var expectedVersion = ExpectedVersion.Any;
            var data = GenerateTestData();
            string metadata = null;

            if (args.Length > 0)
            {
                if (args.Length < 3 || args.Length > 4)
                    return false;
                eventStreamId = args[0];
                expectedVersion = args[1].ToUpper() == "ANY" ? ExpectedVersion.Any : int.Parse(args[1]);
                data = args[2];
                if (args.Length == 4)
                    metadata = args[3];
            }

            context.IsAsync();
            var writeDto = new TcpClientMessageDto.WriteEvents(
                eventStreamId,
                expectedVersion,
                new[]
                {
                    new TcpClientMessageDto.NewEvent(Guid.NewGuid().ToByteArray(),
                                                     "JsonDataEvent",
                                                     1,0,
                                                     Helper.UTF8NoBom.GetBytes(data),
                                                     Helper.UTF8NoBom.GetBytes(metadata ?? string.Empty))
                },
                false);
            var package = new TcpPackage(TcpCommand.WriteEvents, Guid.NewGuid(), writeDto.Serialize());

            var sw = new Stopwatch();
            bool dataReceived = false;

            context.Client.CreateTcpConnection(
                context,
                connectionEstablished: conn =>
                {
                    context.Log.Info("[{0}, L{1}]: Writing...", conn.RemoteEndPoint, conn.LocalEndPoint);
                    sw.Start();
                    conn.EnqueueSend(package.AsByteArray());
                },
                handlePackage: (conn, pkg) =>
                {
                    if (pkg.Command != TcpCommand.WriteEventsCompleted)
                    {
                        context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
                        return;
                    }

                    dataReceived = true;
                    sw.Stop();

                    var dto = pkg.Data.Deserialize<TcpClientMessageDto.WriteEventsCompleted>();
                    if (dto.Result == TcpClientMessageDto.OperationResult.Success)
                    {
                        context.Log.Info("Successfully written. EventId: {0}.", package.CorrelationId);
                        PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword), (int)sw.ElapsedMilliseconds);
                    }
                    else
                    {
                        context.Log.Info("Error while writing: {0} ({1}).", dto.Message, dto.Result);
                    }

                    context.Log.Info("Write request took: {0}.", sw.Elapsed);
                    conn.Close();
                    context.Success();
                },
                connectionClosed: (connection, error) =>
                {
                    if (dataReceived && error == SocketError.Success)
                        context.Success();
                    else
                        context.Fail();
                });

            context.WaitForCompletion();
            return true;
        }
开发者ID:jjvdangelo,项目名称:EventStore,代码行数:81,代码来源:WriteJsonProcessor.cs


示例19: UnwrapCreateStream

 private static ClientMessage.CreateStream UnwrapCreateStream(TcpPackage package, IEnvelope envelope)
 {
     var dto = package.Data.Deserialize<TcpClientMessageDto.CreateStream>();
     if (dto == null) return null;
     return new ClientMessage.CreateStream(package.CorrelationId, envelope, dto.AllowForwarding, dto.EventStreamId, dto.IsJson, dto.Metadata);
 }
开发者ID:robashton,项目名称:EventStore,代码行数:6,代码来源:ClientTcpDispatcher.cs


示例20: Flood


//.........这里部分代码省略.........
                            elapsed = sw.Elapsed;

                        if (elapsed.TotalMinutes > runTimeMinutes)
                        {
                            done = true;
                            doneEvent.Set();
                            break;
                        }

                        if (sentCount == 0)
                        {
                            int elapsedMinutesInt = (int)elapsed.TotalMinutes;
                            lock (_randomLockRoot)
                            {
                                sentCount = minPerSecond == maxPerSecond 
                                            ? maxPerSecond : _random.Next(minPerSecond, maxPerSecond);
                                dataSizeCoefficient = _random.Next(8, 256);
                            }

                            if (currentMinute != elapsedMinutesInt)
                            {
                                currentMinute = elapsedMinutesInt;
                                context.Log.Info("\nElapsed {0} of {1} minutes, sent {2}; next block coef. {3}",
                                                 elapsedMinutesInt,
                                                 runTimeMinutes,
                                                 sent,
                                                 dataSizeCoefficient);
                            }

                            sleepTime = 1000 / sentCount;
                        }

                        var dataSize = dataSizeCoefficient * 8;
                        var write = new TcpClientMessageDto.WriteEvents(
                            esId,
                            ExpectedVersion.Any,
                            new[]
                            {
                                new TcpClientMessageDto.NewEvent(
                                    Guid.NewGuid().ToByteArray(),
                                    "TakeSomeSpaceEvent",
                                    0,0,
                                    Helper.UTF8NoBom.GetBytes("DATA" + dataSize.ToString(" 00000 ") + new string('*', dataSize)),
                                    Helper.UTF8NoBom.GetBytes("METADATA" + new string('$', 100)))
                            },
                            false);
                        var package = new TcpPackage(TcpCommand.WriteEvents, Guid.NewGuid(), write.Serialize());
                        client.EnqueueSend(package.AsByteArray());

                        Interlocked.Increment(ref sent);

                        Thread.Sleep(sleepTime);
                        sentCount -= 1;

                        while (sent - received > context.Client.Options.WriteWindow/clientsCnt)
                        {
                            Thread.Sleep(1);
                        }
                    }
                }));
            }

            foreach (var thread in threads)
            {
                thread.IsBackground = true;
                thread.Start();
            }

            doneEvent.WaitOne();
            sw.Stop();

            foreach (var client in clients)
            {
                client.Close();
            }

            context.Log.Info("Completed. Successes: {0}, failures: {1}", succ, fail);
            var reqPerSec = (requestsCnt + 0.0)/sw.ElapsedMilliseconds*1000;
            context.Log.Info("{0} requests completed in {1}ms ({2:0.00} reqs per sec).",
                             requestsCnt,
                             sw.ElapsedMilliseconds,
                             reqPerSec);

            PerfUtils.LogData(
                    Keyword,
                    PerfUtils.Row(PerfUtils.Col("clientsCnt", clientsCnt),
                         PerfUtils.Col("requestsCnt", requestsCnt),
                         PerfUtils.Col("ElapsedMilliseconds", sw.ElapsedMilliseconds)),
                    PerfUtils.Row(PerfUtils.Col("successes", succ), PerfUtils.Col("failures", fail))
            );

            PerfUtils.LogTeamCityGraphData(string.Format("{0}-{1}-{2}-reqPerSec", Keyword, clientsCnt, requestsCnt),
                        (int)reqPerSec);

            PerfUtils.LogTeamCityGraphData(
                string.Format("{0}-{1}-{2}-failureSuccessRate", Keyword, clientsCnt, requestsCnt),
                100*fail/(fail + succ));

            context.Success();
        }
开发者ID:danieldeb,项目名称:EventStore,代码行数:101,代码来源:WriteLongTermProcessor.cs



注:本文中的EventStore.Core.Services.Transport.Tcp.TcpPackage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Fakes.FakePublisher类代码示例发布时间:2022-05-24
下一篇:
C# Messaging.Message类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap