use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class LossyFrequentWindowTestCase method frequentUniqueWindowTest3.
@Test
public void frequentUniqueWindowTest3() throws InterruptedException {
log.info("LossyFrequentWindow test3");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream purchase (cardNo string, price float); " + "define window purchaseWindow (cardNo string, price float) lossyFrequent(0.3,0.05,cardNo); ";
String query = "" + "@info(name = 'query0') " + "from purchase[price >= 30] " + "insert into purchaseWindow; " + "" + "@info(name = 'query1') " + "from purchaseWindow " + "select cardNo, price " + "insert all events into PotentialFraud ;";
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 += inEvents.length;
}
if (removeEvents != null) {
removeEventCount += removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("purchase");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "3224-3244-2432-4124", 73.36f });
for (int i = 0; i < 25; i++) {
inputHandler.send(new Object[] { "3234-3244-2432-4124", 73.36f });
inputHandler.send(new Object[] { "3234-3244-2432-4124", 78.36f });
inputHandler.send(new Object[] { "1234-3244-2432-123", 86.36f });
// this event will be included because we
inputHandler.send(new Object[] { "3234-3244-2432-4124", 48.36f });
// only consider cardNo
}
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("In Event count", 101, inEventCount);
AssertJUnit.assertEquals("Out Event count", 1, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class LossyFrequentWindowTestCase method testLossyFrequentUniqueWindow1.
@Test
public void testLossyFrequentUniqueWindow1() throws InterruptedException {
log.info("LossyFrequentWindow test1");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream purchase (cardNo string, price float); " + "define window purchaseWindow (cardNo string, price float) lossyFrequent(0.1,0.01); ";
String query = "" + "@info(name = 'query0') " + "from purchase[price >= 30] " + "insert into purchaseWindow; " + "" + "@info(name = 'query1') " + "from purchaseWindow " + "select cardNo, price " + "insert all events into PotentialFraud ;";
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 += inEvents.length;
}
if (removeEvents != null) {
removeEventCount += removeEvents.length;
}
eventArrived = true;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("purchase");
siddhiAppRuntime.start();
for (int i = 0; i < 25; i++) {
inputHandler.send(new Object[] { "3234-3244-2432-4124", 73.36f });
inputHandler.send(new Object[] { "1234-3244-2432-123", 46.36f });
inputHandler.send(new Object[] { "5768-3244-2432-5646", 48.36f });
inputHandler.send(new Object[] { "9853-3244-2432-4125", 78.36f });
}
// these events will not be picked
inputHandler.send(new Object[] { "1124-3244-2432-4126", 78.36f });
inputHandler.send(new Object[] { "1124-3244-2432-4126", 78.36f });
Thread.sleep(1000);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
AssertJUnit.assertEquals("In Event count", 100, inEventCount);
AssertJUnit.assertEquals("Out Event count", 0, removeEventCount);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class SortWindowTestCase method testSortWindow1.
@Test
public void testSortWindow1() throws InterruptedException {
log.info("SortWindow test1");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume long); " + "define window cseEventWindow (symbol string, price float, volume long) sort(2,volume, 'asc'); ";
String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from cseEventWindow " + "select 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);
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", 55.6f, 100L });
inputHandler.send(new Object[] { "IBM", 75.6f, 300L });
inputHandler.send(new Object[] { "WSO2", 57.6f, 200L });
inputHandler.send(new Object[] { "WSO2", 55.6f, 20L });
inputHandler.send(new Object[] { "WSO2", 57.6f, 40L });
Thread.sleep(1000);
AssertJUnit.assertEquals(5, inEventCount);
AssertJUnit.assertEquals(3, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class SortWindowTestCase method testSortWindow2.
@Test
public void testSortWindow2() throws InterruptedException {
log.info("SortWindow test2");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume long); " + "define window cseEventWindow (symbol string, price float, volume long) sort(2,volume, 'asc', price, " + "'desc'); ";
String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from cseEventWindow " + "select 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);
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();
}
use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.
the class TimeBatchWindowTestCase method testTimeWindowBatch2.
@Test
public void testTimeWindowBatch2() throws InterruptedException {
log.info("TimeWindowBatch Test2");
SiddhiManager siddhiManager = new SiddhiManager();
String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseEventWindow (symbol string, price float, volume int) timeBatch(1 sec); ";
String query = "" + "@info(name = 'query0') " + "from cseEventStream " + "insert into cseEventWindow; " + "" + "@info(name = 'query1') " + "from cseEventWindow " + "select symbol, sum(price) as price " + "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);
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("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "IBM", 700f, 1 });
Thread.sleep(1100);
inputHandler.send(new Object[] { "WSO2", 60.5f, 2 });
inputHandler.send(new Object[] { "IBM", 700f, 3 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 4 });
Thread.sleep(1100);
inputHandler.send(new Object[] { "IBM", 700f, 5 });
inputHandler.send(new Object[] { "WSO2", 60.5f, 6 });
Thread.sleep(2000);
AssertJUnit.assertEquals(3, inEventCount);
AssertJUnit.assertEquals(1, removeEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
Aggregations