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

The following examples show how to use org.testng.AssertJUnit#assertArrayEquals() . 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: TestUtil.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
public void receive(Event[] events) {
    // Print the events
    EventPrinter.print(events);

    if (events != null) {
        eventArrived = true;
        for (Event event : events) {
            int inEvent = inEventCount.incrementAndGet();
            if (noOfExpectedEvents > 0 && inEvent <= noOfExpectedEvents) {
                try {
                    AssertJUnit.assertArrayEquals(expected[inEvent - 1], event.getData());
                } catch (AssertionError e) {
                    assertionErrors.add(e);
                }
            }
        }
    }
}
 
Example 2
Source File: TestUtil.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {

    // Print the events
    EventPrinter.print(timestamp, inEvents, removeEvents);

    if (inEvents != null) {
        eventArrived = true;
        for (Event event : inEvents) {
            int inEvent = inEventCount.incrementAndGet();
            if (noOfExpectedEvents > 0 && inEvent <= noOfExpectedEvents) {
                try {
                    AssertJUnit.assertArrayEquals(expected[inEvent - 1], event.getData());
                } catch (AssertionError e) {
                    assertionErrors.add(e);
                }
            }
        }
    }
    if (removeEvents != null) {
        removeEventCount.addAndGet(removeEvents.length);
    }
}
 
Example 3
Source File: BufferingLogDataCollectorProxyTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetLogData() {
  LogData data1 = new LogData();
  data1.setId(1);
  LogData data2 = new LogData();
  data2.setId(2);
  AssertJUnit.assertEquals(0, delegate.getLogData().length);
  bufferingLogDataCollectorProxy.add(data1);
  bufferingLogDataCollectorProxy.add(data2);
  LogData[] logData = bufferingLogDataCollectorProxy.getLogData();
  AssertJUnit.assertEquals(2, logData.length);
  AssertJUnit.assertArrayEquals(new LogData[] { data1, data2 }, logData);

}
 
Example 4
Source File: OnDemandQueryTableTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void test12() throws InterruptedException {
    log.info("Test12 - Test output attributes and its types for table");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long);" +
            "@PrimaryKey('symbol') " +
            "define table StockTable (symbol string, price float, volume long); ";
    String onDemandQuery = "" +
            "from StockTable " +
            "select * ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);

    siddhiAppRuntime.start();
    Attribute[] actualAttributeArray = siddhiAppRuntime.getOnDemandQueryOutputAttributes(
            SiddhiCompiler.parseOnDemandQuery(onDemandQuery));
    Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
    Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
    Attribute volumeAttribute = new Attribute("volume", Attribute.Type.LONG);
    Attribute[] expectedAttributeArray = new Attribute[]{symbolAttribute, priceAttribute, volumeAttribute};
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);

    onDemandQuery = "" +
            "from StockTable " +
            "select symbol, sum(volume) as totalVolume ;";

    actualAttributeArray = siddhiAppRuntime.getOnDemandQueryOutputAttributes(SiddhiCompiler.parseOnDemandQuery
            (onDemandQuery));
    Attribute totalVolumeAttribute = new Attribute("totalVolume", Attribute.Type.LONG);
    expectedAttributeArray = new Attribute[]{symbolAttribute, totalVolumeAttribute};
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
 
Example 5
Source File: OnDemandQueryTableTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void test13() throws InterruptedException {
    log.info("Test13 - Test output attributes and its types for aggregation table");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long);" +
            "define aggregation StockTableAg " +
            "from StockStream " +
            "select symbol, price " +
            "group by symbol " +
            "aggregate every minutes ...year;";
    String onDemandQuery = "" +
            "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, price ";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);

    siddhiAppRuntime.start();
    Attribute[] actualAttributeArray = siddhiAppRuntime.getOnDemandQueryOutputAttributes(
            SiddhiCompiler.parseOnDemandQuery(onDemandQuery));
    Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
    Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
    Attribute[] expectedAttributeArray = new Attribute[]{symbolAttribute, priceAttribute};
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);

    onDemandQuery = "" +
            "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, sum(price) as total";

    actualAttributeArray = siddhiAppRuntime.getOnDemandQueryOutputAttributes(SiddhiCompiler.parseOnDemandQuery
            (onDemandQuery));
    Attribute totalVolumeAttribute = new Attribute("total", Attribute.Type.DOUBLE);
    expectedAttributeArray = new Attribute[]{symbolAttribute, totalVolumeAttribute};
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
 
