Exemple #1
0
        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 corrid = Guid.NewGuid();
            var deleteDto = new ClientMessageDto.DeleteStream(eventStreamId, expectedVersion);
            var package = new TcpPackage(TcpCommand.DeleteStream, corrid, deleteDto.Serialize());

            var sw = new Stopwatch();
            var done = false;

            context.Client.CreateTcpConnection(
                context,
                connectionEstablished: conn =>
                {
                    context.Log.Info("[{0}]: Trying to delete event stream '{1}'...", conn.EffectiveEndPoint, eventStreamId);
                    sw.Start();
                    conn.EnqueueSend(package.AsByteArray());
                },
                handlePackage: (conn, pkg) =>
                {
                    sw.Stop();

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

                    var dto = pkg.Data.Deserialize<ClientMessageDto.DeleteStreamCompleted>();

                    if (dto.ErrorCode == (int)OperationErrorCode.Success)
                        context.Log.Info("DELETED event stream {0}.", eventStreamId);
                    else
                        context.Log.Info("DELETION FAILED for event stream {0}: {1} ({2}).",
                                         eventStreamId,
                                         dto.Error,
                                         (OperationErrorCode) dto.ErrorCode);

                    context.Log.Info("Delete request took: {0}.", sw.Elapsed);

                    PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword), (int)sw.ElapsedMilliseconds);

                    done = true;

                    conn.Close();
                    context.Success();
                },
                connectionClosed:(connection, error) =>
                {
                    if (done && error == SocketError.Success)
                        context.Success();
                    else
                        context.Fail();
                });

            context.WaitForCompletion();
            return true;
        }
 private static TcpPackage WrapDeleteStream(ClientMessage.DeleteStream msg)
 {
     var dto = new ClientMessageDto.DeleteStream(msg.CorrelationId, msg.EventStreamId, msg.ExpectedVersion);
     return new TcpPackage(TcpCommand.DeleteStream, msg.CorrelationId, dto.Serialize());
 }
Exemple #3
0
 public override TcpPackage CreateNetworkPackage(Guid correlationId)
 {
     var dto = new ClientMessageDto.DeleteStream(correlationId, EventStreamId, ExpectedVersion);
     return new TcpPackage(TcpCommand.DeleteStream, correlationId, dto.Serialize());
 }