Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActorPath" /> class.
 /// </summary>
 /// <param name="parentPath"> The parent path. </param>
 /// <param name="name"> The name. </param>
 /// <param name="uid"> The uid. </param>
 protected ActorPath(ActorPath parentPath, string name, long uid)
 {
     Address   = parentPath.Address;
     Uid       = uid;
     Name      = name;
     _elements = new FastLazy <ActorPath, IList <string> >(FillElementsFunc, this);
 }
Beispiel #2
0
 public void Setup()
 {
     lazySafe         = new Lazy <int>(() => 100, LazyThreadSafetyMode.ExecutionAndPublication);
     lazyUnsafe       = new Lazy <int>(() => 100, LazyThreadSafetyMode.None);
     fastLazy         = new FastLazy <int>(() => 100);
     fastLazyWithInit = new FastLazy <int, int>(state => state + 100, 1000);
 }
 public void Setup()
 {
     _fastLazy               = new FastLazy <int>(() => new Random().Next());
     _unsafeLazy             = new Lazy <int>(() => new Random().Next());
     _publishOnlySafeLazy    = new Lazy <int>(() => new Random().Next(), LazyThreadSafetyMode.PublicationOnly);
     _readAndExecuteSafeLazy = new Lazy <int>(() => new Random().Next(), LazyThreadSafetyMode.ExecutionAndPublication);
 }
Beispiel #4
0
        public void FastAtomicLazy_should_produce_value()
        {
            var fal   = new FastLazy <int>(() => 2);
            var value = fal.Value;

            Assert.Equal(2, value);
            Assert.True(fal.IsValueCreated);
        }
Beispiel #5
0
 public void FastAtomicLazy_must_be_threadsafe_AnyRef()
 {
     for (var c = 0; c < 100000; c++) // try this 100000 times
     {
         var values = new ConcurrentBag <string>();
         var fal    = new FastLazy <string>(() => Faker.Generators.Strings.GenerateAlphaNumericString());
         var result = Parallel.For(0, 1000, i => values.Add(fal.Value)); // 1000 concurrent operations
         SpinWait.SpinUntil(() => result.IsCompleted);
         var value = values.First();
         Assert.NotNull(value);
         Assert.True(values.All(x => x.Equals(value)));
     }
 }
Beispiel #6
0
 public void FastAtomicLazy_must_be_threadsafe()
 {
     for (var c = 0; c < 100000; c++) // try this 100000 times
     {
         var values = new ConcurrentBag <int>();
         var fal    = new FastLazy <int>(() => new Random().Next(1, Int32.MaxValue));
         var result = Parallel.For(0, 1000, i => values.Add(fal.Value)); // 1000 concurrent operations
         SpinWait.SpinUntil(() => result.IsCompleted);
         var value = values.First();
         Assert.NotEqual(0, value);
         Assert.True(values.All(x => x.Equals(value)));
     }
 }
Beispiel #7
0
        public MethodInfo this[Type type]
        {
            get
            {
                FastLazy <MethodInfo> result = null;

                if (this.methods.TryGetValue(type, out result))
                {
                    return(result.Value);
                }

                return(null);
            }
        }
Beispiel #8
0
        public DbTableInfo(
            string tableName,
            Type entityType,
            MemberInfo identityField,
            PropertyInfo[] properties,
            IKeyInfo primaryKeyInfo,
            IKeyInfo[] uniqueKeys,
            IKeyInfo[] foreignKeys,
            object[] constraintFactories)
        {
            this.TableName           = tableName;
            this.EntityType          = entityType;
            this.IdentityField       = identityField;
            this.Properties          = properties;
            this.ConstraintFactories = constraintFactories;
            this.PrimaryKeyInfo      = primaryKeyInfo;
            this.UniqueKeys          = uniqueKeys;
            this.ForeignKeys         = foreignKeys;

            this.initializer = new FastLazy <Func <object[], object> >(CreateEntityInitializer);
        }
Beispiel #9
0
        public DbTableInfo(
            string tableName, 
            Type entityType, 
            MemberInfo identityField,
            PropertyInfo[] properties,
            IKeyInfo primaryKeyInfo,
            IKeyInfo[] uniqueKeys,
            IKeyInfo[] foreignKeys,
            object[] constraintFactories)
        {
            this.TableName = tableName;
            this.EntityType = entityType;
            this.IdentityField = identityField;
            this.Properties = properties;
            this.ConstraintFactories = constraintFactories;
            this.PrimaryKeyInfo = primaryKeyInfo;
            this.UniqueKeys = uniqueKeys;
            this.ForeignKeys = foreignKeys;

            this.initializer = new FastLazy<Func<object[], object>>(CreateEntityInitializer);
        }
