public void TestPersistentCall() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; persistComm.RegisterPersistentMethod <IMyLocalService>(nameof(IMyLocalService.RandomMethod)); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); InvokeMethodInfo mInfo = new InvokeMethodInfo(typeof(IMyLocalService), nameof(IMyLocalService.RandomMethod)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); persistComm.InvokeMethod(this, mInfo, session, new object[0]); // 1. not connected call persistComm.InvokeMethod(this, mInfo, session, new object[0]); // 2. not connected call dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed Thread.Sleep(500); Assert.Equal(2, dummyCom.InvokeCounter); }
private void BuildInvokeMethodInfo(string invokeMethodName) { InvokeMethodInfo = JobClassType.GetMethod(invokeMethodName); if (InvokeMethodInfo == null) { throw new SchedulerInitializationException($"Method {invokeMethodName} not found in class {JobClassType.Name}"); } var methodParameters = InvokeMethodInfo.GetParameters(); if (!methodParameters.Any()) { InvokeMethodParameterType = InvokeMethodParameterType.Parameterless; return; } if (methodParameters[0].ParameterType == typeof(string)) { InvokeMethodParameterType = InvokeMethodParameterType.AppName; } if (methodParameters[0].ParameterType == typeof(IJobArgs)) { InvokeMethodParameterType = InvokeMethodParameterType.Args; } }
private InvokeMethodInfo BuildInvokeMethod(BuildMethod method, List <TypeSignature> genericArguments) { var invokeMethodInfo = new InvokeMethodInfo(); int argumentCount = method.Parameters.Count + 1; if (method.HasThis) { argumentCount++; } var arguments = new TypeSignature[argumentCount]; var parameterFlags = new int[argumentCount]; // Arguments { int index = 0; if (method.HasThis) { arguments[index++] = new GenericParameterType(true, 0); genericArguments.Add(TypeReference.GetPrimitiveType(PrimitiveTypeCode.Object, _module.Assembly)); } var parameters = method.Parameters; for (int i = 0; i < parameters.Count; i++) { var parameter = parameters[i]; arguments[index] = BuildType(parameter.Type, genericArguments); parameterFlags[index] = GetParameterFlags(parameter); index++; } // index : [mscorlib]System.Int32 arguments[index++] = TypeReference.GetPrimitiveType(PrimitiveTypeCode.Int32, _module.Assembly); } var returnType = BuildType(method.ReturnType.Type, genericArguments); invokeMethodInfo.CallSite = new CallSite( false, false, MethodCallingConvention.Default, returnType, arguments, -1, genericArguments.Count); invokeMethodInfo.ParameterFlags = parameterFlags; invokeMethodInfo.GenericParameterCount = genericArguments.Count; return(invokeMethodInfo); }
public void TestMethodGetExplicitInterfaceMethodImplementation() { InvokeMethodInfo invokeInfo = new InvokeMethodInfo(typeof(ITestServiceInterface), "StartService", new Type[] { typeof(int) }, typeof(TestServiceImplementation)); Assert.True(invokeInfo.ImplementationMethod != null); // with full qualified method name InvokeMethodInfo invokeInfo2 = new InvokeMethodInfo(typeof(ITestServiceInterface), invokeInfo.QualifiedMethodName, null, typeof(TestServiceImplementation)); Assert.True(invokeInfo2.ImplementationMethod != null); }
public void TestPersistentTransactionContextValue() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; TransactionDefinition trxDef = new TransactionDefinition("Test Transaction"); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.StartTransactionTest)) .RegisterTransactionBegin(trxDef) .RegisterResendAction(new TrxResendActionUseReturnValue("testSessionId")); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.PushTrxData)) .RegisterTransaction(trxDef); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.CompleteTransactionTest)) .RegisterTransactionCommit(trxDef); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); InvokeMethodInfo mInfoBeginTrx = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.StartTransactionTest)); InvokeMethodInfo mInfoTrxData = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.PushTrxData)); InvokeMethodInfo mInfoTrxCommit = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.CompleteTransactionTest)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); Guid startTrxReturn = (Guid)persistComm.InvokeMethod(this, mInfoBeginTrx, session, new object[0]); // Start transaction call persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxCommit, session, new object[] { startTrxReturn }); // transaction commit dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed Thread.Sleep(500); Assert.Equal(3, dummyCom.InvokeCounter); Assert.Equal(2, dummyCom.ReceivedParameterList.Count); foreach (var itemArr in dummyCom.ReceivedParameterList) { Assert.Equal(dummyCom.TransactionTestGuid, itemArr[0]); } }
/// <summary> /// Initializes a new instance of the <see cref="ServiceJob{T}"/> class. /// </summary> /// <param name="invokeMethodName">Name of the invoke method.</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ServiceInitializationException"></exception> public ServiceJob(string invokeMethodName = "Run") { if (invokeMethodName == null) { throw new ArgumentNullException(nameof(invokeMethodName)); } JobClassType = typeof(T); InvokeMethodInfo = JobClassType.GetMethod(invokeMethodName); if (InvokeMethodInfo == null) { throw new ServiceInitializationException($"Method {invokeMethodName} not found in class {JobClassType.Name}"); } IsParameterlessMethod = !InvokeMethodInfo.GetParameters().Any(); }
public void TestPersistentComplexDataCall() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; persistComm.RegisterPersistentMethod <IMyLocalService>(nameof(IMyLocalService.DataMethod)); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); InvokeMethodInfo mInfo = new InvokeMethodInfo(typeof(IMyLocalService), nameof(IMyLocalService.DataMethod)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); string complexDataString = "json within method parameter string: {\"Type\":12,\"RequestId\":8,\"Target\":null,\"Name\":null,\"Payload\":{\"Name\":\"AccessViolationException\",\"TypeName\":\"System.AccessViolationException\",\"Text\":\"System.AccessViolationException: No login received" + Environment.NewLine + @" at .GetTimeInfo() in C:\Docs\x.cs:line 109" + Environment.NewLine + "at BSAG.IOCTalk.Communication.Common.GenericCommunicationBaseService.CallMethod(ISession session, IGenericMessage message) in C:\\GenericCommunicationBaseService.cs:line 1170\",\"Message\":\"No login received\",\"BinaryData\":\"AAEAAAD/////AQAAAAAAAAAEAQAAAB9TeXN0ZW0uQWNjZXNzVmlvbGF0aW9uRXhjZXB0aW9uDAAAAAlDbGFzc05hbWUHTWVzc2FnZQREYXRhDklubmVyRXh3B0aW9uB0hlbHBVUkwQU3RhY2tUcmFjZVN0cmluZxZSZW1vdGVFRyYWNlU3RyaW5nEFJlbW90ZVN0YWNrSW5kZXgPRXhjZXB0aW9uTWV2dXN1bHQGU291cmNlDVdhdHNvbkJ1Y2tldHMBAQMDAQEBAAEAAQceU3lzdGVtLkNvbGxlY3Rpb25zLklEaWN0aW9uYXJ5EFN5c3RlbS5FeGNlcHRpb24ICAIGAgAAAB9TeXN0ZW0uQWNjZXNzVmlvbGF0aW9uRXhjZXB0aW9uBgMAAAARTm8gbG9naW4gcmVjZWl2ZWQKCgoGBAAAAI0EICAgYXQgVGVsZW1hdGljbGluay5CYWNrZW5kLkFjdGl2aXR5VHJhY2tlci5BY3Rpdml0eVRyYWNrZXJDbGllbnlltZUluZm8oKSBpbiBDOlxEb2NzXFh5cGVybGlua1xLdW5kZW5cSW50ZXJuXFRlbGVtYXRpY2xpbmtcVGVsZW1hdGljbGluay5CYWNrZW5kXFRlbGVtYXRpY2xpbmsuQmFja2VuZC5BY3Rpdml0eVRyYWNrZXJcQWN0aXZpdHlUcmFja2VyQ2xpZW50LmNzOmxpbmUgMTA5CiAgIGF0IGxhbWJkYV9tZXRob2QoQ2xvc3VyZSAsIE9iamVjdCAsIE9iamVjdFtdICkKICAgYXQgQlNBRy5JT0NUYWxrLkNvbW11bmljYXRpb24uQ29tbW9uLkdlbmVyaWNDb21tdW5pY2F0aW9uQmFzZVNlcnZpY2UuQ2FsbE1ldGhvZChJU2Vzc2lvbiBzZXNzaW9uLCBJR2VuZXJpY01lc3NhZ2UgbWVzc2FnZSkgaW4gQzpcVXNlcnNcYmVuXFNvdXJjZVxSZXBvc1xpb2N0YWxrLWdpdGh1YlxzcmNcQlNBRy5JT0NUYWxrLkNvbW11bmljYXRpb24uQ29tbW9uXEdlbmVyaWNDb21tdW5pY2F0aW9uQmFzZVNlcnZpY2UuY3M6bGluZSAxMTcwC3gAAAAAKA0AAgAYFAAAAJVRlbGVtYXRpY2xpbmsuQmFja2VuZC5BY3Rpdml0eVRyYWNrZXIKCw==\"}}\" "; object[] complexData = new object[] { 1, DateTime.UtcNow, complexDataString }; persistComm.InvokeMethod(this, mInfo, session, complexData); // 1. not connected call dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed Thread.Sleep(500); Assert.Equal(1, dummyCom.InvokeCounter); }
private void TestAdvancedProxyImplementationOutParams() { Type result = TypeService.BuildProxyImplementation(typeof(ITestServiceSpecialOutPrams)); DummyCommunicationService dummyCommService = new DummyCommunicationService(); var constructorParams = new object[2]; constructorParams[0] = dummyCommService; ITestServiceSpecialOutPrams instance = (ITestServiceSpecialOutPrams)Activator.CreateInstance(result, constructorParams); //int? nullableInt; //instance.GetData(out nullableInt); var invokeMethod = new InvokeMethodInfo(typeof(ITestServiceSpecialOutPrams), nameof(ITestServiceSpecialOutPrams.GetData)); var invokeMethodDeserialize = new InvokeMethodInfo(invokeMethod.InterfaceMethod.DeclaringType, invokeMethod.QualifiedMethodName); Assert.NotNull(invokeMethodDeserialize); }
internal static IActionResult ExecuteHandler(Type handler, object[] constructParameters, HttpContext httpContext, AuthenticationPolicy policy, Type[] customAuthenticators) { IServiceProvider services = httpContext.RequestServices; IHandlerInvokeMethodCache cache = services.GetRequiredService <IHandlerInvokeMethodCache>(); InvokeMethodInfo methodInfo = cache.Get(handler); if (methodInfo != null) { return(ExecuteMethod(methodInfo)); } return(null); IActionResult ExecuteMethod(InvokeMethodInfo info) { try { MethodInfo method = info.Method; object handler_instance = ActivatorUtilities.CreateInstance(services, handler, constructParameters); object invoke_result = method.Invoke(handler_instance, PrepareHandlerMethodParameters(method, services, httpContext, policy, customAuthenticators)); switch (info.ReturnType) { case InvokeMethodReturnType.Void: return(null); case InvokeMethodReturnType.Task: { Task result = (Task)invoke_result; if (result == null) { return(null); } if (result.Status == TaskStatus.WaitingToRun || result.Status == TaskStatus.Created) { result.Start(); } result.Wait(); return(null); } case InvokeMethodReturnType.TaskWithIActionResult: { object awaiter = info.GetAwaiter.Invoke(invoke_result, null); IActionResult result = (IActionResult)info.GetResult.Invoke(awaiter, null); if (result == null) { return(null); } return(result); } case InvokeMethodReturnType.IActionResult: default: { IActionResult result = (IActionResult)invoke_result; if (result == null) { return(null); } return(result); } } } catch (Exception ex) { Debug.WriteLine(ex); return(null); } } }
public void TestPersistentTransactionContext_FunctionalExceptionOnComplete() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; persistComm.ResendSuspensionDelay = TimeSpan.Zero; persistComm.ResendSuspensionGracePeriod = TimeSpan.Zero; TransactionDefinition trxDef = new TransactionDefinition("Test Transaction"); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.StartTransactionTest)) .RegisterTransactionBegin(trxDef) .RegisterResendAction(new TrxResendActionUseReturnValue("testSessionId")); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.PushTrxData)) .RegisterTransaction(trxDef); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.CompleteTransactionTest)) .RegisterTransactionCommit(trxDef); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); InvokeMethodInfo mInfoBeginTrx = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.StartTransactionTest)); InvokeMethodInfo mInfoTrxData = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.PushTrxData)); InvokeMethodInfo mInfoTrxCommit = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.CompleteTransactionTest)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); Guid startTrxReturn = (Guid)persistComm.InvokeMethod(this, mInfoBeginTrx, session, new object[0]); // Start transaction call persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data dummyCom.RaiseFunctionalException = true; Assert.Throws <InvalidOperationException>(() => persistComm.InvokeMethod(this, mInfoTrxCommit, session, new object[] { startTrxReturn })); // transaction commit // close connection to release file persistComm.RealUnderlyingSession.Close(); // raise connection again var firstOnlineCallGuid = dummyCom.TransactionTestGuid; dummyCom.TransactionTestGuid = Guid.NewGuid(); // set new Guid dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed (no messages are expected) Thread.Sleep(500); // 4 calls because last online call threw a function exception resulting in a transaction abort Assert.Equal(4, dummyCom.InvokeCounter); }
public void TestPersistentTransactionContext_CompleteOnlineTransactionCalls_NoResendExpected() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; persistComm.ResendSuspensionDelay = TimeSpan.Zero; persistComm.ResendSuspensionGracePeriod = TimeSpan.Zero; TransactionDefinition trxDef = new TransactionDefinition("Test Transaction"); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.StartTransactionTest)) .RegisterTransactionBegin(trxDef) .RegisterResendAction(new TrxResendActionUseReturnValue("testSessionId")); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.PushTrxData)) .RegisterTransaction(trxDef); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.CompleteTransactionTest)) .RegisterTransactionCommit(trxDef); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); InvokeMethodInfo mInfoBeginTrx = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.StartTransactionTest)); InvokeMethodInfo mInfoTrxData = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.PushTrxData)); InvokeMethodInfo mInfoTrxCommit = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.CompleteTransactionTest)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); Guid startTrxReturn = (Guid)persistComm.InvokeMethod(this, mInfoBeginTrx, session, new object[0]); // Start transaction call persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxCommit, session, new object[] { startTrxReturn }); // transaction commit // loose connection persistComm.RealUnderlyingSession.Close(); //Thread.Sleep(100); // raise connection again dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed Thread.Sleep(500); // 5 calls = 5 online transaction calls till first conn lost. No resend expected because commit mehtod was successfully executed during active connection. Assert.Equal(5, dummyCom.InvokeCounter); // expect 4 parameter values (- start method) Assert.Equal(4, dummyCom.ReceivedParameterList.Count); Assert.Equal(dummyCom.TransactionTestGuid, dummyCom.ReceivedParameterList[0][0]); }
public void TestPersistentTransactionContext_LooseConnDuringSend() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; persistComm.ResendSuspensionDelay = TimeSpan.Zero; persistComm.ResendSuspensionGracePeriod = TimeSpan.Zero; TransactionDefinition trxDef = new TransactionDefinition("Test Transaction"); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.StartTransactionTest)) .RegisterTransactionBegin(trxDef) .RegisterResendAction(new TrxResendActionUseReturnValue("testSessionId")); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.PushTrxData)) .RegisterTransaction(trxDef); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.CompleteTransactionTest)) .RegisterTransactionCommit(trxDef); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); InvokeMethodInfo mInfoBeginTrx = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.StartTransactionTest)); InvokeMethodInfo mInfoTrxData = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.PushTrxData)); InvokeMethodInfo mInfoTrxCommit = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.CompleteTransactionTest)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); Guid startTrxReturn = (Guid)persistComm.InvokeMethod(this, mInfoBeginTrx, session, new object[0]); // Start transaction call persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data // loose connection persistComm.RealUnderlyingSession.Close(); persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxCommit, session, new object[] { startTrxReturn }); // transaction commit // raise connection again var firstOnlineCallGuid = dummyCom.TransactionTestGuid; dummyCom.TransactionTestGuid = Guid.NewGuid(); // set new Guid dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed Thread.Sleep(500); // 8 calls = 3 online transaction till first conn lost + 5 calls on complete transaction resend Assert.Equal(8, dummyCom.InvokeCounter); // expect 6 parameter valus (8 - 2 x Start method) Assert.Equal(6, dummyCom.ReceivedParameterList.Count); for (int i = 0; i < dummyCom.ReceivedParameterList.Count; i++) { var itemArr = dummyCom.ReceivedParameterList[i]; if (i <= 1) { Assert.Equal(firstOnlineCallGuid, itemArr[0]); } else { // expect new guid for complete transaction resend Assert.Equal(dummyCom.TransactionTestGuid, itemArr[0]); } } }