public void ReceptorOfInterfaceTypCalled() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane>(new InterfaceTestReceptor()); sp.ProcessInstance <TestMembrane, InterfaceTestSemanticType>(true); Assert.That(callSuccess, "Expected TestReceptor.Process to be called."); }
public void ReceptorReceivesSemanticTypeOnItsMembrane() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane>(new TestReceptor()); sp.ProcessInstance <TestMembrane, TestSemanticType>(true); Assert.That(callSuccess, "Expected TestReceptor.Process to be called."); }
public void InitializerCalledForSemanticTypeConstruction() { bool initializerCalled = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane, TestReceptor>(); sp.ProcessInstance <TestMembrane, TestSemanticType>((t) => initializerCalled = true, true); Assert.That(initializerCalled, "Expected semantic type initializer to be called."); }
public void BaseClassProcessCalled() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane>(new DerivedTestReceptor()); sp.ProcessInstance <TestMembrane, TestSemanticType>(true); Assert.That(callSuccess, "Expected TestReceptor.Process to be called."); }
public void ReceptorDoesNotReceiveSemanticTypeOnAnotherMembrane() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane>(new TestReceptor()); sp.ProcessInstance <TestMembrane2, TestSemanticType>(true); Assert.That(!callSuccess, "Expected TestReceptor.Process to NOT be called."); }
//public static T Cast<T>(object o) //{ // return (T)o; //} static void Main(string[] args) { SemanticProcessor sp = new SemanticProcessor(); // AnotherType gets notified when instances of OneType are added to the pool. sp.Register <SurfaceMembrane, AReceptor>(); // auto register sp.Register <SurfaceMembrane, BReceptor>(); sp.Register <SurfaceMembrane, CReceptor>(); // Explicit register //sp.TypeNotify<AReceptor, OneType>(); //sp.TypeNotify<AReceptor, SecondType>(); OneType t1 = new OneType(); SecondType t2 = new SecondType(); SecondDerivedType t3 = new SecondDerivedType(); // object foo = Cast<SecondType>(t3); sp.ProcessInstance(sp.Surface, t1); sp.ProcessInstance(sp.Surface, t2); sp.ProcessInstance(sp.Surface, t3); Thread.Sleep(1000); // Wait for threaded processes to complete. Console.WriteLine("\r\nChained processing..."); sp.RemoveTypeNotify <SurfaceMembrane, AReceptor, IOneType>(); sp.RemoveTypeNotify <SurfaceMembrane, AReceptor, SecondType>(); sp.RemoveTypeNotify <SurfaceMembrane, BReceptor, OneType>(); sp.RemoveTypeNotify <SurfaceMembrane, CReceptor, SecondDerivedType>(); // Chaining... // auto register: sp.Register <SurfaceMembrane, Chain1>(); sp.Register <SurfaceMembrane, Chain2>(); // Explicit register: //sp.TypeNotify<Chain1, OneType>(); //sp.TypeNotify<Chain2, SecondType>(); sp.ProcessInstance(sp.Surface, new OneType()); Thread.Sleep(1000); // Wait for threaded processes to complete. }
public void ProcessCallIsLogged() { stLogged = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register<LoggerMembrane, LoggerReceptor>(); sp.Register<LoggerMembrane, ExceptionReceptor>(); sp.Register<TestMembrane, TestReceptor>(); sp.ProcessInstance<TestMembrane, TestSemanticType>(true); Assert.That(stLogged, "Expected Process call to be logged."); }
public void ExceptionIsLogged() { exLogged = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register<LoggerMembrane, LoggerReceptor>(); sp.Register<LoggerMembrane, ExceptionReceptor>(); sp.Register<TestMembrane, TestReceptor>(); sp.ProcessInstance<TestMembrane, TypeThrowsException>(true); Assert.That(exLogged, "Expected Exception call to be logged."); }
public void RemoveType() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane, TestReceptor>(); sp.RemoveTypeNotify <TestMembrane, TestReceptor, TestSemanticType>(); sp.ProcessInstance <TestMembrane, TestSemanticType>(true); Assert.That(!callSuccess, "Expected TestReceptor.Process to NOT be called."); }
public void DistributedComputation() { SemanticProcessor spOut = new SemanticProcessor(); SemanticProcessor spIn = new SemanticProcessor(); received = ""; OutboundDistributedComputingReceptor dcrOut = new OutboundDistributedComputingReceptor(4002); InboundDistributedComputingReceptor dcrIn = new InboundDistributedComputingReceptor(4002, spIn); // Create an "emitter" in which a semantic type emitted on the TestMembrane permeates // into the inner DistributedProcessMembrane for our test type. spOut.AddChild <TestMembrane, DistributedProcessMembrane>(); spOut.OutboundPermeableTo <TestMembrane, TestDistributedSemanticType>(); spOut.InboundPermeableTo <DistributedProcessMembrane, TestDistributedSemanticType>(); // The stateful DCR out lives in the distributed process membrane. spOut.Register <DistributedProcessMembrane>(dcrOut); // Create a "receiver" in which a semantic type is received on the inner DistributedProcessMembrane // and the test type permeates out to a "handler" receptor. spIn.AddChild <TestMembrane, DistributedProcessMembrane>(); spIn.OutboundPermeableTo <DistributedProcessMembrane, TestDistributedSemanticType>(); spIn.InboundPermeableTo <TestMembrane, TestDistributedSemanticType>(); // The stateful DCR in lives in the distributed process membrane. spIn.Register <DistributedProcessMembrane>(dcrIn); // The responding receptor lives in the TestMembrane spIn.Register <TestMembrane, TestReceptor>(); // Put a semantic type instance on the outbound side. spOut.ProcessInstance <TestMembrane, TestDistributedSemanticType>((t) => { t.Message = "Hello World"; }); // Wait a bit for threads to do their thing and Http posts to do their things. // System.Diagnostics.Debug.WriteLine("Waiting..."); // !*!*!*!* Sometimes this wait must be longer -- the unit test engine can really slow things down. // !*!*!*!* This is particularly true when running the test in the debugger! // !*!*!*!* If this delay isn't long enough for the server's message to be processed, you will get // !*!*!*!* errors related to accessing objects on an unloaded AppDomain. // !*!*!*!* In real life this woudn't happen -- this is an artifact of unit testing a complex // !*!*!*!* multi-threaded process. //Thread.Sleep(500); // Because we know it works, we could actually do this, which is particularly useful when we're // debugging and single stepping through code -- we do not want the test in this AppDomain // to exit prematurely! while (String.IsNullOrEmpty(received)) { Thread.Sleep(0); } Assert.That(received == "Hello World", "Expected to receive 'Hello World'"); }
public void DistributedComputation() { SemanticProcessor spOut = new SemanticProcessor(); SemanticProcessor spIn = new SemanticProcessor(); received = ""; OutboundDistributedComputingReceptor dcrOut = new OutboundDistributedComputingReceptor(4002); InboundDistributedComputingReceptor dcrIn = new InboundDistributedComputingReceptor(4002, spIn); // Create an "emitter" in which a semantic type emitted on the TestMembrane permeates // into the inner DistributedProcessMembrane for our test type. spOut.AddChild<TestMembrane, DistributedProcessMembrane>(); spOut.OutboundPermeableTo<TestMembrane, TestDistributedSemanticType>(); spOut.InboundPermeableTo<DistributedProcessMembrane, TestDistributedSemanticType>(); // The stateful DCR out lives in the distributed process membrane. spOut.Register<DistributedProcessMembrane>(dcrOut); // Create a "receiver" in which a semantic type is received on the inner DistributedProcessMembrane // and the test type permeates out to a "handler" receptor. spIn.AddChild<TestMembrane, DistributedProcessMembrane>(); spIn.OutboundPermeableTo<DistributedProcessMembrane, TestDistributedSemanticType>(); spIn.InboundPermeableTo<TestMembrane, TestDistributedSemanticType>(); // The stateful DCR in lives in the distributed process membrane. spIn.Register<DistributedProcessMembrane>(dcrIn); // The responding receptor lives in the TestMembrane spIn.Register<TestMembrane, TestReceptor>(); // Put a semantic type instance on the outbound side. spOut.ProcessInstance<TestMembrane, TestDistributedSemanticType>((t) => { t.Message = "Hello World"; }); // Wait a bit for threads to do their thing and Http posts to do their things. // System.Diagnostics.Debug.WriteLine("Waiting..."); // !*!*!*!* Sometimes this wait must be longer -- the unit test engine can really slow things down. // !*!*!*!* This is particularly true when running the test in the debugger! // !*!*!*!* If this delay isn't long enough for the server's message to be processed, you will get // !*!*!*!* errors related to accessing objects on an unloaded AppDomain. // !*!*!*!* In real life this woudn't happen -- this is an artifact of unit testing a complex // !*!*!*!* multi-threaded process. //Thread.Sleep(500); // Because we know it works, we could actually do this, which is particularly useful when we're // debugging and single stepping through code -- we do not want the test in this AppDomain // to exit prematurely! while (String.IsNullOrEmpty(received)) { Thread.Sleep(0); } Assert.That(received == "Hello World", "Expected to receive 'Hello World'"); }
public void ProcessCallIsLogged() { stLogged = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <LoggerMembrane, LoggerReceptor>(); sp.Register <LoggerMembrane, ExceptionReceptor>(); sp.Register <TestMembrane, TestReceptor>(); sp.ProcessInstance <TestMembrane, TestSemanticType>(true); Assert.That(stLogged, "Expected Process call to be logged."); }
public void ReceptorInstanceCreateDestroy() { SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane>(new TestReceptor()); constructorCalled = false; disposeCalled = false; sp.ProcessInstance <TestMembrane, TestSemanticType>(true); Assert.That(!constructorCalled, "Expected constructor NOT to be called."); Assert.That(!disposeCalled, "Expected Dispose NOT to be called."); }
public void ReceptorTypeCreateDestroy() { constructorCalled = false; disposeCalled = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane, TestReceptor>(); sp.ProcessInstance <TestMembrane, TestSemanticType>(true); Assert.That(constructorCalled, "Expected constructor to be called."); Assert.That(disposeCalled, "Expected Dispose to be called."); }
public void NotPermeableOut() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); // sp.OutboundPermeableTo<InnerMembrane, TestSemanticType>(); sp.InboundPermeableTo<OuterMembrane, TestSemanticType>(); sp.AddChild<OuterMembrane, InnerMembrane>(); sp.Register<OuterMembrane, TestReceptor>(); sp.ProcessInstance<InnerMembrane, TestSemanticType>(true); Assert.That(!callSuccess, "Expected receptor in outer membrane to NOT receive the ST placed in the inner membrane."); }
public void ExceptionIsLogged() { exLogged = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <LoggerMembrane, LoggerReceptor>(); sp.Register <LoggerMembrane, ExceptionReceptor>(); sp.Register <TestMembrane, TestReceptor>(); sp.ProcessInstance <TestMembrane, TypeThrowsException>(true); Assert.That(exLogged, "Expected Exception call to be logged."); }
public void MultipleProcessCalls() { callSuccess = false; callSuccess2 = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane>(new TestReceptor()); sp.Register <TestMembrane>(new TestReceptor2()); sp.ProcessInstance <TestMembrane, TestSemanticType>(true); Assert.That(callSuccess, "Expected TestReceptor.Process to be called."); Assert.That(callSuccess2, "Expected TestReceptor2.Process to be called."); }
public void ComplexTypePropertyProcessing() { simpleTypeProcessed = false; complexTypeProcessed = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane, ComplexReceptor>(); sp.Register <TestMembrane, SimpleReceptor>(); sp.ProcessInstance <TestMembrane, ComplexType>(true); Assert.That(complexTypeProcessed, "Expected ComplexReceptor.Process to be called."); Assert.That(simpleTypeProcessed, "Expected SimpleReceptor.Process to be called."); }
public void TypePermeatesIn() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); sp.OutboundPermeableTo <OuterMembrane, TestSemanticType>(); sp.InboundPermeableTo <InnerMembrane, TestSemanticType>(); sp.AddChild <OuterMembrane, InnerMembrane>(); sp.Register <InnerMembrane, TestReceptor>(); sp.ProcessInstance <OuterMembrane, TestSemanticType>(true); Assert.That(callSuccess, "Expected receptor in inner membrane to process the ST placed in the outer membrane."); }
public void NotPermeableOut() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); // sp.OutboundPermeableTo<InnerMembrane, TestSemanticType>(); sp.InboundPermeableTo <OuterMembrane, TestSemanticType>(); sp.AddChild <OuterMembrane, InnerMembrane>(); sp.Register <OuterMembrane, TestReceptor>(); sp.ProcessInstance <InnerMembrane, TestSemanticType>(true); Assert.That(!callSuccess, "Expected receptor in outer membrane to NOT receive the ST placed in the inner membrane."); }
public void ReceptorInitialization() { receptorInitializerCalled = false; SemanticProcessor sp = new SemanticProcessor(); sp.Register <TestMembrane, TestReceptor>((ir) => { // Unfortunately, a cast is required, because ir is type declared as IReceptor // and I don't think it's possible to fix that because of the late callback. TestReceptor r = (TestReceptor)ir; r.AFlag = true; receptorInitializerCalled = true; }); sp.ProcessInstance <TestMembrane, TestSemanticType>(true); Assert.That(receptorInitializerCalled, "Expected TestReceptor initializer to be called to be called."); }
protected ResponsePacket ProcessInboundSemanticType(Session session, Dictionary <string, object> parms) { string json = parms["Data"].ToString(); JObject jobj = JObject.Parse(json); string type = jobj["_type_"].ToString(); // strip off the _type_ so we can then instantiate the semantic type. json = "{" + json.RightOf(','); // Requires that the namespace also matches the remote's namespace. Type ttarget = Type.GetType(type); ISemanticType target = (ISemanticType)Activator.CreateInstance(ttarget); JsonConvert.PopulateObject(json, target); sp.ProcessInstance <DistributedProcessMembrane>(target); ResponsePacket ret = new ResponsePacket() { Data = Encoding.UTF8.GetBytes("OK"), ContentType = "text" }; return(ret); }
public void TypePermeatesAcross() { callSuccess = false; SemanticProcessor sp = new SemanticProcessor(); sp.OutboundPermeableTo<InnerMembrane, TestSemanticType>(); sp.InboundPermeableTo<OuterMembrane, TestSemanticType>(); sp.OutboundPermeableTo<OuterMembrane, TestSemanticType>(); sp.InboundPermeableTo<InnerMembrane2, TestSemanticType>(); sp.AddChild<OuterMembrane, InnerMembrane>(); sp.AddChild<OuterMembrane, InnerMembrane2>(); sp.Register<InnerMembrane2, TestReceptor>(); sp.ProcessInstance<InnerMembrane, TestSemanticType>(true); Assert.That(callSuccess, "Expected receptor in inner membrane to process the ST placed in the adjacent inner membrane."); }
public void Publish(string _, object st) { sp.ProcessInstance(membrane, (ISemanticType)st, true); }
public void Publish(ISemanticType st) { sp.ProcessInstance <HopeMembrane>(st); }