Search in sources :

Example 1 with StepVerifier

use of reactor.test.StepVerifier in project reactor-core by reactor.

the class SchedulersTest method handleErrorWithJvmFatalForwardsToUncaughtHandlerSyncInnerCallable.

@Test
public void handleErrorWithJvmFatalForwardsToUncaughtHandlerSyncInnerCallable() {
    AtomicBoolean handlerCaught = new AtomicBoolean();
    Scheduler scheduler = Schedulers.fromExecutorService(Executors.newSingleThreadExecutor(r -> {
        Thread thread = new Thread(r);
        thread.setUncaughtExceptionHandler((t, ex) -> {
            handlerCaught.set(true);
            System.err.println("from uncaught handler: " + ex.toString());
        });
        return thread;
    }));
    final StepVerifier stepVerifier = StepVerifier.create(Flux.just("hi").flatMap(item -> Mono.<String>fromCallable(() -> {
        throw new StackOverflowError("boom");
    }).hide().subscribeOn(scheduler))).expectNoFusionSupport().expectErrorMessage(// ignored
    "boom");
    // the exception is still fatal, so the StepVerifier should time out.
    assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> stepVerifier.verify(Duration.ofMillis(100))).withMessageStartingWith("VerifySubscriber timed out on ");
    // nonetheless, the uncaught exception handler should have been invoked
    assertThat(handlerCaught).as("uncaughtExceptionHandler used").isTrue();
}
Also used : Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) AtomicReference(java.util.concurrent.atomic.AtomicReference) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) RunnableScheduledFuture(java.util.concurrent.RunnableScheduledFuture) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assertions(org.assertj.core.api.Assertions) Assert.fail(org.junit.Assert.fail) Disposables(reactor.core.Disposables) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) DirectProcessor(reactor.core.publisher.DirectProcessor) Executor(java.util.concurrent.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) List(java.util.List) Condition(org.assertj.core.api.Condition) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StepVerifier(reactor.test.StepVerifier) Test(org.junit.Test)

Example 2 with StepVerifier

use of reactor.test.StepVerifier in project reactor-core by reactor.

the class SchedulersTest method handleErrorWithJvmFatalForwardsToUncaughtHandlerFusedCallable.

@Test
public void handleErrorWithJvmFatalForwardsToUncaughtHandlerFusedCallable() {
    AtomicBoolean handlerCaught = new AtomicBoolean();
    Scheduler scheduler = Schedulers.fromExecutorService(Executors.newSingleThreadExecutor(r -> {
        Thread thread = new Thread(r);
        thread.setUncaughtExceptionHandler((t, ex) -> {
            handlerCaught.set(true);
            System.err.println("from uncaught handler: " + ex.toString());
        });
        return thread;
    }));
    final StepVerifier stepVerifier = StepVerifier.create(Mono.<String>fromCallable(() -> {
        throw new StackOverflowError("boom");
    }).subscribeOn(scheduler)).expectFusion().expectErrorMessage("boom");
    // the exception is still fatal, so the StepVerifier should time out.
    assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> stepVerifier.verify(Duration.ofMillis(100))).withMessageStartingWith("VerifySubscriber timed out on ");
    // nonetheless, the uncaught exception handler should have been invoked
    assertThat(handlerCaught).as("uncaughtExceptionHandler used").isTrue();
}
Also used : Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) AtomicReference(java.util.concurrent.atomic.AtomicReference) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) RunnableScheduledFuture(java.util.concurrent.RunnableScheduledFuture) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assertions(org.assertj.core.api.Assertions) Assert.fail(org.junit.Assert.fail) Disposables(reactor.core.Disposables) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) DirectProcessor(reactor.core.publisher.DirectProcessor) Executor(java.util.concurrent.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) List(java.util.List) Condition(org.assertj.core.api.Condition) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) StepVerifier(reactor.test.StepVerifier) Test(org.junit.Test)

Example 3 with StepVerifier

use of reactor.test.StepVerifier in project reactor-core by reactor.

the class FluxPublishTest method prematureOnComplete.

