Java Code Examples for org.testng.AssertJUnit#assertEquals()

The following examples show how to use org.testng.AssertJUnit#assertEquals() . 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: LogicalAbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent56"})
public void testQueryAbsent57() throws InterruptedException {
    log.info("Test the query every (not e1 for 1 sec and e2) -> e3 with only e3 after 2 seconds");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from every (not Stream1[price>10] for 1 sec and e2=Stream2[price>20]) -> " +
            "e3=Stream3[price>30] " +
            "select e2.symbol as symbol2, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1");

    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");
    siddhiAppRuntime.start();

    Thread.sleep(1100);
    stream3.send(new Object[]{"WSO2", 35.0f, 100});
    Thread.sleep(100);


    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertFalse("Event arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example 2
Source File: RSplitPaneTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void selectSplitPane() throws InterruptedException {
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            JSplitPane splitPane = (JSplitPane) ComponentUtils.findComponent(JSplitPane.class, frame);
            splitPane.setDividerLocation(150);
            RSplitPane rSplitPane = new RSplitPane(splitPane, null, null, lr);
            rSplitPane.mouseReleased(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("select", call.getFunction());
    AssertJUnit.assertEquals("150", call.getState());
}
 
Example 3
Source File: JScrollBarTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void getAttributes() throws Throwable {
    driver = new JavaDriver();
    List<WebElement> scrollBars = driver.findElements(By.cssSelector("scroll-bar"));
    WebElement scrollbar = scrollBars.get(0);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    new Actions(driver).moveToElement(scrollbar).moveByOffset(0, 40).click().perform();
    int scrollBarValue = Integer.parseInt(scrollbar.getAttribute("value"));
    AssertJUnit.assertTrue(scrollBarValue > 100);

    scrollbar = scrollBars.get(1);
    AssertJUnit.assertEquals("0", scrollbar.getAttribute("value"));
    new Actions(driver).moveToElement(scrollbar).moveByOffset(80, 0).click().perform();
    scrollBarValue = Integer.parseInt(scrollbar.getAttribute("value"));
    AssertJUnit.assertTrue(scrollBarValue > 10);
}
 
Example 4
Source File: AbsentPatternTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent29"})
public void testQueryAbsent30() throws InterruptedException {
    log.info("Test the query e1 -> not e2 for 1 sec -> e3 or e4 without e2");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); " +
            "define stream Stream4 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>10] -> not Stream2[price>20] for 1 sec -> e2=Stream3[price>30] or " +
            "e3=Stream4[price>40]" +
            "select e1.symbol as symbol1, e2.symbol as symbol2, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

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

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"IBM",
            "WSO2", null});

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"IBM", 18.7f, 100});
    Thread.sleep(1100);
    stream3.send(new Object[]{"WSO2", 35.0f, 100});

    TestUtil.waitForInEvents(100, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event not arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example 5
Source File: AbsentSequenceTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = {"testQueryAbsent29"})
public void testQueryAbsent30() throws InterruptedException {
    log.info("Test the query e1, not e2 for 1 sec, e3 or e4 without e2");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "define stream Stream3 (symbol string, price float, volume int); " +
            "define stream Stream4 (symbol string, price float, volume int); ";
    String query = "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>10], not Stream2[price>20] for 1 sec, e2=Stream3[price>30] or " +
            "e3=Stream4[price>40]" +
            "select e1.symbol as symbol1, e2.symbol as symbol2, e3.symbol as symbol3 " +
            "insert into OutputStream ;";

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

    TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"IBM",
            "WSO2", null});

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"IBM", 18.7f, 100});
    Thread.sleep(1100);
    stream3.send(new Object[]{"WSO2", 35.0f, 100});

    TestUtil.waitForInEvents(100, callback, 5);
    callback.throwAssertionErrors();
    AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount());
    AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount());
    AssertJUnit.assertTrue("Event not arrived", callback.isEventArrived());

    siddhiAppRuntime.shutdown();
}
 
