Search in sources :

Example 6 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project siddhi by wso2.

the class JoinPartitionTestCase method testJoinPartition8.

@Test
public void testJoinPartition8() throws InterruptedException {
    log.info("Join partition test8");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int);  define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.volume " + "insert all events into outputStream ;" + "" + "end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
    siddhiAppRuntime.start();
    cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
    twitterStreamHandler.send(new Object[] { "User2", "Hellno World", "WSO2" });
    twitterStreamHandler.send(new Object[] { "User3", "Hellno World", "WSO2" });
    SiddhiTestHelper.waitForEvents(100, 6, count, 6000);
    AssertJUnit.assertEquals(6, count.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 7 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project siddhi by wso2.

the class JoinPartitionTestCase method testJoinPartition3.

@Test
public void testJoinPartition3() throws InterruptedException {
    log.info("Join partition test3");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int);  define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream, user of twitterStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, cseEventStream.user as user,twitterStream.tweet, " + "cseEventStream.volume " + "insert all events into #outputStream ;" + "@info(name = 'query2') from #outputStream select symbol,user insert all events into outStream;" + "end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
    siddhiAppRuntime.start();
    cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
    twitterStreamHandler.send(new Object[] { "User1", "World", "WSO2" });
    cseEventStreamHandler.send(new Object[] { "IBM", "User2", 100 });
    twitterStreamHandler.send(new Object[] { "User2", "Hello World", "IBM" });
    twitterStreamHandler.send(new Object[] { "User2", "World", "IBM" });
    SiddhiTestHelper.waitForEvents(100, 8, count, 6000);
    AssertJUnit.assertEquals(8, count.get());
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 8 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project siddhi by wso2.

the class JoinPartitionTestCase method testJoinPartition7.

@Test
public void testJoinPartition7() throws InterruptedException {
    log.info("Join partition test7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int);  define stream " + "twitterStream (user string, tweet string, company string, volume int);" + "partition with (volume>=100 as 'large' or volume<100 as 'small' of cseEventStream, volume>=100 as " + "'large' or volume<100 as 'small' of twitterStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.user== twitterStream.user " + "select cseEventStream.symbol as symbol, cseEventStream.user as user,twitterStream.tweet, " + "cseEventStream.volume,twitterStream.company " + "insert all events into outputStream;" + "end ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
    siddhiAppRuntime.start();
    cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 200 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2", 200 });
    twitterStreamHandler.send(new Object[] { "User1", "World", "WSO2", 200 });
    cseEventStreamHandler.send(new Object[] { "IBM", "User1", 10 });
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2", 10 });
    twitterStreamHandler.send(new Object[] { "User1", "World", "IBM", 10 });
    SiddhiTestHelper.waitForEvents(100, 8, count, 6000);
    AssertJUnit.assertEquals(8, count.get());
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 9 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project siddhi by wso2.

the class JoinPartitionTestCase method testJoinPartition10.

@Test
public void testJoinPartition10() throws InterruptedException {
    log.info("Join partition test10");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "" + "define stream cseEventStream (symbol string, user string,volume int);  " + "define stream twitterStream (user string, tweet string, company string); " + "" + "partition with (user of cseEventStream, user of twitterStream) " + "begin " + "   @info(name = 'query1') " + "   from cseEventStream#window.length(1) unidirectional join twitterStream#window.length(1) " + "   select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.volume, " + "cseEventStream.user" + "   insert all events into outputStream1 ;" + "" + "end;" + "" + "partition with (user of outputStream1) " + "begin " + "   @info(name = 'query2') " + "   from outputStream1#window.length(1) join twitterStream#window.length(1) " + "   select outputStream1.symbol as symbol, twitterStream.tweet, outputStream1.volume " + "   insert all events into outputStream ;" + "" + "end;" + " ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            count.addAndGet(events.length);
            eventArrived = true;
        }
    });
    InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
    siddhiAppRuntime.start();
    twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
    cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
    cseEventStreamHandler.send(new Object[] { "WSO2", "User2", 100 });
    twitterStreamHandler.send(new Object[] { "User2", "Hello World", "WSO2" });
    twitterStreamHandler.send(new Object[] { "User3", "Hello World", "WSO2" });
    cseEventStreamHandler.send(new Object[] { "WSO2", "User3", 100 });
    SiddhiTestHelper.waitForEvents(100, 3, count, 60000);
    AssertJUnit.assertEquals(3, count.get());
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 10 with User

use of org.wso2.carbon.identity.application.common.model.xsd.User in project siddhi by wso2.

the class PlaybackTestCase method playbackTest4.

@Test
public void playbackTest4() throws InterruptedException {
    log.info("Playback Test 4: Playback with query joining two windows");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "@app:playback(idle.time = '100 millisecond', increment = '1 sec') " + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); ";
    String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.timeBatch(1 sec) join twitterStream#window.timeBatch(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                if (inEvents != null) {
                    inEventCount += (inEvents.length);
                }
                if (removeEvents != null) {
                    removeEventCount += (removeEvents.length);
                }
                eventArrived = true;
            }
        });
        InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
        InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
        siddhiAppRuntime.start();
        long currentTime = System.currentTimeMillis();
        cseEventStreamHandler.send(currentTime, new Object[] { "WSO2", 55.6f, 100 });
        twitterStreamHandler.send(currentTime, new Object[] { "User1", "Hello World", "WSO2" });
        cseEventStreamHandler.send(currentTime, new Object[] { "IBM", 75.6f, 100 });
        currentTime += 1500;
        cseEventStreamHandler.send(currentTime, new Object[] { "WSO2", 57.6f, 100 });
        // Anything more than 100 is enough. Used 200 to be on safe side
        Thread.sleep(200);
        AssertJUnit.assertTrue("In Events can be 1 or 2 ", inEventCount == 1 || inEventCount == 2);
        AssertJUnit.assertEquals(0, removeEventCount);
        AssertJUnit.assertTrue(eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)423 ArrayList (java.util.ArrayList)323 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)322 HashMap (java.util.HashMap)311 UserStoreException (org.wso2.carbon.user.api.UserStoreException)286 Test (org.junit.Test)272 Response (javax.ws.rs.core.Response)233 SQLException (java.sql.SQLException)166 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)158 PreparedStatement (java.sql.PreparedStatement)151 Connection (java.sql.Connection)148 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)134 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)130 Map (java.util.Map)115 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)114 User (org.wso2.charon3.core.objects.User)114 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)112 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)105 Request (org.wso2.msf4j.Request)105 UserStoreException (org.wso2.carbon.user.core.UserStoreException)103