コード例 #1
0
        public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsEqualToZero()
        {
            var options = new RavenStorageOptions();

            Assert.Throws <ArgumentException>(
                () => options.QueuePollInterval = TimeSpan.Zero);
        }
コード例 #2
0
        public RavenDistributedLock(RavenStorage storage, string resource, TimeSpan timeout, RavenStorageOptions options)
        {
            storage.ThrowIfNull("storage");
            if (string.IsNullOrEmpty(resource))
            {
                throw new ArgumentNullException(nameof(resource));
            }
            if (timeout.TotalSeconds > int.MaxValue)
            {
                throw new ArgumentException($"The timeout specified is too large. Please supply a timeout equal to or less than {int.MaxValue} seconds", nameof(timeout));
            }
            options.ThrowIfNull("options");

            _storage  = storage;
            _resource = resource;
            _options  = options;

            if (!AcquiredLocks.Value.ContainsKey(_resource) || AcquiredLocks.Value[_resource] == 0)
            {
                Acquire(timeout);
                AcquiredLocks.Value[_resource] = 1;
                StartHeartBeat();
            }
            else
            {
                AcquiredLocks.Value[_resource]++;
            }
        }
コード例 #3
0
        public void Set_DistributedLockLifetime_ShouldThrowAnException_WhenGivenValueIsNegative()
        {
            var options = new RavenStorageOptions();

            Assert.Throws <ArgumentException>(
                () => options.DistributedLockLifetime = TimeSpan.FromSeconds(-1));
        }
コード例 #4
0
        public RavenDistributedLock([NotNull] RavenStorage storage, [NotNull] string resource, TimeSpan timeout, RavenStorageOptions options)
        {
            storage.ThrowIfNull("storage");
            resource.ThrowIfNull("resource");

            if ((timeout.TotalSeconds + CommandTimeoutAdditionSeconds) > int.MaxValue)
            {
                throw new ArgumentException(string.Format("The timeout specified is too large. Please supply a timeout equal to or less than {0} seconds",
                                                          int.MaxValue - CommandTimeoutAdditionSeconds),
                                            "timeout");
            }

            _storage  = storage;
            _resource = resource;
            _options  = options;

            if (!AcquiredLocks.Value.ContainsKey(_resource))
            {
                Acquire(_resource, timeout);
                AcquiredLocks.Value[_resource] = 1;
            }
            else
            {
                AcquiredLocks.Value[_resource]++;
            }
        }
コード例 #5
0
        public RavenConnection(RavenStorage ravenStorage)
        {
            ravenStorage.ThrowIfNull("RavenStorage");

            _storage = ravenStorage;
            _options = new RavenStorageOptions();
        }
コード例 #6
0
        public void Set_DistributedLockLifetime_ShouldThrowAnException_WhenGivenValueIsEqualToZero()
        {
            var options = new RavenStorageOptions();

            Assert.Throws <ArgumentException>(
                () => options.DistributedLockLifetime = TimeSpan.Zero);
        }
コード例 #7
0
        public void Set_QueuePollInterval_ShouldThrowAnException_WhenGivenIntervalIsNegative()
        {
            var options = new RavenStorageOptions();

            Assert.Throws <ArgumentException>(
                () => options.QueuePollInterval = TimeSpan.FromSeconds(-1));
        }
コード例 #8
0
        public RavenJobQueueProvider([NotNull] RavenStorage storage, [NotNull] RavenStorageOptions options)
        {
            storage.ThrowIfNull("storage");
            options.ThrowIfNull("options");

            _jobQueue      = new RavenJobQueue(storage, options);
            _monitoringApi = new RavenJobQueueMonitoringApi(storage);
        }
コード例 #9
0
        public RavenJobQueue([NotNull] RavenStorage storage, RavenStorageOptions options)
        {
            storage.ThrowIfNull("storage");
            options.ThrowIfNull("options");

            _storage = storage;
            _options = options;
        }
コード例 #10
0
        public RavenConnection(RavenStorage ravenStorage, RavenStorageOptions options)
            : this(ravenStorage)
        {
            options.ThrowIfNull("options");

            _storage = ravenStorage;
            _options = options;
        }
コード例 #11
0
        public void Set_DistributedLockLifetime_SetsTheValue()
        {
            var options = new RavenStorageOptions
            {
                DistributedLockLifetime = TimeSpan.FromSeconds(1)
            };

            Assert.Equal(TimeSpan.FromSeconds(1), options.DistributedLockLifetime);
        }
