public void SetSubscription() { SetDBState.SetAdminInstalledDB(CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginPass); SqlParameterCollection sqlParameters = GetSqlParameterCollectionForTestProcedure(10); Subscription subscription = new Subscription( CommonTestsValues.MainServiceName, CommonTestsValues.FirstSunscriberName, CommonTestsValues.SubscribedProcedureSchema, "P_TestGetProcedure", sqlParameters); SqlProceduresInstance.InstallSubscription(subscription); List <Tuple <string> > testResult = SetDBState.RunFile <Tuple <string> >( Resources.SetSubscription_Test, SetDBState.AccesType.StandardUser, CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginName, CommonTestsValues.SchemaName, CommonTestsValues.Username, CommonTestsValues.QueryName, CommonTestsValues.ServiceName, CommonTestsValues.SubscribersTableName, CommonTestsValues.FirstSunscriberName); if (testResult.Count != 1 || string.IsNullOrWhiteSpace(testResult[0].Item1) || testResult[0].Item1.Substring(0, 1) != "1") { Assert.Fail(testResult[0].Item1); } }
public void AdminUninstallOnAdminInstalledDB() { SetDBState.SetAdminInstalledDB(CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginPass); AdminDependencyDBInstance.AdminUnInstall(CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginName); List <Tuple <string> > testResult = SetDBState.RunFile <Tuple <string> >( Resources.AdminUnInstall_Test, SetDBState.AccesType.Admin, CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginName, CommonTestsValues.SchemaName, CommonTestsValues.Username, CommonTestsValues.QueryName, CommonTestsValues.ServiceName, CommonTestsValues.SubscribersTableName); if (testResult.Count != 1 && !string.IsNullOrWhiteSpace(testResult[0].Item1)) { Assert.Fail(testResult[0].Item1); } }
public void PublicReceiveSingleSubscription() { SetDBState.SetAdminInstalledDB( CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginPass); DependencyDB.AddReceiver( CommonTestsValues.MainServiceName, CommonTestsValues.ServiceConnectionString ); Receiver receiver = DependencyDB.GetReceiver(CommonTestsValues.MainServiceName); receiver.MessageHandler += HandleMsg; receiver.ErrorMessageHandler += HandleMsg; receiver.UnsubscribedMessageHandler += HandleMsg; Task receiverTask = new Task(receiver.Listen); receiverTask.Start(); SqlParameterCollection sqlParameters = SqlProceduresTests.GetSqlParameterCollectionForTestProcedure(10); DateTime validTill = (DateTime.Now).AddDays(5.0); receiver.Subscribe( CommonTestsValues.FirstSunscriberName, CommonTestsValues.SubscribedProcedureSchema, "P_TestGetProcedure", sqlParameters, validTill ); AccessDB accessDB = new AccessDB(CommonTestsValues.AdminConnectionString); SqlCommand dataChangeCommand = new SqlCommand("dbo.P_TestSetProcedure"); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param1", SqlDbType.Int, 10)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param2", SqlDbType.Int, 10)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert1", SqlDbType.Bit, true)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert2", SqlDbType.Bit, true)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete1", SqlDbType.Bit, false)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete2", SqlDbType.Bit, false)); accessDB.SQLRunNonQueryProcedure(dataChangeCommand, 30); Task waitForResults = new Task(() => { while (Message == null) { Thread.Sleep(100); } }); waitForResults.Start(); waitForResults.Wait(10000); receiverTask.Wait(1); DependencyDB.StopReceiver(CommonTestsValues.MainServiceName); if (Message == null) { Assert.Fail(); } }
public void ParallelUnSubscribeSubscribeTest() { ParallelUnSubscribeTest_Subscribers = new List <string>(); SetDBState.SetAdminInstalledDB( CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginPass); DependencyDB.AddReceiver( CommonTestsValues.MainServiceName, CommonTestsValues.ServiceConnectionString ); Receiver receiver = DependencyDB.GetReceiver(CommonTestsValues.MainServiceName); receiver.MessageHandler += ParallelUnSubscribeSubscribeTest_HandleMsg; receiver.ErrorMessageHandler += ParallelUnSubscribeSubscribeTest_HandleMsg; receiver.UnsubscribedMessageHandler += ParallelUnSubscribeSubscribeTest_HandleMsg; Task receiverTask = new Task(receiver.Listen); receiverTask.Start(); SqlParameterCollection sqlParameters = SqlProceduresTests.GetSqlParameterCollectionForTestProcedure(10); DateTime validTill = (DateTime.Now).AddDays(5.0); for (int i = 0; i < CountParallelInstances; i++) { string subscriberName = "subscriber" + i; ParallelUnSubscribeTest_Subscribers.Add(subscriberName); } Parallel.ForEach(ParallelUnSubscribeTest_Subscribers, (subscriberName) => { switch (subscriberName.GetHashCode() % 2) { case 1: accesDB.SQLRunNonQueryProcedure(new SqlCommand(Resources.SelectFromTable)); break; default: receiver.Subscribe( subscriberName, CommonTestsValues.SubscribedProcedureSchema, "P_TestGetProcedure", sqlParameters, validTill ); break; } }); Parallel.ForEach(ParallelUnSubscribeTest_Subscribers, (subscriberName) => { switch (subscriberName.GetHashCode() % 3) { case 1: accesDB.SQLRunNonQueryProcedure(new SqlCommand(Resources.SelectFromTable)); break; case 2: receiver.UnSubscribe( subscriberName, CommonTestsValues.SubscribedProcedureSchema, "P_TestGetProcedure", sqlParameters ); break; default: receiver.Subscribe( subscriberName, CommonTestsValues.SubscribedProcedureSchema, "P_TestGetProcedure", sqlParameters, validTill ); break; } }); receiverTask.Wait(1); DependencyDB.StopReceiver(CommonTestsValues.MainServiceName); }
public void SingleChangeWithMultipleSubscribers() { SingleChangeWithMultipleSubscribers_Subscribers = new List <string>(); SetDBState.SetAdminInstalledDB( CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginPass); DependencyDB.AddReceiver( CommonTestsValues.MainServiceName, CommonTestsValues.ServiceConnectionString ); Receiver receiver = DependencyDB.GetReceiver(CommonTestsValues.MainServiceName); receiver.MessageHandler += SingleChangeWithMultipleSubscribers_HandleMsg; receiver.ErrorMessageHandler += SingleChangeWithMultipleSubscribers_HandleMsg; receiver.UnsubscribedMessageHandler += SingleChangeWithMultipleSubscribers_HandleMsg; Task receiverTask = new Task(receiver.Listen); receiverTask.Start(); SqlParameterCollection sqlParameters = SqlProceduresTests.GetSqlParameterCollectionForTestProcedure(10); DateTime validTill = (DateTime.Now).AddDays(5.0); for (int i = 0; i < CountParallelInstances; i++) { string subscriberName = "subscriber" + i; SingleChangeWithMultipleSubscribers_Subscribers.Add(subscriberName); receiver.Subscribe( subscriberName, CommonTestsValues.SubscribedProcedureSchema, "P_TestGetProcedure", sqlParameters, validTill ); } AccessDB accessDB = new AccessDB(CommonTestsValues.AdminConnectionString); SqlCommand dataChangeCommand = new SqlCommand("dbo.P_TestSetProcedure"); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param1", SqlDbType.Int, 10)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param2", SqlDbType.Int, 10)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert1", SqlDbType.Bit, true)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert2", SqlDbType.Bit, true)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete1", SqlDbType.Bit, false)); dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete2", SqlDbType.Bit, false)); accessDB.SQLRunNonQueryProcedure(dataChangeCommand, 30); Task waitForResults = new Task(() => { while (SingleChangeWithMultipleSubscribers_Subscribers.Count > 0) { Thread.Sleep(100); } }); waitForResults.Start(); waitForResults.Wait(20000); receiverTask.Wait(1); DependencyDB.StopReceiver(CommonTestsValues.MainServiceName); if (SingleChangeWithMultipleSubscribers_Subscribers.Count > 0) { Assert.Fail(SingleChangeWithMultipleSubscribers_Subscribers.Count + " subscribers not recived notification."); } }