@Test
public void prematureOnComplete() {
    EmitterProcessor<Flux<String>> incomingProcessor = EmitterProcessor.create(false);
    Flux.just("ALPHA", "BRAVO", "CHARLIE", "DELTA", "ALPHA", "BRAVO", "CHARLIE", "DELTA", "ALPHA", "BRAVO", "CHARLIE", "DELTA").log("stream.incoming").windowWhile(s -> !"DELTA".equals(s), 1).subscribe(incomingProcessor);
    AtomicInteger windowIndex = new AtomicInteger(0);
    AtomicInteger nextIndex = new AtomicInteger(0);
    System.out.println("ZERO");
    incomingProcessor.next().flatMapMany(flux -> flux.takeWhile(s -> !"CHARLIE".equals(s)).log(String.format("stream.window.%d", windowIndex.getAndIncrement()))).log(String.format("stream.next.%d", nextIndex.getAndIncrement())).as(StepVerifier::create).expectNextCount(2).verifyComplete();
    System.out.println("ONE");
    incomingProcessor.next().flatMapMany(flux -> flux.takeWhile(s -> !"CHARLIE".equals(s)).log(String.format("stream.window.%d", windowIndex.getAndIncrement()))).log(String.format("stream.next.%d", nextIndex.getAndIncrement())).as(StepVerifier::create).expectNextCount(2).verifyComplete();
    System.out.println("TWO");
    incomingProcessor.next().flatMapMany(flux -> flux.takeWhile(s -> !"CHARLIE".equals(s)).log(String.format("stream.window.%d", windowIndex.getAndIncrement()))).log(String.format("stream.next.%d", nextIndex.getAndIncrement())).as(StepVerifier::create).expectNextCount(2).verifyComplete();
}
Also used : Arrays(java.util.Arrays) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) CancellationException(java.util.concurrent.CancellationException) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Queues(reactor.util.concurrent.Queues) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StepVerifier(reactor.test.StepVerifier) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 4 with StepVerifier

use of reactor.test.StepVerifier in project cf-java-client by cloudfoundry.

the class DefaultApplicationsTest method pushNoDomainPrivate.

