Java Code Examples for io.siddhi.core.SiddhiManager#shutdown()

The following examples show how to use io.siddhi.core.SiddhiManager#shutdown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSiddhiOperator.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
/**
 * Validate execution plan during building DAG before submitting to execution environment and fail-fast.
 */
private static void validate(final SiddhiOperatorContext siddhiPlan) {
    SiddhiManager siddhiManager = siddhiPlan.createSiddhiManager();
    try {
        siddhiManager.validateSiddhiApp(siddhiPlan.getAllEnrichedExecutionPlan());
    } finally {
        siddhiManager.shutdown();
    }
}
 
Example 2
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void externalTimeBatchWindowTest13() throws InterruptedException {
    log.info("externalTimeBatchWindow Test13");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream cseEventStream (timestamp long, symbol string, price float, volume int); " +
            "define stream twitterStream (timestamp long, user string, tweet string, company string); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.externalTimeBatch(timestamp, 1 sec, 0) join twitterStream#window" +
            ".externalTimeBatch(timestamp, 1 sec, 0) " +
            "on cseEventStream.symbol== twitterStream.company " +
            "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " +
            "insert all events 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();
        cseEventStreamHandler.send(new Object[]{1366335804341L, "WSO2", 55.6f, 100});
        twitterStreamHandler.send(new Object[]{1366335804341L, "User1", "Hello World", "WSO2"});
        twitterStreamHandler.send(new Object[]{1366335805301L, "User2", "Hello World2", "WSO2"});
        cseEventStreamHandler.send(new Object[]{1366335805341L, "WSO2", 75.6f, 100});
        cseEventStreamHandler.send(new Object[]{1366335806541L, "WSO2", 57.6f, 100});
        Thread.sleep(1000);
        org.testng.AssertJUnit.assertEquals(2, inEventCount);
        org.testng.AssertJUnit.assertEquals(1, removeEventCount);
        org.testng.AssertJUnit.assertTrue(eventArrived);
    } finally {
        siddhiManager.shutdown();
    }
}
 
Example 3
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void externalTimeBatchWindowTest10() throws InterruptedException {
    log.info("externalTimeBatchWindow test10");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "" +
            "define stream LoginEvents (timestamp long, ip string) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0, 2 sec) " +
            "select timestamp, ip, count() as total  " +
            "insert into uniqueIps ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            for (Event event : inEvents) {
                inEventCount++;
                if (inEventCount == 1) {
                    AssertJUnit.assertEquals(4L, event.getData(2));
                } else if (inEventCount == 2) {
                    AssertJUnit.assertEquals(3L, event.getData(2));
                } else if (inEventCount == 3) {
                    AssertJUnit.assertEquals(5L, event.getData(2));
                } else if (inEventCount == 4) {
                    AssertJUnit.assertEquals(7L, event.getData(2));
                } else if (inEventCount == 5) {
                    AssertJUnit.assertEquals(2L, event.getData(2));
                }
            }
            eventArrived = true;
        }

    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"});
    inputHandler.send(new Object[]{1366335804599L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335804600L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335804607L, "192.10.1.6"});
    inputHandler.send(new Object[]{1366335805599L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335805600L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335805607L, "192.10.1.6"});
    Thread.sleep(2100);
    inputHandler.send(new Object[]{1366335805606L, "192.10.1.7"});
    inputHandler.send(new Object[]{1366335805605L, "192.10.1.8"});
    Thread.sleep(2100);
    inputHandler.send(new Object[]{1366335805606L, "192.10.1.91"});
    inputHandler.send(new Object[]{1366335805605L, "192.10.1.92"});
    inputHandler.send(new Object[]{1366335806606L, "192.10.1.9"});
    inputHandler.send(new Object[]{1366335806690L, "192.10.1.10"});
    Thread.sleep(3000);

    org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    org.testng.AssertJUnit.assertEquals("In Events ", 5, inEventCount);
    org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
    siddhiManager.shutdown();
}
 
