コード例 #1
0
 private Task <SemaphoreSlimSignalable.SemaphoreWaitResult>[] CreateWaitTasks(
     SemaphoreSlimSignalable semaphore,
     bool async,
     bool isSignaledWait,
     int threadsCount,
     TimeSpan timeout,
     CancellationToken cancellationToken = default) =>
 async?
 TasksUtils.CreateTasks(threadsCount, _ => isSignaledWait?semaphore.WaitSignaledAsync(timeout, cancellationToken) : semaphore.WaitAsync(timeout, cancellationToken)) :
     TasksUtils.CreateTasksOnOwnThread(threadsCount, _ => isSignaledWait ? semaphore.WaitSignaled(timeout, cancellationToken) : semaphore.Wait(timeout, cancellationToken));
コード例 #2
0
        public async Task Ensure_server_session_are_allocated_only_on_connection_checkout()
        {
            var eventCapturer = new EventCapturer()
                                .Capture <ConnectionPoolCheckedOutConnectionEvent>()
                                .Capture <CommandStartedEvent>();

            using var client = DriverTestConfiguration.CreateDisposableClient(
                      (MongoClientSettings settings) =>
            {
                settings.MaxConnectionPoolSize = 1;
                settings.ClusterConfigurator   = c => c.Subscribe(eventCapturer);
            },
                      logger: null);

            var database = client.GetDatabase("test");

            var collection = database.GetCollection <BsonDocument>("inventory");

            database.DropCollection("inventory");

            collection.InsertOne(new BsonDocument("x", 0));

            var serverSessionPool  = (CoreServerSessionPool)Reflector.GetFieldValue(client.Cluster, "_serverSessionPool");
            var serverSessionsList = (List <ICoreServerSession>)Reflector.GetFieldValue(serverSessionPool, "_pool");

            var serverSession = serverSessionsList.Single();

            eventCapturer.Clear();

            var eventsTask = eventCapturer.NotifyWhen(events =>
            {
                var connectionCheckedOutEvent = events.OfType <ConnectionPoolCheckedOutConnectionEvent>().FirstOrDefault();
                var commandStartedEvent       = events.OfType <CommandStartedEvent>().FirstOrDefault();

                if (commandStartedEvent.ConnectionId != null)
                {
                    serverSessionsList.Count.Should().Be(0);
                    commandStartedEvent.Command["lsid"].Should().Be(serverSession.Id);

                    return(true);
                }
                else if (connectionCheckedOutEvent.ConnectionId != null)
                {
                    serverSessionsList.Single().Should().Be(serverSession);
                }

                return(false);
            });

            collection.InsertOne(new BsonDocument("x", 1));
            await TasksUtils.WithTimeout(eventsTask, 1000);
        }
コード例 #3
0
        public Task Route(EnvelopeFromClient envelope)
        {
            var delivery = _state.GetEnvelopes(envelope)
                           .Select(d =>
            {
                var transporter = _config.Transporters.GetTransporter(d.To);
                if (transporter == null)
                {
                    this.LogError($"There is no transporter defined for {d.To}");
                    return(TasksUtils.EmptyTask());
                }
                return(Send(transporter, d));
            }).ToArray();

            return(Task.WhenAll(delivery));
        }
コード例 #4
0
        public static T GetBlocking <T>(Func <T> factory, int retries = 10, int sleep = 100) where T : class
        {
            T   data;
            var i = 0;

            do
            {
                data = factory();
                if (data != null)
                {
                    break;
                }
                i++;
                TasksUtils.Sleep(null, TimeSpan.FromMilliseconds(100));
            } while (i < retries);
            return(data);
        }
コード例 #5
0
 // private methods
 private void AssignTask(Action action)
 {
     if (_testState.Tasks.ContainsKey(_name))
     {
         var taskAction = _testState.Tasks[_name];
         if (taskAction != null)
         {
             throw new Exception($"Task {_name} must not be processed.");
         }
         else
         {
             // We don't think this custom scheduler is necessary but we think it may have solved some test failures for reasons we don't understand
             // so we are leaving it in for now with a TODO to either remove this custom scheduler or actually understand what is going on
             _testState.Tasks[_name] = TasksUtils.CreateTaskOnOwnThread(action);
         }
     }
     else
     {
         throw new ArgumentException($"Task {_name} must be started before usage.");
     }
 }
コード例 #6
0
 public Task SendMessages(EnvelopeFromClient envelope) => TasksUtils.EmptyTask();
コード例 #7
0
ファイル: NullStorage.cs プロジェクト: DomainBus/DomainBus
 public Task Add(string queueId, IEnumerable <IMessage> items)
 => TasksUtils.EmptyTask();