Search in sources :

Example 6 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testAccessingChangedGlobalVarInAnotherResource.

@Test(description = "Test accessing changed global var in another resource in same service", enabled = false)
public void testAccessingChangedGlobalVarInAnotherResource() {
    HTTPTestRequest cMsgChange = MessageUtils.generateHTTPMessage("/globalvar/change-resource-level", "GET");
    Services.invokeNew(result, cMsgChange);
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/get-changed-resource-level", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"glbVarFloatChange":77.87}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("glbVarFloatChange").asText(), "77.87");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 7 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testAccessingChangedGlobalVarInAnotherResourceInAnotherService.

@Test(description = "Test accessing changed global var in another resource in different service", enabled = false)
public void testAccessingChangedGlobalVarInAnotherResourceInAnotherService() {
    HTTPTestRequest cMsgChange = MessageUtils.generateHTTPMessage("/globalvar/change-resource-level", "GET");
    Services.invokeNew(result, cMsgChange);
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-second/get-changed-resource-level", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"glbVarFloatChange":77.87}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("glbVarFloatChange").asText(), "77.87");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 8 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testDefiningGlobalVarInService.

@Test(description = "Test defining global variables in services", enabled = false)
public void testDefiningGlobalVarInService() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/defined", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"glbVarInt":800, "glbVarString":"value", "glbVarFloat":99.34323}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("glbVarInt").asText(), "800");
    Assert.assertEquals(bJson.value().get("glbVarString").asText(), "value");
    Assert.assertEquals(bJson.value().get("glbVarFloat").asText(), "99.34323");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 9 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testAccessingGlobalVarInServiceLevel.

@Test(description = "Test accessing global variables in service level", enabled = false)
public void testAccessingGlobalVarInServiceLevel() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/access-service-level", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"serviceVarFloat":99.34323}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("serviceVarFloat").asText(), "99.34323");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 10 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.

the class LocksInServicesTest method testServiceLvlVarLockComplex.

@Test(description = "Test locking service level variable complex", enabled = false)
public void testServiceLvlVarLockComplex() {
    Semaphore semaphore = new Semaphore(-11);
    ExecutorService executor = TestThreadPool.getInstance().getExecutor();
    for (int i = 0; i < 4; i++) {
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo"));
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo1"));
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo2"));
    }
    try {
        if (!semaphore.tryAcquire(10, TimeUnit.MINUTES)) {
            Assert.fail("request execution not finished within 2s");
        }
        String path = "/sample1/getResult";
        HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
        HTTPCarbonMessage response = Services.invokeNew(compileResult, cMsg);
        Assert.assertNotNull(response, "Response message not found");
        String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
        Assert.assertEquals(responseMsgPayload, "3333333333331224.01455555555555513.026.0777777777777", "incorrect request count");
    } catch (InterruptedException e) {
        Assert.fail("thread interrupted before request execution finished - " + e.getMessage(), e);
    }
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ExecutorService(java.util.concurrent.ExecutorService) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Semaphore(java.util.concurrent.Semaphore) Test(org.testng.annotations.Test)

Aggregations

HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)176 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)172 Test (org.testng.annotations.Test)172 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)172 BJSON (org.ballerinalang.model.values.BJSON)104 BString (org.ballerinalang.model.values.BString)21 ArrayList (java.util.ArrayList)5 Header (org.wso2.carbon.messaging.Header)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ExecutorService (java.util.concurrent.ExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BStruct (org.ballerinalang.model.values.BStruct)2 StringDataSource (org.ballerinalang.runtime.message.StringDataSource)2 MIMEPart (org.jvnet.mimepull.MIMEPart)2 EncoderException (io.netty.handler.codec.EncoderException)1 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1