Exemplo n.º 1
0
        public void Do(ActorAffinity affinity)
        {
            int [] providedSequence = { 1, 7, 8, 6, 6, 5, 67 };
            var    sequence         = new List <int>();
            var    r = new Actor(affinity);

            Task.WaitAll(providedSequence.Select(item => r.Do(() => sequence.Add(item))).ToArray());

            Assert.Equal(providedSequence, sequence.ToArray());
        }
Exemplo n.º 2
0
 public ActorEngine(ActorAffinity affintiy)
 {
     if (affintiy == ActorAffinity.LongRunningThread)
     {
         Task.Factory.StartNew(() => StartInvokesOnDedicatedThread(), TaskCreationOptions.LongRunning);
     }
     else
     {
         Task.Factory.StartNew(async() => await StartInvokesOnArbitraryThread());
     }
 }
Exemplo n.º 3
0
        public async void GivenThrowsAlwaysExpectExceptionToBubbleThrough(ActorAffinity affinity)
        {
            var a = new Actor(affinity);

            Task delay    = Task.Delay(10000);
            Task expected = Assert.ThrowsAsync <Exception>(async() => await a.Do(() => Throw()));


            Task result = await Task.WhenAny(delay, expected);

            Assert.Equal(result, expected);
        }
Exemplo n.º 4
0
        public void DoRangeWithRandomSleep(ActorAffinity affinity)
        {
            int []       providedSequence = Enumerable.Range(0, 100).ToArray();
            var          sequence         = new List <int>();
            var          r = new Actor(affinity);
            Action <int> f = (item) => {
                Thread.Sleep(new Random().Next(100));
                sequence.Add(item);
            };

            Task.WaitAll(providedSequence.Select(item => r.Do(() => f(item))).ToArray());
            Assert.Equal(providedSequence, sequence.ToArray());
        }
Exemplo n.º 5
0
        public async Task EnsureOrder(ActorAffinity affinity)
        {
            int [] given = { 1, 4 };
            var    actor = ActorFactory.Create <ITypedSequenceTest, TypedSequenceTestImpl>(() => new TypedSequenceTestImpl(), affinity);

            Task t1 = actor.Add(3000, given[0]);
            Task t2 = actor.Add(1000, given[1]);

            await Task.WhenAll(t1, t2);

            int[] result = await actor.GetElements();

            // after ActoR tasks have been executed the order should be ok
            Assert.Equal(given, result);
        }
Exemplo n.º 6
0
        public void EnsureOrder(ActorAffinity affinity)
        {
            List <int> result = new List <int>();

            int [] given = { 1, 4 };
            var    r     = new Actor(affinity);

            Task t1 = r.Do(() => {
                Thread.Sleep(3000);
                result.Add(given[0]);
            });
            Task t2 = r.Do(() => {
                Thread.Sleep(1000);
                result.Add(given[1]);
            });

            Assert.True(!result.Any()); // since we are pausing all tasks initially we should have 0. This test is however a little insecure

            Task.WaitAll(t1, t2);
            // after ActoR tasks have been executed the order should be ok
            Assert.Equal(given, result.ToArray());
        }
Exemplo n.º 7
0
 public ActorInterceptor(T t, ActorAffinity affintiy)
 {
     m_T           = t;
     m_ActorEngine = new ActorEngine(affintiy);
 }
Exemplo n.º 8
0
 public Actor(ActorAffinity affinity)
 {
     m_ActorEngine = new ActorEngine(affinity);
 }
Exemplo n.º 9
0
 public async void TestTaskOfT(ActorAffinity affinity)
 {
     ITypedThrowing actor = ActorFactory.Create <ITypedThrowing, TypedThrowing>(() => new TypedThrowing(), affinity);
     await Assert.ThrowsAsync <TypedThrowing.BException>(async() => await actor.B());
 }
Exemplo n.º 10
0
        public static TInterface Create <TInterface, TConcrete>(Func <TConcrete> instanceFactory, ActorAffinity affinity)
            where TConcrete : TInterface
            where TInterface : class
        {
            var generator = new ProxyGenerator();

            TInterface proxy = generator.CreateInterfaceProxyWithoutTarget <TInterface>(
                new ActorInterceptor <TConcrete>(instanceFactory(), affinity));

            return(proxy);
        }
Exemplo n.º 11
0
 public static Actor Create(ActorAffinity affinity)
 {
     return(new Actor(affinity));
 }