Example 4
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void externalTimeBatchWindowTest25() throws InterruptedException {
    log.info("externalTimeBatchWindow test25");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" +
            "define stream LoginEvents (timestamp long, ip string) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from LoginEvents#window.externalTimeBatch(timestamp, '1 sec', 123L, 100) " +
            "select timestamp, ip, count() as total  " +
            "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"});
    inputHandler.send(new Object[]{1366335804342L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335805341L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335814341L, "192.10.1.6"});
    inputHandler.send(new Object[]{1366335814345L, "192.10.1.7"});
    inputHandler.send(new Object[]{1366335824341L, "192.10.1.8"});
    inputHandler.send(new Object[]{1366335824351L, "192.10.1.9"});
    inputHandler.send(new Object[]{1366335824441L, "192.10.1.10"});
    Thread.sleep(1000);
    org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    org.testng.AssertJUnit.assertEquals("In Events ", 4, inEventCount);
    org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
    siddhiManager.shutdown();
}
 
Example 5
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void externalTimeBatchWindowTest12() throws InterruptedException {
    log.info("externalTimeBatchWindow Test12");

    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" +
            "define stream cseEventStream (timestamp long, symbol string, price float, volume int); " +
            "define stream twitterStream (timestamp long, user string, tweet string, company string); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.externalTimeBatch(timestamp, 1 sec, 0) join twitterStream#window" +
            ".externalTimeBatch(timestamp, 1 sec, 0) " +
            "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();
        cseEventStreamHandler.send(new Object[]{1366335804341L, "WSO2", 55.6f, 100});
        twitterStreamHandler.send(new Object[]{1366335804341L, "User1", "Hello World", "WSO2"});
        twitterStreamHandler.send(new Object[]{1366335805301L, "User2", "Hello World2", "WSO2"});
        cseEventStreamHandler.send(new Object[]{1366335805341L, "WSO2", 75.6f, 100});
        cseEventStreamHandler.send(new Object[]{1366335806541L, "WSO2", 57.6f, 100});
        Thread.sleep(1000);
        org.testng.AssertJUnit.assertEquals(2, inEventCount);
        org.testng.AssertJUnit.assertEquals(0, removeEventCount);
        org.testng.AssertJUnit.assertTrue(eventArrived);
    } finally {
        siddhiManager.shutdown();
    }
}
 
Example 6
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void externalTimeBatchWindowTest7() throws InterruptedException {
    log.info("externalTimeBatchWindow test7");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "" +
            "define stream LoginEvents (timestamp long, ip string) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0, 2 sec) " +
            "select timestamp, ip, count() as total  " +
            "insert all events into uniqueIps ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"});
    inputHandler.send(new Object[]{1366335804599L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335804600L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335804607L, "192.10.1.6"});
    inputHandler.send(new Object[]{1366335805599L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335805600L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335805607L, "192.10.1.6"});
    Thread.sleep(3000);
    inputHandler.send(new Object[]{1366335805606L, "192.10.1.7"});
    inputHandler.send(new Object[]{1366335805605L, "192.10.1.8"});
    Thread.sleep(3000);
    inputHandler.send(new Object[]{1366335806606L, "192.10.1.9"});
    inputHandler.send(new Object[]{1366335806690L, "192.10.1.10"});
    Thread.sleep(3000);

    org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    org.testng.AssertJUnit.assertEquals("In Events ", 4, inEventCount);
    org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
    siddhiManager.shutdown();

}
 