Example 6
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery97() throws InterruptedException {
    log.info("Filter test97");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE)
            .attribute("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.GREATER_THAN_EQUAL,
            Expression.value(60L))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression
            .variable("price")).select("quantity", Expression.variable("quantity")));
    query.insertInto("outputStream");

    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count.addAndGet(inEvents.length);
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"WSO2", 500f, 50d, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 60d, 2});
    inputHandler.send(new Object[]{"WSO2", 60f, 300d, 4});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    AssertJUnit.assertEquals(2, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example 7
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void getLabelText() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.cssSelector("label"));
    AssertJUnit.assertEquals("lbl:Enter The Text", element1.getAttribute("labelText"));
}
 
Example 8
Source File: HtmlTagTest.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testMutilTagInSamePage() throws Exception
{

	Template t = gt.getTemplate("/tag/html3_template.html");
	this.bind(t, "list", User.getTestUsers());
	String str = t.render();
	AssertJUnit.assertEquals(this.getFileContent("/tag/html3_expected.html"), str);

	t = gt.getTemplate("/tag/html3_template.html");
	this.bind(t, "list", User.getTestUsers());
	str = t.render();
	AssertJUnit.assertEquals(this.getFileContent("/tag/html3_expected.html"), str);

}
 
Example 9
Source File: EventOutputRateLimitTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void testEventOutputRateLimitQuery18() throws InterruptedException {
    log.info("EventOutputRateLimit test18");

    SiddhiManager siddhiManager = new SiddhiManager();

    String siddhiApp = "" +
            "@app:name('EventOutputRateLimitTest8') " +
            "" +
            "define stream LoginEvents (timestamp long, ip string);" +
            "" +
            "@info(name = 'query1') " +
            "from LoginEvents " +
            "select ip " +
            "output first every 2 events " +
            "insert into uniqueIps ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

    log.info("Running : " + siddhiAppRuntime.getName());

    siddhiAppRuntime.addCallback("query1", new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            if (inEvents != null) {
                count += inEvents.length;
                for (Event event : inEvents) {
                    Assert.assertTrue(event.getData(0).equals("192.10.1.5") ||
                            event.getData(0).equals("192.10.1.4"));
                }
            } else {
                AssertJUnit.fail("Remove events emitted");
            }
            eventArrived = true;
        }

    });

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

    siddhiAppRuntime.start();

    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.9"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.4"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.4"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.4"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.30"});
    inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5"});
    Thread.sleep(1000);

    AssertJUnit.assertEquals("Event arrived", true, eventArrived);
    AssertJUnit.assertEquals("Number of output event value", 6, count);
    siddhiAppRuntime.shutdown();
}
 
Example 10
Source File: LengthBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void testLengthBatchWindow6() throws InterruptedException {

    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " +
            "define window cseWindow (symbol string, price float, volume int) lengthBatch(4); ";
    String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow; " +
            "@info(name = 'query2') from cseWindow " +
            "select symbol,sum(price) as sumPrice,volume " +
            "insert into outputStream ;";

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

    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                AssertJUnit.assertEquals("Events cannot be expired", false, event.isExpired());
                inEventCount++;
                if (inEventCount == 1) {
                    AssertJUnit.assertEquals(100.0, event.getData(1));
                } else if (inEventCount == 2) {
                    AssertJUnit.assertEquals(240.0, event.getData(1));
                }
            }

            eventArrived = true;
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"IBM", 10f, 0});
    inputHandler.send(new Object[]{"WSO2", 20f, 1});
    inputHandler.send(new Object[]{"IBM", 30f, 0});
    inputHandler.send(new Object[]{"WSO2", 40f, 1});
    inputHandler.send(new Object[]{"IBM", 50f, 0});
    inputHandler.send(new Object[]{"WSO2", 60f, 1});
    inputHandler.send(new Object[]{"WSO2", 60f, 1});
    inputHandler.send(new Object[]{"IBM", 70f, 0});
    inputHandler.send(new Object[]{"WSO2", 80f, 1});
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertEquals(2, inEventCount);
    AssertJUnit.assertTrue(eventArrived);

}
 
