Java Code Examples for org.testng.AssertJUnit#assertTrue()
The following examples show how to use
org.testng.AssertJUnit#assertTrue() .
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: AndRuleTest.java From otroslogviewer with Apache License 2.0 | 6 votes |
/** * Test And of Level and Time. */ @Test public void test3() { Stack<Object> stack = new Stack<>(); stack.push(LevelEqualsRule.getRule("INFO")); stack.push(TimestampInequalityRule.getRule(">=", "2008-05-21 00:44:45")); Rule rule = AndRule.getRule(stack); AssertJUnit.assertEquals(0, stack.size()); Calendar cal = new GregorianCalendar(2008, 4, 21, 0, 45, 44); // LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger", // Logger.getRootLogger(), cal.getTimeInMillis(), Level.INFO, // "Hello, World", null); LogData ld = new LogDataBuilder().withClass("org.apache.log4j.Logger").withLoggerName("").withDate(new Date(cal.getTimeInMillis())) .withLevel(java.util.logging.Level.INFO).withMessage("Hello, World").build(); AssertJUnit.assertTrue(rule.evaluate(ld, null)); }
Example 2
Source File: JavaDriverTest.java From marathonv5 with Apache License 2.0 | 6 votes |
public void executeScriptWithPrimitiveReturn() throws Throwable { try { driver = new JavaDriver(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame.setLocationRelativeTo(null); frame.setVisible(true); } }); WebElement element1 = driver.findElement(By.name("text-field")); Number width = (Number) ((JavascriptExecutor) driver).executeScript("return Double.valueOf($1.getSize().getWidth());", element1); AssertJUnit.assertTrue(width.doubleValue() > 0); } finally { JavaElementFactory.reset(); } }
Example 3
Source File: CallbackTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void callbackTest5() throws InterruptedException { log.info("callback test5"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream " + "select symbol, price , symbol as sym1 " + "insert into OutputStream ;"; StreamCallback streamCallback = new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); eventArrived = true; if (events != null) { count += events.length; } } }; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutputStream", streamCallback); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 0f, 100L}); siddhiAppRuntime.removeCallback(streamCallback); inputHandler.send(new Object[]{"WSO2", 0f, 100L}); SiddhiTestHelper.waitForEvents(10, count, 1, 100); AssertJUnit.assertEquals(1, count); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 4
Source File: TestZKUtil.java From helix with Apache License 2.0 | 5 votes |
@Test() public void testUpdateIfExists() { String path = PropertyPathBuilder.instanceConfig(clusterName, "id3"); ZNRecord record = new ZNRecord("id4"); ZKUtil.updateIfExists(_gZkClient, path, record, false); AssertJUnit.assertFalse(_gZkClient.exists(path)); _gZkClient.createPersistent(path); ZKUtil.updateIfExists(_gZkClient, path, record, false); AssertJUnit.assertTrue(_gZkClient.exists(path)); record = _gZkClient.readData(path); AssertJUnit.assertEquals("id4", record.getId()); }
Example 5
Source File: LogicalAbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent11"}) public void testQueryAbsent12() throws InterruptedException { log.info("Test the query e1, not e2 for 1 sec or e3 with e1 and e3 with extra 1 sec to make sure no " + "duplicates"); 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 e1=Stream1[price>10], not Stream2[price>20] for 1 sec or e3=Stream3[price>30] " + "select e1.symbol as symbol1, e3.symbol as symbol3 " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2", "GOOGLE"}); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 15.0f, 100}); Thread.sleep(100); stream3.send(new Object[]{"GOOGLE", 35.0f, 100}); TestUtil.waitForInEvents(1000, 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 arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 6
Source File: AbsentWithEverySequenceTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testQuery1() throws InterruptedException { log.info("Test the query every e1, not e2 for 1 sec with e1 only"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price1 float, volume int); "; String query = "" + "@info(name = 'query1') " + "from every e1=Stream1[price>20], not Stream2[price1>e1.price] for 1sec " + "select e1.symbol as symbol " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"GOOG"}); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 55.6f, 100}); Thread.sleep(100); stream1.send(new Object[]{"GOOG", 55.6f, 100}); Thread.sleep(1100); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertTrue("Event arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 7
Source File: TestResourceComputationStage.java From helix with Apache License 2.0 | 5 votes |
@Test public void testNull() { ResourceComputationStage stage = new ResourceComputationStage(); StageContext context = new StageContext(); stage.init(context); stage.preProcess(); boolean exceptionCaught = false; try { stage.process(event); } catch (Exception e) { exceptionCaught = true; } AssertJUnit.assertTrue(exceptionCaught); stage.postProcess(); }
Example 8
Source File: LengthWindowTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void lengthWindowTest1() throws InterruptedException { log.info("Testing length window with no of events smaller than window size"); SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);"; String query = "@info(name = 'query1') from cseEventStream#window.length(4) select symbol,price,volume insert" + " all events 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); AssertJUnit.assertEquals("Message order inEventCount", inEventCount, inEvents[0].getData(2)); AssertJUnit.assertEquals("Events cannot be expired", false, inEvents[0].isExpired()); inEventCount = inEventCount + inEvents.length; eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 0}); inputHandler.send(new Object[]{"WSO2", 60.5f, 1}); AssertJUnit.assertEquals(2, inEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 9
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPartitionQuery22() throws InterruptedException { log.info("Partition test22"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest10') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream#window.time(1 sec) " + "select symbol, avg(price) as avgPrice, volume " + "having avgPrice > 10" + "insert expired events into OutStockStream ;" + "end "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { count.incrementAndGet(); if (count.get() == 1) { AssertJUnit.assertEquals(75.0, event.getData()[1]); } eventArrived = true; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75f, 100}); inputHandler.send(new Object[]{"IBM", 75f, 100}); SiddhiTestHelper.waitForEvents(200, 1, count, 60000); AssertJUnit.assertTrue(1 <= count.get()); siddhiAppRuntime.shutdown(); }
Example 10
Source File: TimestampInequalityRuleTest.java From otroslogviewer with Apache License 2.0 | 5 votes |
@Test public void testRuleMinus1Days() throws IOException, ClassNotFoundException { Rule rule = TimestampInequalityRule.getRule(">", "-1d"); Calendar cal = new GregorianCalendar(); cal.setTime(new Date(System.currentTimeMillis())); cal.add(Calendar.HOUR_OF_DAY, -1); LogData logData = createLogData(cal); AssertJUnit.assertTrue(rule.evaluate(logData, null)); }
Example 11
Source File: AbsentWithEveryPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testQuery4() throws InterruptedException { log.info("Test the query not e1 for 1 sec -> every e2 with e2 only"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); "; String query = "" + "@info(name = 'query1') " + "from not Stream1[price>10] for 1sec -> every e2=Stream2[price>20] " + "select e2.symbol as symbol " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2"}, new Object[]{"GOOG"}); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); siddhiAppRuntime.start(); Thread.sleep(1100); stream2.send(new Object[]{"WSO2", 55.6f, 100}); Thread.sleep(100); stream2.send(new Object[]{"GOOG", 55.6f, 100}); Thread.sleep(100); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 2, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertTrue("Event arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 12
Source File: LogicalAbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent40"}) public void testQueryAbsent41() throws InterruptedException { log.info("Test the query e1, e2 or not e3 for 1 sec with e1 and e3 within 1 sec"); 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 e1=Stream1[price>10], e2=Stream2[price>20] or not Stream3[price>30] for 1 sec " + "select e1.symbol as symbol1, e2.symbol as symbol2 " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2", "GOOGLE"}); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 15.0f, 100}); Thread.sleep(100); stream2.send(new Object[]{"GOOGLE", 25.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 arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 13
Source File: SelectOptimisationAggregationTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "aggregationFunctionTestcase10") public void aggregationFunctionTestcase11() throws InterruptedException { LOG.info("aggregationFunctionTestcase10: testing latest incremental aggregator - different select "); 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 symbol, sum(price) as sumPrice " + "group by symbol " + "aggregate by timestamp every sec...year ;" + "define stream inputStream (symbol string); " + "@info(name = 'query1') " + "from inputStream as i join stockAggregation as s " + "within 1496200000000L, 1596535449000L " + "per \"seconds\" " + "select s.symbol, sum(s.sumPrice) as sumPrice " + "group by i.symbol " + "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[]{"WSO22", 75f, null, 40L, 10, 1496289950100L}); // Thursday, June 1, 2017 4:05:52 AM stockStreamInputHandler.send(new Object[]{"WSO23", 60f, 44f, 200L, 56, 1496289952000L}); stockStreamInputHandler.send(new Object[]{"WSO24", 100f, null, 200L, 16, 1496289952000L}); // Thursday, June 1, 2017 4:05:50 AM - Out of order event stockStreamInputHandler.send(new Object[]{"WSO23", 70f, null, 40L, 10, 1496289950090L}); // Thursday, June 1, 2017 4:05:54 AM stockStreamInputHandler.send(new Object[]{"IBM", 101f, null, 200L, 26, 1496289954000L}); stockStreamInputHandler.send(new Object[]{"IBM1", 102f, null, 200L, 100, 1496289954000L}); // Thursday, June 1, 2017 4:05:56 AM stockStreamInputHandler.send(new Object[]{"IBM", 900f, null, 200L, 60, 1496289956000L}); stockStreamInputHandler.send(new Object[]{"IBM1", 500f, null, 200L, 7, 1496289956000L}); Thread.sleep(100); inputStreamInputHandler.send(new Object[]{"IBM"}); Thread.sleep(100); SiddhiTestHelper.waitForEvents(100, 1, inEventCount, 10000); AssertJUnit.assertTrue("Event arrived", eventArrived); AssertJUnit.assertEquals("Number of success events", 1, inEventCount.get()); AssertJUnit.assertTrue("In events matched", Arrays.equals(inEventsList.get(0), new Object[]{"WSO22", 1958.0})); } finally { siddhiAppRuntime.shutdown(); } }
Example 14
Source File: InstanceOfFunctionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testInstanceOfBooleanFunctionExtensionTestCase() throws InterruptedException { log.info("testInstanceOfBooleanFunctionExtension TestCase"); SiddhiManager siddhiManager = new SiddhiManager(); String sensorEventStream = "define stream sensorEventStream (timestamp long, " + "isPowerSaverEnabled bool, sensorId int , sensorName string, longitude double, latitude double, " + "humidity float, sensorValue double);"; String query = ("@info(name = 'query1') " + "from sensorEventStream " + "select sensorName ,instanceOfBoolean(isPowerSaverEnabled) as valid, isPowerSaverEnabled " + "insert into outputStream;"); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(sensorEventStream + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); for (Event inEvent : inEvents) { count++; if (count == 1) { AssertJUnit.assertEquals(true, inEvent.getData(1)); } if (count == 2) { AssertJUnit.assertEquals(false, inEvent.getData(1)); } eventArrived = true; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("sensorEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{19900813115534L, false, 601, "temperature", 90.34344, 20.44345, 2.3f, 20.44345}); inputHandler.send(new Object[]{19900813115534L, "notAvailable", 602, "temperature", 90.34344, 20.44345, 2.3f, 20.44345}); Thread.sleep(100); org.testng.AssertJUnit.assertEquals(2, count); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 15
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery20() throws InterruptedException { log.info("Partition test20"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "@app:name('PartitionTest20') " + "" + "" + "define stream cseEventStream (symbol string, price float,volume int); " + "" + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "" + "@info(name = 'query')" + "from cseEventStreamOne " + "select symbol, price, volume " + "insert into cseEventStream;" + " " + "partition with (price>=100 as 'large' or price<100 as 'medium' or price<50 as 'small' of " + "cseEventStream) " + " begin" + " @info(name = 'query1') " + " from cseEventStream " + " select symbol, sum(price) as price " + " insert into #OutStockStream1 ; " + " " + " @info(name = 'query2') " + " from #OutStockStream1 " + " insert into #OutStockStream2 ;" + " " + " @info(name = 'query3') " + " from #OutStockStream2 " + " insert into OutStockStream ;" + " " + " end ; "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { count.incrementAndGet(); eventArrived = true; if (count.get() == 1) { AssertJUnit.assertEquals(25.0, event.getData()[1]); } else if (count.get() == 2) { AssertJUnit.assertEquals(25.0, event.getData()[1]); } else if (count.get() == 3) { AssertJUnit.assertEquals(7005.60009765625, event.getData()[1]); } else if (count.get() == 4) { AssertJUnit.assertTrue(event.getData()[1].equals(75.0) || event.getData()[1].equals(100.0)); } else if (count.get() == 5) { AssertJUnit.assertTrue(event.getData()[1].equals(50.0) || event.getData()[1].equals(100.0)); } else if (count.get() == 6) { AssertJUnit.assertEquals(50.0, event.getData()[1]); } } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 25f, 100}); inputHandler.send(new Object[]{"WSO2", 7005.6f, 100}); inputHandler.send(new Object[]{"IBM", 50f, 100}); inputHandler.send(new Object[]{"ORACLE", 25f, 100}); SiddhiTestHelper.waitForEvents(100, 5, count, 60000); AssertJUnit.assertTrue(6 >= count.get()); siddhiAppRuntime.shutdown(); }
Example 16
Source File: MaximumFunctionExtensionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testMaxFunctionExtension9() throws InterruptedException { log.info("MaximumFunctionExecutor TestCase 9"); SiddhiManager siddhiManager = new SiddhiManager(); String inStreamDefinition = "define stream inputStream (price1 float,price2 float, price3 float);"; String query = ("@info(name = 'query1') from inputStream " + "select maximum(price1, price2, price3) as max " + "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(36.75f, event.getData(0)); break; case 2: AssertJUnit.assertEquals(38.12f, event.getData(0)); break; case 3: AssertJUnit.assertEquals(39.25f, event.getData(0)); break; case 4: AssertJUnit.assertEquals(37.75f, event.getData(0)); break; case 5: AssertJUnit.assertEquals(38.12f, event.getData(0)); break; case 6: AssertJUnit.assertEquals(40.0f, event.getData(0)); break; default: AssertJUnit.fail(); } } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{36f, 36.75f, 35.75f}); inputHandler.send(new Object[]{37.88f, 38.12f, 37.62f}); inputHandler.send(new Object[]{39.00f, 39.25f, 38.62f}); inputHandler.send(new Object[]{36.88f, 37.75f, 36.75f}); inputHandler.send(new Object[]{38.12f, 38.12f, 37.75f}); inputHandler.send(new Object[]{38.12f, 40f, 37.75f}); Thread.sleep(300); AssertJUnit.assertEquals(6, count); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 17
Source File: JoinTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void joinTest12() throws InterruptedException { log.info("Join test12"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "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.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select * " + "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.getAndAdd(inEvents.length); } if (removeEvents != null) { removeEventCount.getAndAdd(removeEvents.length); } eventArrived = true; } }); InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream"); siddhiAppRuntime.start(); cseEventStreamHandler.send(new Object[]{"WSO2", 55.6f, 100}); twitterStreamHandler.send(new Object[]{"User1", "Hello World", "WSO2"}); SiddhiTestHelper.waitForEvents(100, 1, inEventCount, 60000); AssertJUnit.assertEquals("inEventCount", 1, inEventCount.get()); AssertJUnit.assertEquals("removeEventCount", 0, removeEventCount.get()); AssertJUnit.assertTrue(eventArrived); } finally { siddhiAppRuntime.shutdown(); } }
Example 18
Source File: TimeLengthWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void timeLengthWindowTest3() throws InterruptedException { log.info("Testing timeLength window with no of events greater than window length and time period less than " + "window time"); SiddhiManager siddhiManager = new SiddhiManager(); String sensorStream = "define stream sensorStream (id string, sensorValue float);"; String query = "@info(name = 'query1') from sensorStream#window.timeLength(10 sec,4)" + " select id,sensorValue" + " insert all events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(sensorStream + 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) { AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount > removeEventCount); removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("sensorStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"id1", 10d}); Thread.sleep(500); inputHandler.send(new Object[]{"id2", 20d}); Thread.sleep(500); inputHandler.send(new Object[]{"id3", 30d}); Thread.sleep(500); inputHandler.send(new Object[]{"id4", 40d}); Thread.sleep(500); inputHandler.send(new Object[]{"id5", 50d}); Thread.sleep(500); inputHandler.send(new Object[]{"id6", 60d}); Thread.sleep(500); inputHandler.send(new Object[]{"id7", 70d}); Thread.sleep(500); inputHandler.send(new Object[]{"id8", 80d}); Thread.sleep(2000); AssertJUnit.assertEquals(8, inEventCount); AssertJUnit.assertEquals(4, removeEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 19
Source File: AbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"testQueryAbsent20"}) public void testQueryAbsent21() throws InterruptedException { log.info("Test the query e1, e2, not e3 for 1 sec, e4 with e1, e2, and e4"); 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], e2=Stream2[price>20], not Stream3[price>30] for 1 sec, " + "e4=Stream4[price>40] " + "select e1.symbol as symbol1, e2.symbol as symbol2, e4.symbol as symbol4 " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2", "IBM", "ORACLE"}); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); InputHandler stream4 = siddhiAppRuntime.getInputHandler("Stream4"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 15.6f, 100}); Thread.sleep(100); stream2.send(new Object[]{"IBM", 28.7f, 100}); Thread.sleep(1100); stream4.send(new Object[]{"ORACLE", 44.7f, 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 arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 20
Source File: LengthBatchWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void lengthBatchWindowTest7() 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.lengthBatch(4) " + "select symbol,sum(price) as sumPrice,volume " + "insert all events 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); AssertJUnit.assertEquals("Events cannot be expired", false, removeEvents != null); for (Event event : inEvents) { 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}); siddhiAppRuntime.shutdown(); AssertJUnit.assertEquals(2, inEventCount); AssertJUnit.assertTrue(eventArrived); }