Example 7
Source File: InMemoryTransportTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"inMemoryTestCase21"})
public void inMemoryTestCase22() throws InterruptedException {
    log.info("Test inMemoryTestCase22");
    SiddhiManager siddhiManager = new SiddhiManager();

    String publisherApp = "" +
            "define stream CheckStockStream (symbol1 string, totalPrice double); " +
            "@sink(type='inMemory', topic='OutputStream', @map(type='passThrough')) " +
            "define stream OutputStream (symbol1 string, totalPrice double); " +
            "" +
            "from CheckStockStream " +
            "select * " +
            "insert into OutputStream; ";

    String consumerApp = "" +
            "@source(type='inMemory', topic='OutputStream', @map(type='passThrough')) " +
            "define stream InputStream (symbol1 string, totalPrice double); ";

    SiddhiAppRuntime publisherRuntime = siddhiManager.createSiddhiAppRuntime(publisherApp);
    SiddhiAppRuntime consumerRuntime = siddhiManager.createSiddhiAppRuntime(consumerApp);

    consumerRuntime.addCallback("InputStream", new StreamCallback() {
        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            wso2Count.incrementAndGet();
        }
    });
    InputHandler stockStream = publisherRuntime.getInputHandler("CheckStockStream");

    publisherRuntime.start();
    consumerRuntime.start();

    stockStream.send(new Object[]{"WSO2", 50.0f});
    stockStream.send(new Object[]{"WSO2", 70.0f});
    Executors.newSingleThreadExecutor().execute(new Runnable() {
        @Override
        public void run() {
            consumerRuntime.getSources().iterator().next().get(0).pause();
        }
    });
    Executors.newSingleThreadExecutor().execute(new Runnable() {
        @Override
        public void run() {
            try {
                stockStream.send(new Object[]{"WSO2", 90f});
            } catch (InterruptedException ignored) {
            }
        }
    });
    Thread.sleep(2000);
    consumerRuntime.getSources().iterator().next().get(0).resume();
    Thread.sleep(2000);
    Assert.assertEquals(wso2Count.get(), 3);
    siddhiManager.shutdown();
}
 
Example 8
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void externalTimeBatchWindowTest5() throws InterruptedException {
    log.info("externalTimeBatchWindow test5");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "" +
            "define stream LoginEvents (timestamp long, ip string) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 0, 3 sec) " +
            "select timestamp, ip, count() as total  " +
            "insert all events into uniqueIps ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {

            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"});
    inputHandler.send(new Object[]{1366335804599L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335804600L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335804607L, "192.10.1.6"});

    Thread.sleep(5000);

    org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    org.testng.AssertJUnit.assertEquals("In Events ", 1, inEventCount);
    org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
    siddhiManager.shutdown();

}
 
Example 9
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void externalTimeBatchWindowTest26() throws InterruptedException {
    log.info("externalTimeBatchWindow test26");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" +
            "define stream LoginEvents (timestamp long, ip string) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, 1/2, 100) " +
            "select timestamp, ip, count() as total  " +
            "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"});
    inputHandler.send(new Object[]{1366335804342L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335805341L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335814341L, "192.10.1.6"});
    inputHandler.send(new Object[]{1366335814345L, "192.10.1.7"});
    inputHandler.send(new Object[]{1366335824341L, "192.10.1.8"});
    inputHandler.send(new Object[]{1366335824351L, "192.10.1.9"});
    inputHandler.send(new Object[]{1366335824441L, "192.10.1.10"});
    Thread.sleep(1000);
    org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    org.testng.AssertJUnit.assertEquals("In Events ", 4, inEventCount);
    org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
    siddhiManager.shutdown();
}
 
Example 10
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void externalTimeBatchWindowTest3() throws InterruptedException {
    log.info("externalTimeBatchWindow test3");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "" +
            "define stream LoginEvents (timestamp long, ip string) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec) " +
            "select timestamp, ip, count() as total  " +
            "insert all events into uniqueIps ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"});
    inputHandler.send(new Object[]{1366335804342L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335805341L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335814341L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335814345L, "192.10.1.6"});
    inputHandler.send(new Object[]{1366335824341L, "192.10.1.7"});

    Thread.sleep(1000);

    org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    org.testng.AssertJUnit.assertEquals("In Events ", 3, inEventCount);
    org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
    siddhiManager.shutdown();

}
 
