protected override Task OnOpenAsync(StatefulServiceExecutionContext executionContext) { TaskCompletionSource <LifeCycleState> taskProducer = new TaskCompletionSource <LifeCycleState>(); // Generate proxy type, this is static typeinfo generated once per type. ReplicableTypeInfo typeInfo = ReplicableTypeInfo.GenerateReplicableTypeInfo(typeof(TInstance)); if (typeInfo == null) { taskProducer.SetException(new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Unexpected failure. ReplicableTypeInfo could not be generated for type '{0}'.", typeof(TInstance).FullName))); } else { taskProducer.SetResult(LifeCycleState.Opened); } return(taskProducer.Task); }
public static void ClassInitialize(TestContext context) { TestStatefulServiceReplica service = new TestStatefulServiceReplica(); StatefulServiceReplicaBroker broker = new StatefulServiceReplicaBroker(service, ReplicationWithLockingTests.DefaultInitializationParameters, ReplicationWithLockingTests.DefaultReplicaId); TestNativePartition nativePartition = new TestNativePartition(); StatefulServicePartition statefulServicePartition = new StatefulServicePartition(nativePartition, ServicePartitionInformation.CreateFromNative(nativePartition.PartitionInfo)); //((IServiceCatalog)ServiceCatalog.Current).AddService(service.Name, statefulServicePartition.Id, service); ((IStatefulServiceReplica)service).OpenAsync(statefulServicePartition); ((IStatefulServiceReplica)service).ChangeRoleAsync(ReplicaRole.Primary).Wait(); ReplicationWithLockingTests.Context = new StatefulServiceExecutionContext( service, new Dictionary <string, object> { { System.Fabric.Common.Constants.PropertyNames.Service, service.Name }, { System.Fabric.Common.Constants.PropertyNames.PartitionId, service.Partition.Id } }); ReplicationWithLockingTests.TypeInfo = ReplicableTypeInfo.GenerateReplicableTypeInfo(typeof(SampleService)); ReplicationWithLockingTests.ProgramInstance = new StatefulProgramInstance(service, Guid.NewGuid(), TypeInfo, new SampleService()); ReplicationWithLockingTests.StateReplicator = nativePartition.StateReplicator; }