Example 6
Source File: QueryAPITestCaseForTestStore.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void test12() {
    log.info("Test12 - Test output attributes and its types for table");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "@Store(type=\"testStoreContainingInMemoryTable\")\n" +
            "define table StockTable (symbol string, price float, volume long); ";
    String storeQuery = "" +
            "from StockTable " +
            "select * ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);

    siddhiAppRuntime.start();
    Attribute[] actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery
            (storeQuery));
    Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
    Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
    Attribute volumeAttribute = new Attribute("volume", Attribute.Type.LONG);
    Attribute[] expectedAttributeArray = new Attribute[]{symbolAttribute, priceAttribute, volumeAttribute};
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);

    storeQuery = "" +
            "from StockTable " +
            "select symbol, sum(volume) as totalVolume ;";

    actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery
            (storeQuery));
    Attribute totalVolumeAttribute = new Attribute("totalVolume", Attribute.Type.LONG);
    expectedAttributeArray = new Attribute[]{symbolAttribute, totalVolumeAttribute};
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
 
Example 7
Source File: QueryAPITestCaseForTableWithCache.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void test12() {
    log.info("Test12 - Test output attributes and its types for table");

    SiddhiManager siddhiManager = new SiddhiManager();

    String streams = "" +
            "define stream StockStream (symbol string, price float, volume long); " +
            "@Store(type=\"testStoreDummyForCache\", @Cache(size=\"10\"))\n" +
            "define table StockTable (symbol string, price float, volume long); ";
    String storeQuery = "" +
            "from StockTable " +
            "select * ;";

    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);

    siddhiAppRuntime.start();
    Attribute[] actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery
            (storeQuery));
    Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
    Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
    Attribute volumeAttribute = new Attribute("volume", Attribute.Type.LONG);
    Attribute[] expectedAttributeArray = new Attribute[]{symbolAttribute, priceAttribute, volumeAttribute};
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);

    storeQuery = "" +
            "from StockTable " +
            "select symbol, sum(volume) as totalVolume ;";

    actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery
            (storeQuery));
    Attribute totalVolumeAttribute = new Attribute("totalVolume", Attribute.Type.LONG);
    expectedAttributeArray = new Attribute[]{symbolAttribute, totalVolumeAttribute};
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
 
Example 8
Source File: EventTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateMetaEvent() {
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);

    Attribute price = new Attribute("price", Attribute.Type.FLOAT);
    Attribute volume = new Attribute("volume", Attribute.Type.INT);
    Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);

    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addData(volume);
    metaStreamEvent.addData(price);
    metaStreamEvent.addData(symbol);
    metaStreamEvent.initializeOnAfterWindowData();
    metaStreamEvent.addData(price);
    metaStreamEvent.addOutputData(symbol);
    metaStreamEvent.addOutputData(null);
    MetaStateEvent metaStateEvent = new MetaStateEvent(1);
    metaStateEvent.addEvent(metaStreamEvent);

    VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute
            ("price", Attribute.Type.FLOAT), 0, 0);
    VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute
            ("volume", Attribute.Type.INT), 0, 0);
    VariableExpressionExecutor symbolVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute
            ("symbol", Attribute.Type.STRING), 0, 0);

    QueryParserHelper.reduceMetaComplexEvent(metaStateEvent);
    QueryParserHelper.updateVariablePosition(metaStateEvent, Arrays.asList(priceVariableExpressionExecutor,
            volumeVariableExpressionExecutor, symbolVariableExpressionExecutor));

    AssertJUnit.assertEquals(1, metaStreamEvent.getBeforeWindowData().size());
    AssertJUnit.assertEquals(1, metaStreamEvent.getOnAfterWindowData().size());
    AssertJUnit.assertEquals(2, metaStreamEvent.getOutputData().size());
    AssertJUnit.assertArrayEquals(new int[]{0, 0, 1, 0}, priceVariableExpressionExecutor.getPosition());
    AssertJUnit.assertArrayEquals(new int[]{0, 0, 0, 0}, volumeVariableExpressionExecutor.getPosition());
    AssertJUnit.assertArrayEquals(new int[]{0, 0, 2, 0}, symbolVariableExpressionExecutor.getPosition());
}
 