Example 11
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void externalTimeBatchWindowTest2() throws InterruptedException {
    log.info("externalTimeBatchWindow test2");

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "" +
            "define stream LoginEvents (timestamp long, ip string) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec) " +
            "select timestamp, ip, count() as total  " +
            "insert all events into uniqueIps ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"});
    inputHandler.send(new Object[]{1366335804342L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335805340L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335814341L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335814345L, "192.10.1.6"});
    inputHandler.send(new Object[]{1366335824341L, "192.10.1.7"});

    Thread.sleep(1000);

    org.testng.AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    org.testng.AssertJUnit.assertEquals("In Events ", 2, inEventCount);
    org.testng.AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
    siddhiManager.shutdown();

}
 
Example 12
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void schedulerLastBatchTriggerTest() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "define stream inputStream(currentTime long,value int); ";
    String query = " " +
            "@info(name='query') " +
            "from inputStream#window.externalTimeBatch(currentTime,5 sec, 0, 6 sec) " +
            "select value, currentTime " +
            "insert current events into outputStream; ";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
    siddhiAppRuntime.addCallback("query", new QueryCallback() {
        int count = 0;

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            if (count == 0) {
                AssertJUnit.assertEquals(1, inEvents[0].getData(0));
            } else if (count == 1) {
                AssertJUnit.assertEquals(6, inEvents[0].getData(0));
            } else if (count == 2) {
                AssertJUnit.assertEquals(11, inEvents[0].getData(0));
            } else if (count == 3) {
                AssertJUnit.assertEquals(14, inEvents[0].getData(0));
            } else if (count == 4) {
                AssertJUnit.assertEquals(15, inEvents[0].getData(0));
            }
            count += 1;
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{10000L, 1});
    Thread.sleep(100);
    inputHandler.send(new Object[]{11000L, 2});
    Thread.sleep(100);
    inputHandler.send(new Object[]{12000L, 3});
    Thread.sleep(100);
    inputHandler.send(new Object[]{13000L, 4});
    Thread.sleep(100);
    inputHandler.send(new Object[]{14000L, 5});
    Thread.sleep(100);
    inputHandler.send(new Object[]{15000L, 6});
    Thread.sleep(100);
    inputHandler.send(new Object[]{16500L, 7});
    Thread.sleep(100);
    inputHandler.send(new Object[]{17000L, 8});
    Thread.sleep(100);
    inputHandler.send(new Object[]{18000L, 9});
    Thread.sleep(100);
    inputHandler.send(new Object[]{19000L, 10});
    Thread.sleep(100);
    inputHandler.send(new Object[]{20100L, 11});
    Thread.sleep(100);
    inputHandler.send(new Object[]{20500L, 12});
    Thread.sleep(100);
    inputHandler.send(new Object[]{22000L, 13});
    Thread.sleep(100);
    inputHandler.send(new Object[]{25000L, 14});
    Thread.sleep(100);
    inputHandler.send(new Object[]{32000L, 15});
    Thread.sleep(100);
    inputHandler.send(new Object[]{33000L, 16});
    Thread.sleep(6000);
    siddhiManager.shutdown();
}
 
Example 13
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void test22() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "define stream inputStream(currentTime int,value int); ";
    String query = " " +
            "@info(name='query') " +
            "from inputStream#window.externalTimeBatch(currentTime,5 sec) " +
            "select value " +
            "insert into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
    siddhiAppRuntime.addCallback("query", new QueryCallback() {
        int count = 0;

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (count == 0) {
                AssertJUnit.assertEquals(1, inEvents[0].getData(0));
            } else if (count == 1) {
                AssertJUnit.assertEquals(6, inEvents[0].getData(0));
            } else if (count == 2) {
                AssertJUnit.assertEquals(13, inEvents[0].getData(0));
            }
            count += 1;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{1000, 1});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1100, 2});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1200, 3});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1300, 4});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1400, 5});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1500, 6});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1650, 7});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1700, 8});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1800, 9});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1900, 10});
    Thread.sleep(100);
    inputHandler.send(new Object[]{2000, 11});
    Thread.sleep(100);
    inputHandler.send(new Object[]{2050, 12});
    Thread.sleep(100);
    inputHandler.send(new Object[]{2200, 13});
    Thread.sleep(100);
    inputHandler.send(new Object[]{2300, 14});
    Thread.sleep(100);
    siddhiManager.shutdown();
}
 
