Esempio n. 1
0
    def testDBandCSVSimulation(self):
        logging.info("Test: Random Simulation - Property and Primitive")

        target = {
            "properties": {
                "simulationName": "simulationCSV",
                "timestampStartTime": "1488615136958",
                "timestampEndTime": "1488615136966",
                "timeInterval": "1000"
            },
            "sources": [{
                "simulationType": "DATABASE_SIMULATION",
                "streamName": "FooStream",
                "siddhiAppName": "TestSiddhiApp",
                "dataSourceLocation":
                "jdbc:mysql:\/\/localhost:3306\/DatabaseFeedSimulation",
                "driver": "com.mysql.jdbc.Driver",
                "username": "******",
                "password": "******",
                "tableName": "foostream3",
                "timestampAttribute": "timestamp",
                "columnNamesList": "symbol,price,volume"
            }, {
                "simulationType": "CSV_SIMULATION",
                "streamName": "FooStream",
                "siddhiAppName": "TestSiddhiApp",
                "fileName": "sample.csv",
                "timestampAttribute": "0",
                "isOrdered": "False",
                "delimiter": ","
            }]
        }

        dasPythonClient = DASClient(self.hostUrl)
        eventSimulatorClient = dasPythonClient.getEventSimulatorClient()

        svr = FeedSimulationConfiguration("simulationCSV")
        svr.properties.timestampStartTime = 1488615136958
        svr.properties.timestampEndTime = 1488615136966
        svr.properties.timeInterval = 1000

        s1 = SimulationSource(
            simulationType=SimulationSource.Type.DATABASE_SIMULATION)
        s1.streamName = "FooStream"
        s1.siddhiAppName = "TestSiddhiApp"
        s1.dataSourceLocation = "jdbc:mysql:\/\/localhost:3306\/DatabaseFeedSimulation"
        s1.driver = "com.mysql.jdbc.Driver"
        s1.username = "******"
        s1.password = "******"
        s1.tableName = "foostream3"
        s1.timestampAttribute = "timestamp"
        s1.columnNamesList = "symbol,price,volume"

        svr.sources.append(s1)

        s2 = SimulationSource(
            simulationType=SimulationSource.Type.CSV_SIMULATION)
        s2.streamName = "FooStream"
        s2.siddhiAppName = "TestSiddhiApp"
        s2.fileName = "sample.csv"
        s2.timestampAttribute = 0
        s2.isOrdered = False
        s2.delimiter = ","

        svr.sources.append(s2)

        match = svr.toJSONObject()

        self.assertDictEqual(target["sources"][1], match["sources"][1])

        self.assertTrue(
            eventSimulatorClient.uploadCSV("sample.csv",
                                           path=resources_path + "sample.csv"))
        logging.info("Successfully Uploaded CSV")

        sleep(5)

        self.assertTrue(
            eventSimulatorClient.saveSimulationFeedConfiguration(svr))
        logging.info("Successfully Saved Simulation Feed Configuration")

        sleep(5)

        self.assertTrue(
            eventSimulatorClient.runSimulationFeedConfiguration(svr))
        logging.info("Successfully Started Simulation Feed Configuration")

        sleep(5)

        self.assertTrue(
            eventSimulatorClient.deleteSimulationFeedConfiguration(
                svr.properties.simulationName))
        logging.info("Successfully Deleted Simulation Feed Configuration")

        self.assertTrue(eventSimulatorClient.deleteCSV("sample.csv"))
        logging.info("Successfully Deleted CSV")
Esempio n. 2
0
    def testDBSimulationOneSourceWOColumnNames(self):
        logging.info("Test: DB Simulation - One Source w\o column names")

        target = {
            "properties": {
                "simulationName": "simDbNoColumnsList",
                "timestampStartTime": "1488615136958",
                "timestampEndTime": "1488615136961",
                "timeInterval": "1000"
            },
            "sources": [{
                "simulationType": "DATABASE_SIMULATION",
                "streamName": "FooStream",
                "siddhiAppName": "TestSiddhiApp",
                "dataSourceLocation":
                "jdbc:mysql:\/\/localhost:3306\/DatabaseFeedSimulation",
                "driver": "com.mysql.jdbc.Driver",
                "username": "******",
                "password": "******",
                "tableName": "foostream3",
                "timestampAttribute": "timestamp",
                "columnNamesList": None
            }]
        }

        dasPythonClient = DASClient(self.hostUrl)
        eventSimulatorClient = dasPythonClient.getEventSimulatorClient()

        svr = FeedSimulationConfiguration("simDbNoColumnsList")
        svr.properties.timestampStartTime = 1488615136958
        svr.properties.timestampEndTime = 1488615136961
        svr.properties.timeInterval = 1000

        s1 = SimulationSource(
            simulationType=SimulationSource.Type.DATABASE_SIMULATION)
        s1.streamName = "FooStream"
        s1.siddhiAppName = "TestSiddhiApp"
        s1.dataSourceLocation = "jdbc:mysql:\/\/localhost:3306\/DatabaseFeedSimulation"
        s1.driver = "com.mysql.jdbc.Driver"
        s1.username = "******"
        s1.password = "******"
        s1.tableName = "foostream3"
        s1.timestampAttribute = "timestamp"
        s1.columnNamesList = None
        svr.sources.append(s1)

        match = svr.toJSONObject()

        self.assertDictEqual(target, match)

        self.assertTrue(
            eventSimulatorClient.saveSimulationFeedConfiguration(svr))
        logging.info("Successfully Saved Simulation Feed Configuration")

        sleep(5)

        self.assertTrue(
            eventSimulatorClient.runSimulationFeedConfiguration(svr))
        logging.info("Successfully Started Simulation Feed Configuration")

        sleep(5)

        self.assertTrue(
            eventSimulatorClient.deleteSimulationFeedConfiguration(
                svr.properties.simulationName))
        logging.info("Successfully Deleted Simulation Feed Configuration")