Example 9
Source File: AttributeValueMarshallerTest.java    From aws-dynamodb-encryption-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testVersioningCompatibility() {
    AttributeValue newObject = buildComplexAttributeValue();
    byte[] oldBytes = Base64.decode(COMPLEX_ATTRIBUTE_MARSHALLED);
    byte[] newBytes = marshall(newObject).array();
    AssertJUnit.assertArrayEquals(oldBytes, newBytes);

    AttributeValue oldObject = unmarshall(ByteBuffer.wrap(oldBytes));
    assertEquals(oldObject, newObject);
}
 
Example 10
Source File: BufferingLogDataCollectorProxyTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Test(invocationCount = 10)
public void testAddLogDataArray() throws InterruptedException {
  LogData data1 = new LogData();
  data1.setId(1);
  LogData data2 = new LogData();
  data2.setId(2);
  LogData[] toAdd = { data1, data2 };
  bufferingLogDataCollectorProxy.add(toAdd);

  AssertJUnit.assertArrayEquals(toAdd, bufferingLogDataCollectorProxy.getLogData());
  Thread.sleep(3 * sleepTime);
  AssertJUnit.assertArrayEquals(toAdd, delegate.getLogData());

}
 
Example 11
Source File: Aggregation1TestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"incrementalStreamProcessorTest9"})
public void incrementalStreamProcessorTest11() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest11");
    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, avg(price) as avgPrice, sum(price) as totalPrice, " +
                    "(price * quantity) as lastTradeValue  " +
                    "group by symbol " +
                    "aggregate every sec...hour ;";

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

    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();

    stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});
    Thread.sleep(2000);

    stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});
    Thread.sleep(2000);

    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});
    Thread.sleep(5000);

    LocalDate currentDate = LocalDate.now();
    String year = String.valueOf(currentDate.getYear());
    String month = String.valueOf(currentDate.getMonth().getValue());
    if (month.length() == 1) {
        month = "0".concat(month);
    }

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "on symbol == \"IBM\" " +
            "within \"" + year + "-" + month + "-** **:**:** +05:30\" " +
            "per \"seconds\"; ");

    EventPrinter.print(events);
    Assert.assertNotNull(events);
    AssertJUnit.assertEquals(1, events.length);

    Object[] copyEventsWithoutTime = new Object[4];
    System.arraycopy(events[0].getData(), 1, copyEventsWithoutTime, 0, 4);
    AssertJUnit.assertArrayEquals(new Object[]{"IBM", 100.0, 200.0, 9600f}, copyEventsWithoutTime);

    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
 
Example 12
Source File: Aggregation1TestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"incrementalStreamProcessorTest24"})
public void incrementalStreamProcessorTest25() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest25");
    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, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " +
            "as lastTradeValue  " +
            "group by symbol " +
            "aggregate by timestamp every sec...hour ;";

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

    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();

    stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});

    stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});

    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});
    Thread.sleep(2000);

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "within \"2017-06-** **:**:**\" " +
            "per \"seconds\" " +
            "select * " +
            "order by AGG_TIMESTAMP ;");
    EventPrinter.print(events);
    Assert.assertNotNull(events);
    AssertJUnit.assertEquals(3, events.length);
    for (int i = 0; i < events.length; i++) {
        switch (i) {
            case 0:
                AssertJUnit.assertArrayEquals(new Object[]{1496289950000L, "WSO2", 60.0, 120.0, 700f},
                        events[i].getData());
                break;
            case 1:
                AssertJUnit.assertArrayEquals(new Object[]{1496289952000L, "WSO2", 80.0, 160.0, 1600f},
                        events[i].getData());
                break;
            case 2:
                AssertJUnit.assertArrayEquals(new Object[]{1496289954000L, "IBM", 100.0, 200.0, 9600f},
                        events[i].getData());
                break;
            default:
                //Not reached
                AssertJUnit.fail();
        }
    }

    siddhiAppRuntime.shutdown();
}
 