Example 14
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void test1() throws InterruptedException {
    final AtomicInteger count = new AtomicInteger(0);
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "define stream inputStream(currentTime long,value int); ";
    String query = " " +
            "@info(name='query') " +
            "from inputStream#window.externalTimeBatch(currentTime,5 sec) " +
            "select value " +
            "insert into outputStream; ";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
    siddhiAppRuntime.addCallback("query", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            count.getAndIncrement();
            if (count.get() == 1) {
                AssertJUnit.assertEquals(1, inEvents[0].getData(0));
            } else if (count.get() == 2) {
                AssertJUnit.assertEquals(6, inEvents[0].getData(0));
            } else if (count.get() == 3) {
                AssertJUnit.assertEquals(11, inEvents[0].getData(0));
            }
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{10000L, 1});
    Thread.sleep(100);
    inputHandler.send(new Object[]{11000L, 2});
    Thread.sleep(100);
    inputHandler.send(new Object[]{12000L, 3});
    Thread.sleep(100);
    inputHandler.send(new Object[]{13000L, 4});
    Thread.sleep(100);
    inputHandler.send(new Object[]{14000L, 5});
    Thread.sleep(100);
    inputHandler.send(new Object[]{15000L, 6});
    Thread.sleep(100);
    inputHandler.send(new Object[]{16500L, 7});
    Thread.sleep(100);
    inputHandler.send(new Object[]{17000L, 8});
    Thread.sleep(100);
    inputHandler.send(new Object[]{18000L, 9});
    Thread.sleep(100);
    inputHandler.send(new Object[]{19000L, 10});
    Thread.sleep(100);
    inputHandler.send(new Object[]{20000L, 11});
    Thread.sleep(100);
    inputHandler.send(new Object[]{20500L, 12});
    Thread.sleep(100);
    inputHandler.send(new Object[]{22000L, 13});
    Thread.sleep(100);
    inputHandler.send(new Object[]{25000L, 14});
    Thread.sleep(100);
    AssertJUnit.assertEquals(3, count.get());
    siddhiManager.shutdown();
}
 
Example 15
Source File: TimeWindowSample.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {

        //Create Siddhi Manager
        SiddhiManager siddhiManager = new SiddhiManager();

        //Siddhi Application
        String siddhiApp = "" +
                "define stream StockEventStream (symbol string, price float, volume long); " +
                " " +
                "@info(name = 'query1') " +
                "from StockEventStream#window.time(5 sec)  " +
                "select symbol, sum(price) as price, sum(volume) as volume " +
                "group by symbol " +
                "insert into AggregateStockStream ;";

        //Generate runtime
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

        //Add callback to retrieve output events from stream
        siddhiAppRuntime.addCallback("AggregateStockStream", new StreamCallback() {
            @Override
            public void receive(Event[] events) {
                EventPrinter.print(events);
            }
        });

        //Retrieve input handler to push events into Siddhi
        InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockEventStream");

        //Start event processing
        siddhiAppRuntime.start();

        //Send events to Siddhi
        inputHandler.send(new Object[]{"IBM", 100f, 100L});
        Thread.sleep(1000);
        inputHandler.send(new Object[]{"IBM", 200f, 300L});
        inputHandler.send(new Object[]{"WSO2", 60f, 200L});
        Thread.sleep(1000);
        inputHandler.send(new Object[]{"WSO2", 70f, 400L});
        inputHandler.send(new Object[]{"GOOG", 50f, 30L});
        Thread.sleep(1000);
        inputHandler.send(new Object[]{"IBM", 200f, 400L});
        Thread.sleep(2000);
        inputHandler.send(new Object[]{"WSO2", 70f, 50L});
        Thread.sleep(2000);
        inputHandler.send(new Object[]{"WSO2", 80f, 400L});
        inputHandler.send(new Object[]{"GOOG", 60f, 30L});
        Thread.sleep(1000);

        //Shutdown the runtime
        siddhiAppRuntime.shutdown();

        //Shutdown Siddhi Manager
        siddhiManager.shutdown();

    }
 
