use of org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint in project wso2-axis2-transports by wso2.
the class AxisTestEndpoint method setUp.
@Setup
@SuppressWarnings("unused")
private void setUp(LogManager logManager, AxisTestEndpointContext context, Channel channel, AxisServiceConfigurator[] configurators) throws Exception {
this.context = context;
TransportListener listener = context.getTransportListener();
if (listener instanceof TransportErrorSource) {
transportErrorSource = (TransportErrorSource) listener;
errorListener = new TransportErrorListener() {
public void error(TransportError error) {
AxisService s = error.getService();
if (s == null || s == service) {
onTransportError(error.getException());
}
}
};
transportErrorSource.addErrorListener(errorListener);
} else {
transportErrorSource = null;
}
String path;
try {
path = new URI(channel.getEndpointReference().getAddress()).getPath();
} catch (URISyntaxException ex) {
path = null;
}
String serviceName;
if (path != null && path.startsWith(Channel.CONTEXT_PATH + "/")) {
serviceName = path.substring(Channel.CONTEXT_PATH.length() + 1);
} else {
serviceName = "TestService-" + UUID.randomUUID();
}
service = new AxisService(serviceName);
service.addOperation(createOperation());
if (configurators != null) {
for (AxisServiceConfigurator configurator : configurators) {
configurator.setupService(service, false);
}
}
// Output service parameters to log file
// FIXME: This actually doesn't give the expected result because the AxisTestEndpoint might be reused
// by several test cases and in that case the log file is only produced once
List<Parameter> params = (List<Parameter>) service.getParameters();
if (!params.isEmpty()) {
PrintWriter log = new PrintWriter(logManager.createLog("service-parameters"), false);
try {
for (Parameter param : params) {
log.print(param.getName());
log.print("=");
log.println(param.getValue());
}
} finally {
log.close();
}
}
// We want to receive all messages through the same operation:
service.addParameter(AxisService.SUPPORT_SINGLE_OP, true);
context.getAxisConfiguration().addService(service);
// The transport may disable the service. In that case, fail directly.
if (!BaseUtils.isUsingTransport(service, context.getTransportName())) {
Assert.fail("The service has been disabled by the transport");
}
}
use of org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint in project wso2-axis2-transports by wso2.
the class MinConcurrencyTest method runTest.
@Override
protected void runTest() throws Throwable {
int endpointCount = channels.length;
int expectedConcurrency = endpointCount * messages;
final MessageReceiver messageReceiver = new MessageReceiver() {
public void receive(MessageContext msgContext) throws AxisFault {
synchronized (concurrencyReachedLock) {
concurrencyReached++;
concurrencyReachedLock.notifyAll();
}
try {
synchronized (shutdownAwaitLock) {
shutdownAwaitLock.wait();
}
} catch (InterruptedException ex) {
}
}
};
TestResourceSet[] clientResourceSets = new TestResourceSet[endpointCount];
TestResourceSet[] endpointResourceSets = new TestResourceSet[endpointCount];
try {
for (int i = 0; i < endpointCount; i++) {
TestResourceSet clientResourceSet = new TestResourceSet(getResourceSet());
AsyncChannel channel = channels[i];
clientResourceSet.addResource(channel);
AxisAsyncTestClient client = new AxisAsyncTestClient(false);
clientResourceSet.addResource(client);
clientResourceSet.setUp();
clientResourceSets[i] = clientResourceSet;
TestResourceSet endpointResourceSet = new TestResourceSet(clientResourceSet);
endpointResourceSet.addResource(new AxisTestEndpoint() {
@Override
protected AxisOperation createOperation() {
AxisOperation operation = new InOnlyAxisOperation(new QName("in"));
operation.setMessageReceiver(messageReceiver);
return operation;
}
@Override
protected void onTransportError(Throwable ex) {
// TODO Auto-generated method stub
}
});
if (!preloadMessages) {
endpointResourceSet.setUp();
endpointResourceSets[i] = endpointResourceSet;
}
for (int j = 0; j < messages; j++) {
ClientOptions options = new ClientOptions(client, new ContentType(SOAP11Constants.SOAP_11_CONTENT_TYPE), "UTF-8");
AxisMessage message = new AxisMessage();
message.setMessageType(SOAP11Constants.SOAP_11_CONTENT_TYPE);
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
message.setEnvelope(envelope);
client.sendMessage(options, new ContentType(message.getMessageType()), message);
}
if (preloadMessages) {
endpointResourceSet.setUp();
endpointResourceSets[i] = endpointResourceSet;
}
}
long startTime = System.currentTimeMillis();
while (concurrencyReached < expectedConcurrency && System.currentTimeMillis() < (startTime + 5000)) {
synchronized (concurrencyReachedLock) {
concurrencyReachedLock.wait(5000);
}
}
synchronized (shutdownAwaitLock) {
shutdownAwaitLock.notifyAll();
}
if (concurrencyReached < expectedConcurrency) {
fail("Concurrency reached is " + concurrencyReached + ", but expected " + expectedConcurrency);
}
} finally {
for (int i = 0; i < endpointCount; i++) {
if (endpointResourceSets[i] != null) {
endpointResourceSets[i].tearDown();
}
if (clientResourceSets[i] != null) {
clientResourceSets[i].tearDown();
}
}
}
}
Aggregations