Search in sources :

Example 1 with TestResourceSet

use of org.apache.axis2.transport.testkit.tests.TestResourceSet in project wso2-axis2-transports by wso2.

the class ManagedTestSuite method run.

@Override
public void run(TestResult result) {
    LogManager logManager = LogManager.INSTANCE;
    if (!reuseResources) {
        super.run(result);
    } else {
        TestResourceSet resourceSet = null;
        for (Enumeration<?> e = tests(); e.hasMoreElements(); ) {
            Test test = (Test) e.nextElement();
            if (test instanceof ManagedTestCase) {
                ManagedTestCase ttest = (ManagedTestCase) test;
                TestResourceSet newResourceSet = ttest.getResourceSet();
                try {
                    if (resourceSet == null) {
                        logManager.setTestCase(ttest);
                        newResourceSet.setUp();
                    } else {
                        TestResourceSetTransition transition = new TestResourceSetTransition(resourceSet, newResourceSet);
                        transition.tearDown();
                        logManager.setTestCase(ttest);
                        transition.setUp();
                    }
                } catch (Throwable t) {
                    result.addError(this, t);
                    return;
                }
                resourceSet = newResourceSet;
            }
            runTest(test, result);
        }
        if (resourceSet != null) {
            try {
                resourceSet.tearDown();
                logManager.setTestCase(null);
            } catch (Throwable t) {
                result.addError(this, t);
                return;
            }
        }
    }
}
Also used : ManagedTestCase(org.apache.axis2.transport.testkit.tests.ManagedTestCase) Test(junit.framework.Test) TestResourceSet(org.apache.axis2.transport.testkit.tests.TestResourceSet) TestResourceSetTransition(org.apache.axis2.transport.testkit.tests.TestResourceSetTransition) LogManager(org.apache.axis2.transport.testkit.util.LogManager)

Example 2 with TestResourceSet

use of org.apache.axis2.transport.testkit.tests.TestResourceSet 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();
            }
        }
    }
}
Also used : ClientOptions(org.apache.axis2.transport.testkit.client.ClientOptions) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) ContentType(javax.mail.internet.ContentType) QName(javax.xml.namespace.QName) AsyncChannel(org.apache.axis2.transport.testkit.channel.AsyncChannel) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) MessageReceiver(org.apache.axis2.engine.MessageReceiver) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) AxisAsyncTestClient(org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient) MessageContext(org.apache.axis2.context.MessageContext) TestResourceSet(org.apache.axis2.transport.testkit.tests.TestResourceSet) AxisMessage(org.apache.axis2.transport.testkit.message.AxisMessage)

Aggregations

TestResourceSet (org.apache.axis2.transport.testkit.tests.TestResourceSet)2 ContentType (javax.mail.internet.ContentType)1 QName (javax.xml.namespace.QName)1 Test (junit.framework.Test)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 MessageContext (org.apache.axis2.context.MessageContext)1 AxisOperation (org.apache.axis2.description.AxisOperation)1 InOnlyAxisOperation (org.apache.axis2.description.InOnlyAxisOperation)1 MessageReceiver (org.apache.axis2.engine.MessageReceiver)1 AxisAsyncTestClient (org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient)1 AxisTestEndpoint (org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint)1 AsyncChannel (org.apache.axis2.transport.testkit.channel.AsyncChannel)1 ClientOptions (org.apache.axis2.transport.testkit.client.ClientOptions)1 AxisMessage (org.apache.axis2.transport.testkit.message.AxisMessage)1 ManagedTestCase (org.apache.axis2.transport.testkit.tests.ManagedTestCase)1 TestResourceSetTransition (org.apache.axis2.transport.testkit.tests.TestResourceSetTransition)1 LogManager (org.apache.axis2.transport.testkit.util.LogManager)1