Beispiel #10
0
        public void FastAtomicLazy_only_single_value_creation_attempt_AnyRef()
        {
            int           attempts         = 0;
            Func <string> slowValueFactory = () =>
            {
                Interlocked.Increment(ref attempts);
                Thread.Sleep(100);
                return(Faker.Generators.Strings.GenerateAlphaNumericString());
            };

            var values = new ConcurrentBag <string>();
            var fal    = new FastLazy <string>(slowValueFactory);
            var result = Parallel.For(0, 1000, i => values.Add(fal.Value)); // 1000 concurrent operations

            SpinWait.SpinUntil(() => result.IsCompleted);
            var value = values.First();

            Assert.NotNull(value);
            Assert.True(values.All(x => x.Equals(value)));
            Assert.Equal(1000, values.Count);
            Assert.Equal(1, attempts);
        }
Beispiel #11
0
        public void FastAtomicLazy_only_single_value_creation_attempt()
        {
            int        attempts         = 0;
            Func <int> slowValueFactory = () =>
            {
                Interlocked.Increment(ref attempts);
                Thread.Sleep(100);
                return(new Random().Next(1, Int32.MaxValue));
            };

            var values = new ConcurrentBag <int>();
            var fal    = new FastLazy <int>(slowValueFactory);
            var result = Parallel.For(0, 1000, i => values.Add(fal.Value)); // 1000 concurrent operations

            SpinWait.SpinUntil(() => result.IsCompleted);
            var value = values.First();

            Assert.NotEqual(0, value);
            Assert.True(values.All(x => x.Equals(value)));
            Assert.Equal(1000, values.Count);
            Assert.Equal(1, attempts);
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Serializer" /> class.
 /// </summary>
 /// <param name="system">The actor system to associate with this serializer. </param>
 protected Serializer(ExtendedActorSystem system)
 {
     this.system = system;
     _value      = new FastLazy <int>(() => SerializerIdentifierHelper.GetSerializerIdentifierFromConfig(GetType(), system));
 }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActorPath" /> class.
 /// </summary>
 /// <param name="address"> The address. </param>
 /// <param name="name"> The name. </param>
 protected ActorPath(Address address, string name)
 {
     Name      = name;
     Address   = address;
     _elements = new FastLazy <ActorPath, IList <string> >(FillElementsFunc, this);
 }
Beispiel #14
0
 public LazyExecutorServiceDelegate(string id, ExecutorServiceFactory executorServiceFactory)
 {
     _id = id;
     _executorServiceFactory = executorServiceFactory;
     _executor = new FastLazy <ExecutorService>(() => executorServiceFactory.Produce(_id));
 }
Beispiel #15
0
 public LazyExecutorServiceDelegate(string id, ExecutorServiceFactory executorServiceFactory)
 {
     _id = id;
     _executorServiceFactory = executorServiceFactory;
     _executor = new FastLazy<ExecutorService>(() => executorServiceFactory.Produce(_id));
 }
Beispiel #16
0
        /// <summary>
        /// Prevents a default instance of the <see cref="LinqMethodProvider" /> class from
        /// being created.
        /// </summary>
        private LinqMethodProvider()
        {
            this.select     = CreateLazy(CreateSelect);
            this.selectMany = CreateLazy(CreateSelectMany);
            this.selectManyWithResultSelector = CreateLazy(CreateSelectManyWithResultSelector);

            this.count   = CreateLazy(CreateCount);
            this.where   = CreateLazy(CreateWhere);
            this.take    = CreateLazy(CreateTake);
            this.skip    = CreateLazy(CreateSkip);
            this.groupBy = CreateLazy(CreateGroupBy);

            this.orderBy           = CreateLazy(CreateOrderBy);
            this.orderByDescending = CreateLazy(CreateOrderByDescending);
            this.thenBy            = CreateLazy(CreateThenBy);
            this.thenByDescending  = CreateLazy(CreateThenByDescending);

            this.first          = CreateLazy(CreateFirst);
            this.firstOrDefault = CreateLazy(CreateFirstOrDefault);
            this.any            = CreateLazy(CreateAny);
            this.defaultIfEmpty = CreateLazy(CreateDefaultIfEmpty);
            this.asQueryable    = CreateLazy(CreateAsQueryable);

            this.distinct  = CreateLazy(CreateDistinct);
            this.except    = CreateLazy(CreateExcept);
            this.intersect = CreateLazy(CreateIntersect);
            this.union     = CreateLazy(CreateUnion);
            this.concat    = CreateLazy(CreateConcat);

            this.sum = new MethodInfoGroup(
                Tuple.Create(typeof(int), CreateLazy(CreateSumInt)),
                Tuple.Create(typeof(int?), CreateLazy(CreateSumNInt)),
                Tuple.Create(typeof(long), CreateLazy(CreateSumLong)),
                Tuple.Create(typeof(long?), CreateLazy(CreateSumNLong)),
                Tuple.Create(typeof(float), CreateLazy(CreateSumFloat)),
                Tuple.Create(typeof(float?), CreateLazy(CreateSumNFloat)),
                Tuple.Create(typeof(double), CreateLazy(CreateSumDouble)),
                Tuple.Create(typeof(double?), CreateLazy(CreateSumNDouble)),
                Tuple.Create(typeof(decimal), CreateLazy(CreateSumDecimal)),
                Tuple.Create(typeof(decimal?), CreateLazy(CreateSumNDecimal)));

            this.min = new MethodInfoGroup(
                Tuple.Create(typeof(int), CreateLazy(CreateMinInt)),
                Tuple.Create(typeof(int?), CreateLazy(CreateMinNInt)),
                Tuple.Create(typeof(long), CreateLazy(CreateMinLong)),
                Tuple.Create(typeof(long?), CreateLazy(CreateMinNLong)),
                Tuple.Create(typeof(float), CreateLazy(CreateMinFloat)),
                Tuple.Create(typeof(float?), CreateLazy(CreateMinNFloat)),
                Tuple.Create(typeof(double), CreateLazy(CreateMinDouble)),
                Tuple.Create(typeof(double?), CreateLazy(CreateMinNDouble)),
                Tuple.Create(typeof(decimal), CreateLazy(CreateMinDecimal)),
                Tuple.Create(typeof(decimal?), CreateLazy(CreateMinNDecimal)));

            this.max = new MethodInfoGroup(
                Tuple.Create(typeof(int), CreateLazy(CreateMaxInt)),
                Tuple.Create(typeof(int?), CreateLazy(CreateMaxNInt)),
                Tuple.Create(typeof(long), CreateLazy(CreateMaxLong)),
                Tuple.Create(typeof(long?), CreateLazy(CreateMaxNLong)),
                Tuple.Create(typeof(float), CreateLazy(CreateMaxFloat)),
                Tuple.Create(typeof(float?), CreateLazy(CreateMaxNFloat)),
                Tuple.Create(typeof(double), CreateLazy(CreateMaxDouble)),
                Tuple.Create(typeof(double?), CreateLazy(CreateMaxNDouble)),
                Tuple.Create(typeof(decimal), CreateLazy(CreateMaxDecimal)),
                Tuple.Create(typeof(decimal?), CreateLazy(CreateMaxNDecimal)));

            this.average = new MethodInfoGroup(
                Tuple.Create(typeof(int), CreateLazy(CreateAvgInt)),
                Tuple.Create(typeof(int?), CreateLazy(CreateAvgNInt)),
                Tuple.Create(typeof(long), CreateLazy(CreateAvgLong)),
                Tuple.Create(typeof(long?), CreateLazy(CreateAvgNLong)),
                Tuple.Create(typeof(float), CreateLazy(CreateAvgFloat)),
                Tuple.Create(typeof(float?), CreateLazy(CreateAvgNFloat)),
                Tuple.Create(typeof(double), CreateLazy(CreateAvgDouble)),
                Tuple.Create(typeof(double?), CreateLazy(CreateAvgNDouble)),
                Tuple.Create(typeof(decimal), CreateLazy(CreateAvgDecimal)),
                Tuple.Create(typeof(decimal?), CreateLazy(CreateAvgNDecimal)));

            this.minGeneric     = CreateLazy(CreateMinGeneric);
            this.maxGeneric     = CreateLazy(CreateMaxGeneric);
            this.averageGeneric = CreateLazy(CreateAvgGeneric);
        }
Beispiel #17
0
        public void FastAtomicLazy_should_indicate_no_value_has_been_produced()
        {
            var fal = new FastLazy <int>(() => 2);

            Assert.False(fal.IsValueCreated);
        }