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()); }
public ActorEngine(ActorAffinity affintiy) { if (affintiy == ActorAffinity.LongRunningThread) { Task.Factory.StartNew(() => StartInvokesOnDedicatedThread(), TaskCreationOptions.LongRunning); } else { Task.Factory.StartNew(async() => await StartInvokesOnArbitraryThread()); } }
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); }
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()); }
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); }
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()); }
public ActorInterceptor(T t, ActorAffinity affintiy) { m_T = t; m_ActorEngine = new ActorEngine(affintiy); }
public Actor(ActorAffinity affinity) { m_ActorEngine = new ActorEngine(affinity); }
public async void TestTaskOfT(ActorAffinity affinity) { ITypedThrowing actor = ActorFactory.Create <ITypedThrowing, TypedThrowing>(() => new TypedThrowing(), affinity); await Assert.ThrowsAsync <TypedThrowing.BException>(async() => await actor.B()); }
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); }
public static Actor Create(ActorAffinity affinity) { return(new Actor(affinity)); }