@Test
public void pushNoDomainPrivate() throws IOException {
    Path testApplication = new ClassPathResource("test-application.zip").getFile().toPath();
    requestApplicationsEmpty(this.cloudFoundryClient, "test-name", TEST_SPACE_ID);
    requestCreateApplication(this.cloudFoundryClient, ApplicationManifest.builder().path(testApplication).name("test-name").build(), TEST_SPACE_ID, null, "test-application-id");
    requestSpace(this.cloudFoundryClient, TEST_SPACE_ID, TEST_ORGANIZATION_ID);
    requestPrivateDomains(this.cloudFoundryClient, TEST_ORGANIZATION_ID, "test-private-domain-id");
    requestSharedDomainsEmpty(this.cloudFoundryClient);
    requestListMatchingResources(this.cloudFoundryClient, Arrays.asList(new ResourceMatchingUtils.ArtifactMetadata("da39a3ee5e6b4b0d3255bfef95601890afd80709", "Staticfile", "100644", 0), new ResourceMatchingUtils.ArtifactMetadata("45044a6ddbfe11415a8f8a6219de68a2c66b496b", "index.html", "100644", 178)));
    requestApplicationRoutesEmpty(this.cloudFoundryClient, "test-application-id");
    this.applications.push(PushApplicationRequest.builder().path(testApplication).name("test-name").build()).as(StepVerifier::create).consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("No default domain found")).verify(Duration.ofSeconds(5));
}
Also used : Path(java.nio.file.Path) LogMessage(org.cloudfoundry.doppler.LogMessage) Arrays(java.util.Arrays) GetApplicationResponse(org.cloudfoundry.client.v2.applications.GetApplicationResponse) StepVerifier(reactor.test.StepVerifier) GetJobRequest(org.cloudfoundry.client.v2.jobs.GetJobRequest) SharedDomainEntity(org.cloudfoundry.client.v2.shareddomains.SharedDomainEntity) CancelTaskResponse(org.cloudfoundry.client.v3.tasks.CancelTaskResponse) OrderDirection(org.cloudfoundry.client.v2.OrderDirection) SpaceResource(org.cloudfoundry.client.v2.spaces.SpaceResource) LifecycleType(org.cloudfoundry.client.v3.LifecycleType) ApplicationEntity(org.cloudfoundry.client.v2.applications.ApplicationEntity) ListRoutesResponse(org.cloudfoundry.client.v2.routes.ListRoutesResponse) TestObjects.fill(org.cloudfoundry.operations.TestObjects.fill) Duration(java.time.Duration) Map(java.util.Map) ListApplicationsResponse(org.cloudfoundry.client.v3.applications.ListApplicationsResponse) GetSpaceSummaryResponse(org.cloudfoundry.client.v2.spaces.GetSpaceSummaryResponse) Path(java.nio.file.Path) GetStackRequest(org.cloudfoundry.client.v2.stacks.GetStackRequest) PrivateDomainEntity(org.cloudfoundry.client.v2.privatedomains.PrivateDomainEntity) SharedDomainResource(org.cloudfoundry.client.v2.shareddomains.SharedDomainResource) SpaceApplicationSummary(org.cloudfoundry.client.v2.spaces.SpaceApplicationSummary) Envelope(org.cloudfoundry.doppler.Envelope) UpdateApplicationRequest(org.cloudfoundry.client.v2.applications.UpdateApplicationRequest) PrivateDomainResource(org.cloudfoundry.client.v2.privatedomains.PrivateDomainResource) ListEventsResponse(org.cloudfoundry.client.v2.events.ListEventsResponse) CloudFoundryClient(org.cloudfoundry.client.CloudFoundryClient) RETURNS_SMART_NULLS(org.mockito.Mockito.RETURNS_SMART_NULLS) CancelTaskRequest(org.cloudfoundry.client.v3.tasks.CancelTaskRequest) DopplerClient(org.cloudfoundry.doppler.DopplerClient) Mockito.mock(org.mockito.Mockito.mock) RouteEntity(org.cloudfoundry.client.v2.routes.RouteEntity) RecentLogsRequest(org.cloudfoundry.doppler.RecentLogsRequest) CreateRouteResponse(org.cloudfoundry.client.v2.routes.CreateRouteResponse) ListApplicationsRequest(org.cloudfoundry.client.v3.applications.ListApplicationsRequest) TaskResource(org.cloudfoundry.client.v3.tasks.TaskResource) GetSpaceRequest(org.cloudfoundry.client.v2.spaces.GetSpaceRequest) Supplier(java.util.function.Supplier) AssociateApplicationRouteRequest(org.cloudfoundry.client.v2.applications.AssociateApplicationRouteRequest) ListOrganizationSpacesRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationSpacesRequest) Lifecycle(org.cloudfoundry.client.v3.Lifecycle) Resource(org.cloudfoundry.client.v2.resourcematch.Resource) ListOrganizationPrivateDomainsResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationPrivateDomainsResponse) Statistics(org.cloudfoundry.client.v2.applications.Statistics) ApplicationInstanceInfo(org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo) RemoveApplicationRouteRequest(org.cloudfoundry.client.v2.applications.RemoveApplicationRouteRequest) ErrorDetails(org.cloudfoundry.client.v2.jobs.ErrorDetails) VirtualTimeScheduler(reactor.test.scheduler.VirtualTimeScheduler) ApplicationStatisticsResponse(org.cloudfoundry.client.v2.applications.ApplicationStatisticsResponse) ListApplicationServiceBindingsRequest(org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) IOException(java.io.IOException) ApplicationStatisticsRequest(org.cloudfoundry.client.v2.applications.ApplicationStatisticsRequest) ListApplicationRoutesResponse(org.cloudfoundry.client.v2.applications.ListApplicationRoutesResponse) UpdateApplicationResponse(org.cloudfoundry.client.v2.applications.UpdateApplicationResponse) Flux(reactor.core.publisher.Flux) InstanceStatistics(org.cloudfoundry.client.v2.applications.InstanceStatistics) EventEntity(org.cloudfoundry.client.v2.events.EventEntity) FluentMap(org.cloudfoundry.util.FluentMap) OrganizationResource(org.cloudfoundry.client.v2.organizations.OrganizationResource) ListEventsRequest(org.cloudfoundry.client.v2.events.ListEventsRequest) OrganizationEntity(org.cloudfoundry.client.v2.organizations.OrganizationEntity) GetSharedDomainRequest(org.cloudfoundry.client.v2.shareddomains.GetSharedDomainRequest) BuildpackData(org.cloudfoundry.client.v3.BuildpackData) StreamRequest(org.cloudfoundry.doppler.StreamRequest) ListSharedDomainsResponse(org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsResponse) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ListSpaceApplicationsResponse(org.cloudfoundry.client.v2.spaces.ListSpaceApplicationsResponse) SpaceEntity(org.cloudfoundry.client.v2.spaces.SpaceEntity) EventResource(org.cloudfoundry.client.v2.events.EventResource) AbstractOperationsTest(org.cloudfoundry.operations.AbstractOperationsTest) ApplicationEnvironmentResponse(org.cloudfoundry.client.v2.applications.ApplicationEnvironmentResponse) UploadApplicationRequest(org.cloudfoundry.client.v2.applications.UploadApplicationRequest) GetSpaceSummaryRequest(org.cloudfoundry.client.v2.spaces.GetSpaceSummaryRequest) GetSharedDomainResponse(org.cloudfoundry.client.v2.shareddomains.GetSharedDomainResponse) TerminateApplicationInstanceRequest(org.cloudfoundry.client.v2.applications.TerminateApplicationInstanceRequest) ListApplicationRoutesRequest(org.cloudfoundry.client.v2.applications.ListApplicationRoutesRequest) ListSpaceApplicationsRequest(org.cloudfoundry.client.v2.spaces.ListSpaceApplicationsRequest) Collection(java.util.Collection) UploadApplicationResponse(org.cloudfoundry.client.v2.applications.UploadApplicationResponse) ListOrganizationsResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse) ResourceMatchingUtils(org.cloudfoundry.util.ResourceMatchingUtils) JobEntity(org.cloudfoundry.client.v2.jobs.JobEntity) CreateApplicationResponse(org.cloudfoundry.client.v2.applications.CreateApplicationResponse) SummaryApplicationRequest(org.cloudfoundry.client.v2.applications.SummaryApplicationRequest) ServiceBindingResource(org.cloudfoundry.client.v2.servicebindings.ServiceBindingResource) CreateRouteRequest(org.cloudfoundry.client.v2.routes.CreateRouteRequest) Optional(java.util.Optional) ListOrganizationPrivateDomainsRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationPrivateDomainsRequest) RouteResource(org.cloudfoundry.client.v2.routes.RouteResource) Queue(java.util.Queue) EventType(org.cloudfoundry.doppler.EventType) ListStacksRequest(org.cloudfoundry.client.v2.stacks.ListStacksRequest) GetJobResponse(org.cloudfoundry.client.v2.jobs.GetJobResponse) Usage(org.cloudfoundry.client.v2.applications.Usage) ClassPathResource(org.springframework.core.io.ClassPathResource) RestageApplicationResponse(org.cloudfoundry.client.v2.applications.RestageApplicationResponse) DeleteRouteResponse(org.cloudfoundry.client.v2.routes.DeleteRouteResponse) CreateTaskResponse(org.cloudfoundry.client.v3.tasks.CreateTaskResponse) CopyApplicationResponse(org.cloudfoundry.client.v2.applications.CopyApplicationResponse) ListStacksResponse(org.cloudfoundry.client.v2.stacks.ListStacksResponse) ListOrganizationsRequest(org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest) ApplicationResource(org.cloudfoundry.client.v2.applications.ApplicationResource) CopyApplicationRequest(org.cloudfoundry.client.v2.applications.CopyApplicationRequest) ListRoutesRequest(org.cloudfoundry.client.v2.routes.ListRoutesRequest) ListOrganizationSpacesResponse(org.cloudfoundry.client.v2.organizations.ListOrganizationSpacesResponse) LinkedList(java.util.LinkedList) ListMatchingResourcesResponse(org.cloudfoundry.client.v2.resourcematch.ListMatchingResourcesResponse) GetStackResponse(org.cloudfoundry.client.v2.stacks.GetStackResponse) ApplicationEnvironmentRequest(org.cloudfoundry.client.v2.applications.ApplicationEnvironmentRequest) ListMatchingResourcesRequest(org.cloudfoundry.client.v2.resourcematch.ListMatchingResourcesRequest) CreateTaskRequest(org.cloudfoundry.client.v3.tasks.CreateTaskRequest) Mockito.when(org.mockito.Mockito.when) ListApplicationServiceBindingsResponse(org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsResponse) ServiceInstance(org.cloudfoundry.client.v2.serviceinstances.ServiceInstance) GetSpaceResponse(org.cloudfoundry.client.v2.spaces.GetSpaceResponse) ListSharedDomainsRequest(org.cloudfoundry.client.v2.shareddomains.ListSharedDomainsRequest) DateUtils(org.cloudfoundry.util.DateUtils) ApplicationInstancesResponse(org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse) ApplicationState(org.cloudfoundry.client.v3.applications.ApplicationState) ClientV2Exception(org.cloudfoundry.client.v2.ClientV2Exception) StackEntity(org.cloudfoundry.client.v2.stacks.StackEntity) CreateApplicationRequest(org.cloudfoundry.client.v2.applications.CreateApplicationRequest) Metadata(org.cloudfoundry.client.v2.Metadata) RemoveApplicationServiceBindingRequest(org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest) Collections(java.util.Collections) ApplicationInstancesRequest(org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest) SummaryApplicationResponse(org.cloudfoundry.client.v2.applications.SummaryApplicationResponse) StepVerifier(reactor.test.StepVerifier) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) AbstractOperationsTest(org.cloudfoundry.operations.AbstractOperationsTest)

