use of org.mule.runtime.api.connection.ConnectionHandler in project mule by mulesoft.
the class PagingProviderProducerTestCase method setUp.
@Before
public void setUp() throws MuleException {
when(config.getValue()).thenReturn("config");
ConnectionHandler handler = mock(ConnectionHandler.class);
when(handler.getConnection()).thenReturn(new Object());
when(extensionConnectionSupplier.getConnection(executionContext)).thenReturn(handler);
}
use of org.mule.runtime.api.connection.ConnectionHandler in project mule by mulesoft.
the class PagingProviderProducerTestCase method produceWithDifferentConnections.
@Test
public void produceWithDifferentConnections() throws Exception {
ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
when(extensionConnectionSupplier.getConnection(any())).thenReturn(connectionHandler);
produce();
produce();
verify(connectionHandler, times(2)).getConnection();
verify(connectionHandler, times(2)).release();
}
use of org.mule.runtime.api.connection.ConnectionHandler in project mule by mulesoft.
the class PagingProviderProducerTestCase method produceWithStickyConnection.
@Test
public void produceWithStickyConnection() throws Exception {
when(delegate.useStickyConnections()).thenReturn(true);
producer = createProducer();
ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
when(extensionConnectionSupplier.getConnection(any())).thenReturn(connectionHandler);
produce();
produce();
verify(connectionHandler, times(1)).getConnection();
verify(connectionHandler, never()).release();
producer.close();
verify(connectionHandler).release();
}
use of org.mule.runtime.api.connection.ConnectionHandler in project mule by mulesoft.
the class ConnectionArgumentResolverTestCase method resolve.
@Test
public void resolve() throws Exception {
ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
final Object connection = new Object();
when(connectionHandler.getConnection()).thenReturn(connection);
when(operationContext.getVariable(CONNECTION_PARAM)).thenReturn(connectionHandler);
assertThat(resolver.resolve(operationContext).get(), is(sameInstance(connection)));
}
use of org.mule.runtime.api.connection.ConnectionHandler in project mule by mulesoft.
the class ConnectionArgumentResolver method resolve.
/**
* Returns the connection previously set on the {@code executionContext} under the key
* {@link ExtensionProperties#CONNECTION_PARAM}
*
* @param executionContext an {@link ExecutionContext}
* @return the connection
* @throws IllegalArgumentException if the connection was not set
* @throws ClassCastException if {@code executionContext} is not an {@link ExecutionContextAdapter}
*/
@Override
public LazyValue<Object> resolve(ExecutionContext executionContext) {
return new LazyValue<>(() -> {
ConnectionHandler connectionHandler = ((ExecutionContextAdapter<ComponentModel>) executionContext).getVariable(CONNECTION_PARAM);
checkArgument(connectionHandler != null, "No connection was provided for the component [" + executionContext.getComponentModel().getName() + "]");
try {
return connectionHandler.getConnection();
} catch (ConnectionException e) {
throw new MuleRuntimeException(I18nMessageFactory.createStaticMessage(String.format("Error was found trying to obtain a connection to execute %s '%s' of extension '%s'", getComponentModelTypeName(executionContext.getComponentModel()), executionContext.getComponentModel().getName(), executionContext.getExtensionModel().getName())), e);
}
});
}
Aggregations