Example 11
Source File: JTableTest.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public void getheaderText() throws Throwable {
    driver = new JavaDriver();
    WebElement header = driver.findElement(By.cssSelector("table::header"));
    AssertJUnit.assertEquals("[\"First Name\",\"Last Name\",\"Sport\",\"# of Years\",\"Vegetarian\"]", header.getText());
}
 
Example 12
Source File: SelectorParserTest.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public void parseSelfSelectorWithParams() throws Throwable {
    SelectorParser parser = new SelectorParser(".::call-select('Hello World')");
    Selector selector = parser.parse();
    AssertJUnit.assertNotNull(selector);
    AssertJUnit.assertEquals(".::call-select(\"Hello World\")", selector.toString());
}
 
Example 13
Source File: TimeBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void timeWindowBatchTest14() throws InterruptedException {
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" +
            "define stream cseEventStream (symbol string, price float, volume int);";
    String query = "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.timeBatch('2 sec', 0) " +
            "select symbol, sum(price) as sumPrice, volume " +
            "insert into outputStream ;";
    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 (inEventCount == 0) {
                AssertJUnit.assertTrue("Remove Events will only arrive after the second time period. ", removeEvents
                        == null);
            }
            if (inEvents != null) {
                inEventCount = inEventCount + inEvents.length;
            } else if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    // Start sending events in the beginning of a cycle
    while (System.currentTimeMillis() % 2000 != 0) {
    }
    inputHandler.send(new Object[]{"IBM", 700f, 0});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 1});
    Thread.sleep(8500);
    inputHandler.send(new Object[]{"WSO2", 60.5f, 1});
    inputHandler.send(new Object[]{"II", 60.5f, 1});
    Thread.sleep(13000);
    inputHandler.send(new Object[]{"TT", 60.5f, 1});
    inputHandler.send(new Object[]{"YY", 60.5f, 1});
    Thread.sleep(5000);
    AssertJUnit.assertEquals(3, inEventCount);
    AssertJUnit.assertEquals(0, removeEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();

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

    SiddhiManager siddhiManager = new SiddhiManager();
    String planName = "@app:name('sortWindow2') ";
    String cseEventStream = "" +
            "define stream cseEventStream (symbol string, price int, volume long);";
    String query = "" +
            "@info(name = 'query1') " +
            "from cseEventStream#window.sort(2,volume, 'asc', price, 'desc') " +
            "select price, volume " +
            "insert all events into outputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(planName +
            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("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"WSO2", 50, 100L});
    inputHandler.send(new Object[]{"IBM", 20, 100L});
    inputHandler.send(new Object[]{"WSO2", 40, 50L});
    inputHandler.send(new Object[]{"WSO2", 100, 20L});
    inputHandler.send(new Object[]{"WSO2", 50, 50L});
    Thread.sleep(1000);
    AssertJUnit.assertEquals(5, inEventCount);
    AssertJUnit.assertEquals(3, removeEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();

}
 
Example 15
Source File: LengthBatchWindowTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void testLengthBatchWindow3() throws InterruptedException {
    log.info("Testing length batch window with no of events greater than window size");

    final int length = 2;
    SiddhiManager siddhiManager = new SiddhiManager();

    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " +
            "define window cseWindow (symbol string, price float, volume int) lengthBatch(" + length + ") output " +
            "all events; ";
    String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow ;" +
            "@info(name = 'query2') from cseWindow insert all events into outputStream ;";


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

    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                if ((count / length) % 2 == 1) {
                    removeEventCount++;
                    AssertJUnit.assertEquals("Remove event order", removeEventCount, event.getData(2));
                    if (removeEventCount == 1) {
                        AssertJUnit.assertEquals("Expired event triggering position", length, inEventCount);
                    }
                } else {
                    inEventCount++;
                    AssertJUnit.assertEquals("In event order", inEventCount, event.getData(2));
                }
                count++;
            }

            AssertJUnit.assertEquals("No of emitted events at window expiration", inEventCount - length,
                    removeEventCount);
            eventArrived = true;
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"IBM", 700f, 1});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 2});
    inputHandler.send(new Object[]{"IBM", 700f, 3});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 4});
    inputHandler.send(new Object[]{"IBM", 700f, 5});
    inputHandler.send(new Object[]{"WSO2", 60.5f, 6});
    Thread.sleep(500);
    AssertJUnit.assertEquals("In event count", 6, inEventCount);
    AssertJUnit.assertEquals("Remove event count", 4, removeEventCount);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();

}
 
