Search in sources :

Example 26 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class SourceConfigurer method configure.

/**
 * Performs the configuration of the given {@code source} and returns the result
 *
 * @param source a {@link Source}
 * @param config the {@link ConfigurationInstance config instance} associated to {@code this} source object.
 * @return the configured instance
 * @throws MuleException
 */
public Source configure(Source source, Optional<ConfigurationInstance> config) throws MuleException {
    ResolverSetBasedObjectBuilder<Source> builder = new ResolverSetBasedObjectBuilder<Source>(source.getClass(), model, resolverSet) {

        @Override
        protected Source instantiateObject() {
            return source;
        }

        @Override
        public Source build(ValueResolvingContext context) throws MuleException {
            Source source = build(resolverSet.resolve(context));
            injectDefaultEncoding(model, source, muleContext.getConfiguration().getDefaultEncoding());
            injectComponentLocation(source, componentLocation);
            config.ifPresent(c -> injectRefName(source, c.getName(), getReflectionCache()));
            return source;
        }
    };
    CoreEvent initialiserEvent = null;
    try {
        initialiserEvent = getInitialiserEvent(muleContext);
        Source configuredSource = builder.build(from(initialiserEvent, config));
        if (configuredSource instanceof PollingSource) {
            Scheduler scheduler = (Scheduler) resolverSet.getResolvers().get(SCHEDULING_STRATEGY_PARAMETER_NAME).resolve(ValueResolvingContext.from(initialiserEvent));
            configuredSource = new PollingSourceWrapper((PollingSource) configuredSource, scheduler);
        }
        return configuredSource;
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage("Exception was found trying to configure source of type " + source.getClass().getName()), e);
    } finally {
        if (initialiserEvent != null) {
            ((BaseEventContext) initialiserEvent.getContext()).success();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ResolverSetBasedObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.ResolverSetBasedObjectBuilder) ValueResolvingContext(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) Source(org.mule.runtime.extension.api.runtime.source.Source) PollingSourceWrapper(org.mule.runtime.module.extension.internal.runtime.source.poll.PollingSourceWrapper) MuleException(org.mule.runtime.api.exception.MuleException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 27 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class DefaultEventContextTestCase method multipleLevelsGrandchildFirst.

@Test
@Description("Parent EventContext only completes once response publisher completes with a value and all child and grandchild contexts are complete.")
public void multipleLevelsGrandchildFirst() throws Exception {
    child = addChild(parent);
    BaseEventContext grandchild = child(child, empty());
    grandchild.success(testEvent());
    assertChild(is(nullValue()), is(nullValue()), false);
    assertParent(is(nullValue()), is(nullValue()), false, false);
    child.success(testEvent());
    assertChild(is(testEvent()), is(nullValue()), true);
    assertParent(is(nullValue()), is(nullValue()), false, false);
    parent.success(testEvent());
    assertChild(is(testEvent()), is(nullValue()), true);
    assertParent(is(testEvent()), is(nullValue()), true, true);
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 28 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class DefaultEventContextTestCase method componentDataFromSingleComponent.

@Test
@Description("Verify that a single component location produces connector and source data.")
public void componentDataFromSingleComponent() throws Exception {
    BaseEventContext context = this.context.get();
    assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), is(CORE_PREFIX));
    assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getName(), is("test"));
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 29 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class DefaultEventContextTestCase method multipleLevelsParentFirst.

@Test
@Description("Parent EventContext only completes once response publisher completes with a value and all child and grandchild contexts are complete, even if parent response is available earlier.")
public void multipleLevelsParentFirst() throws Exception {
    child = addChild(parent);
    BaseEventContext grandchild = child(child, empty());
    parent.success(testEvent());
    assertChild(is(nullValue()), is(nullValue()), false);
    assertParent(is(testEvent()), is(nullValue()), false, false);
    child.success(testEvent());
    assertChild(is(testEvent()), is(nullValue()), false);
    assertParent(is(testEvent()), is(nullValue()), false, false);
    grandchild.success();
    assertChild(is(testEvent()), is(nullValue()), true);
    assertParent(is(testEvent()), is(nullValue()), true, true);
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 30 with BaseEventContext

use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.

the class ExecutableComponentTestCase method testExecuteWithInputEvent.

@Test
public void testExecuteWithInputEvent() throws Exception {
    ExecutionResult executionResult = executableComponent.execute(InputEvent.create().message(requestMessage)).get();
    Event response = executionResult.getEvent();
    assertThat(componentInEvent.get().getMessage(), equalTo(requestMessage));
    assertThat(response.getMessage(), equalTo(responseMessage));
    assertThat(componentInEvent.get().getContext(), equalTo(response.getContext()));
    BaseEventContext eventContext = (BaseEventContext) componentInEvent.get().getContext();
    assertThat(eventContext.isTerminated(), is(false));
    executionResult.complete();
    assertThat(eventContext.isTerminated(), is(true));
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) InputEvent(org.mule.runtime.api.component.execution.InputEvent) Event(org.mule.runtime.api.event.Event) ExecutionResult(org.mule.runtime.api.component.execution.ExecutionResult) Test(org.junit.Test)

Aggregations

BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)45 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)34 Test (org.junit.Test)24 MuleException (org.mule.runtime.api.exception.MuleException)10 Message (org.mule.runtime.api.message.Message)10 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)8 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)7 Description (io.qameta.allure.Description)6 Optional.of (java.util.Optional.of)6 HeisenbergExtension (org.mule.test.heisenberg.extension.HeisenbergExtension)6 Optional (java.util.Optional)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 EventContext (org.mule.runtime.api.event.EventContext)5 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)5 Publisher (org.reactivestreams.Publisher)5 Mono.from (reactor.core.publisher.Mono.from)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Processor (org.mule.runtime.core.api.processor.Processor)4 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)4 String.format (java.lang.String.format)3