Пример #1
0
        public void GetValueIncrement()
        {
            var provider = GlobalSetup.Container.Resolve <IBlobStorageProvider>();

            provider.CreateContainerIfNotExist(ContainerName);

            var counter = new BlobCounter(provider, ContainerName, BlobName);

            var val = (int)counter.GetValue();

            if (0 != val)
            {
                counter.Delete();
            }

            counter.Increment(10);
            val = (int)counter.GetValue();
            Assert.AreEqual(10, val, "#A00");

            var val2 = counter.Increment(-5);

            val = (int)counter.GetValue();
            Assert.AreEqual(5, val, "#A01");
            Assert.AreEqual(val, val2, "#A02");

            var flag1 = counter.Delete();
            var flag2 = counter.Delete();

            Assert.IsTrue(flag1, "#A03");
            Assert.IsFalse(flag2, "#A04");
        }
Пример #2
0
		public void GetValueIncrement()
		{
			var provider = GlobalSetup.Container.Resolve<IBlobStorageProvider>();
			provider.CreateContainer(ContainerName);

			var counter = new BlobCounter(provider, ContainerName, BlobName);

			var val = (int)counter.GetValue();

			if (0 != val) counter.Delete();

			counter.Increment(10);
			val = (int) counter.GetValue();
			Assert.AreEqual(10, val, "#A00");

			var val2 = counter.Increment(-5);
			val = (int)counter.GetValue();
			Assert.AreEqual(5, val, "#A01");
			Assert.AreEqual(val, val2, "#A02");

			var flag1 = counter.Delete();
			var flag2 = counter.Delete();

			Assert.IsTrue(flag1, "#A03");
			Assert.IsFalse(flag2, "#A04");
		}
Пример #3
0
        public void IncrementMultiThread()
        {
            var provider = GlobalSetup.Container.Resolve <IBlobStorageProvider>();

            provider.CreateContainerIfNotExist(ContainerName);

            //creating thread parameters
            var counter = new BlobCounter(provider, ContainerName, "SomeBlobName");

            counter.Reset(0);

            var       random       = new Random();
            const int threadsCount = 4;
            var       increments   = Range.Array(threadsCount).Select(e => Range.Array(5).Select(i => random.Next(20)).ToArray()).ToArray();

            var localSums = increments.AsParallel().Select(
                e =>
            {
                var c = new BlobCounter(provider, ContainerName, "SomeBlobName");
                foreach (var increment in e)
                {
                    c.Increment(increment);
                }
                return(e.Sum());
            }).ToList();

            Assert.AreEqual(increments.Sum(i => i.Sum()), localSums.Sum(), "Broken invariant.");
            Assert.AreEqual(localSums.Sum(), counter.GetValue(), "Values should be equal, BlobCounter supposed to be thread-safe");
        }
Пример #4
0
        /// <summary>Retrieves the aggregated result of a map/reduce job.</summary>
        /// <typeparam name="T">The type of the result.</typeparam>
        /// <param name="jobName">The name of the job.</param>
        /// <returns>The aggregated result.</returns>
        /// <exception cref="InvalidOperationException">If the is not yet complete.</exception>
        /// <exception cref="ArgumentException">If <paramref name="jobName"/> refers to an inexistent job.</exception>
        public T GetAggregatedResult <T>(string jobName)
        {
            var config = GetJobConfig(jobName);

            if (!config.HasValue)
            {
                throw new ArgumentException("Unknown job", "jobName");
            }

            var counter           = new BlobCounter(_blobStorage, BlobCounterName.Create(jobName));
            int completedBlobsets = (int)counter.GetValue();

            if (completedBlobsets < config.Value.BlobSetCount)
            {
                throw new InvalidOperationException("Job is not complete (there still are blobsets to process)");
            }

            Type mapOut = Type.GetType(config.Value.TMapOutType);

            var    blobName = AggregatedBlobName.Create(jobName);
            string ignored;
            var    aggregatedResult = _blobStorage.GetBlob(blobName.ContainerName, blobName.ToString(), mapOut, out ignored);

            if (!aggregatedResult.HasValue)
            {
                throw new InvalidOperationException("Job is not complete (reduced items must still be aggregated)");
            }

            return((T)aggregatedResult.Value);
        }
Пример #5
0
        /// <summary>Gets the number of completed blobsets of a job.</summary>
        /// <param name="jobName">The name of the job.</param>
        /// <returns>The number of completed blobsets (<c>Tuple.Item1</c>) and the total number of blobsets (<c>Tuple.Item2</c>).</returns>
        /// <exception cref="ArgumentException">If <paramref name="jobName"/> refers to an inexistent job.</exception>
        public System.Tuple <int, int> GetCompletedBlobSets(string jobName)
        {
            var config = GetJobConfig(jobName);

            if (!config.HasValue)
            {
                throw new ArgumentException("Unknown job", "jobName");
            }

            var counter           = new BlobCounter(_blobStorage, BlobCounterName.Create(jobName));
            int completedBlobsets = (int)counter.GetValue();

            return(new System.Tuple <int, int>(completedBlobsets, config.Value.BlobSetCount));
        }
Пример #6
0
		public void IncrementMultiThread()
		{
			var provider = GlobalSetup.Container.Resolve<IBlobStorageProvider>();
			provider.CreateContainer(ContainerName);

			//creating thread parameters
			var count = new BlobCounter(provider, ContainerName, "SomeBlobName");
			count.Reset(0);

			var random = new Random();
			const int threadsCount = 4;
			var increments = Range.Array(threadsCount).Convert(e => Range.Array(5).Convert(i => random.Next(20) - 10));
			var localSums = increments.SelectInParallel(e =>
				{
					var counter = new BlobCounter(provider, ContainerName, "SomeBlobName");
					foreach (var increment in e)
					{
						counter.Increment(increment);
					}
					return e.Sum();
				}, threadsCount);

			Assert.AreEqual(localSums.Sum(), count.GetValue(), "values should be equal, BlobCounter supposed to be thread-safe");
		}