Beispiel #1
0
        public virtual void Mdc()
        {
            HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>();

            Org.Mockito.Mockito.When(request.GetUserPrincipal()).ThenReturn(null);
            Org.Mockito.Mockito.When(request.GetMethod()).ThenReturn("METHOD");
            Org.Mockito.Mockito.When(request.GetPathInfo()).ThenReturn("/pathinfo");
            ServletResponse response = Org.Mockito.Mockito.Mock <ServletResponse>();
            AtomicBoolean   invoked  = new AtomicBoolean();
            FilterChain     chain    = new _FilterChain_55(invoked);

            MDC.Clear();
            Filter filter = new MDCFilter();

            filter.Init(null);
            filter.DoFilter(request, response, chain);
            NUnit.Framework.Assert.IsTrue(invoked.Get());
            NUnit.Framework.Assert.IsNull(MDC.Get("hostname"));
            NUnit.Framework.Assert.IsNull(MDC.Get("user"));
            NUnit.Framework.Assert.IsNull(MDC.Get("method"));
            NUnit.Framework.Assert.IsNull(MDC.Get("path"));
            Org.Mockito.Mockito.When(request.GetUserPrincipal()).ThenReturn(new _Principal_78
                                                                                ());
            invoked.Set(false);
            chain = new _FilterChain_86(invoked);
            filter.DoFilter(request, response, chain);
            NUnit.Framework.Assert.IsTrue(invoked.Get());
            HostnameFilter.HostnameTl.Set("HOST");
            invoked.Set(false);
            chain = new _FilterChain_103(invoked);
            filter.DoFilter(request, response, chain);
            NUnit.Framework.Assert.IsTrue(invoked.Get());
            HostnameFilter.HostnameTl.Remove();
            filter.Destroy();
        }
 public void Flush()
 {
     if (!_offline.Get())
     {
         SubmitMessage(new EventProcessorInternal.FlushMessage());
     }
 }
 /// <exception cref="HazelcastException"></exception>
 private void CheckLive()
 {
     if (!_live.Get())
     {
         throw new HazelcastException("ConnectionManager is not active");
     }
 }
Beispiel #4
0
            public void Run()
            {
                var publication = Publication;

                using (var buffer = new UnsafeBuffer(new byte[publication.MaxMessageLength]))
                {
                    long backPressureCount = 0;
                    long totalMessageCount = 0;

                    while (Running.Get())
                    {
                        for (var i = 0; i < BurstLength; i++)
                        {
                            while (publication.Offer(buffer, 0, MessageLength) <= 0)
                            {
                                ++backPressureCount;
                                if (!Running.Get())
                                {
                                    break;
                                }
                            }

                            ++totalMessageCount;
                        }
                    }

                    var backPressureRatio = backPressureCount / (double)totalMessageCount;
                    Console.WriteLine($"Publisher back pressure ratio: {backPressureRatio}");
                }
            }
Beispiel #5
0
        public Address GetPartitionOwner(int partitionId)
        {
            Address partitionOwner = null;

            while (_live.Get() && !_partitions.TryGetValue(partitionId, out partitionOwner))
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Address of a partition cannot be null. Retrying to get it...");
                }
                Thread.Sleep(100);
            }
            if (!_live.Get())
            {
                throw new HazelcastException("Client is shut down.");
            }

            var member = _client.GetClientClusterService().GetMember(partitionOwner);

            if (member == null)
            {
                throw new TargetNotMemberException("Invalid Member address");
            }
            return(partitionOwner);
        }
            public void Run()
            {
                var  publication       = Publication;
                var  bufferClaim       = new BufferClaim();
                long backPressureCount = 0;
                long totalMessageCount = 0;

                while (Running.Get())
                {
                    for (var i = 0; i < BurstLength; i++)
                    {
                        while (publication.TryClaim(MessageLength, bufferClaim) <= 0)
                        {
                            ++backPressureCount;
                            if (!Running.Get())
                            {
                                break;
                            }
                        }

                        var offset = bufferClaim.Offset;
                        bufferClaim.Buffer.PutInt(offset, i); // Example field write
                        // Real app would write whatever fields are required via a flyweight like SBE

                        bufferClaim.Commit();

                        ++totalMessageCount;
                    }
                }


                var backPressureRatio = backPressureCount / (double)totalMessageCount;

                Console.WriteLine($"Publisher back pressure ratio: {backPressureRatio}");
            }