Example 5 with StepVerifier

use of reactor.test.StepVerifier in project cf-java-client by cloudfoundry.

the class RoutesTest method unmap.

@Test
public void unmap() throws IOException {
    String applicationName = this.nameFactory.getApplicationName();
    String domainName = this.nameFactory.getDomainName();
    String hostName = this.nameFactory.getHostName();
    String path = this.nameFactory.getPath();
    Mono.when(createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path), requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true)).then(requestMapRoute(this.cloudFoundryOperations, applicationName, domainName, hostName, path)).then(this.cloudFoundryOperations.routes().unmap(UnmapRouteRequest.builder().applicationName(applicationName).domain(domainName).host(hostName).path(path).build())).thenMany(requestListRoutes(this.cloudFoundryOperations)).filter(filterRoutes(domainName, hostName, path, applicationName)).as(StepVerifier::create).expectComplete().verify(Duration.ofMinutes(5));
}
Also used : StepVerifier(reactor.test.StepVerifier) ClassPathResource(org.springframework.core.io.ClassPathResource) AbstractIntegrationTest(org.cloudfoundry.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

StepVerifier (reactor.test.StepVerifier)82 Mono (reactor.core.publisher.Mono)56 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)48 Test (org.junit.jupiter.api.Test)45 Flux (reactor.core.publisher.Flux)41 Test (org.junit.Test)37 Duration (java.time.Duration)31 ClassPathResource (org.springframework.core.io.ClassPathResource)28 AbstractIntegrationTest (org.cloudfoundry.AbstractIntegrationTest)24 Collections (java.util.Collections)20 Mockito.mock (org.mockito.Mockito.mock)20 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)20 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)19 Connection (io.r2dbc.spi.Connection)17 IOException (java.io.IOException)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)17 BeforeEach (org.junit.jupiter.api.BeforeEach)16 Autowired (org.springframework.beans.factory.annotation.Autowired)16 Result (io.r2dbc.spi.Result)14 Path (java.nio.file.Path)14