public IEnumerable <ProxySync.PreCommitResponse> TestPreCommitVersionCompare_FacebookUser(long differentBetweenHostingVersionAndLocalVersion, out ProxySync.ObjectState facebookUserObjectState) { facebookUserObjectState = NextObjectState(); facebookUserObjectState.HostingId = -1; facebookUserObjectState.ObjectDetailType = (int)SEMObjectDetailType.FacebookUser; facebookUserObjectState.IsVersionCompare = true; facebookUserObjectState.EngineType = (int)SearchEngineType.Facebook; facebookUserObjectState.LocalId = SyncDataServiceHelper.GenerateLocalId(facebookUserObjectState); TblFacebookUser facebookUserEntity = NextFacebookUserEntity(); facebookUserEntity.Id = facebookUserObjectState.ObjectId; facebookUserEntity.Version = facebookUserObjectState.LocalVersion + differentBetweenHostingVersionAndLocalVersion; RegisterCreatedFacebookUserEntityForCleanup(facebookUserEntity); InsertFacebookUserIntoDB(facebookUserEntity); ProxySync.PreCommitResponse[] responses = null; ProxySync.ObjectState facebookUserObejctStateForLambdaExpression = facebookUserObjectState; WCFHelper.Using <SyncDataServiceClient>(new SyncDataServiceClient(), client => { responses = client.PreCommit(new ProxySync.ObjectState[] { facebookUserObejctStateForLambdaExpression }); }); return(responses); }
/// <summary> ///随机产生ObjectState对象,不包括计算LocalId /// </summary> /// <returns></returns> public ProxySync.ObjectState NextObjectState() { ProxySync.ObjectState objectState = new ProxySync.ObjectState(); objectState.ObjectDetailType = (int)NextSEMObjectDetailType(); objectState.LocalVersion = (Int64)RandomData.NextUInt32(); objectState.Operation = NextOperationType(); objectState.EngineType = (int)NextSearchEngineType(); objectState.IsVersionCompare = RandomData.NextBoolean(); objectState.HostingId = (Int64)RandomData.NextUInt32(); objectState.ParentId = (Int64)RandomData.NextUInt32(); objectState.ObjectId = (Int64)RandomData.NextUInt32(); return(objectState); }
public static Guid GenerateLocalId(ProxySync.ObjectState objectState) { if (objectState.ObjectDetailType == (int)SEMObjectDetailType.FacebookAccount || objectState.ObjectDetailType == (int)SEMObjectDetailType.FacebookUser || objectState.ObjectDetailType == (int)SEMObjectDetailType.GoogleAccountInfo || objectState.ObjectDetailType == (int)SEMObjectDetailType.GoogleUser || objectState.ObjectDetailType == (int)SEMObjectDetailType.AdCenterAccount || objectState.ObjectDetailType == (int)SEMObjectDetailType.AdCenterUser) { return(GuidGenerationHelper.StringToGUID( objectState.EngineType.ToString() + objectState.ObjectId.ToString())); } else { return(GuidGenerationHelper.StringToGuiD( (int)objectState.EngineType, (int)objectState.ObjectDetailType, objectState.ParentId, objectState.HostingId)); } }
public ProxySync.PreCommitResponse DoPreCommitInitialize_FacebookCampaign(out ProxySync.ObjectState facebookCampaignObjectState) { return(TestPreCommitVersionCompare_FacebookCampaign(0, out facebookCampaignObjectState).First()); }
public void TestMultipleClientsDoPreCommit_FacebookCampaign() { ProxySync.ObjectState facebookCampaignObjectState = SyncDataServiceHelper.NextObjectState(); facebookCampaignObjectState.HostingId = -1; facebookCampaignObjectState.ObjectDetailType = (int)SEMObjectDetailType.FacebookCampaign; facebookCampaignObjectState.IsVersionCompare = true; facebookCampaignObjectState.EngineType = (int)SearchEngineType.Facebook; facebookCampaignObjectState.LocalId = SyncDataServiceHelper.GenerateLocalId(facebookCampaignObjectState); TblFacebookCampaign facebookCampaignEntity = SyncDataServiceHelper.NextFacebookCampaignEntity(); facebookCampaignEntity.Id = facebookCampaignObjectState.ObjectId; facebookCampaignEntity.ParentId = facebookCampaignObjectState.ParentId; facebookCampaignEntity.Version = facebookCampaignObjectState.LocalVersion; SyncDataServiceHelper.RegisterCreatedFacebookCampaignEntityForCleanup(facebookCampaignEntity); SyncDataServiceHelper.InsertFacebookCampaignIntoDB(facebookCampaignEntity); var taskA = Task.Factory.StartNew <ProxySync.PreCommitResponse[]>(() => { ProxySync.PreCommitResponse[] responsesA = null; ProxySync.ObjectState facebookCampaignObejctStateForLambdaExpressionA = facebookCampaignObjectState; WCFHelper.Using <SyncDataServiceClient>(new SyncDataServiceClient(), client => { responsesA = client.PreCommit(new ProxySync.ObjectState[] { facebookCampaignObejctStateForLambdaExpressionA }); }); return(responsesA); }); var taskB = Task.Factory.StartNew <ProxySync.PreCommitResponse[]>(() => { ProxySync.PreCommitResponse[] responsesB = null; ProxySync.ObjectState facebookCampaignObejctStateForLambdaExpressionB = facebookCampaignObjectState; WCFHelper.Using <SyncDataServiceClient>(new SyncDataServiceClient(), client => { responsesB = client.PreCommit(new ProxySync.ObjectState[] { facebookCampaignObejctStateForLambdaExpressionB }); }); return(responsesB); }); Task.WaitAll(taskA, taskB); //Verify two task results if (taskA.Result == null && taskB.Result == null) { Assert.Fail("The two clients all return NULL!!"); } if (taskA.Result != null && taskB.Result != null) { Assert.Fail("The two clients all don't return NULL!!"); } if (taskA.Result != null && taskB.Result == null) { Assert.AreEqual(1, taskA.Result.Length, "The length of PreCommitResponse array should be equal 1!!"); Assert.AreEqual(facebookCampaignObjectState.LocalId, taskA.Result[0].GrainId, "The inputed objectstate object's LocalId should be equal to PreCommitResponse's GrainId returned from Server!!"); } if (taskA.Result == null && taskB.Result != null) { Assert.AreEqual(1, taskB.Result.Length, "The length of PreCommitResponse array should be equal 1!!"); Assert.AreEqual(facebookCampaignObjectState.LocalId, taskB.Result[0].GrainId, "The inputed objectstate object's LocalId should be equal to PreCommitResponse's GrainId returned from Server!!"); } }