Example 16
Source File: SimpleFilterSample.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {

        // Create Siddhi Manager
        SiddhiManager siddhiManager = new SiddhiManager();

        //Siddhi Application
        String siddhiApp = "" +
                "define stream StockStream (symbol string, price float, volume long); " +
                "" +
                "@info(name = 'query1') " +
                "from StockStream[volume < 150] " +
                "select symbol, price " +
                "insert into OutputStream;";

        //Generate runtime
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

        //Adding callback to retrieve output events from stream
        siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() {
            @Override
            public void receive(Event[] events) {
                EventPrinter.print(events);
                //To convert and print event as a map
                //EventPrinter.print(toMap(events));
            }
        });

        //Get InputHandler to push events into Siddhi
        InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");

        //Start processing
        siddhiAppRuntime.start();

        //Sending events to Siddhi
        inputHandler.send(new Object[]{"IBM", 700f, 100L});
        inputHandler.send(new Object[]{"WSO2", 60.5f, 200L});
        inputHandler.send(new Object[]{"GOOG", 50f, 30L});
        inputHandler.send(new Object[]{"IBM", 76.6f, 400L});
        inputHandler.send(new Object[]{"WSO2", 45.6f, 50L});
        Thread.sleep(500);

        //Shutdown runtime
        siddhiAppRuntime.shutdown();

        //Shutdown Siddhi Manager
        siddhiManager.shutdown();

    }
 
Example 17
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void test23() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String inputStream = "define stream inputStream(currentTime int,value int); ";
    String query = " " +
            "@info(name='query') " +
            "from inputStream#window.externalTimeBatch('currentTime',5 sec) " +
            "select value " +
            "insert into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream + query);
    siddhiAppRuntime.addCallback("query", new QueryCallback() {
        int count = 0;

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {

            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (count == 0) {
                AssertJUnit.assertEquals(1, inEvents[0].getData(0));
            } else if (count == 1) {
                AssertJUnit.assertEquals(6, inEvents[0].getData(0));
            } else if (count == 2) {
                AssertJUnit.assertEquals(13, inEvents[0].getData(0));
            }
            count += 1;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{1000, 1});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1100, 2});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1200, 3});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1300, 4});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1400, 5});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1500, 6});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1650, 7});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1700, 8});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1800, 9});
    Thread.sleep(100);
    inputHandler.send(new Object[]{1900, 10});
    Thread.sleep(100);
    inputHandler.send(new Object[]{2000, 11});
    Thread.sleep(100);
    inputHandler.send(new Object[]{2050, 12});
    Thread.sleep(100);
    inputHandler.send(new Object[]{2200, 13});
    Thread.sleep(100);
    inputHandler.send(new Object[]{2300, 14});
    Thread.sleep(100);
    siddhiManager.shutdown();
}
 
Example 18
Source File: PartitionSample.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {

        // Create Siddhi Manager
        SiddhiManager siddhiManager = new SiddhiManager();

        //Siddhi Application
        String siddhiApp = "" +
                "define stream StockStream (symbol string, price float,volume int);" +
                "" +
                "partition with (symbol of StockStream)" +
                "begin" +
                "   @info(name = 'query') " +
                "   from StockStream#window.length(2)" +
                "   select symbol, sum(price) as price, volume " +
                "   insert into OutStockStream ;" +
                "end ";

        //Generate runtime
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

        //Add callback to retrieve output events from stream
        siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() {
            @Override
            public void receive(Event[] events) {
                EventPrinter.print(events);
            }
        });

        //Retrieve InputHandler to push events into Siddhi
        InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream");

        //Starting event processing
        siddhiAppRuntime.start();

        //Send events to Siddhi
        inputHandler.send(new Object[]{"IBM", 75f, 100});
        inputHandler.send(new Object[]{"IBM", 76f, 100});
        inputHandler.send(new Object[]{"WSO2", 705f, 100});
        inputHandler.send(new Object[]{"WSO2", 711f, 100});
        inputHandler.send(new Object[]{"IBM", 90f, 100});
        inputHandler.send(new Object[]{"ORACLE", 50.0f, 100});
        inputHandler.send(new Object[]{"ORACLE", 51.0f, 100});
        inputHandler.send(new Object[]{"ORACLE", 50.5f, 100});
        Thread.sleep(1000);

        //Shutdown the runtime
        siddhiAppRuntime.shutdown();

        //Shutdown Siddhi Manager
        siddhiManager.shutdown();
    }
 
