Search in sources :

Example 1 with API

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;
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler)

Example 2 with API

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);
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 3 with API

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);
}
Also used : StoreQuery(org.wso2.siddhi.query.api.execution.query.StoreQuery) Test(org.testng.annotations.Test)

Example 4 with API

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);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 5 with API

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);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)582 ArrayList (java.util.ArrayList)374 API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)350 HashMap (java.util.HashMap)318 Test (org.junit.Test)316 API (org.wso2.carbon.apimgt.api.model.API)307 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)255 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)234 SQLException (java.sql.SQLException)190 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)186 IOException (java.io.IOException)181 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 PreparedStatement (java.sql.PreparedStatement)169 Connection (java.sql.Connection)158 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)149 JSONObject (org.json.simple.JSONObject)142 Resource (org.wso2.carbon.registry.core.Resource)139