use of org.apache.axis2.transport.base.threads.NativeWorkerPool in project wso2-synapse by wso2.
the class PassThroughHttpSenderTest method testInit.
/**
* This method tests the initialization of PassThroughHttpSender
* @throws Exception
*/
@Test
public void testInit() throws Exception {
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
configurationContext.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL, workerPool);
TransportOutDescription transportOutDescription = new TransportOutDescription("passthru");
PassThroughHttpSender passThroughHttpSender = new PassThroughHttpSender();
passThroughHttpSender.init(configurationContext, transportOutDescription);
}
use of org.apache.axis2.transport.base.threads.NativeWorkerPool in project wso2-synapse by wso2.
the class TargetResponseTest method testTrue.
/**
* Testing the starting of target response when response body is expected
*
* @throws Exception
*/
@Test
public void testTrue() throws Exception {
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
targetConfiguration.build();
HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
PowerMockito.mockStatic(TargetContext.class);
TargetContext cntxt = new TargetContext(targetConfiguration);
PowerMockito.when(TargetContext.get(any(NHttpClientConnection.class))).thenReturn(cntxt);
TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, true, false);
try {
targetResponse.start(conn);
} catch (Exception e) {
logger.error(e);
Assert.fail("Unable to start the target response!");
}
}
use of org.apache.axis2.transport.base.threads.NativeWorkerPool in project wso2-synapse by wso2.
the class TargetResponseTest method testFalse.
/**
* Testing the starting of target response when response body is not expected
*
* @throws Exception
*/
@Test
public void testFalse() throws Exception {
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
TargetConnections connections = PowerMockito.mock(TargetConnections.class);
targetConfiguration.setConnections(connections);
PowerMockito.mockStatic(TargetContext.class);
TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, false, false);
try {
targetResponse.start(conn);
} catch (Exception e) {
logger.error(e);
Assert.fail("Unable to start the target response!");
}
}
use of org.apache.axis2.transport.base.threads.NativeWorkerPool in project wso2-synapse by wso2.
the class TargetResponseTest method testRead.
/**
* Testing reading from a pipe
* @throws Exception
*/
@Test
public void testRead() throws Exception {
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
targetConfiguration.build();
HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
ContentDecoder decoder = PowerMockito.mock(ContentDecoder.class);
TargetConnections connections = PowerMockito.mock(TargetConnections.class);
targetConfiguration.setConnections(connections);
PowerMockito.mockStatic(TargetContext.class);
TargetContext cntxt = new TargetContext(targetConfiguration);
PowerMockito.when(TargetContext.get(any(NHttpClientConnection.class))).thenReturn(cntxt);
PowerMockito.when(decoder.read(any(ByteBuffer.class))).thenReturn(12);
PowerMockito.when(decoder.isCompleted()).thenReturn(true);
TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, true, false);
targetResponse.start(conn);
int result = targetResponse.read(conn, decoder);
Assert.assertEquals(12, result);
}
use of org.apache.axis2.transport.base.threads.NativeWorkerPool in project wso2-synapse by wso2.
the class TargetHandlerTest method testOutputReady.
/**
* Testing whether output-ready connection is processed
*
* @throws Exception
*/
@Test
public void testOutputReady() throws Exception {
DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
ClientConnFactory connFactory = mock(ClientConnFactory.class);
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
TargetContext targetContext = new TargetContext(targetConfiguration);
MessageContext messageContext = new MessageContext();
targetContext.setRequestMsgCtx(messageContext);
TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
TargetRequest request = mock(TargetRequest.class);
NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
ContentEncoder encoder = mock(ContentEncoder.class);
mockStatic(TargetContext.class);
when(TargetContext.get(conn)).thenReturn(targetContext);
when(TargetContext.getState(conn)).thenReturn(ProtocolState.REQUEST_HEAD);
when(TargetContext.getRequest(conn)).thenReturn(request);
when(request.hasEntityBody()).thenReturn(true);
when(request.write(conn, encoder)).thenReturn(12);
when(encoder.isCompleted()).thenReturn(true);
targetHandler.outputReady(conn, encoder);
}
Aggregations