public void performBackgroundOperation(OperationAndData <String> operationAndData)
 {
     try
     {
         TimeTrace trace    = client.getZookeeperClient().startTracer("GetChildrenBuilderImpl-Background");
         var       callback = new AsyncCallback.Children2Callback()
         {
 public void BeginScope_NoTrace_ScopeIsNull()
 {
     using (var scope = TimeTrace.BeginScope("TestScope"))
     {
         scope.Should().BeNull();
     }
 }
Exemple #3
0
        public void performBackgroundOperation(OperationAndData <PathAndBytes> operationAndData)
        {
            try
            {
                TimeTrace   trace   = client.getZookeeperClient().startTracer("SetDataBuilderImpl-Background");
                object      taskCtx = backgrounding.getContext();
                Task <Stat> task    = client.getZooKeeper().setDataAsync
                                      (
                    operationAndData.getData().getPath(),
                    operationAndData.getData().getData(),
                    version //,
//                     new AsyncCallback.StatCallback()
//                     {
//                         public void processResult(int rc, String path, Object ctx, Stat stat)
//                         {
//                             trace.commit();
//                             ICuratorEvent @event = new CuratorEventImpl(client, CuratorEventType.SET_DATA, rc, path, null, ctx, stat, null, null, null, null);
//                             client.processBackgroundOperation(operationAndData, @event);
//                         };
//                    },
//                    backgrounding.getContext()
                                      );
                task.ContinueWith(statTask =>
                {
                    trace.commit();
                    int errorCode = 0;
                    if (statTask.IsFaulted)
                    {
                        if (!(statTask.Exception.InnerException is KeeperException))
                        {
                            throw new Exception($"{nameof(SetDataBuilderImpl)}." +
                                                $"{nameof(performBackgroundOperation)} operation failed " +
                                                $"with unexpected exception of type " +
                                                $"{statTask.Exception.InnerException.GetType().FullName}." +
                                                $"Expected type {nameof(KeeperException)}");
                        }
                        KeeperException keeperException
                                  = (KeeperException)statTask.Exception.InnerException;
                        errorCode = (int)keeperException.getCode();
                    }
                    ICuratorEvent @event = new CuratorEventImpl(client,
                                                                CuratorEventType.SET_DATA,
                                                                errorCode,
                                                                operationAndData.getData().getPath(),
                                                                null,
                                                                taskCtx,
                                                                statTask.Result,
                                                                null,
                                                                null,
                                                                null,
                                                                null);
                    client.processBackgroundOperation(operationAndData, @event);
                });
            }
            catch (Exception e)
            {
                backgrounding.checkError(e);
            }
        }
        public void BeginScope_NameIsNullEmptyOrWhiteSpace_ThrowsException(string name)
        {
            Action act = () => TimeTrace.BeginScope(name);

            var exception = act.Should().Throw <ArgumentException>();

            exception.Which.ParamName.Should().Be("name");
        }
Exemple #5
0
 public void performBackgroundOperation(OperationAndData <String> operationAndData)
 {
     try
     {
         TimeTrace trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Background");
         AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
         {
             @Override
        public void Current_IsSetOnCreation_AndRemovedOnDispose()
        {
            using (var trace = new TimeTrace())
            {
                TimeTrace.Current.Should().BeSameAs(trace);
            }

            TimeTrace.Current.Should().BeNull();
        }
Exemple #7
0
        public void performBackgroundOperation(OperationAndData <String> operationAndData)
        {
            try
            {
                TimeTrace trace        = client.getZookeeperClient().startTracer("SyncBuilderImpl-Background");
                String    path         = operationAndData.getData();
                String    adjustedPath = client.fixForNamespace(path);

                AsyncCallback.VoidCallback voidCallback = new AsyncCallback.VoidCallback()
                {
        public void performBackgroundOperation(OperationAndData <String> operationAndData)
        {
            TimeTrace trace = client.getZookeeperClient().startTracer("BackgroundSyncImpl");

            client.getZooKeeper().sync
            (
                operationAndData.getData(),
                new AsyncCallback.VoidCallback()
            {
                @Override
 public void BeginScope_TraceExists_ScopeIsCreatedWithCorrectName()
 {
     using (var trace = new TimeTrace())
     {
         using (var scope = TimeTrace.BeginScope("Foo"))
         {
             scope.Should().NotBeNull();
             scope.Name.Should().Be("Foo");
         }
     }
 }
        public void Current_NestedTraces()
        {
            using (var outerTrace = new TimeTrace())
            {
                using (var innerTrace = new TimeTrace())
                {
                    TimeTrace.Current.Should().BeSameAs(innerTrace);
                }

                TimeTrace.Current.Should().BeSameAs(outerTrace);
            }
        }
Exemple #11
0
 public void performBackgroundOperation(OperationAndData <String> operationAndData)
 {
     try
     {
         TimeTrace trace = client.getZookeeperClient().startTracer("DeleteBuilderImpl-Background");
         client.getZooKeeper().delete
         (
             operationAndData.getData(),
             version,
             new AsyncCallback.VoidCallback()
         {
             @Override
 public void performBackgroundOperation(OperationAndData <String> operationAndData)
 {
     try
     {
         TimeTrace trace = client.getZookeeperClient().startTracer("SetACLBuilderImpl-Background");
         String    path  = operationAndData.getData();
         client.getZooKeeper().setACL
         (
             path,
             acling.getAclList(path),
             version,
             new AsyncCallback.StatCallback()
         {
 public void performBackgroundOperation(OperationAndData <PathAndBytes> operationAndData)
 {
     try
     {
         TimeTrace trace = client.getZookeeperClient().startTracer("CreateBuilderImpl-Background");
         client.getZooKeeper().create
         (
             operationAndData.getData().getPath(),
             operationAndData.getData().getData(),
             acling.getAclList(operationAndData.getData().getPath()),
             createMode,
             new AsyncCallback.StringCallback()
         {
             @Override
        public void Scope_Disposed_MetricsAddedToTrace()
        {
            using (var trace = new TimeTrace())
            {
                using (var scope = TimeTrace.BeginScope("Foo"))
                {
                    Thread.Sleep(500);
                }

                var metric = trace.Metrics.Single();

                metric.Count.Should().Be(1);
                metric.TotalDuration.Should().BeCloseTo(TimeSpan.FromMilliseconds(500), precision: 1);
            }
        }
Exemple #15
0
        public EntityLogic Evolve(TimeTrace evolutionState, EntityChangeSet outChangeSet, ICollection <ClientMessage> clientMessages, EntityChange.ExecutionContext ctx, bool locationIsInconsistent)
        {
            EntityLogic state = null;

            evolutionState.Begin();
            if (Helper.Length(SerialLogicState) > 0)
            {
                try
                {
                    state = MyLogic;
                    transientDeserializedLogic = null;
                    evolutionState.SignalDeserializationDone();
                    if (state == null)
                    {
                        throw new ExecutionException(ID, "Unable to deserialize logic");
                    }


                    var actions = new EntityLogic.Actions(this);
#if DRY_RUN
                    Debug.Assert(transientDeserializedLogic == null, "Should be null");
#endif
                    state.Execute(ref actions, AddClientMessages(clientMessages), ctx.GenerationNumber, new EntityRandom(this, ctx.GenerationNumber), ctx.Ranges, locationIsInconsistent);
                    evolutionState.SignalEvolutionDone();

                    byte[] serialLogic = Helper.SerializeToArray(state);
                    evolutionState.SignalReserializationDone();

                    actions.ApplyTo(outChangeSet, state, serialLogic, ctx);
                }
                catch
                {
#if STATE_ADV
                    outChangeSet.Add(new EntityChange.StateAdvertisement(new EntityContact(ID, Appearances, Vec3.Zero)));
#endif
                    transientDeserializedLogic = null;
                    throw;
                }
            }
            else
            {
                transientDeserializedLogic = null;
            }

            evolutionState.End();
            return(state);
        }
Exemple #16
0
        private Stat pathInForeground(string path, byte[] data)
        {
            TimeTrace trace      = client.getZookeeperClient().startTracer("SetDataBuilderImpl-Foreground");
            Stat      resultStat = RetryLoop.callWithRetry
                                   (
                client.getZookeeperClient(),
                CallableUtils.FromFunc(() =>
            {
                Task <Stat> task = client.getZooKeeper().setDataAsync(path, data, version);
                task.Wait();
                return(task.Result);
            })
                                   );

            trace.commit();
            return(resultStat);
        }
        public void Scope_NestedScope_NamedCorrectly()
        {
            using (var trace = new TimeTrace())
            {
                using (var scope1 = TimeTrace.BeginScope("Foo"))
                {
                    scope1.Name.Should().Be("Foo");

                    using (var scope2 = TimeTrace.BeginScope("Bar"))
                        using (var scope3 = TimeTrace.BeginScope("Baz"))
                        {
                            scope2.Name.Should().Be("Foo/Bar");
                            scope3.Name.Should().Be("Foo/Bar/Baz");
                        }

                    using (var scope4 = TimeTrace.BeginScope("Ping"))
                    {
                        scope4.Name.Should().Be("Foo/Ping");
                    }
                }
            }
        }
Exemple #18
0
        public byte[] forPath(String path)
        {
            String localPath = client.fixForNamespace(path);

            TimeTrace trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Foreground");

            byte[]
            responseData = RetryLoop.callWithRetry
                           (
                client.getZookeeperClient(),
                CallableUtils.FromFunc(() =>
            {
                var dataAsync = client.getZooKeeper().getDataAsync(localPath, false);
                dataAsync.Wait();
                responseStat = dataAsync.Result.Stat;
                return(dataAsync.Result.Data);
            })
                           );
            trace.commit();

            return(decompress
                    ? client.getCompressionProvider().decompress(path, responseData)
                    : responseData);
        }