Example 16
Source File: SelectOptimisationAggregationTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void aggregationFunctionTestcase1() throws InterruptedException {
    LOG.info("aggregationFunctionTestcase1 - count w/o group by");
    SiddhiManager siddhiManager = new SiddhiManager();

    String stockStream =
            "define stream stockStream (symbol string, price float, lastClosingPrice float, volume long , " +
                    "quantity int, timestamp long);";
    String query =

            "define aggregation stockAggregation " +
            "from stockStream " +
            "select count() as count " +
            "aggregate every sec, min ;" +

            "define stream inputStream (symbol string, value int, startTime string, " +
            "endTime string, perValue string); " +

            "@info(name = 'query1') " +
            "from inputStream as i join stockAggregation as s " +
            "within 1496200000000L, 1596434876000L " +
            "per \"seconds\" " +
            "select count " +
            "order by AGG_TIMESTAMP " +
            "insert all events into outputStream; ";

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

    try {
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {
            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                if (inEvents != null) {
                    EventPrinter.print(timestamp, inEvents, removeEvents);
                    for (Event event : inEvents) {
                        inEventsList.add(event.getData());
                        inEventCount.incrementAndGet();
                    }
                    eventArrived = true;
                }
            }
        });
        InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
        InputHandler inputStreamInputHandler = siddhiAppRuntime.getInputHandler("inputStream");
        siddhiAppRuntime.start();

        // Thursday, June 1, 2017 4:05:50 AM
        stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
        stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});
        Thread.sleep(1000);

        // Thursday, June 1, 2017 4:05:52 AM
        stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
        stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});
        Thread.sleep(1000);

        // Thursday, June 1, 2017 4:05:54 AM
        stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
        stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});
        Thread.sleep(1000);

        // Thursday, June 1, 2017 4:05:56 AM
        stockStreamInputHandler.send(new Object[]{"IBM", 900f, null, 200L, 60, 1496289956000L});
        stockStreamInputHandler.send(new Object[]{"IBM", 500f, null, 200L, 7, 1496289956000L});
        Thread.sleep(1000);

        // Thursday, June 1, 2017 4:06:56 AM
        stockStreamInputHandler.send(new Object[]{"IBM", 400f, null, 200L, 9, 1496290016000L});
        Thread.sleep(1000);

        // Thursday, June 1, 2017 4:07:56 AM
        stockStreamInputHandler.send(new Object[]{"IBM", 600f, null, 200L, 6, 1496290076000L});
        Thread.sleep(1000);

        // Thursday, June 1, 2017 5:07:56 AM
        stockStreamInputHandler.send(new Object[]{"CISCO", 700f, null, 200L, 20, 1496293676000L});
        Thread.sleep(2000);

        inputStreamInputHandler.send(new Object[]{"IBM", 1, "2017-06-01 09:35:51 +05:30",
                "2017-06-01 09:35:52 +05:30", "seconds"});
        Thread.sleep(100);

        // AGG_TIMESTAMP cannot be asserted as it is based on the time test case is run
        List<Object[]> expected = Arrays.asList(
                new Object[]{2L},
                new Object[]{2L},
                new Object[]{2L},
                new Object[]{2L},
                new Object[]{1L},
                new Object[]{1L},
                new Object[]{1L}
        );
        SiddhiTestHelper.waitForEvents(100, 7, inEventCount, 60000);
        AssertJUnit.assertTrue("Event arrived", eventArrived);
        AssertJUnit.assertEquals("Number of success events", 7, inEventCount.get());
        AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isEventsMatch(inEventsList, expected));
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
 
