use of org.wso2.siddhi.query.api.aggregation.Within in project siddhi by wso2.
the class PatternQueryTestCase method testPatternQuery9.
// from every (e1=Stream1[price >= 30]) -> e2=Stream1[ prev.price >= 20]<5:> within 3 min -> e3=Stream2[ price >=
// e1.price] -> e4=Stream3[price>74]
// select e1.symbol, avg(e2.price ) as avgPrice
// insert into OutputStream
@Test
public void testPatternQuery9() {
Query query = Query.query();
query.from(InputStream.patternStream(State.next(State.every(State.stream(InputStream.stream("e1", "Stream1").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(30))))), State.next(State.countMoreThanEqual(State.stream(InputStream.stream("e2", "Stream1").filter(Expression.compare(Expression.variable("price").ofStream("e2", Variable.LAST), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)))), 5, Expression.Time.minute(3)), State.next(State.stream(InputStream.stream("e3", "Stream2").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("price").ofStream("e1")))), State.stream(InputStream.stream("e4", "Stream3").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(74)))))))));
query.select(Selector.selector().select("symbol", Expression.variable("symbol").ofStream("e1")).select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2"))));
query.insertInto("OutputStream");
}
use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.
the class SwaggerConverterUtils method generateOAS3Definitions.
/**
* This method will generate open API 3.X specification for given ballerina service. Since we will need to
* support both swagger 2.0 and OAS 3.0 it was implemented to convert to swagger by default and convert it
* to OAS on demand.
*
* @param ballerinaSource ballerina source to be converted to swagger/OAS definition
* @param serviceName specific service name within ballerina source that need to map OAS
* @return Generated OAS3 string output.
* @throws IOException When error occurs while converting, parsing input source.
*/
public static String generateOAS3Definitions(String ballerinaSource, String serviceName) throws IOException {
// Get the ballerina model using the ballerina source code.
BFile balFile = new BFile();
balFile.setContent(ballerinaSource);
// Create empty swagger object.
Swagger swaggerDefinition = new Swagger();
BLangCompilationUnit topCompilationUnit = SwaggerConverterUtils.getTopLevelNodeFromBallerinaFile(balFile);
String httpAlias = getAlias(topCompilationUnit, Constants.BALLERINA_HTTP_PACKAGE_NAME);
String swaggerAlias = getAlias(topCompilationUnit, Constants.SWAGGER_PACKAGE_NAME);
SwaggerServiceMapper swaggerServiceMapper = new SwaggerServiceMapper(httpAlias, swaggerAlias);
String swaggerSource = StringUtils.EMPTY;
for (TopLevelNode topLevelNode : topCompilationUnit.getTopLevelNodes()) {
if (topLevelNode instanceof BLangService) {
ServiceNode serviceDefinition = (ServiceNode) topLevelNode;
// Generate swagger string for the mentioned service name.
if (StringUtils.isNotBlank(serviceName)) {
if (serviceDefinition.getName().getValue().equals(serviceName)) {
swaggerDefinition = swaggerServiceMapper.convertServiceToSwagger(serviceDefinition);
break;
}
} else {
// If no service name mentioned, then generate swagger definition for the first service.
swaggerDefinition = swaggerServiceMapper.convertServiceToSwagger(serviceDefinition);
break;
}
}
}
swaggerSource = swaggerServiceMapper.generateSwaggerString(swaggerDefinition);
SwaggerConverter converter = new SwaggerConverter();
return Yaml.pretty(converter.readContents(swaggerSource, null, null).getOpenAPI());
}
use of org.wso2.siddhi.query.api.aggregation.Within 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.aggregation.Within 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.aggregation.Within in project ballerina by ballerina-lang.
the class ServiceEndpointTest method testGetProtocolConnectionStruct.
@Test(description = "Test the protocol value of ServiceEndpoint struct within a service")
public void testGetProtocolConnectionStruct() {
String protocolValue = "http";
String path = "/hello/protocol";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200);
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("protocol").asText(), protocolValue);
}
Aggregations