public void T1() { using(var app = new ServiceBaseApplication(null, CONFIG1.AsLaconicConfig())) { Assert.AreEqual(150, app.EventTimer.ResolutionMs); var lst = new List<string>(); new Event(app.EventTimer, "A", (e) => {lock(lst) lst.Add("a");}) { Interval = new TimeSpan(0,0,1), Context = 123 }; new Event(app.EventTimer, "B", (e) => {lock(lst) lst.Add("b");}) { Interval = new TimeSpan(0,0,3), Context = 234 }; Assert.AreEqual(2, app.EventTimer.Events.Count); Assert.AreEqual(123, app.EventTimer.Events["A"].Context); Assert.AreEqual(234, app.EventTimer.Events["B"].Context); Thread.Sleep(10000); app.EventTimer.Events["A"].Dispose(); app.EventTimer.Events["B"].Dispose(); Assert.AreEqual(0, app.EventTimer.Events.Count); Console.WriteLine(string.Join(" , ", lst)); Assert.AreEqual(10, lst.Count(s=>s=="a")); Assert.AreEqual(4, lst.Count(s=>s=="b")); } }
public void GetAuthTokenTest() { var conf = LACONF.AsLaconicConfig(); var paySystem = getPaySystem(); using (var app = new ServiceBaseApplication(null, conf)) using (var session = paySystem.StartSession()) { Assert.IsNotNull(session); Assert.IsInstanceOf<PayPalSession>(session); Assert.IsNotNull(session.User); Assert.AreEqual(session.User.AuthenticationType, PayPalSystem.PAYPAL_REALM); Assert.IsNotNull(session.User.Credentials); Assert.IsInstanceOf<PayPalCredentials>(session.User.Credentials); Assert.IsNotNull(session.User.AuthToken.Data); Assert.IsInstanceOf<PayPalOAuthToken>(session.User.AuthToken.Data); var token = session.User.AuthToken.Data as PayPalOAuthToken; Assert.IsTrue(token.ObtainTime > App.TimeSource.Now.AddMinutes(-1)); Assert.IsTrue(token.ObtainTime < App.TimeSource.Now); Assert.AreEqual(3600, token.ExpirationMargin); Assert.IsNotNullOrEmpty(token.ApplicationID); Assert.IsTrue(token.ExpiresInSeconds > 0); Assert.IsNotNullOrEmpty(token.AccessToken); Assert.IsNotNullOrEmpty(token.Scope); Assert.IsNotNullOrEmpty(token.Nonce); } }
/// <summary> /// Takes optional args[] and root configuration. If configuration is null then /// application is configured from a file co-located with entry-point assembly and /// called the same name as assembly with '.config' extension, unless args are specified and "/config file" /// switch is used in which case 'file' has to be locatable and readable. /// </summary> public ServiceBaseApplication(string[] args, ConfigSectionNode rootConfig) { lock(typeof(ServiceBaseApplication)) { if (s_Instance != null) throw new NFXException(StringConsts.SVCAPP_INSTANCE_ALREADY_CREATED_ERROR); try { Configuration argsConfig; if (args != null) argsConfig = new CommandArgsConfiguration(args); else argsConfig = new MemoryConfiguration(); m_CommandArgs = argsConfig.Root; m_ConfigRoot = rootConfig ?? GetConfiguration().Root; InitApplication(); s_Instance = this; } catch { Destructor(); throw; } } }
public static void TASK_TestContractA_TwoWayCall_Timeout(string CONF_SRC) { TestServerA.s_Accumulator = 0; var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractAClient(App.ConfigRoot.AttrByName("cs").Value); cl.TimeoutMs = 2000; System.Threading.Tasks.Task<CallSlot> task = null; try { task = cl.Async_Sleeper(10000).AsTask; task.Result.GetValue<int>(); } catch(ClientCallException err) { Assert.AreEqual(CallStatus.Timeout, err.CallStatus); return; } catch(System.IO.IOException err) //sync binding throws IO exception { Assert.IsTrue( err.Message.Contains("after a period of time") ); return; } Assert.Fail("Invalid Call status: " + (task!=null ? task.Result.CallStatus.ToString() : "task==null")); } }
public void Configed_MemoryBufferDestination() { var conf = LaconicConfiguration.CreateFromString(CONF_SRC1); using( var app = new ServiceBaseApplication(null, conf.Root)) { var mbd = ((LogService)app.Log).Destinations.First() as MemoryBufferDestination; System.Threading.Thread.Sleep( 3000 ); mbd.ClearBuffer(); app.Log.Write( new Message{ Type = Log.MessageType.Info, From = "test", Text = "Hello1"}); System.Threading.Thread.Sleep( 1000 ); app.Log.Write( new Message{ Type = Log.MessageType.Info, From = "test", Text = "Hello2"}); System.Threading.Thread.Sleep( 3000 ); Assert.AreEqual(2, mbd.Buffered.Count()); Assert.AreEqual("Hello1", mbd.BufferedTimeAscending.First().Text); Assert.AreEqual("Hello2", mbd.BufferedTimeAscending.Last().Text); Assert.AreEqual("Hello2", mbd.BufferedTimeDescending.First().Text); Assert.AreEqual("Hello1", mbd.BufferedTimeDescending.Last().Text); } }
public void StartFinish() { var confSource=@" nfx{ starters{ starter{ type='NFX.NUnit.AppModel.MySuperStarter, NFX.NUnit'} } }"; RESULT = ""; var conf = LaconicConfiguration.CreateFromString(confSource); using( var app = new ServiceBaseApplication(null, conf.Root)) { } Assert.AreEqual("ABCD", RESULT); }
public void PayoutLimitExceedPayoutTest() { var conf = LACONF.AsLaconicConfig(); var paySystem = getPaySystem(); using (var app = new ServiceBaseApplication(null, conf)) using (var session = paySystem.StartSession() as PayPalSession) { var to = new Account("user", 211, 3000001); var amount = new Amount("USD", 100000.0m); // paypal payout limit is $10k var transaction = session.Transfer(null, Account.EmptyInstance, to, amount); } }
static void Main(string[] args) { using (var application = new ServiceBaseApplication(args, null)) { try { var clientLogin = new ClientLoginProcessor(); clientLogin.Run(); } catch { Console.WriteLine("CRITICAL ERROR"); Console.ReadKey(); } } }
/// <summary> /// Start servers /// </summary> /// <param name="args">run arguments (not used now)</param> public void StartServer(string[] args) { lock (ApplicationLock) { if (_application == null) { // NFX app base var nfx_arg = new string[] { "/config", "AuthService.Server.laconf" }; _application = new ServiceBaseApplication( args: nfx_arg, rootConfig: null); Log.Info("server is running..."); Log.Info("Glue servers:"); foreach (var service in App.Glue.Servers) Log.Info(" " + service); } } }
public void SimplePayoutTest() { var conf = LACONF.AsLaconicConfig(); var paySystem = getPaySystem(); using (var app = new ServiceBaseApplication(null, conf)) using (var session = paySystem.StartSession() as PayPalSession) { var to = new Account("user", 211, 3000001); var amount = new Amount("USD", 1.0m); var transaction = session.Transfer(null, Account.EmptyInstance, to, amount); Assert.IsNotNull(transaction); Assert.AreEqual(TransactionType.Transfer, transaction.Type); Assert.AreEqual(amount, transaction.Amount); Assert.AreEqual(Account.EmptyInstance, transaction.From); Assert.AreEqual(to, transaction.To); } }
public static void TASK_TestContractA_TwoWayCall(string CONF_SRC) { TestServerA.s_Accumulator = 0; var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractAClient(App.ConfigRoot.AttrByName("cs").Value); var call = cl.Async_Method1(12); var task = call.AsTask; var result = task.Result.GetValue<string>(); Assert.AreEqual( "12", result); Assert.AreEqual(12, TestServerA.s_Accumulator); } }
static void Main(string[] args) { try { using (var application = new ServiceBaseApplication(args, null)) { Console.WriteLine("ChatApp Server 1.0\n\nserver is running...\n"); foreach (var server in App.Glue.Servers) Console.WriteLine(server); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("error:"); Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
/// <summary> /// Stop servers /// </summary> public void StopServer() { Log.Info("server is stoping..."); ServiceBaseApplication app; lock (ApplicationLock) { app = _application; _application = null; } if (app == null) { Log.Info("server is already stoped."); } else { app.Dispose(); Log.Info("server is stoped."); } }
static void Main(string[] args) { try { using (var app = new ServiceBaseApplication(args, null)) using (var server = new WaveServer()) { server.Configure(null); server.Start(); Console.WriteLine("server started..."); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("Critical error:"); Console.WriteLine(ex); Environment.ExitCode = -1; } }
static void Main(string[] args) { try { using (var application = new ServiceBaseApplication(args, null)) { Console.WriteLine("server is running..."); Console.WriteLine("Glue servers:"); foreach (var service in App.Glue.Servers) Console.WriteLine(" " + service); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("error:"); Console.WriteLine(ex.ToString()); } }
static void Main(string[] args) { try { using (var app = new ServiceBaseApplication(args, null)) using (var server = new WaveServer()) { server.Configure(null); server.Start(); Console.WriteLine("Web server started at {0}.", DateTime.Now); Console.WriteLine("Press <ENTER> to terminate..."); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("Critical error:"); Console.WriteLine(ex.ToMessageWithType()); Environment.ExitCode = -1; } }
public void Configed_MemoryBufferDestinationCapacity() { var conf = LaconicConfiguration.CreateFromString(CONF_SRC1); using( var app = new ServiceBaseApplication(null, conf.Root)) { var mbd = ((LogService)app.Log).Destinations.First() as MemoryBufferDestination; System.Threading.Thread.Sleep( 3000 ); mbd.BufferSize = 10; for(int i=0; i<100; i++) app.Log.Write( new Message{Type = Log.MessageType.Info, From = "test", Text = "i={0}".Args(i)} ); System.Threading.Thread.Sleep( 3000 ); Assert.AreEqual(10, mbd.Buffered.Count()); Assert.AreEqual("i=99", mbd.BufferedTimeDescending.First().Text); Assert.AreEqual("i=90", mbd.BufferedTimeDescending.Last().Text); } }
public void T6() { var lst = TeztHandler.s_List; lst.Clear(); using(var app = new ServiceBaseApplication(null, CONFIG3_HANDLERS.AsLaconicConfig())) { Thread.Sleep(10000); } Console.WriteLine(string.Join(" , ", lst)); Assert.AreEqual(14, lst.Count); Assert.AreEqual(10, lst.Count(s=>s=="ItonTV::Gorin.True")); Assert.AreEqual(4, lst.Count(s=>s=="Nativ::Kedmi.False")); }
public void T5() { using(var app = new ServiceBaseApplication(null, CONFIG2_ARZAMAS.AsLaconicConfig())) { Assert.AreEqual(150, app.EventTimer.ResolutionMs); var lst = new List<string>(); var utcNow = app.TimeSource.UTCNow; new Event(app.EventTimer, "A", (e) => {lock(lst) lst.Add("a");}) { Interval = new TimeSpan(0,0,1), StartDate = DateTime.SpecifyKind(utcNow + ARZAMAS_OFFSET, DateTimeKind.Local) }; new Event(app.EventTimer, "B", (e) => {lock(lst) lst.Add("b");}) { Interval = new TimeSpan(0,0,3), StartDate = utcNow }; Thread.Sleep(10000); app.EventTimer.Events["A"].Dispose(); app.EventTimer.Events["B"].Dispose(); Assert.AreEqual(0, app.EventTimer.Events.Count); Console.WriteLine(string.Join(" , ", lst)); Assert.AreEqual(10, lst.Count(s=>s=="a")); Assert.AreEqual(4, lst.Count(s=>s=="b")); } }
public void T4() { using(var app = new ServiceBaseApplication(null, CONFIG1.AsLaconicConfig())) { Assert.AreEqual(150, app.EventTimer.ResolutionMs); var lst = new List<string>(); var limpopoTime = new TimeLocation(new TimeSpan(0, 0, 2), "Limpopo Time is 2 seconds ahead of UTC"); var utcNow = app.TimeSource.UTCNow; Console.WriteLine( utcNow.Kind ); new Event(app.EventTimer, "A", (e) => {lock(lst) lst.Add("a");}, new TimeSpan(0,0,1)) { TimeLocation = limpopoTime, StartDate = utcNow.AddSeconds(-2) }; new Event(app.EventTimer, "B", (e) => {lock(lst) lst.Add("b");}, new TimeSpan(0,0,3)) { TimeLocation = TimeLocation.UTC, StartDate = utcNow }; Thread.Sleep(10000); app.EventTimer.Events["A"].Dispose(); app.EventTimer.Events["B"].Dispose(); Assert.AreEqual(0, app.EventTimer.Events.Count); Console.WriteLine(string.Join(" , ", lst)); Assert.AreEqual(10, lst.Count(s=>s=="a")); Assert.AreEqual(4, lst.Count(s=>s=="b")); } }
public void T3() { using(var app = new ServiceBaseApplication(null, CONFIG1.AsLaconicConfig())) { Assert.AreEqual(150, app.EventTimer.ResolutionMs); var lst = new List<string>(); var appNow = app.LocalizedTime; new Event(app.EventTimer, "A", (e) => {lock(lst) lst.Add("a");}) { Interval = new TimeSpan(0,0,1), StartDate = appNow.AddSeconds(3.0)}; new Event(app.EventTimer, "B", (e) => {lock(lst) lst.Add("b");}) { Interval = new TimeSpan(0,0,3), StartDate = appNow.AddSeconds(-100.0)}; Thread.Sleep(10000); app.EventTimer.Events["A"].Dispose(); app.EventTimer.Events["B"].Dispose(); Assert.AreEqual(0, app.EventTimer.Events.Count); Console.WriteLine(string.Join(" , ", lst)); Assert.AreEqual(7, lst.Count(s=>s=="a")); Assert.AreEqual(4, lst.Count(s=>s=="b")); } }
//this will throw public static void TestContractB_9(string CONF_SRC) { var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value); Exception err = null; try { cl.GetDailyStatuses(1);//this is needed to init type registry for sync binding //because otherwise it will abort the channel instead of marshalling exception back cl.GetDailyStatuses(550); } catch(Exception error) { err = error; } Assert.IsNotNull( err ); Assert.AreEqual( typeof(RemoteException), err.GetType()); Assert.IsTrue( err.Message.Contains("MessageSizeException")); Assert.IsTrue( err.Message.Contains("exceeds limit")); } }
public static void TestContractB_8(string CONF_SRC) { var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value); var ret = cl.GetDailyStatuses(150); Assert.AreEqual( 150, ret.Count); var dt = new DateTime(1980,1,1); Assert.AreEqual( 100, ret[dt].Count); Assert.AreEqual( "Oleg0", ret[dt][0].FirstName); Assert.AreEqual( "Oleg99", ret[dt][99].FirstName); Assert.AreEqual( "Popov99", ret[dt][99].LastName); Assert.AreEqual( 99000m, ret[dt][99].Salary); dt = dt.AddSeconds(ret.Count-1); Assert.AreEqual( 100, ret[dt].Count); Assert.AreEqual( "Oleg0", ret[dt][0].FirstName); Assert.AreEqual( "Oleg99", ret[dt][99].FirstName); Assert.AreEqual( "Popov99", ret[dt][99].LastName); Assert.AreEqual( 99000m, ret[dt][99].Salary); dumpBindingTransports( cl.Binding ); } }
public static void TestContractB_6(string CONF_SRC) { var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value); var ret = cl.GetPersonalData(new int[]{1,23,97}, true, 127000m); Assert.AreEqual( 3, ret.Count); Assert.AreEqual( 1, ret[0].ID); Assert.AreEqual( 23, ret[1].ID); Assert.AreEqual( 97, ret[2].ID); Assert.AreEqual( "Oleg1", ret[0].FirstName); Assert.AreEqual( "Oleg23", ret[1].FirstName); Assert.AreEqual( "Oleg97", ret[2].FirstName); Assert.AreEqual( "Popov1", ret[0].LastName); Assert.AreEqual( "Popov23", ret[1].LastName); Assert.AreEqual( "Popov97", ret[2].LastName); Assert.AreEqual( true, ret[0].Certified); Assert.AreEqual( true, ret[1].Certified); Assert.AreEqual( true, ret[2].Certified); Assert.AreEqual( 127000m, ret[0].Salary); Assert.AreEqual( 127000m, ret[1].Salary); Assert.AreEqual( 127000m, ret[2].Salary); dumpBindingTransports( cl.Binding ); } }
public static void TestContractB_4_Parallel_ManyClients(string CONF_SRC, bool threadSafe) { const int CNT = 10000; const int CLCNT = 157; var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var rnd = new Random(); var rndBound = (int)(CLCNT * 1.3751d); var clients = new List<TestContractBClient>(); for(var i=0; i<CLCNT; i++) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName(threadSafe?"cs":"cs2").Value); Assert.AreEqual( "Felix1223", cl.GetName(1223));//alloc server clients.Add(cl); } var set = new HashSet<int>(); var watch = System.Diagnostics.Stopwatch.StartNew(); //.....for making many parallel calls System.Threading.Tasks.Parallel.For(0, CNT, (i, loop)=> { var id = System.Threading.Thread.CurrentThread.ManagedThreadId; lock(set) set.Add( id ); var idx = rnd.Next( rndBound ); if (idx>=clients.Count) idx = clients.Count-1; var cl = clients[idx]; //Testing overloaded calls Assert.AreEqual( "Felix{0}".Args(i), cl.GetName(i)); }); var elps = watch.ElapsedMilliseconds; Console.WriteLine("Parallel Many Clients Glue test made {0} calls in {1} ms at {2} call/sec and was done by these threads:".Args(CNT, elps, CNT / (elps / 1000d)) ); dumpBindingTransports( App.Glue.Bindings.First() ); var cnt = 0; foreach(var id in set) { Console.Write( id+", " ); cnt++; } Console.WriteLine( cnt + " total"); } }
public static void TestContractB_4_Parallel(string CONF_SRC, bool threadSafe) { const int CNT = 10000; var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { //Use the same client..... var cl = new TestContractBClient(App.ConfigRoot.AttrByName(threadSafe?"cs":"cs2").Value); Assert.AreEqual( "Felix1223", cl.GetName(1223));//alloc server var set = new HashSet<int>(); var watch = System.Diagnostics.Stopwatch.StartNew(); //.....for making many parallel calls System.Threading.Tasks.Parallel.For(0, CNT, (i, loop)=> { var id = System.Threading.Thread.CurrentThread.ManagedThreadId; lock(set) set.Add( id ); //Testing overloaded calls var result = cl.GetName(i); Assert.AreEqual( "Felix{0}".Args(i), result); }); var elps = watch.ElapsedMilliseconds; Console.WriteLine("Parallel Glue Test made {0} calls in {1} ms at {2} call/sec and was done by these threads:".Args(CNT, elps, CNT / (elps / 1000d)) ); dumpBindingTransports( cl.Binding ); var cnt = 0; foreach(var id in set) { Console.Write( id+", " ); cnt++; } Console.WriteLine( cnt + " total"); } }
public void T7() { using(var app = new ServiceBaseApplication(null, CONFIG1.AsLaconicConfig())) { new Event(app.EventTimer, "A") { Interval = new TimeSpan(0,0,1), Context = 123, StartDate = new DateTime(2079, 12, 12), EndDate = new DateTime(1980, 1, 1) }; Assert.AreEqual(EventStatus.NotStarted, app.EventTimer.Events["A"].Status); Thread.Sleep(2000); Assert.AreEqual(EventStatus.Invalid, app.EventTimer.Events["A"].Status); app.EventTimer.Events["A"].StartDate = new DateTime(1979, 1,1); Thread.Sleep(2000); Assert.AreEqual(EventStatus.Expired, app.EventTimer.Events["A"].Status); app.EventTimer.Events["A"].EndDate = new DateTime(2979, 1,1); Thread.Sleep(2000); Assert.AreEqual(EventStatus.Started, app.EventTimer.Events["A"].Status); } }
public static void TestContractB_3(string CONF_SRC) { var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value); Assert.AreEqual( "Felix", cl.GetName()); dumpBindingTransports( cl.Binding ); } }
public static void TestContractB_4_Async(string CONF_SRC) { var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value); Assert.AreEqual( "Felix", cl.GetName());//alloc first //Testing overloaded calls via CallSlot Assert.AreEqual( "Felix", cl.Async_GetName() .GetValue<string>()); Assert.AreEqual( "Felix23", cl.Async_GetName(23).GetValue<string>()); Assert.AreEqual( "Felix42", cl.Async_GetName(42).GetValue<string>()); Assert.AreEqual( "Felix", cl.Async_GetName() .GetValue<string>()); dumpBindingTransports( cl.Binding ); } }
public static void TestContractB_4_AsyncReactor(string CONF_SRC) { var conf = LaconicConfiguration.CreateFromString(CONF_SRC); using( var app = new ServiceBaseApplication(null, conf.Root)) { var cl = new TestContractBClient(App.ConfigRoot.AttrByName("cs").Value); var reactor = new CallReactor( new Call( cl.Async_GetName(), (r,c)=> Assert.AreEqual( "Felix", c.CallSlot.GetValue<string>() ) ), new Call( cl.Async_GetName(23), (r,c)=> Assert.AreEqual( "Felix23", c.CallSlot.GetValue<string>() ) ), new Call( cl.Async_GetName(42), (r,c)=> Assert.AreEqual( "Felix42", c.CallSlot.GetValue<string>() ) ), new Call( cl.Async_GetName(2, DateTime.Now), (r,c)=> Assert.IsTrue( c.CallSlot.GetValue<string>().StartsWith("Felix2") ) ) ); reactor.Wait(); dumpBindingTransports( cl.Binding ); Assert.IsTrue(reactor.Finished); } }