Beispiel #7
0
            public void Run()
            {
                var publication = Publication;

                using (var byteBuffer = BufferUtil.AllocateDirectAligned(publication.MaxMessageLength, BitUtil.CACHE_LINE_LENGTH))
                    using (var buffer = new UnsafeBuffer(byteBuffer))
                    {
                        long backPressureCount = 0;
                        long totalMessageCount = 0;

                        while (Running.Get())
                        {
                            for (var i = 0; i < BurstLength; i++)
                            {
                                while (publication.Offer(buffer, 0, MessageLength) <= 0)
                                {
                                    ++backPressureCount;
                                    if (!Running.Get())
                                    {
                                        break;
                                    }
                                }

                                ++totalMessageCount;
                            }
                        }

                        var backPressureRatio = backPressureCount / (double)totalMessageCount;
                        Console.WriteLine($"Publisher back pressure ratio: {backPressureRatio}");
                    }
            }
        /// <summary>
        /// Get a View that displays the data at the specified  position in the data set. In this case, if we are at
        /// the end of the list and we are still in append mode, we ask for a pending view and return it, plus kick off the
        /// background task to append more data to the wrapped adapter.
        /// </summary>
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View result;

            if (position == base.Count && _keepOnAppending.Get())
            {
                result = GetPendingItemView(parent);

                // Uncomment when bug #13788 fixed
                // https://bugzilla.xamarin.com/show_bug.cgi?id=13788
                // This is not working correctly:

/*
 *                              Task.Factory.StartNew(
 *                              () => ExecuteItemLoadAsync(),
 *                              CancellationToken.None,
 *                              TaskCreationOptions.None,
 *                              TaskScheduler.FromCurrentSynchronizationContext());
 */

                ExecuteItemLoadAsync();
            }
            else
            {
                result = base.GetView(position, convertView, parent);
            }

            return(result);
        }
