Beispiel #1
0
        public async Task CartCanUpdateCartAsync()
        {
            // Arrange
            if (!GrainClient.IsInitialized)
            {
                GrainClient.Initialize();
            }
            IGrainCart cartGrain = GrainFactory.GetGrain <IGrainCart>(Guid.NewGuid());
            Cart       cart      = new Cart();

            // Act
            cart = await cartGrain.AddCartItemAsync(_cartItem);

            await cartGrain.UpdateCartAsync();

            cart = await cartGrain.GetCartAsync();

            // Assert
            Assert.IsNotNull(cart);
            Assert.IsInstanceOfType(cart, typeof(Cart));
            Assert.IsNotNull(cart.CartItems);
            Assert.AreEqual(cart.Total, 2.58M);

            // Clean up
            await cartGrain.ClearStateAsync();

            GrainClient.Uninitialize();
        }
        public void ClientInit_ErrorDuringInitialize()
        {
            ClientConfiguration cfg = TestClusterOptions.BuildClientConfiguration(HostedCluster.ClusterConfiguration);

            cfg.TraceFileName = "TestOnlyThrowExceptionDuringInit.log";

            // First initialize will have been done by orleans unit test base class, so uninitialize back to null state
            GrainClient.Uninitialize();
            Assert.False(GrainClient.IsInitialized, "GrainClient.IsInitialized");
            Assert.False(LogManager.IsInitialized, "Logger.IsInitialized");

            try
            {
                OutsideRuntimeClient.TestOnlyThrowExceptionDuringInit = true;
                Assert.Throws <InvalidOperationException>(() =>
                                                          GrainClient.Initialize(cfg));

                Assert.False(GrainClient.IsInitialized, "GrainClient.IsInitialized");
                Assert.False(LogManager.IsInitialized, "Logger.IsInitialized");

                OutsideRuntimeClient.TestOnlyThrowExceptionDuringInit = false;

                GrainClient.Initialize(cfg);
                Assert.True(GrainClient.IsInitialized, "GrainClient.IsInitialized");
                Assert.True(LogManager.IsInitialized, "Logger.IsInitialized");
            }
            finally
            {
                OutsideRuntimeClient.TestOnlyThrowExceptionDuringInit = false;
            }
        }
Beispiel #3
0
        public async Task CartCanRemoveCartItemAsync()
        {
            // Arrange
            if (!GrainClient.IsInitialized)
            {
                GrainClient.Initialize();
            }
            IGrainCart cartGrain = GrainFactory.GetGrain <IGrainCart>(Guid.NewGuid());
            Cart       cart      = new Cart(); // do we have CartItems?

            // Act
            cart = await cartGrain.AddCartItemAsync(_cartItem);

            cart = await cartGrain.RemoveCartItemAsync(_cartItem);

            var t = cart.CartItems.Find(i => i.CartItemId == _cartItem.CartItemId);

            // Assert
            Assert.IsNotNull(cart);
            Assert.IsInstanceOfType(cart, typeof(Cart));
            Assert.IsNotNull(cart.CartItems);
            Assert.AreEqual(cart.CartItems.Count, 0);

            // Clean up
            await cartGrain.ClearStateAsync();

            GrainClient.Uninitialize();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Starting client {ClientName}");

            var configFile = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), "ClientConfiguration.xml");

            GrainClient.Initialize(configFile);

            var streamProvider = GrainClient.GetStreamProvider("DefaultProvider");

            var messageStream = streamProvider.GetStream <MessageBatch>(ClientName, "AccountSteams");

            var watcher            = new MessageWatcher();
            var subscriptionHandle = messageStream.SubscribeAsync(watcher).Result;

            var cts           = new CancellationTokenSource();
            var publisherTask = Task.Factory.StartNew(PublishMessages, cts.Token);

            Console.WriteLine("client started");
            Console.WriteLine("Press ENTER to stop this publisher.");
            Console.ReadLine();

            Console.WriteLine("Stopping client");
            cts.Cancel();
            publisherTask = null;
            subscriptionHandle.UnsubscribeAsync().Wait();

            GrainClient.Uninitialize();
            Console.WriteLine("Publisher client");
        }
