use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class TestSiddhiLatency method isThrottled.
public static boolean isThrottled(Object[] throttleRequest) {
log.info("Start latency =" + (System.currentTimeMillis() - (Long) throttleRequest[7]));
if (ruleCount.get() != 0) {
String uniqueKey = (String) throttleRequest[0];
ResultContainer result = new ResultContainer(ruleCount.get());
resultMap.put(uniqueKey.toString(), result);
for (InputHandler inputHandler : requestStreamInputHandlerMap.values()) {
try {
inputHandler.send(Arrays.copyOf(throttleRequest, throttleRequest.length));
} catch (InterruptedException e) {
// interrupt current thread so that interrupt can propagate
Thread.currentThread().interrupt();
log.error(e.getMessage(), e);
}
}
log.info("sending latency =" + (System.currentTimeMillis() - (Long) throttleRequest[7]));
// Blocked call to return synchronous result
boolean isThrottled = false;
try {
isThrottled = result.isThrottled();
log.info("After result latency =" + (System.currentTimeMillis() - (Long) throttleRequest[7]));
if (log.isDebugEnabled()) {
log.debug("Throttling status for request to API " + throttleRequest[2] + " is " + isThrottled);
}
} catch (InterruptedException e) {
// interrupt current thread so that interrupt can propagate
Thread.currentThread().interrupt();
// log.error(e.getMessage(), e);
}
if (!isThrottled) {
// Converting properties map into json compatible String
if (throttleRequest[6] != null) {
throttleRequest[6] = (throttleRequest[6]).toString();
}
// Only send served throttleRequest to global throttler
// sendToGlobalThrottler(throttleRequest);
}
resultMap.remove(uniqueKey);
log.info("Return latency =" + (System.currentTimeMillis() - (Long) throttleRequest[7]));
return isThrottled;
} else {
return false;
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class DefineStreamTestCase method testCreatingStreamDefinition.
// define stream StockStream (symbol string, price int, volume float );
@Test
public void testCreatingStreamDefinition() {
StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream StockStream ( symbol " + "string, price int, volume float );");
StreamDefinition api = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT);
AssertJUnit.assertEquals(api, streamDefinition);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class QueryStoreTestCase method test3.
@Test
public void test3() {
StoreQuery query = SiddhiCompiler.parseStoreQuery("" + "from StockTable " + "on price > 40 " + "select symbol, price " + "group by symbol " + "having (7 > price) ;");
AssertJUnit.assertNotNull(query);
StoreQuery api = StoreQuery.query().from(InputStore.store("StockTable").on(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(40)))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select(Expression.variable("price")).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.value(7), Compare.Operator.GREATER_THAN, Expression.variable("price"))));
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class SimpleQueryTestCase method test12.
@Test
public void test12() throws SiddhiParserException {
Query query = SiddhiCompiler.parseQuery("from StockStream[price>3]#window.length(50) " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having (price >= 20)" + "order by avgPrice desc " + "limit 5 " + "insert all events into StockQuote; ");
AssertJUnit.assertNotNull(query);
Query api = Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(3))).window("length", Expression.value(50))).select(Selector.selector().select(Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))).orderBy(Expression.variable("avgPrice"), OrderByAttribute.Order.DESC).limit(Expression.value(5))).insertInto("StockQuote", OutputStream.OutputEventType.ALL_EVENTS);
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.API in project siddhi by wso2.
the class SimpleQueryTestCase method test7.
@Test
public void test7() {
Query query = SiddhiCompiler.parseQuery("from StockStream[7+9.5 < price or 100 <= volume]#window.length(50) " + " " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having avgPrice!= 50 " + "insert into OutStockStream ;");
AssertJUnit.assertNotNull(query);
Query api = Query.query();
api.from(InputStream.stream("StockStream").filter(Expression.or(Expression.compare(Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.LESS_THAN, Expression.variable("price")), Expression.compare(Expression.value(100), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("volume")))).window("length", Expression.value(50)));
api.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.NOT_EQUAL, Expression.value(50))));
api.insertInto("OutStockStream");
AssertJUnit.assertEquals(api, query);
}
Aggregations