Example 19
Source File: TestSiddhiAggregator.java    From eagle with Apache License 2.0 4 votes vote down vote up
@Test
public void testSiddhi() throws Exception {
    String ql = "define stream s (host string, timestamp long, metric string, site string, value double);" +
        " @info(name='query') " +
        " from s[metric == \"missingblocks\"]#window.externalTimeBatch(timestamp, 1 min, 0) select host, count(value) as avg group by host insert into tmp; ";
    SiddhiManager sm = new SiddhiManager();
    SiddhiAppRuntime runtime = sm.createSiddhiAppRuntime(ql);

    InputHandler input = runtime.getInputHandler("s");

    AtomicInteger index = new AtomicInteger(0);

    runtime.addCallback("query", new QueryCallback() {
        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            printEvents(inEvents);
            if (index.get() == 0) {
                Assert.assertEquals(3, inEvents.length);
                Assert.assertEquals("host1", inEvents[0].getData()[0]);
                Assert.assertEquals(3L, inEvents[0].getData()[1]);
                Assert.assertEquals("host2", inEvents[1].getData()[0]);
                Assert.assertEquals(4L, inEvents[1].getData()[1]);
                Assert.assertEquals("host3", inEvents[2].getData()[0]);
                Assert.assertEquals(2L, inEvents[2].getData()[1]);
                index.incrementAndGet();
            } else if (index.get() == 1) {
                Assert.assertEquals(3, inEvents.length);
                Assert.assertEquals("host1", inEvents[0].getData()[0]);
                Assert.assertEquals(1L, inEvents[0].getData()[1]);
                Assert.assertEquals("host2", inEvents[1].getData()[0]);
                Assert.assertEquals(2L, inEvents[1].getData()[1]);
                Assert.assertEquals("host3", inEvents[2].getData()[0]);
                Assert.assertEquals(2L, inEvents[2].getData()[1]);
                index.incrementAndGet();
            }
        }
    });
    runtime.start();

    sendEvents(3, 4, 2, input, 1000L);
    Thread.sleep(1000);
    sendEvents(1, 2, 2, input, 61000L);
    sendEvents(3, 10, 7, input, 121000L);
    runtime.shutdown();
    sm.shutdown();
    Thread.sleep(1000);
}
 
Example 20
Source File: ExternalTimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void externalTimeBatchWindowTest20() throws InterruptedException {
    log.info("externalTimeBatchWindow test20");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" +
            "define stream LoginEvents (timestamp long, ip string) ;";
    String query = "" +
            "@info(name = 'query1') " +
            "from LoginEvents#window.externalTimeBatch(timestamp, 1 sec, timestamp, 10.5) " +
            "select timestamp, ip, count() as total  " +
            "insert all events into uniqueIps ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{1366335804341L, "192.10.1.3"});
    inputHandler.send(new Object[]{1366335804342L, "192.10.1.4"});
    inputHandler.send(new Object[]{1366335805341L, "192.10.1.5"});
    inputHandler.send(new Object[]{1366335814341L, "192.10.1.6"});
    inputHandler.send(new Object[]{1366335814345L, "192.10.1.7"});
    inputHandler.send(new Object[]{1366335824341L, "192.10.1.8"});
    inputHandler.send(new Object[]{1366335824351L, "192.10.1.9"});
    inputHandler.send(new Object[]{1366335824441L, "192.10.1.10"});
    Thread.sleep(1000);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("In Events ", 4, inEventCount);
    AssertJUnit.assertEquals("Remove Events ", 0, removeEventCount);
    siddhiManager.shutdown();
}