コード例 #12
0
        public void Set_QueuePollInterval_SetsTheValue()
        {
            var options = new RavenStorageOptions
            {
                QueuePollInterval = TimeSpan.FromSeconds(1)
            };

            Assert.Equal(TimeSpan.FromSeconds(1), options.QueuePollInterval);
        }
コード例 #13
0
        public void Ctor_SetsTheDefaultOptions_ShouldGenerateUniqueClientId()
        {
            var options1 = new RavenStorageOptions();
            var options2 = new RavenStorageOptions();
            var options3 = new RavenStorageOptions();

            IEnumerable <string> result = new[] { options1.ClientId, options2.ClientId, options3.ClientId }.Distinct();

            Assert.Equal(3, result.Count());
        }
コード例 #14
0
        public RavenJobQueue([NotNull] RavenStorage storage, RavenStorageOptions options)
        {
            storage.ThrowIfNull("storage");
            options.ThrowIfNull("options");

            _storage = storage;
            _options = options;
            _queue   = new Dictionary <string, BlockingCollection <JobQueue> >();

            using (var session = _storage.Repository.OpenSession())
            {
                // -- Queue listening
                if (options.QueueNames == null)
                {
                    throw new ArgumentNullException("options.QueueNames", "You should define a set of QueueNames.");
                }

                var config = session.Load <RavenJobQueueConfig>("Config/RavenJobQueue")
                             ?? new RavenJobQueueConfig();

                foreach (var queue in options.QueueNames)
                {
                    Console.WriteLine($"Starting on queue: {queue}");

                    // Creating queue
                    _queue.Add(queue, new BlockingCollection <JobQueue>());

                    // Create subscription (if not already exist)
                    if (!config.Subscriptions.ContainsKey(queue))
                    {
                        config.Subscriptions[queue] = _storage.Repository
                                                      .Subscriptions()
                                                      .Create <JobQueue>(new SubscriptionCriteria <JobQueue>()
                        {
                            KeyStartsWith   = $"{Repository.GetId(typeof(JobQueue), queue)}/",
                            PropertiesMatch = new Dictionary <Expression <Func <JobQueue, object> >, RavenJToken>()
                            {
                                { x => x.FetchedAt, RavenJToken.FromObject(null) }
                            }
                        });
                    }

                    // Open subscription
                    var subscription = _storage.Repository.Subscriptions().Open <JobQueue>(
                        config.Subscriptions[queue],
                        new SubscriptionConnectionOptions()
                    {
                        IgnoreSubscribersErrors = false,
                        Strategy = SubscriptionOpeningStrategy.ForceAndKeep
                    });

                    // Subscribe to it
                    subscription.Subscribe(new RepositoryObserver <JobQueue>(a =>
                    {
                        Console.WriteLine(a.Id);
                        _queue[queue].Add(a);
                    }));
                }

                session.Store(config);
                session.SaveChanges();
            }
        }
コード例 #15
0
        public void Ctor_SetsTheDefaultOptions_ShouldGenerateClientId()
        {
            var options = new RavenStorageOptions();

            Assert.False(String.IsNullOrWhiteSpace(options.ClientId));
        }
コード例 #16
0
        public void Ctor_SetsTheDefaultOptions()
        {
            RavenStorageOptions options = new RavenStorageOptions();

            Assert.True(options.InvisibilityTimeout > TimeSpan.Zero);
        }
コード例 #17
0
        public static IGlobalConfiguration <RavenStorage> UseEmbeddedRavenStorage(this IGlobalConfiguration configuration, RavenStorageOptions options)
        {
            configuration.ThrowIfNull("configuration");
            options.ThrowIfNull("options");

            Repository.Embedded = true;

            var storage = new RavenStorage(options);

            return(configuration.UseStorage(storage));
        }
コード例 #18
0
        public static IGlobalConfiguration <RavenStorage> UseRavenStorage(this IGlobalConfiguration configuration, string connectionUrl, string database, RavenStorageOptions options)
        {
            configuration.ThrowIfNull("configuration");
            connectionUrl.ThrowIfNull("connectionUrl");
            database.ThrowIfNull("database");
            options.ThrowIfNull("options");

            if (!connectionUrl.StartsWith("http"))
            {
                throw new ArgumentException("Connection Url must begin with http or https!");
            }

            Repository.ConnectionUrl   = connectionUrl;
            Repository.DefaultDatabase = database;

            var storage = new RavenStorage(options);

            return(configuration.UseStorage(storage));
        }