use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class GlobalVarServicePkgTest method testAssigningGlobalVarToServiceVarFromDiffPkg.
@Test(description = "Test assigning global variable to service variable from different package", enabled = false)
public void testAssigningGlobalVarToServiceVarFromDiffPkg() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-pkg/assign-to-service-var-from-diff-pkg", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"serviceVarString":"stringval"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("serviceVarString").asText(), "stringval");
}
use of org.wso2.siddhi.query.api.expression.Variable 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);
}
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class LocksInServicesTest method testServiceLvlVarLockBasic.
@Test(description = "Test locking service level variable basic", enabled = false)
public void testServiceLvlVarLockBasic() {
Semaphore semaphore = new Semaphore(-9999);
ExecutorService executor = TestThreadPool.getInstance().getExecutor();
for (int i = 0; i < 10000; i++) {
executor.submit(new TestRequestSender(compileResult, semaphore, "/sample/echo"));
}
try {
if (!semaphore.tryAcquire(20, TimeUnit.MINUTES)) {
Assert.fail("request execution not finished within 2s");
}
String path = "/sample/getCount";
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, "count - 10000", "incorrect request count");
} catch (InterruptedException e) {
Assert.fail("thread interrupted before request execution finished - " + e.getMessage(), e);
}
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class DocumentationTest method testDocConstant.
@Test(description = "Test doc constant.")
public void testDocConstant() {
CompileResult compileResult = BCompileUtil.compile("test-src/documentation/constant.bal");
Assert.assertEquals(0, compileResult.getWarnCount());
PackageNode packageNode = compileResult.getAST();
List<BLangDocumentation> docNodes = ((BLangVariable) packageNode.getGlobalVariables().get(0)).docAttachments;
BLangDocumentation dNode = docNodes.get(0);
Assert.assertNotNull(dNode);
Assert.assertEquals(dNode.documentationText, " Documentation for testConst constant\n");
Assert.assertEquals(dNode.getAttributes().size(), 1);
Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "testConst");
Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " constant variable `testConst`");
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class ServiceProtoUtils method getInvocationExpression.
private static BLangInvocation getInvocationExpression(BlockNode body) {
if (body == null) {
return null;
}
for (StatementNode statementNode : body.getStatements()) {
BLangExpression expression = null;
// example : conn.send inside while block.
if (statementNode instanceof BLangWhile) {
BLangWhile langWhile = (BLangWhile) statementNode;
BLangInvocation invocExp = getInvocationExpression(langWhile.getBody());
if (invocExp != null) {
return invocExp;
}
}
// example : conn.send inside for block.
if (statementNode instanceof BLangForeach) {
BLangForeach langForeach = (BLangForeach) statementNode;
BLangInvocation invocExp = getInvocationExpression(langForeach.getBody());
if (invocExp != null) {
return invocExp;
}
}
// example : conn.send inside if block.
if (statementNode instanceof BLangIf) {
BLangIf langIf = (BLangIf) statementNode;
BLangInvocation invocExp = getInvocationExpression(langIf.getBody());
if (invocExp != null) {
return invocExp;
}
invocExp = getInvocationExpression((BLangBlockStmt) langIf.getElseStatement());
if (invocExp != null) {
return invocExp;
}
}
// example : _ = conn.send(msg);
if (statementNode instanceof BLangAssignment) {
BLangAssignment assignment = (BLangAssignment) statementNode;
expression = assignment.getExpression();
}
// example : grpc:HttpConnectorError err = conn.send(msg);
if (statementNode instanceof BLangVariableDef) {
BLangVariableDef variableDef = (BLangVariableDef) statementNode;
BLangVariable variable = variableDef.getVariable();
expression = variable.getInitialExpression();
}
if (expression != null && expression instanceof BLangInvocation) {
BLangInvocation invocation = (BLangInvocation) expression;
if ("send".equals(invocation.getName().getValue())) {
return invocation;
}
}
}
return null;
}
Aggregations