Example 13
Source File: Aggregation1TestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"incrementalStreamProcessorTest30"})
public void incrementalStreamProcessorTest31() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest31");
    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, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " +
            "as lastTradeValue  " +
            "group by symbol " +
            "aggregate by timestamp every sec...hour ;";

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

    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();

    stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});

    stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});

    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});

    stockStreamInputHandler.send(new Object[]{"CISCO", 100f, null, 200L, 26, 1513578087000L});
    stockStreamInputHandler.send(new Object[]{"CISCO", 100f, null, 200L, 96, 1513578087000L});

    Thread.sleep(2000);

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "within \"2017-**-** **:**:**\" " +
            "per \"seconds\" " +
            "select * " +
            "order by AGG_TIMESTAMP ;");
    EventPrinter.print(events);
    Assert.assertNotNull(events);
    AssertJUnit.assertEquals(4, events.length);
    for (int i = 0; i < events.length; i++) {
        switch (i) {
            case 0:
                AssertJUnit.assertArrayEquals(new Object[]{1496289950000L, "WSO2", 60.0, 120.0, 700f},
                        events[i].getData());
                break;
            case 1:
                AssertJUnit.assertArrayEquals(new Object[]{1496289952000L, "WSO2", 80.0, 160.0, 1600f},
                        events[i].getData());
                break;
            case 2:
                AssertJUnit.assertArrayEquals(new Object[]{1496289954000L, "IBM", 100.0, 200.0, 9600f},
                        events[i].getData());
                break;
            case 3:
                AssertJUnit.assertArrayEquals(new Object[]{1513578087000L, "CISCO", 100.0, 200.0, 9600f},
                        events[i].getData());
                break;
            default:
                AssertJUnit.fail();
        }
    }

    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
 
Example 14
Source File: Aggregation1TestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"incrementalStreamProcessorTest32"})
public void incrementalStreamProcessorTest33() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest33");
    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, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " +
            "as lastTradeValue  " +
            "group by symbol " +
            "aggregate by timestamp every sec...hour ;";

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

    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();

    stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});

    stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});

    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});

    stockStreamInputHandler.send(new Object[]{"CISCO", 100f, null, 200L, 26, 1513578087000L});
    stockStreamInputHandler.send(new Object[]{"CISCO", 100f, null, 200L, 96, 1513578087000L});

    Thread.sleep(2000);

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "within \"2017-12-18 06:**:**\" " +
            "per \"seconds\" " +
            "select * " +
            "order by AGG_TIMESTAMP ;");
    EventPrinter.print(events);

    Assert.assertNotNull(events);
    AssertJUnit.assertEquals(1, events.length);
    AssertJUnit.assertArrayEquals(new Object[]{1513578087000L, "CISCO", 100.0, 200.0, 9600f}, events[0].getData());

    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
 
Example 15
Source File: Aggregation1TestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"incrementalStreamProcessorTest33"})
public void incrementalStreamProcessorTest34() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest34");
    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, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " +
            "as lastTradeValue  " +
            "group by symbol " +
            "aggregate by timestamp every sec...hour ;";

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

    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();

    stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});

    stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});

    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});

    stockStreamInputHandler.send(new Object[]{"CISCO", 100f, null, 200L, 26, 1513578087000L});
    stockStreamInputHandler.send(new Object[]{"CISCO", 100f, null, 200L, 96, 1513578087000L});

    Thread.sleep(2000);

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "within \"2017-12-18 06:21:**\" " +
            "per \"seconds\" " +
            "select * " +
            "order by AGG_TIMESTAMP ;");
    EventPrinter.print(events);
    Assert.assertNotNull(events);
    AssertJUnit.assertEquals(1, events.length);
    AssertJUnit.assertArrayEquals(new Object[]{1513578087000L, "CISCO", 100.0, 200.0, 9600f}, events[0].getData());

    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
 