Beispiel #9
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        public virtual void TestNMshutdownWhenResyncThrowException()
        {
            NodeManager       nm   = new TestNodeManagerResync.TestNodeManager3(this);
            YarnConfiguration conf = CreateNMConfig();

            nm.Init(conf);
            nm.Start();
            NUnit.Framework.Assert.AreEqual(1, ((TestNodeManagerResync.TestNodeManager3)nm).GetNMRegistrationCount
                                                ());
            nm.GetNMDispatcher().GetEventHandler().Handle(new NodeManagerEvent(NodeManagerEventType
                                                                               .Resync));
            lock (isNMShutdownCalled)
            {
                while (isNMShutdownCalled.Get() == false)
                {
                    try
                    {
                        Sharpen.Runtime.Wait(isNMShutdownCalled);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            NUnit.Framework.Assert.IsTrue("NM shutdown not called.", isNMShutdownCalled.Get()
                                          );
            nm.Stop();
        }
Beispiel #10
0
 private void LoadAllTaskAttempts()
 {
     if (taskAttemptsLoaded.Get())
     {
         return;
     }
     taskAttemptsLock.Lock();
     try
     {
         if (taskAttemptsLoaded.Get())
         {
             return;
         }
         foreach (JobHistoryParser.TaskAttemptInfo attemptHistory in taskInfo.GetAllTaskAttempts
                      ().Values)
         {
             CompletedTaskAttempt attempt = new CompletedTaskAttempt(taskId, attemptHistory);
             Sharpen.Collections.AddAll(reportDiagnostics, attempt.GetDiagnostics());
             attempts[attempt.GetID()] = attempt;
             if (successfulAttempt == null && attemptHistory.GetTaskStatus() != null && attemptHistory
                 .GetTaskStatus().Equals(TaskState.Succeeded.ToString()))
             {
                 successfulAttempt = TypeConverter.ToYarn(attemptHistory.GetAttemptId());
             }
         }
         taskAttemptsLoaded.Set(true);
     }
     finally
     {
         taskAttemptsLock.Unlock();
     }
 }
 private void CreateTask()
 {
     if (!_isTaskRunning.Get())
     {
         Task.Factory.StartNew(GetFlagData);
     }
 }
 public virtual void Close()
 {
     if (!_closed.Get())
     {
         _closed.Set(true);
         _dispatcher.Close();
     }
 }
Beispiel #13
0
 public void Dispatch(Dispatchable dispatchable)
 {
     if (_processDispatch.Get())
     {
         var dispatchId = dispatchable.Id;
         _access.WriteUsing("dispatched", dispatchId, new Dispatch(dispatchable.TypedState <TextState>(), dispatchable.Entries));
     }
 }
            public override void Release()
            {
                if (!_inUse.Get())
                {
                    throw new InvalidOperationException($"Attempt to release unclaimed buffer: {this}");
                }

                NotInUse();
            }
Beispiel #15
0
        public void TestSet()
        {
            var b = new AtomicBoolean(true);

            b.Set(false);
            Assert.Equal(false, b.Get());

            b.Set(true);
            Assert.Equal(true, b.Get());
        }
Beispiel #16
0
 public void Dispatch(Dispatchable <TEntry, TState> dispatchable)
 {
     _dispatchAttemptCount++;
     if (_processDispatch.Get())
     {
         var dispatchId = dispatchable.Id;
         _access.WriteUsing("dispatched", dispatchable);
         _control.ConfirmDispatched(dispatchId, _confirmDispatchedResultInterest);
     }
 }
Beispiel #17
0
        internal override void InnerInvoke(BasicCompletes completedCompletes)
        {
            if (TimedOut.Get() || executed.Get())
            {
                return;
            }

            base.InnerInvoke(completedCompletes);
            executed.Set(true);
        }
Beispiel #18
0
        public void TestSet()
        {
            var b = new AtomicBoolean(true);

            b.Set(false);
            Assert.False(b.Get());

            b.Set(true);
            Assert.True(b.Get());
        }
Beispiel #19
0
        internal override bool InnerInvoke(BasicCompletes completedCompletes)
        {
            if (TimedOut.Get() || _executed.Get())
            {
                return(false);
            }

            base.InnerInvoke(completedCompletes);
            _executed.Set(true);
            return(true);
        }
Beispiel #20
0
 private static void FixPrng()
 {
     if (!prngFixed.Get())
     {
         lock (prngLock) {
             if (!prngFixed.Get())
             {
                 AesCbcWithIntegrity.PrngFixes.Apply();
                 prngFixed.Set(true);
             }
         }
     }
 }
Beispiel #21
0
 public void Shutdown()
 {
     if (_shutdownInitiated.Get())
     {
         Logger.Debug("shutdown already initiated on the client. It is safe to ignore this message");
     }
     else
     {
         Logger.Debug("client shutdown called");
         _shutdownInitiated.Set(true);
         Dispose();
     }
 }
 /// <summary>
 /// Adds a shutdownHook with a priority, the higher the priority
 /// the earlier will run.
 /// </summary>
 /// <remarks>
 /// Adds a shutdownHook with a priority, the higher the priority
 /// the earlier will run. ShutdownHooks with same priority run
 /// in a non-deterministic order.
 /// </remarks>
 /// <param name="shutdownHook">shutdownHook <code>Runnable</code></param>
 /// <param name="priority">priority of the shutdownHook.</param>
 public virtual void AddShutdownHook(Runnable shutdownHook, int priority)
 {
     if (shutdownHook == null)
     {
         throw new ArgumentException("shutdownHook cannot be NULL");
     }
     if (shutdownInProgress.Get())
     {
         throw new InvalidOperationException("Shutdown in progress, cannot add a shutdownHook"
                                             );
     }
     hooks.AddItem(new ShutdownHookManager.HookEntry(shutdownHook, priority));
 }
Beispiel #23
0
 public virtual Task GetTask(TaskId taskId)
 {
     if (tasksLoaded.Get())
     {
         return(tasks[taskId]);
     }
     else
     {
         TaskID        oldTaskId     = TypeConverter.FromYarn(taskId);
         CompletedTask completedTask = new CompletedTask(taskId, jobInfo.GetAllTasks()[oldTaskId
                                                         ]);
         return(completedTask);
     }
 }
Beispiel #24
0
 public void ScheduleWithFixedDelay(Action command, long initialDelay, long period, TimeUnit unit, CancellationToken token)
 {
     if (!_live.Get())
     {
         throw new HazelcastException("Client is shut down.");
     }
     ScheduleWithCancellation(command, initialDelay, unit, token).ContinueWith(task =>
     {
         if (!task.IsCanceled)
         {
             ScheduleWithFixedDelay(command, period, period, unit, token);
         }
     }, token).IgnoreExceptions();
 }
        /// <summary>
        /// Completes the current queue and joins the thread.
        /// </summary>
        public void Shutdown()
        {
            if (!_running.Get())
            {
                return;
            }

            if (_shuttingDown.CompareAndSet(false, true))
            {
                _actions.Enqueue(() => {
                    _running.CompareAndSet(true, false);
                });
                _thread.Join();
            }
        }
        public void Close(bool flush)
        {
            if (open.Get())
            {
                open.Set(false);

                if (flush)
                {
                    Flush();
                }

                shouldExecutorRun = false;
                executorThread.Interrupt();
            }
        }
            public override void Run()
            {
                while (!stop.Get())
                {
                    try
                    {
                        // Sleep for up to 20 msec:
                        Thread.Sleep(Random().Next(20));

                        if (VERBOSE)
                        {
                            Console.WriteLine("TEST: reopen");
                        }

                        mgr.MaybeRefresh();

                        if (VERBOSE)
                        {
                            Console.WriteLine("TEST: reopen done");
                        }
                    }
                    catch (Exception ioe)
                    {
                        throw new Exception(ioe.Message, ioe);
                    }
                }
            }
Beispiel #28
0
            public override void Run()
            {
#if FEATURE_THREAD_PRIORITY
                Priority += 1;
#endif
                try
                {
                    while (!stop.Get())
                    {
                        try
                        {
                            outerInstance.CheckCommonSuggestions(reader);

                            Thread.Sleep(10);// don't starve refresh()'s CPU, which sleeps every 50 bytes for 1 ms
                        }
                        catch (ObjectDisposedException /*e*/)
                        {
                            return;
                        }
                        catch (Exception e)
                        {
                            e.printStackTrace();
                            error = e;
                            return;
                        }
                    }
                }
                finally
                {
                    terminated = true;
                }
            }
Beispiel #29
0
        public int Write(MemoryStream buffer)
        {
            while (_channel == null && _retries < DefaultRetries)
            {
                PreparedChannel();
            }

            var totalBytesWritten = 0;

            if (_channel == null || !_isConnected.Get())
            {
                return(totalBytesWritten);
            }

            try
            {
                while (buffer.HasRemaining())
                {
                    var bytes = new byte[buffer.Length];
                    buffer.Read(bytes, 0, bytes.Length);
                    totalBytesWritten += bytes.Length;
                    _logger.Debug($"{this}: Sending bytes [{bytes.Length}]");
                    _channel?.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, SendCallback, _channel);
                }
            }
            catch (Exception e)
            {
                _logger.Error($"{this}: Write to channel failed because: {e.Message}", e);
                Close();
            }

            return(totalBytesWritten);
        }
Beispiel #30
0
        public void TestCompareAndSet()
        {
            var  b1     = new AtomicBoolean(true);
            bool result = b1.CompareAndSet(true, false);

            Assert.Equal(true, result);
            Assert.Equal(false, b1.Get());

            result = b1.CompareAndSet(true, true);
            Assert.Equal(false, result);
            Assert.Equal(false, b1.Get());

            result = b1.CompareAndSet(false, true);
            Assert.Equal(true, result);
            Assert.Equal(true, b1.Get());
        }