Beispiel #5
0
        public override void Dispose()
        {
            if (GrainClient.IsInitialized)
            {
                GrainClient.Uninitialize();
            }

            if (ServiceAppDomain != null)
            {
                ServiceAppDomain.RunOnContext(() =>
                {
                    Host.Stop();

                    Host.Dispose();

                    var completed = StopTask.Wait(60000);

                    if (!completed)
                    {
                        throw new TimeoutException("ServiceTester: The service failed to shutdown within the 60 second limit.");
                    }
                });

                Kill();
            }

            LogListener.Close();
        }
Beispiel #6
0
    //-------------------------------------------------------------------------
    static void Main(string[] args)
    {
        GrainClient.Initialize("BaseClientConfiguration.xml");

        Console.Title = "FishingBase";

        ProgramConfig config = new ProgramConfig();

        config.load("./FishingBase.exe.config");

        EsEngineSettings settings;

        settings.NodeType            = 2;
        settings.NodeTypeString      = "Base";
        settings.ListenIp            = config.ListenIp;
        settings.ListenPort          = config.ListenPort;
        settings.RootEntityType      = "EtRoot";
        settings.EnableCoSupersocket = true;
        settings.Log4NetConfigPath   = "../../../Media/Fishing/Config/FishingBase.log4net.config";

        try
        {
            EsEngine e = new EsEngine(ref settings, new EsEngineListener());
            e.run();
        }
        catch (System.Exception ex)
        {
            EbLog.Note(ex.ToString());
        }

        GrainClient.Uninitialize();
    }
        public void ClientInit_ErrorDuringInitialize()
        {
            ClientConfiguration cfg = this.fixture.ClientConfiguration;

            // First initialize will have been done by orleans unit test base class, so uninitialize back to null state
            GrainClient.Uninitialize();
            GrainClient.ConfigureLoggingDelegate = builder => builder.AddFile("TestOnlyThrowExceptionDuringInit.log");
            Assert.False(GrainClient.IsInitialized, "GrainClient.IsInitialized");

            try
            {
                OutsideRuntimeClient.TestOnlyThrowExceptionDuringInit = true;
                Assert.Throws <InvalidOperationException>(() =>
                                                          GrainClient.Initialize(cfg));

                Assert.False(GrainClient.IsInitialized, "GrainClient.IsInitialized");

                OutsideRuntimeClient.TestOnlyThrowExceptionDuringInit = false;

                GrainClient.Initialize(cfg);
                Assert.True(GrainClient.IsInitialized, "GrainClient.IsInitialized");
            }
            finally
            {
                OutsideRuntimeClient.TestOnlyThrowExceptionDuringInit = false;
            }
        }
Beispiel #8
0
            public async Task BingLocationCanGetGeocodeAsyncFromGeoLocation()
            {
                // Arrange
                if (!GrainClient.IsInitialized)
                {
                    GrainClient.Initialize();
                }

                var geoLocation = new GeoLocation()
                {
                    addressLine   = "2400 NW 80th St. #163",
                    locality      = "Seattle",
                    adminDistrict = "WA",
                    postalCode    = "98117",
                    countryRegion = "US",
                };

                // Act
                var testGrain       = GrainFactory.GetGrain <IServiceGrainBingLocation>(Guid.NewGuid());
                var testGrainResult = await testGrain.GetGeocodeAsync(geoLocation);

                // Assert
                Assert.IsNotNull(testGrainResult);
                Assert.IsInstanceOfType(testGrainResult, typeof(GeoLocation));
                Assert.IsNotNull(testGrainResult.latitude);
                Assert.IsNotNull(testGrainResult.longitude);

                // Clean up
                GrainClient.Uninitialize();
            }
Beispiel #9
0
 protected override void ProcessRecord()
 {
     if (GrainClient.IsInitialized)
     {
         GrainClient.Uninitialize();
     }
 }