Example 16
Source File: Aggregation1TestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"incrementalStreamProcessorTest34"})
public void incrementalStreamProcessorTest35() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest35");
    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, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " +
            "as lastTradeValue  " +
            "group by symbol " +
            "aggregate by timestamp every sec...hour ;";

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

    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();

    stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});

    stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});

    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});

    stockStreamInputHandler.send(new Object[]{"CISCO", 100f, null, 200L, 26, 1513578087000L});
    stockStreamInputHandler.send(new Object[]{"CISCO", 100f, null, 200L, 96, 1513578087000L});

    Thread.sleep(2000);

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "within \"2017-12-18 11:51:27 +05:30\" " +
            "per \"seconds\" " +
            "select * " +
            "order by AGG_TIMESTAMP ;");
    EventPrinter.print(events);
    Assert.assertNotNull(events);
    AssertJUnit.assertEquals(1, events.length);
    AssertJUnit.assertArrayEquals(new Object[]{1513578087000L, "CISCO", 100.0, 200.0, 9600f}, events[0].getData());

    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
 
Example 17
Source File: AggregationFilterTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"aggregationFilterTestCase3"})
public void aggregationFilterTestCase4() throws InterruptedException {
    LOG.info("incrementalStreamProcessorTest11");
    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, avg(price) as avgPrice, sum(price) as totalPrice, " +
                    "(price * quantity) as lastTradeValue  " +
                    "group by symbol " +
                    "aggregate every sec...hour ;";

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

    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();

    stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});
    Thread.sleep(2000);

    stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});
    Thread.sleep(2000);

    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});
    Thread.sleep(5000);

    LocalDate currentDate = LocalDate.now();
    String year = String.valueOf(currentDate.getYear());
    String month = String.valueOf(currentDate.getMonth().getValue());
    if (month.length() == 1) {
        month = "0".concat(month);
    }

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "on symbol == \"IBM\" " +
            "within \"" + year + "-" + month + "-** **:**:** +05:30\" " +
            "per \"seconds\"; ");

    EventPrinter.print(events);
    AssertJUnit.assertNotNull(events);
    AssertJUnit.assertEquals(1, events.length);

    Object[] copyEventsWithoutTime = new Object[4];
    System.arraycopy(events[0].getData(), 1, copyEventsWithoutTime, 0, 4);
    AssertJUnit.assertArrayEquals(new Object[]{"IBM", 100.0, 200.0, 9600f}, copyEventsWithoutTime);

    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
 
Example 18
Source File: AggregationFilterTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = {"aggregationFilterTestCase4"})
public void aggregationFilterTestCase5() throws InterruptedException {
    LOG.info("AggregationFilterTestCase5");
    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, avg(price) as avgPrice, sum(price) as totalPrice, (price * quantity) " +
            "as lastTradeValue  " +
            "group by symbol " +
            "aggregate by timestamp every sec...hour ;";

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

    InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream");
    siddhiAppRuntime.start();

    stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 60f, 90L, 6, 1496289950000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 70f, null, 40L, 10, 1496289950000L});

    stockStreamInputHandler.send(new Object[]{"WSO2", 60f, 44f, 200L, 56, 1496289952000L});
    stockStreamInputHandler.send(new Object[]{"WSO2", 100f, null, 200L, 16, 1496289952000L});

    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 26, 1496289954000L});
    stockStreamInputHandler.send(new Object[]{"IBM", 100f, null, 200L, 96, 1496289954000L});
    Thread.sleep(100);

    Event[] events = siddhiAppRuntime.query("from stockAggregation " +
            "on symbol==\"IBM\" " +
            "within \"2017-06-** **:**:**\" " +
            "per \"seconds\" " +
            "select symbol, avgPrice;");
    EventPrinter.print(events);
    AssertJUnit.assertEquals(1, events.length);
    AssertJUnit.assertArrayEquals(new Object[]{"IBM", 100.0}, events[0].getData());
    Thread.sleep(100);
    siddhiAppRuntime.shutdown();
}
 