Example 17
Source File: MinimumFunctionExtensionTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void testMinFunctionExtension9() throws InterruptedException {

    log.info("MinimumFunctionExecutor TestCase 9");
    SiddhiManager siddhiManager = new SiddhiManager();

    String inStreamDefinition = "define stream inputStream (price1 long,price2 long, price3 long);";
    String query = ("@info(name = 'query1') from inputStream " +
            "select minimum(price1, price2, price3) as min " +
            "insert into outputStream;");
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);

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

            EventPrinter.print(timeStamp, inEvents, removeEvents);
            eventArrived = true;
            for (Event event : inEvents) {
                count++;
                switch (count) {
                    case 1:
                        AssertJUnit.assertEquals(36L, event.getData(0));
                        break;
                    case 2:
                        AssertJUnit.assertEquals(3762L, event.getData(0));
                        break;
                    case 3:
                        AssertJUnit.assertEquals(3862L, event.getData(0));
                        break;
                    case 4:
                        AssertJUnit.assertEquals(3675L, event.getData(0));
                        break;
                    case 5:
                        AssertJUnit.assertEquals(3775L, event.getData(0));
                        break;
                    case 6:
                        AssertJUnit.assertEquals(40L, event.getData(0));
                        break;
                    default:
                        org.testng.Assert.fail();
                }
            }
        }
    });

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

    inputHandler.send(new Object[]{36L, 3675L, 3575L});
    inputHandler.send(new Object[]{3788L, 3812L, 3762L});
    inputHandler.send(new Object[]{3900L, 3925L, 3862L});
    inputHandler.send(new Object[]{3688L, 3775L, 3675L});
    inputHandler.send(new Object[]{3812L, 3812L, 3775L});
    inputHandler.send(new Object[]{3812L, 40L, 3775L});

    Thread.sleep(300);
    AssertJUnit.assertEquals(6, count);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();

}
 
Example 18
Source File: IncrementalPersistenceTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void incrementalPersistenceTest2() throws InterruptedException {
    log.info("Incremental persistence test 2 - length batch window query");
    final int inputEventCount = 10;
    final int eventWindowSize = 4;

    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setIncrementalPersistenceStore(new IncrementalFileSystemPersistenceStore(storageFilePath));

    String siddhiApp = "" +
            "@app:name('incrementalPersistenceTest2') " +
            "" +
            "define stream StockStream ( symbol string, price float, volume int );" +
            "" +
            "@info(name = 'query1')" +
            "from StockStream[price>10]#window.lengthBatch(" + eventWindowSize + ") " +
            "select symbol, price, sum(volume) as totalVol " +
            "insert all events into OutStream";

    QueryCallback queryCallback = new QueryCallback() {
        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            eventArrived = true;
            for (Event inEvent : inEvents) {
                count++;
                AssertJUnit.assertTrue("IBM".equals(inEvent.getData(0)) ||
                        "WSO2".equals(inEvent.getData(0)));
                lastValue = (Long) inEvent.getData(2);
            }
        }
    };

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", queryCallback);

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

    for (int i = 0; i < inputEventCount; i++) {
        inputHandler.send(new Object[]{"IBM", 75.6f + i, 100});
    }
    Thread.sleep(100);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(new Long(400), lastValue);

    //persisting
    siddhiAppRuntime.persist();
    Thread.sleep(5000);

    inputHandler.send(new Object[]{"WSO2", 100.4f, 150});
    //Thread.sleep(100);
    inputHandler.send(new Object[]{"WSO2", 200.4f, 110});

    inputHandler.send(new Object[]{"IBM", 300.4f, 100});
    //Thread.sleep(100);
    inputHandler.send(new Object[]{"WSO2", 400.4f, 300});

    inputHandler.send(new Object[]{"IBM", 500.6f, 120});
    Thread.sleep(10);
    inputHandler.send(new Object[]{"WSO2", 600.6f, 400});

    Thread.sleep(100);
    siddhiAppRuntime.persist();
    Thread.sleep(5000);

    siddhiAppRuntime.shutdown();
    siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", queryCallback);
    inputHandler = siddhiAppRuntime.getInputHandler("StockStream");
    //loading
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed", e);
    }
    siddhiAppRuntime.start();

    Thread.sleep(500);
    inputHandler.send(new Object[]{"IBM", 700.6f, 230});
    Thread.sleep(10);
    inputHandler.send(new Object[]{"WSO2", 800.6f, 125});

    inputHandler.send(new Object[]{"IBM", 900.6f, 370});
    Thread.sleep(10);
    inputHandler.send(new Object[]{"WSO2", 1000.6f, 140});

    //shutdown Siddhi app
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();

    AssertJUnit.assertTrue(count <= (inputEventCount + 6));
    AssertJUnit.assertEquals(new Long(865), lastValue);
    AssertJUnit.assertEquals(true, eventArrived);
}
 