Beispiel #10
0
            public async Task EmailCanSendTestUsingGrain()
            {
                // Arrange
                if (!GrainClient.IsInitialized)
                {
                    GrainClient.Initialize();
                }

                IServiceGrainSendGrid sendGridGrain = GrainFactory.GetGrain <IServiceGrainSendGrid>(Guid.NewGuid());

                // Act
                try
                {
                    _testEmailMessage.Subject = "(CanSendTestEmailUsingGrain) Test message";

                    Task  t = sendGridGrain.SendEmail(_testEmailMessage);
                    await t;

                    if (t.Exception != null)
                    {
                        throw new ApplicationException(t.Exception.Message, t.Exception);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }

                // Clean up
                // Delete state
                GrainClient.Uninitialize();
            }
Beispiel #11
0
        public void Stop()
        {
            HttpServiceListener.Dispose();


            try
            {
                if (Silo != null && Silo.IsStarted)
                {
                    Silo.StopOrleansSilo();
                }
            }
            catch (System.Net.Sockets.SocketException)
            {
                //Orleans 1.3.1 thorws this exception most of the time
            }
            finally
            {
                try
                {
                    GrainClient.Uninitialize();
                }
                catch (Exception exc)
                {
                    Log.Warn("Exception Uninitializing grain client", exception: exc);
                }
            }
        }
Beispiel #12
0
        public async Task CartCanAddCartItemAsync()
        {
            // Arrange
            if (!GrainClient.IsInitialized)
            {
                GrainClient.Initialize();
            }
            IGrainCart cartGrain = GrainFactory.GetGrain <IGrainCart>(Guid.NewGuid());
            Cart       cart      = new Cart();

            // Act
            try
            {
                cart = await cartGrain.AddCartItemAsync(_cartItem);
            }
            catch (Exception ex)
            {
                throw;
            }

            // Assert
            Assert.IsNotNull(cart);
            Assert.IsInstanceOfType(cart, typeof(Cart));
            Assert.IsNotNull(cart.CartItems);
            Assert.AreEqual(cart.CartItems.Count, 1);

            // Clean up
            await cartGrain.ClearStateAsync();

            GrainClient.Uninitialize();
        }
Beispiel #13
0
        protected BaseClusterFixture()
        {
            TestDefaultConfiguration.InitializeDefaults();
            GrainClient.Uninitialize();
            var hostedCluster = CreateClusterHost();

            this.HostedCluster = hostedCluster;
        }
 public void Uninitialize()
 {
     if (!GrainClient.IsInitialized)
     {
         return;
     }
     GrainClient.Uninitialize();
 }
        public HostedTestClusterPerTest()
        {
            TestDefaultConfiguration.InitializeDefaults();

            GrainClient.Uninitialize();
            SerializationManager.InitializeForTesting();
            this.HostedCluster = this.CreateSiloHost();
        }
Beispiel #16
0
        public void ClientInit_UnThenReinitialize()
        {
            GrainClient.Uninitialize();
            Assert.IsFalse(GrainClient.IsInitialized);

            GrainClient.Initialize(HostedCluster.ClientConfiguration);
            Assert.IsTrue(GrainClient.IsInitialized);
        }
        public void ClientInit_UnThenReinitialize()
        {
            GrainClient.Uninitialize();
            Assert.False(GrainClient.IsInitialized);

            GrainClient.Initialize(fixture.ClientConfiguration);
            Assert.True(GrainClient.IsInitialized);
        }
Beispiel #18
0
        protected BaseClusterFixture()
        {
            GrainClient.Uninitialize();
            SerializationManager.InitializeForTesting();
            var hostedCluster = CreateClusterHost();

            this.HostedCluster = hostedCluster;
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            //SayHelloTest().Wait();
            StreamingTest().Wait();

            Console.ReadLine();
            GrainClient.Uninitialize();
        }
Beispiel #20
0
        public void ClientInit_UnThenReinitialize()
        {
            GrainClient.Uninitialize();
            Assert.IsFalse(GrainClient.IsInitialized);

            GrainClient.Initialize("ClientConfigurationForTesting.xml");
            Assert.IsTrue(GrainClient.IsInitialized);
        }
            protected override TestCluster CreateTestCluster()
            {
                GrainClient.Uninitialize();
                var options = new TestClusterOptions(1);

                AdjustConfig(options.ClusterConfiguration);
                AdjustConfig(options.ClientConfiguration);
                return(new TestCluster(options));
            }
Beispiel #22
0
        /// <summary>
        /// Uninitializes the Orleans client runtime in this Azure process.
        /// </summary>
        public static void Uninitialize()
        {
            if (!GrainClient.IsInitialized)
            {
                return;
            }

            Trace.TraceInformation("Uninitializing connection to Orleans gateway silo.");
            GrainClient.Uninitialize();
        }
Beispiel #23
0
        /// <summary>
        /// Stops the default Primary silo.
        /// </summary>
        public void StopPrimarySilo()
        {
            try
            {
                GrainClient.Uninitialize();
            }
            catch (Exception exc) { WriteLog("Exception Uninitializing grain client: {0}", exc); }

            StopSilo(Primary);
        }
        public async Task Grain_SimpleSQLStore_SiloRestart()
        {
            var initialServiceId    = this.HostedCluster.ClusterConfiguration.Globals.ServiceId;
            var initialDeploymentId = this.HostedCluster.DeploymentId;

            Console.WriteLine("DeploymentId={0} ServiceId={1}", this.HostedCluster.DeploymentId, this.HostedCluster.ClusterConfiguration.Globals.ServiceId);

            Guid id = Guid.NewGuid();

            if (!GrainClient.IsInitialized)
            {
                GrainClient.Initialize(HostedCluster.ClientConfiguration);
            }
            ISimpleSQLStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <ISimpleSQLStorageTestGrain>(id);

            int val = await grain.GetValue();

            Assert.Equal(0, val); // "Initial value");

            await grain.DoWrite(1);

            Console.WriteLine("About to reset Silos");
            //this.HostedCluster.RestartDefaultSilos(true);    //only TestSiloHost supports this, make TestCluster a public get/set to force a recreate
            this.HostedCluster.StopAllSilos();
            this.HostedCluster = null;
            this.HostedCluster = CreateTestCluster();
            this.HostedCluster.Deploy();
            Console.WriteLine("Silos restarted");

            Console.WriteLine("DeploymentId={0} ServiceId={1}", this.HostedCluster.DeploymentId, this.HostedCluster.ClusterConfiguration.Globals.ServiceId);
            Assert.Equal(initialServiceId, this.HostedCluster.ClusterConfiguration.Globals.ServiceId); // "ServiceId same after restart.");
            Assert.NotEqual(initialDeploymentId, this.HostedCluster.DeploymentId);                     // "DeploymentId different after restart.");

            //something wonky with the global GrainClient in 1.5 - probably should stop using that guy anyway but for now, hard restart it
            if (GrainClient.IsInitialized)
            {
                GrainClient.Uninitialize();
                GrainClient.Initialize(HostedCluster.ClientConfiguration);
            }

            grain = GrainClient.GrainFactory.GetGrain <ISimpleSQLStorageTestGrain>(id);
            val   = await grain.GetValue();

            Assert.Equal(1, val); // "Value after Write-1");

            await grain.DoWrite(2);

            val = await grain.GetValue();

            Assert.Equal(2, val); // "Value after Write-2");

            val = await grain.DoRead();

            Assert.Equal(2, val); // "Value after Re-Read");
        }
Beispiel #25
0
        protected void Initialize()
        {
            GrainClient.Uninitialize();
            var testCluster = CreateTestCluster();

            if (testCluster.Primary == null)
            {
                testCluster.Deploy();
            }
            this.HostedCluster = testCluster;
        }
Beispiel #26
0
        protected BaseTestClusterFixture()
        {
            GrainClient.Uninitialize();
            var testCluster = CreateTestCluster();

            if (testCluster?.Primary == null)
            {
                testCluster?.Deploy();
            }
            this.HostedCluster = testCluster;
        }
Beispiel #27
0
        public TestClusterPerTest()
        {
            GrainClient.Uninitialize();
            var testCluster = this.CreateTestCluster();

            if (testCluster.Primary == null)
            {
                testCluster.Deploy();
            }
            this.HostedCluster = testCluster;
        }
        protected BaseTestClusterFixture()
        {
            GrainClient.Uninitialize();
            SerializationManager.InitializeForTesting();
            var testCluster = CreateTestCluster();

            if (testCluster.Primary == null)
            {
                testCluster.Deploy();
            }
            this.HostedCluster = testCluster;
        }
Beispiel #29
0
        public async Task Stop()
        {
            try
            {
                GrainClient.Uninitialize();

                await bootstrapChannel.CloseAsync();
            }
            finally
            {
                Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync());
            }
        }
        public virtual void Dispose()
        {
//          Stopwatch profile = Stopwatch.StartNew();
            GrainClient.Uninitialize();
            //GrainClient.HardKill();
            foreach (var silo in HostedCluster.GetActiveSilos())
            {
                HostedCluster.KillSilo(silo);
            }
            //this.HostedCluster.StopAllSilos();
//          profile.Stop();
//          System.IO.File.AppendAllText(System.IO.Path.Combine(System.IO.Path.GetTempPath(), "kookyfile.txt"), $"BaseTestClusterFixture: HostedCluster.StopAllSilos() took {profile.Elapsed.TotalSeconds} seconds\r\n");
        }