public async Task Call_ValidateUnsuccessfulResponse() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); var error = new DaprError() { ErrorCode = "ERR_STATE_STORE", Message = "State Store Error" }; var message = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(JsonSerializer.Serialize(error)) }; entry.Completion.SetResult(message); await FluentActions.Awaiting(async() => await task).Should().ThrowAsync <DaprApiException>(); }
private ActorManager CreateActorManager(Type type, ActorActivator activator = null) { var registration = new ActorRegistration(ActorTypeInformation.Get(type)); var interactor = new DaprHttpInteractor(clientHandler: null, "http://localhost:3500", apiToken: null); return(new ActorManager(registration, activator ?? new DefaultActorActivator(), JsonSerializerDefaults.Web, NullLoggerFactory.Instance, ActorProxy.DefaultProxyFactory, interactor)); }
public void Call_WithoutApiToken() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); entry.Request.Headers.TryGetValues("dapr-api-token", out var headerValues); headerValues.Should().BeNull(); }
public void Call_WithApiTokenEnvVar() { Environment.SetEnvironmentVariable("DAPR_API_TOKEN", "test_token"); var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); entry.Request.Headers.TryGetValues("dapr-api-token", out var headerValues); headerValues.Count().Should().Be(1); headerValues.First().Should().Be("test_token"); }
public void SaveStateTransactionally_ValidateRequest() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var data = "StateData"; var task = httpInteractor.SaveStateTransactionallyAsync(actorType, actorId, data); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); var actualPath = entry.Request.RequestUri.LocalPath.TrimStart('/'); var expectedPath = string.Format(CultureInfo.InvariantCulture, Constants.ActorStateRelativeUrlFormat, actorType, actorId); actualPath.Should().Be(expectedPath); entry.Request.Method.Should().Be(HttpMethod.Put); }
public void GetState_ValidateRequest() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var keyName = "StateKey_Test"; var task = httpInteractor.GetStateAsync(actorType, actorId, keyName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); var actualPath = entry.Request.RequestUri.LocalPath.TrimStart('/'); var expectedPath = string.Format(CultureInfo.InvariantCulture, Constants.ActorStateKeyRelativeUrlFormat, actorType, actorId, keyName); actualPath.Should().Be(expectedPath); entry.Request.Method.Should().Be(HttpMethod.Get); }
public async Task Call_ValidateUnauthorizedResponse() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var task = httpInteractor.UnregisterTimerAsync(actorType, actorId, timerName); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); var message = new HttpResponseMessage(HttpStatusCode.Unauthorized); entry.Completion.SetResult(message); await FluentActions.Awaiting(async() => await task).Should().ThrowAsync <AuthenticationException>(); }
public void RegisterTimer_ValidateRequest() { var handler = new TestHttpClientHandler(); var httpInteractor = new DaprHttpInteractor(handler); var actorType = "ActorType_Test"; var actorId = "ActorId_Test"; var timerName = "TimerName"; var payload = "JsonData"; var task = httpInteractor.RegisterTimerAsync(actorType, actorId, timerName, payload); handler.Requests.TryDequeue(out var entry).Should().BeTrue(); var actualPath = entry.Request.RequestUri.LocalPath.TrimStart('/'); var expectedPath = string.Format(CultureInfo.InvariantCulture, Constants.ActorTimerRelativeUrlFormat, actorType, actorId, timerName); actualPath.Should().Be(expectedPath); entry.Request.Method.Should().Be(HttpMethod.Put); }
internal ActorRuntime(ActorRuntimeOptions options, ILoggerFactory loggerFactory, ActorActivatorFactory activatorFactory, IActorProxyFactory proxyFactory) { this.options = options; this.logger = loggerFactory.CreateLogger(this.GetType()); this.activatorFactory = activatorFactory; this.proxyFactory = proxyFactory; // Loop through actor registrations and create the actor manager for each one. // We do this up front so that we can catch initialization errors early, and so // that access to state can have a simple threading model. // // Revisit this if actor initialization becomes a significant source of delay for large projects. foreach (var actor in options.Actors) { var daprInteractor = new DaprHttpInteractor(clientHandler: null, httpEndpoint: options.HttpEndpoint, apiToken: options.DaprApiToken, requestTimeout: null); this.actorManagers[actor.Type.ActorTypeName] = new ActorManager( actor, actor.Activator ?? this.activatorFactory.CreateActivator(actor.Type), this.options.JsonSerializerOptions, loggerFactory, proxyFactory, daprInteractor); } }