Example 19
Source File: WithinPatternTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void testQuery7() throws InterruptedException {
    log.info("testPatternWithin5 - OUT 1 : Within clause for grouped pattern states(3)");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream Stream1 (symbol string, price float, volume int); ";

    String query = "" +
            "@info(name = 'query1') " +
            "from every (e1=Stream1 -> e2=Stream1[symbol == e1.symbol] -> e3=Stream1[symbol == e2.symbol]) " +
            "within 5 sec " +
            " select e1.symbol as symbol1, e1.volume as volume1, e2.symbol as symbol2, e2.volume as volume2, " +
            " e3.symbol as symbol3, e3.volume as volume3" +
            " insert into OutputStream ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + 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;
                AssertJUnit.assertArrayEquals(new Object[]{"WSO2", 150, "WSO2", 200, "WSO2", 250},
                        inEvents[0].getData());
                eventArrived = true;
            }
            if (removeEvents != null) {
                removeEventCount = removeEventCount + removeEvents.length;
            }
            eventArrived = true;
        }

    });

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");

    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 55.6f, 100});
    Thread.sleep(6000);
    stream1.send(new Object[]{"WSO2", 56.6f, 150});
    stream1.send(new Object[]{"WSO2", 57.7f, 200});
    Thread.sleep(500);
    stream1.send(new Object[]{"WSO2", 58.7f, 250});
    stream1.send(new Object[]{"WSO2", 57.7f, 300});
    stream1.send(new Object[]{"WSO2", 59.7f, 350});
    Thread.sleep(500);

    AssertJUnit.assertEquals("Number of success events", 1, inEventCount);
    AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);

    siddhiAppRuntime.shutdown();
}
 
Example 20
Source File: ExtensionTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test
public void extensionTest3() throws InterruptedException {
    log.info("extension test3");
    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setExtension("custom:plus", CustomFunctionExtension.class);
    siddhiManager.setExtension("email:getAllNew", StringConcatAggregatorExecutorString.class);

    String cseEventStream = "" +
            "" +
            "define stream cseEventStream (symbol string, price float, volume long);";
    String query = ("" +
            "@info(name = 'query1') " +
            "from cseEventStream " +
            "select price , email:getAllNew(symbol,'') as toConcat " +
            "group by volume " +
            "insert into mailOutput;");
    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);
            count = count + inEvents.length;
            if (count == 3) {
                AssertJUnit.assertEquals("WSO2ABC", inEvents[inEvents.length - 1].getData(1));
            }
            eventArrived = true;
        }

    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"IBM", 700f, 100L});
    Thread.sleep(100);
    inputHandler.send(new Object[]{"WSO2", 60.5f, 200L});
    Thread.sleep(100);
    inputHandler.send(new Object[]{"ABC", 60.5f, 200L});
    Thread.sleep(100);
    AssertJUnit.assertEquals(3, count);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}