-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1585 from suhothayan/master
Fix Siddhi sending events to wrong stream when stopped and started.
- Loading branch information
Showing
6 changed files
with
158 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
modules/siddhi-core/src/test/java/io/siddhi/core/managment/StartStopTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.siddhi.core.managment; | ||
|
||
import io.siddhi.core.SiddhiAppRuntime; | ||
import io.siddhi.core.SiddhiManager; | ||
import io.siddhi.core.event.Event; | ||
import io.siddhi.core.stream.input.InputHandler; | ||
import io.siddhi.core.stream.output.StreamCallback; | ||
import io.siddhi.core.util.EventPrinter; | ||
import org.apache.log4j.Logger; | ||
import org.testng.Assert; | ||
import org.testng.AssertJUnit; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class StartStopTestCase { | ||
private static final Logger log = Logger.getLogger(StartStopTestCase.class); | ||
private AtomicInteger count; | ||
private boolean eventArrived; | ||
|
||
@BeforeMethod | ||
public void init() { | ||
count = new AtomicInteger(); | ||
eventArrived = false; | ||
} | ||
|
||
@Test(expectedExceptions = InterruptedException.class) | ||
public void startStopTest1() throws InterruptedException { | ||
log.info("startStop test 1"); | ||
|
||
SiddhiManager siddhiManager = new SiddhiManager(); | ||
|
||
String siddhiApp = "" + | ||
"define stream cseEventStream (symbol string, price float, volume int);" + | ||
"define stream cseEventStream2 (symbol string, price float, volume int);" + | ||
"" + | ||
"@info(name = 'query1') " + | ||
"from cseEventStream " + | ||
"select 1 as eventFrom " + | ||
"insert into outputStream ;" + | ||
"" + | ||
"@info(name = 'query2') " + | ||
"from cseEventStream2 " + | ||
"select 2 as eventFrom " + | ||
"insert into outputStream ;"; | ||
|
||
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); | ||
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { | ||
|
||
@Override | ||
public void receive(Event[] events) { | ||
EventPrinter.print(events); | ||
} | ||
|
||
}); | ||
|
||
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream2"); | ||
siddhiAppRuntime.start(); | ||
siddhiAppRuntime.shutdown(); | ||
siddhiAppRuntime.start(); | ||
inputHandler.send(new Object[]{"WSO2", 55.6f, 100}); | ||
siddhiAppRuntime.shutdown(); | ||
} | ||
|
||
@Test() | ||
public void startStopTest2() throws InterruptedException { | ||
log.info("startStop test 2"); | ||
|
||
SiddhiManager siddhiManager = new SiddhiManager(); | ||
|
||
String siddhiApp = "" + | ||
"define stream cseEventStream (symbol string, price float, volume int);" + | ||
"define stream cseEventStream2 (symbol string, price float, volume int);" + | ||
"" + | ||
"@info(name = 'query1') " + | ||
"from cseEventStream " + | ||
"select 1 as eventFrom " + | ||
"insert into outputStream ;" + | ||
"" + | ||
"@info(name = 'query2') " + | ||
"from cseEventStream2 " + | ||
"select 2 as eventFrom " + | ||
"insert into outputStream ;"; | ||
|
||
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); | ||
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { | ||
|
||
@Override | ||
public void receive(Event[] events) { | ||
EventPrinter.print(events); | ||
Assert.assertEquals(events[0].getData(0), 1); | ||
eventArrived = true; | ||
count.incrementAndGet(); | ||
} | ||
|
||
}); | ||
|
||
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream2"); | ||
inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); | ||
siddhiAppRuntime.start(); | ||
siddhiAppRuntime.shutdown(); | ||
siddhiAppRuntime.start(); | ||
inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); | ||
inputHandler.send(new Object[]{"WSO2", 55.6f, 100}); | ||
siddhiAppRuntime.shutdown(); | ||
AssertJUnit.assertTrue(eventArrived); | ||
AssertJUnit.assertEquals(1, count.get()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters