public async Task Grain_GuidKey_SimpleSQLStore_Read_Write()
        {
            Guid id = Guid.NewGuid();
            ISimpleSQLStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <ISimpleSQLStorageTestGrain>(id);

            int val = await grain.GetValue();

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

            await grain.DoWrite(1);

            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");
        }
        public async Task SimpleSQLStore_Delete()
        {
            Guid id = Guid.NewGuid();

            if (!GrainClient.IsInitialized)
            {
                GrainClient.Initialize(HostedCluster.ClientConfiguration);
            }

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

            await grain.DoWrite(1);

            await grain.DoDelete();

            int val = await grain.GetValue(); // Should this throw instead?

            Assert.Equal(0, val);             // "Value after Delete");

            await grain.DoWrite(2);

            val = await grain.GetValue();

            Assert.Equal(2, val); // "Value after Delete + New Write");
        }
        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");
        }
        public async Task SimpleSQLStore_Delete()
        {
            Guid id = Guid.NewGuid();
            ISimpleSQLStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <ISimpleSQLStorageTestGrain>(id);

            await grain.DoWrite(1);

            await grain.DoDelete();

            int val = await grain.GetValue(); // Should this throw instead?

            Assert.Equal(0, val);             // "Value after Delete");

            await grain.DoWrite(2);

            val = await grain.GetValue();

            Assert.Equal(2, val); // "Value after Delete + New Write");
        }
        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();
            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.");

            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");
        }