Example 19
Source File: PersistenceTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(dependsOnMethods = "persistenceTest1")
public void persistenceTest2() throws InterruptedException {
    log.info("persistence test 2 - pattern count query");

    PersistenceStore persistenceStore = new InMemoryPersistenceStore();

    SiddhiManager siddhiManager = new SiddhiManager();
    siddhiManager.setPersistenceStore(persistenceStore);

    String siddhiApp = "" +
            "@app:name('Test') " +
            "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>20] <2:5> -> e2=Stream2[price>20] " +
            "select e1[0].price as price1_0, e1[1].price as price1_1, e1[2].price as price1_2, " +
            "   e1[3].price as price1_3, e2.price as price2 " +
            "insert into OutputStream ;";


    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.assertArrayEquals(new Object[]{25.6f, 47.6f, null, null, 45.7f}, inEvent.getData());
            }
        }
    };

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

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

    stream1.send(new Object[]{"WSO2", 25.6f, 100});
    Thread.sleep(100);
    stream1.send(new Object[]{"GOOG", 47.6f, 100});
    Thread.sleep(100);
    stream1.send(new Object[]{"GOOG", 13.7f, 100});
    Thread.sleep(100);

    AssertJUnit.assertEquals("Number of success events", 0, count);
    AssertJUnit.assertEquals("Event arrived", false, eventArrived);

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

    //restarting siddhi app
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();
    siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", queryCallback);
    stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();

    //loading
    try {
        siddhiAppRuntime.restoreLastRevision();
    } catch (CannotRestoreSiddhiAppStateException e) {
        Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed");
    }

    stream2.send(new Object[]{"IBM", 45.7f, 100});
    Thread.sleep(500);
    stream1.send(new Object[]{"GOOG", 47.8f, 100});
    Thread.sleep(500);
    stream2.send(new Object[]{"IBM", 55.7f, 100});
    Thread.sleep(500);

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

    AssertJUnit.assertEquals("Number of success events", 1, count);
    AssertJUnit.assertEquals("Event arrived", true, eventArrived);

}
 
Example 20
Source File: PersistenceTestCase.java    From siddhi with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = NoPersistenceStoreException.class, dependsOnMethods = "persistenceTest2")
public void persistenceTest3() throws Exception {
    log.info("persistence test 3 - no store defined");

    SiddhiManager siddhiManager = new SiddhiManager();

    String siddhiApp = "" +
            "@app:name('Test') " +
            "" +
            "define stream Stream1 (symbol string, price float, volume int); " +
            "define stream Stream2 (symbol string, price float, volume int); " +
            "" +
            "@info(name = 'query1') " +
            "from e1=Stream1[price>20] <2:5> -> e2=Stream2[price>20] " +
            "select e1[0].price as price1_0, e1[1].price as price1_1, e1[2].price as price1_2, " +
            "   e1[3].price as price1_3, e2.price as price2 " +
            "insert into OutputStream ;";


    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.assertArrayEquals(new Object[]{25.6f, 47.6f, null, null, 45.7f}, inEvent.getData());
            }
        }
    };

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

    InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1");
    InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2");
    siddhiAppRuntime.start();

    stream1.send(new Object[]{"WSO2", 25.6f, 100});
    Thread.sleep(100);
    stream1.send(new Object[]{"GOOG", 47.6f, 100});
    Thread.sleep(100);
    stream1.send(new Object[]{"GOOG", 13.7f, 100});
    Thread.sleep(100);

    AssertJUnit.assertEquals("Number of success events", 0, count);
    AssertJUnit.assertEquals("Event arrived", false, eventArrived);

    //persisting
    Thread.sleep(500);
    PersistenceReference persistenceReference = siddhiAppRuntime.persist();
    try {
        persistenceReference.getFuture().get();
    } catch (ExecutionException e) {
        throw e.getCause() instanceof NoPersistenceStoreException ? new NoPersistenceStoreException() : e;
    }

    //restarting siddhi app
    Thread.sleep(500);
    siddhiAppRuntime.shutdown();

}