// Mocking helpers private ApplicationWrapper CreateApp_1Service_SingletonPartition_1Replica( string appTypeName, string serviceTypeName, out ServiceWrapper service, out ReplicaWrapper replica, out PartitionWrapper partition, ServiceKind serviceKind = ServiceKind.Stateless) { service = CreateService(appTypeName, serviceTypeName, 1, 1, out var replicas, out var partitions, serviceKind); replica = replicas[0]; partition = partitions[0]; Mock_ServicesResponse(new Uri($"fabric:/{appTypeName}"), service); return(SFTestHelpers.FakeApp(appTypeName, appTypeName)); }
private ApplicationWrapper CreateApp_2StatelessService_SingletonPartition_1Replica( string appTypeName, string serviceTypeName1, string serviceTypeName2, out ServiceWrapper service1, out ServiceWrapper service2, out ReplicaWrapper service1replica, out ReplicaWrapper service2replica, out PartitionWrapper service1partition, out PartitionWrapper service2partition) { service1 = CreateService(appTypeName, serviceTypeName1, 1, 1, out var replicas1, out var partitions1); service2 = CreateService(appTypeName, serviceTypeName2, 1, 1, out var replicas2, out var partitions2); service1replica = replicas1[0]; service2replica = replicas2[0]; service1partition = partitions1[0]; service2partition = partitions2[0]; Mock_ServicesResponse(new Uri($"fabric:/{appTypeName}"), service1, service2); return(SFTestHelpers.FakeApp(appTypeName, appTypeName)); }
/// <summary> /// Build a <see cref="DestinationConfig" /> from a Service Fabric <see cref="ReplicaWrapper" />. /// </summary> /// <remarks> /// The address JSON of the replica is expected to have exactly one endpoint, and that one will be used. /// </remarks> internal static KeyValuePair <string, DestinationConfig> BuildDestinationFromReplicaAndPartition(ReplicaWrapper replica, PartitionWrapper partition, string healthListenerName = null) { ServiceEndpointCollection.TryParseEndpointsString(replica.ReplicaAddress, out var endpoints); endpoints.TryGetFirstEndpointAddress(out var address); string healthAddressUri = null; if (healthListenerName != null) { endpoints.TryGetEndpointAddress(healthListenerName, out healthAddressUri); } var destinationId = $"{partition.Id}/{replica.Id}"; return(KeyValuePair.Create( destinationId, new DestinationConfig { Address = address, Health = healthAddressUri, Metadata = new Dictionary <string, string> { { "PartitionId", partition.Id.ToString() ?? string.Empty }, { "NamedPartitionName", partition.Name ?? string.Empty }, { "ReplicaId", replica.Id.ToString() ?? string.Empty } } })); }
private DestinationConfig BuildDestination(ReplicaWrapper replica, string listenerName, string healthListenerName, PartitionWrapper partition) { if (!ServiceEndpointCollection.TryParseEndpointsString(replica.ReplicaAddress, out var serviceEndpointCollection)) { throw new ConfigException($"Could not parse endpoints for replica {replica.Id}."); } // TODO: FabricServiceEndpoint has some other fields we are ignoring here. Decide which ones are relevant and fix this call. var serviceEndpoint = new FabricServiceEndpoint( listenerNames: new[] { listenerName }, allowedSchemePredicate: HttpsSchemeSelector, emptyStringMatchesAnyListener: true); if (!FabricServiceEndpointSelector.TryGetEndpoint(serviceEndpoint, serviceEndpointCollection, out var endpointUri)) { throw new ConfigException($"No acceptable endpoints found for replica '{replica.Id}'. Search criteria: listenerName='{listenerName}', emptyStringMatchesAnyListener=true."); } // Get service endpoint from the health listener, health listener is optional. Uri healthEndpointUri = null; if (!string.IsNullOrEmpty(healthListenerName)) { var healthEndpoint = new FabricServiceEndpoint( listenerNames: new[] { healthListenerName }, allowedSchemePredicate: HttpsSchemeSelector, emptyStringMatchesAnyListener: true); if (!FabricServiceEndpointSelector.TryGetEndpoint(healthEndpoint, serviceEndpointCollection, out healthEndpointUri)) { throw new ConfigException($"No acceptable health endpoints found for replica '{replica.Id}'. Search criteria: listenerName='{healthListenerName}', emptyStringMatchesAnyListener=true."); } } return new DestinationConfig { Address = endpointUri.AbsoluteUri, Health = healthEndpointUri?.AbsoluteUri, Metadata = new Dictionary<string, string> { { "PartitionId", partition.Id.ToString() ?? string.Empty }, { "NamedPartitionName", partition.Name ?? string.Empty }, { "ReplicaId", replica.Id.ToString() ?? string.Empty } } }; }