class BlinktBaseTest(BaseTest): def __init__(self, descriptor, outdir, runner): BaseTest.__init__(self, descriptor, outdir, runner) # Load the plugin and wrapper from the build or install if hasattr(self, 'TEST_AGAINST_INSTALL'): self.BlinktMonitors = ApamaWorkMonitors else: self.BlinktMonitors = BlinktProjectDir os.environ["LD_LIBRARY_PATH"] = BlinktProjectDir + os.pathsep + os.environ["LD_LIBRARY_PATH"] # Initialise a correlator with the Blinkt plugin, the plugin # wrapper and other required supporting code. self.correlator = CorrelatorHelper(self, name='BlinktCorrelator') process = self.correlator.start() self.correlatorLog = process.stdout self.correlatorOut = process.stdout self.correlatorErr = process.stderr self.correlator.injectEPL(filenames=[ join(ApamaHomeMonitors, 'TimeFormatEvents.mon'), join(ApamaWorkMonitors, 'GPIOPlugin.mon'), join(self.BlinktMonitors, 'BlinktHelper.mon') ]) self.waitForSignal(self.correlatorLog, expr="Blinkt initialised")
def execute(self): correlator = CorrelatorHelper(self, name='testcorrelator') correlator.start(logfile='testcorrelator.log') correlator.injectEPL(filenames=['RandomPlugin.mon'], filedir=PROJECT.APAMA_WORK + '/monitors') correlator.injectEPL(filenames=['test.mon']) correlator.flush()
class SenseHATBaseTest(BaseTest): def __init__(self, descriptor, outsubdir, runner): BaseTest.__init__(self, descriptor, outsubdir, runner) self.BASE_DIR = os.path.join(self.project.root, '..') os.environ["LD_LIBRARY_PATH"] = self.BASE_DIR + os.pathsep + os.environ["LD_LIBRARY_PATH"] self.sense = SenseHat() def start(self): self.correlator = CorrelatorHelper(self) self.correlator.start() def clearPixels(self): self.sense.clear() def getPixel(self, x, y): return self.sense.get_pixel(x, y) # 3 bits lost for red, 2 for green and 3 for blue def checkPixel(self, x, y, values): values[0] = int(8*math.floor(values[0] / 8)) values[1] = int(4*math.floor(values[1] / 4)) values[2] = int(8*math.floor(values[2] / 8)) self.assertTrue(self.getPixel(x, y) == values) def getTemperature(self): return self.sense.get_temperature() def getHumidity(self): return self.sense.get_humidity() def getPressure(self): return self.sense.get_pressure()
def start(self): self.correlator = CorrelatorHelper(self) #, name='SPICorrelator') self.correlator.start() self.correlator.injectMonitorscript( filenames=[os.path.join(self.BASE_DIR, '../GPIOPlugin.mon')]) self.correlator.injectMonitorscript( filenames=[os.path.join(self.BASE_DIR, 'SPIPlugin.mon')])
def execute(self): correlator = CorrelatorHelper(self) correlator.start(logfile='correlator.log', arguments=['--config', self.input + '/project']) correlator.injectJava('test.jar') correlator.injectEPL('test.mon') correlator.flush()
def execute(self): # copy the build(Release folder) and config yaml to output fileutils.mkdir(self.output + '/Release') with socketProcessMutex: self.copytree(TEST_SUBJECT_DIR + '/Release', self.output + '/Release') filecopy.filecopy(self.input + '/sample.yaml', self.output + '/sample.yaml') # create the correlator helper and start the correlator and an # engine receive listening on the Echo Channel correlator = CorrelatorHelper(self, name='mycorrelator') correlator.start(logfile='mycorrelator.log', inputLog='mycorrelator.input.log', config=[self.output + '/sample.yaml']) correlator.injectEPL( ['ConnectivityPluginsControl.mon', 'ConnectivityPlugins.mon'], filedir=PROJECT.APAMA_HOME + '/monitors') correlator.receive(filename='receive.evt', channels=['EchoChannel']) # inject the simple monitor into the correlator correlator.injectEPL(filenames=[self.input + '/DemoApp.mon']) #self.wait(3) # wait for receipt msg towards transport # we could use correlator.flush() here instead self.waitForSignal('mycorrelator.log', expr="Towards Host:", condition="==8")
def execute(self): for t, _ in self.testVectors: # Can specify which port the correlator runs on using '-X CORR_PORT=15903' on the # PySys command line else it will be randomly allocated correlator = CorrelatorHelper(self, name='correlator-'+t, port=self.CORR_PORT if hasattr(self, 'CORR_PORT') else None) correlator.start(arguments=['--connectivityConfig', self.input+'/'+t+'.yaml'], waitForServerUp=False, ignoreExitStatus=True) correlator.process.wait(30)
def execute(self): correlator = CorrelatorHelper(self, name='mycorrelator') correlator.start(logfile='mycorrelator.log', config=[self.input+'/sample.yaml'], configPropertyOverrides={'EXAMPLES_DIR':self.project.EXAMPLES_DIR, 'RUST_TARGET': self.project.RUST_TARGET}) correlator.injectEPL(['ConnectivityPluginsControl.mon', 'ConnectivityPlugins.mon'], filedir=PROJECT.APAMA_HOME+'/monitors') correlator.injectEPL(filenames=[self.input+'/DemoApp.mon']) self.waitForSignal('mycorrelator.log', expr="Got echo response", process=correlator, errorExpr=[' ERROR ', ' FATAL ', 'Failed to parse event']) correlator.shutdown()
def start(self): self.correlator = CorrelatorHelper(self) self.correlator.start(config=self.config) self.correlator.injectMonitorscript(filenames=[ os.path.join(self.BASE_DIR, 'monitors', 'utils', 'SenseHATHelper.mon') ]) self.correlator.injectMonitorscript(filenames=[ os.path.join(self.BASE_DIR, 'monitors', 'api', 'SenseHATAPI.mon') ])
def execute(self): self.correlator = CorrelatorHelper(self) self.correlator.start( environ={'APAMA_FILEPLUGIN_ROOT_DIR': self.output}) self.correlator.injectEPL(filenames=['FilePlugin.mon'], filedir=PROJECT.APAMA_WORK + '/monitors') self.correlator.injectMonitorscript(filenames=['test.mon']) self.waitForSignal('correlator.out', expr='Test finished', errorExpr=[' (ERROR|FATAL) '])
def execute(self): # create the correlator helper, start the correlator and attach an # engine_receive process listening to a test channel. The helper will # automatically get an available port that will be used for all # operations against it correlator = CorrelatorHelper(self, name='testcorrelator') self.project.APAMA_WORK = self.descriptor.testDir + '/../../EPLApp' correlator.start(logfile='testcorrelator.log', config=[ os.path.join(self.project.APAMA_WORK, 'initialization.yaml') ]) receiveProcess = correlator.receive(filename='receive.evt', channels=['EchoChannel'], logChannels=True) correlator.applicationEventLogging(enable=True) # not strictly necessary in this testcase, but a useful example of waiting # for a log message self.waitForSignal('testcorrelator.out', expr="AverageReadings\(\"S001\",105\.25,825\)", process=correlator.process, errorExpr=[' (ERROR|FATAL) .*']) # wait for all events to be processed correlator.flush()
def execute(self): self.assertTrue( os.path.exists( f'{PROJECT.EXAMPLES_DIR}/FileTransport/Release/libGoFileTransport.so' )) for f in ['read.txt', 'config.yaml']: filecopy(f'{self.input}/{f}', f'{self.output}/{f}') correlator = CorrelatorHelper(self, name='correlator') correlator.start( logfile='correlator.log', inputLog='correlator.input.log', config=[f'{self.output}/config.yaml'], environ={'EXAMPLES_DIR': PROJECT.EXAMPLES_DIR}, arguments=['-DEXAMPLES_DIR=%s' % PROJECT.EXAMPLES_DIR]) correlator.injectEPL(filenames=[ 'ConnectivityPluginsControl.mon', 'ConnectivityPlugins.mon' ], filedir=f'{PROJECT.APAMA_HOME}/monitors') correlator.injectEPL(filenames=['simple.mon']) self.waitForSignal('correlator.log', expr="Hello from transport", condition=">=10") self.waitForSignal('write.txt', expr="Hello from correlator", condition=">=10")
def execute(self): self.correlator_default = CorrelatorHelper(self, name='correlator_default') self.correlator_tailored = CorrelatorHelper(self, name='correlator_tailored') self.correlator_default.start() self.correlator_tailored.start(environ={'APAMA_FILEPLUGIN_ROOT_DIR':self.output}) self.correlator_default.injectEPL(filenames=['FilePlugin.mon'], filedir=PROJECT.APAMA_WORK + '/monitors') self.correlator_tailored.injectEPL(filenames=['FilePlugin.mon'], filedir=PROJECT.APAMA_WORK + '/monitors') self.correlator_default.injectMonitorscript(filenames=['test.mon']) self.correlator_tailored.injectMonitorscript(filenames=['test.mon']) self.waitForSignal('correlator_default.out', expr='Test finished') self.waitForSignal('correlator_tailored.out', expr='Test finished')
def execute(self): # create the correlator helper, start the correlator and attach an # engine_receive process listening to a test channel. The helper will # automatically get an available port that will be used for all # operations against it correlator = CorrelatorHelper(self, name='testcorrelator') correlator.start( logfile='testcorrelator.log', config=[os.path.join(self.project.APAMA_WORK, 'complex.yaml')]) correlator.applicationEventLogging(enable=True) # inject the monitor (directory defaults to the testcase input) correlator.injectEPL(filenames=[ os.path.join(self.project.APAMA_WORK, 'ComplexPlugin.mon') ]) # wait for all events to be processed correlator.flush()
def __init__(self, parent, port=None, host=None, name='correlator'): CorrelatorHelper.__init__(self, parent, port, host, name) self.log = self.parent.log self.eventSender = None self.AntAunitImports = os.path.join(os.environ['AUNIT_BUNDLE_HOME'], 'ant_macros', 'aunit-imports.xml') ################################################################# # Set Classpath for ANT Call ################################################################# self.ANT_HOME = os.environ['ANT_HOME'] self.environ = {} for key in os.environ: self.environ[stringToUnicode(key)] = stringToUnicode( os.environ[key]) self.environ['CLASSPATH'] = '' self.environ['CLASSPATH'] = os.path.join( self.ANT_HOME) + ENVSEPERATOR + self.environ['CLASSPATH'] self.environ['CLASSPATH'] = os.path.join( self.ANT_HOME, 'lib', 'ant-launcher.jar') + ENVSEPERATOR + self.environ['CLASSPATH'] self.environ['CLASSPATH'] = os.path.join( getattr(PROJECT, "APAMA_HOME"), 'lib', 'engine_client%s.jar' % getattr(PROJECT, "APAMA_LIBRARY_VERSION") ) + ENVSEPERATOR + self.environ['CLASSPATH'] self.environ['CLASSPATH'] = os.path.join( getattr(PROJECT, "APAMA_HOME"), 'lib', 'util%s.jar' % getattr(PROJECT, "APAMA_LIBRARY_VERSION") ) + ENVSEPERATOR + self.environ['CLASSPATH'] self.environ['CLASSPATH'] = os.path.join( PROJECT.root, 'tools', 'classes') + ENVSEPERATOR + self.environ['CLASSPATH'] self.environ['CLASSPATH'] = os.path.join( getattr(PROJECT, "APAMA_HOME"), 'lib') + ENVSEPERATOR + self.environ['CLASSPATH'] self.environ['CLASSPATH'] = os.path.join( getattr(PROJECT, "APAMA_HOME"), 'bin') + ENVSEPERATOR + self.environ['CLASSPATH'] self.environ['CLASSPATH'] = stringToUnicode(self.environ['CLASSPATH'])
def execute(self): # create a project with C8Y bundles project = self.createProject("c8y-basic") self.addC8YPropertiesToProject(project) # copy EPL app to be tested to the project's monitors dir self.copy(self.project.EPL_APPS + "/AlarmOnMeasurementThreshold.mon", project.monitorsDir() + "/AlarmOnMeasurementThreshold.mon") # copy EPL test file from Input dir to project's monitors dir self.copy( self.input + "/AlarmOnMeasurementThresholdTest.mon", project.monitorsDir() + "/AlarmOnMeasurementThresholdTest.mon") project.deploy() # start local correlator correlator = CorrelatorHelper(self, name='c8y-correlator') correlator.start(logfile='c8y-correlator.log', config=project.deployedDir()) # wait for all events to be processed correlator.flush() # wait until the correlator gets a complete self.waitForGrep( 'c8y-correlator.log', expr="Removed monitor AlarmOnMeasurementThresholdTest")
class SPIBaseTest(BaseTest): def __init__(self, descriptor, outsubdir, runner): BaseTest.__init__(self, descriptor, outsubdir, runner) self.BASE_DIR = os.path.join(self.project.root, '../SPI') GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) os.environ[ "LD_LIBRARY_PATH"] = self.BASE_DIR + os.pathsep + os.environ[ "LD_LIBRARY_PATH"] def __del__(self): GPIO.cleanup() def start(self): self.correlator = CorrelatorHelper(self) #, name='SPICorrelator') self.correlator.start() self.correlator.injectMonitorscript( filenames=[os.path.join(self.BASE_DIR, '../GPIOPlugin.mon')]) self.correlator.injectMonitorscript( filenames=[os.path.join(self.BASE_DIR, 'SPIPlugin.mon')]) def checkPin(self, pinID, expectedValue): GPIO.setup(pinID, GPIO.IN) self.assertTrue(expectedValue == GPIO.input(pinID)) def waitForEdge(self, pinID, rising): GPIO.setup(pinID, GPIO.IN) if rising == True: return GPIO.wait_for_edge(pinID, GPIO.RISING, timeout=5000) else: return GPIO.wait_for_edge(pinID, GPIO.FALLING, timeout=5000)
def startApplication(self): correlator = CorrelatorHelper(self.parent, name='defaultCorrelator') correlator.start(logfile='correlator.log') receiver = correlator.receive(filename='receive.evt', logChannels=True) correlator.injectEPL(filenames=['Cumulocity_EventDefinitions.mon'], filedir=os.path.join( self.project.APAMA_MONITORS_DIR, 'cumulocity', '10.5')) correlator.injectEPL(filenames=['GAPDemo.mon'], filedir=self.project.MONITORS_DIR) self.parent.waitForSignal( 'receive.evt', expr="com.apama.cumulocity.FindManagedObject", condition="==1") self.correlator = correlator return correlator
def execute(self): """ Runs all the tests in the Input directory against the applications configured in the EPL_APPS directory or with the EPLApps directive. """ # Check APAMA_HOME and EPL_TESTING_SDK env are valid if not os.path.isdir(self.project.APAMA_HOME): self.abort(BLOCKED, f'APAMA_HOME project property is not valid ({self.project.APAMA_HOME}). Try running in an Apama command prompt.') if not os.path.isdir(self.project.EPL_TESTING_SDK): self.abort(BLOCKED, f'EPL_TESTING_SDK is not valid ({self.project.EPL_TESTING_SDK}). Please set the EPL_TESTING_SDK environment variable.') from apama.correlator import CorrelatorHelper # Create test project and add C8Y properties and EPL Apps project = self.createProject("test-project") self.addC8YPropertiesToProject(project) eplApps = self.getTestSubjectEPLApps() self.addEPLAppsToProject(eplApps, project) project.deploy() # Run local correlator connected to C8Y with Apama EPL Apps and test files deployed correlator = CorrelatorHelper(self, name='c8y-correlator') correlator.start(logfile='c8y-correlator.log', config=project.deployedDir()) # Wait for our EPL App test subjects to be added correlator.flush() # Inject test mon files from Input directory to correlator inputFiles = os.listdir(self.input) for inputFile in inputFiles: # Check file is a .mon file before injecting if os.path.splitext(inputFile)[1] == '.mon': self.log.info(f"Injecting {inputFile} test case") correlator.injectEPL(inputFile, self.input) # Wait for test to complete correlator.flush() activeTestMonitors = self.getMonitorsFromInjectedFile(correlator, os.path.join(self.input, inputFile)) for monitor in activeTestMonitors: self.waitForGrep('c8y-correlator.log', expr=f"Removed monitor {monitor}", process=correlator)
class GPIOBaseTest(BaseTest): def __init__(self, descriptor, outsubdir, runner): BaseTest.__init__(self, descriptor, outsubdir, runner) self.BASE_DIR = os.path.join(self.project.root, '..') GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) os.environ[ "LD_LIBRARY_PATH"] = self.BASE_DIR + os.pathsep + os.environ[ "LD_LIBRARY_PATH"] def __del__(self): GPIO.cleanup() def start(self): self.correlator = CorrelatorHelper(self) #, name='GPIOCorrelator') self.correlator.start() self.correlator.injectMonitorscript( filenames=[os.path.join(self.BASE_DIR, 'GPIOPlugin.mon')]) def initialPinSetup(self, lowPins=None, highPins=None): if (lowPins): for lp in lowPins: self.writePin(lp, GPIO.LOW) if (highPins): for hp in highPins: self.writePin(hp, GPIO.HIGH) def checkPin(self, pinID, expectedValue): GPIO.setup(pinID, GPIO.IN) self.assertTrue(expectedValue == GPIO.input(pinID)) def writePin(self, pinID, value): GPIO.setup(pinID, GPIO.OUT) GPIO.output(pinID, value)
class PySysTest(BaseTest): def execute(self): self.correlator = CorrelatorHelper(self) self.correlator.start(environ={'APAMA_FILEPLUGIN_ROOT_DIR':self.output}) self.correlator.injectEPL(filenames=['FilePlugin.mon'], filedir=PROJECT.APAMA_WORK + '/monitors') self.correlator.injectMonitorscript(filenames=['test.mon']) self.waitForSignal('correlator.out', expr='Test finished', errorExpr=[' (ERROR|FATAL) ']) def validate(self): self.assertGrep('correlator.out', expr=' (ERROR|FATAL) ', contains=False) self.assertGrep('correlator.out', expr='correlator.out') self.assertGrep('correlator.out', expr='correlator.err')
def execute(self): correlator = CorrelatorHelper(self, name='mycorrelator') correlator.start(logfile='mycorrelator.log', config=[self.input + '/sample.yaml'], configPropertyOverrides={ 'EXAMPLES_DIR': self.project.EXAMPLES_DIR, 'RUST_TARGET': self.project.RUST_TARGET }) correlator.injectEPL( ['ConnectivityPluginsControl.mon', 'ConnectivityPlugins.mon'], filedir=PROJECT.APAMA_HOME + '/monitors') correlator.injectEPL(filenames=[self.input + '/DemoApp.mon']) self.message_count = 100000 res = asyncio.get_event_loop().run_until_complete( self.start_send_recv('ws://127.0.0.1:4999', self.message_count)) s, r = res self.sent = s self.receved = r
def startCorrelator(self, url=None, city='London', xclock=True): '''Start a correlator and set logging, return correlator object handle. ''' self.correlator = CorrelatorHelper(self) self.log.info('Allocating port %s for correlator'%self.correlator.port) arguments = [] arguments.extend(['--inputLog',os.path.join(self.output,'correlator-input.log')]) if not(url is None): replaceDict = {'${apama.project}': PROJECT.root, '${app.city}': city, '${app.data.url}': url} replace(os.path.join(PROJECT.root, 'config', 'connectors.yaml'), os.path.join(self.output, 'connectors.yaml'), replaceDict) arguments.extend(['--connectivityConfig',os.path.join(self.output, 'connectors.yaml')]) if xclock: arguments.append('-Xclock') self.correlator.start(logfile='correlator.log', arguments=arguments) self.correlator.receive('correlator_input.log', channels=['com.apama.input']) self.correlator.receive('correlator_output.log') self.setApplicationLogFile(self.correlator, 'application.log', 'com.jtech') self.setApplicationLogLevel(self.correlator, 'DEBUG', 'com.jtech')
class PySysTest(BaseTest): def execute(self): self.correlator = CorrelatorHelper(self) self.correlator.start( environ={'APAMA_FILEPLUGIN_ROOT_DIR': self.output}) self.correlator.injectEPL(filenames=['FilePlugin.mon'], filedir=PROJECT.APAMA_WORK + '/monitors') self.correlator.injectMonitorscript(filenames=['test.mon']) self.waitForSignal('correlator.out', expr='Test finished', errorExpr=[' (ERROR|FATAL) ']) def validate(self): self.assertGrep('correlator.out', expr=' (ERROR|FATAL) ', contains=False) # non standard exception messages means we can't succinctly check for specifics self.assertGrep('correlator.out', expr='in plugin method read') self.assertGrep('correlator.out', expr='in plugin method get_file_size_KB') self.assertGrep('correlator.out', expr='in plugin method copy') self.assertGrep('correlator.out', expr='in plugin method remove')
class SenseHATBaseTest(BaseTest): def __init__(self, descriptor, outsubdir, runner): BaseTest.__init__(self, descriptor, outsubdir, runner) self.BASE_DIR = os.path.join(self.project.root, '..') self.config = os.path.join(self.BASE_DIR, 'config', 'CorrelatorConfig.yaml') os.environ[ "LD_LIBRARY_PATH"] = self.BASE_DIR + os.pathsep + "/usr/local/lib" + os.pathsep + os.environ[ "LD_LIBRARY_PATH"] os.environ["AP_PYTHONHOME"] = '/usr/local' def start(self): self.correlator = CorrelatorHelper(self) self.correlator.start(config=self.config) self.correlator.injectMonitorscript(filenames=[ os.path.join(self.BASE_DIR, 'monitors', 'utils', 'SenseHATHelper.mon') ]) self.correlator.injectMonitorscript(filenames=[ os.path.join(self.BASE_DIR, 'monitors', 'api', 'SenseHATAPI.mon') ])
def execute(self): correlator = CorrelatorHelper(self, name='correlator') correlator.start(logfile='correlator.log', config=os.path.join(PROJECT.TEST_SUBJECT_DIR, 'initialization.yaml')) correlator.flush() correlator.injectEPL(filenames='testUtils.mon', filedir=PROJECT.UTILS_DIR) # Set the log level to DEBUG so that we can see when the listeners are killed correlator.setApplicationLogLevel(verbosity='DEBUG') # Start test results receiver correlator.receive(filename='TestResult.evt', channels=['TestResult'], logChannels=True) # Inject test correlator.injectEPL(filenames=['test.mon']) # wait for all events to be processed correlator.flush() # wait for test to complete self.waitForSignal('TestResult.evt', expr="TestComplete", condition="==1", timeout=10) # Output the engine_inspect result to a file to check for any remaining subscribed channels correlator.inspect(filename='preTerminateInspect.txt', arguments=['-x']) correlator.sendEventStrings('utils.KeepAliveUntilTerminated()') # Output the engine_inspect result to a file to check for non-terminated listeners correlator.inspect(filename='postTerminateInspect.txt', raw=True, arguments=['-x'])
def startAnalyticsBuilderCorrelator(self, blockSourceDir=None, Xclock=True, numWorkers=4, injectBlocks = True, **kwargs): """ Start a correlator with the EPL for Analytics Builder loaded. :param blockSourceDir: A location of blocks to include, or a list of locations :param Xclock: Externally clock correlator (on by default). :param numWorkers: Number of workers for Analytics Builder runtime (4 by default). :param injectBlocks: if false, don't inject the actual block EPL (use if there are dependencies), returns blockOutput directory. Also skips applicationInitialized call. :param \**kwargs: extra kwargs are passed to startCorrelator """ # Build and extract the block extension: if blockSourceDir == None: blockSourceDir = self.input if not isinstance(blockSourceDir, list): blockSourceDir = [blockSourceDir] blockOutput = self.output+'/block-output-' blockOutputDirs=[] blockSrcOutput = self.output+'/block-src-' for blockDir in blockSourceDir: blockOutput=blockSrcOutput + os.path.basename(blockDir) self.buildExtensionDirectory(blockDir, blockOutput) blockOutputDirs.append(Path(blockOutput)) # Start the correlator: corr = CorrelatorHelper(self) arguments=kwargs.get('arguments', []) arguments.append(f'-DanalyticsBuilder.numWorkerThreads={numWorkers}') arguments.append(f'-DanalyticsBuilder.timedelay_secs=0.1') kwargs['arguments']=arguments logfile=kwargs.get('logfile', 'correlator.log') kwargs['logfile']=logfile corr.start(Xclock=Xclock, **kwargs) corr.logfile = logfile corr.injectEPL([self.project.APAMA_HOME+'/monitors/'+i+'.mon' for i in ['ScenarioService', 'data_storage/MemoryStore', 'JSONPlugin', 'AnyExtractor', 'ManagementImpl', 'Management', 'ConnectivityPluginsControl', 'ConnectivityPlugins', 'HTTPClientEvents', 'AutomaticOnApplicationInitialized']]) corr.injectCDP(self.project.ANALYTICS_BUILDER_SDK+'/block-api/framework/analyticsbuilder-framework.cdp') self.injectCumulocityEvents(corr) corr.injectCDP(self.project.ANALYTICS_BUILDER_SDK + '/block-api/framework/cumulocity-inventoryLookup-events.cdp') corr.injectEPL(self.project.ANALYTICS_BUILDER_SDK+'/testframework/resources/TestHelpers.mon') for blockOutput in blockOutputDirs: corr.send(sorted(list(blockOutput.rglob('*.evt')))) self.analyticsBuilderCorrelator = corr corr.receive('output.evt', channels=['TestOutput']) corr.injectTestEventLogger(channels=['TestOutput']) if not injectBlocks: return blockOutputDirs self.preInjectBlock(corr) # inject block files: for blockOutput in blockOutputDirs: corr.injectEPL(sorted(list(blockOutput.rglob('*.mon')))) corr.send(sorted(list(blockOutput.rglob('*.evt')))) # now done corr.sendEventStrings('com.apama.connectivity.ApplicationInitialized()') corr.flush(count=10) return corr
def execute(self): correlator = CorrelatorHelper(self, name='correlator') correlator.start(logfile='correlator.log', config=os.path.join(PROJECT.TEST_SUBJECT_DIR, 'initialization.yaml')) correlator.flush() correlator.injectEPL(filenames='testUtils.mon', filedir=PROJECT.UTILS_DIR) # Start test results receiver correlator.receive(filename='TestResult.evt', channels=['TestResult'], logChannels=True) # Inject test correlator.injectEPL(filenames=['test.mon']) # wait for all events to be processed correlator.flush() # wait for test to complete self.waitForSignal('TestResult.evt', expr="TestComplete", condition="==1", timeout=10)
def execute(self): corr = CorrelatorHelper(self, name='correlator') corr.start(logfile='correlator.log', arguments=[ '-Dasserts=true', '--config', self.input + '/correlator.yaml' ]) corr.injectEPL( os.getenv('APAMA_HOME', '') + '/monitors/ManagementImpl.mon') corr.injectEPL( os.getenv('APAMA_HOME', '') + '/monitors/Management.mon') corr.injectEPL('../../../src/Assert.mon') corr.injectEPL('../../../src/AssertHelper.mon') for test in [ 'ConfigAssert.mon', 'DebugAssert.mon', 'AssertDieWithError.mon' ]: corr.injectEPL(test) corr.flush() corr.shutdown()
def execute(self): correlator = CorrelatorHelper(self, name='testcorrelator') correlator.start(logfile='testcorrelator.log', config=self.input+'/config.yaml') correlator.injectEPL(filenames=['ConnectivityPluginsControl.mon'], filedir=PROJECT.APAMA_HOME+'/monitors') correlator.injectEPL(filenames=['ConnectivityPlugins.mon'], filedir=PROJECT.APAMA_HOME+'/monitors') correlator.injectEPL(filenames=['test.mon']) correlator.flush() self.waitForSignal(file='testcorrelator.log', expr='Round-trip', condition='>=2')
def execute(self): corr = CorrelatorHelper(self, name='correlator') corr.start(logfile='correlator.log') corr.injectEPL(os.getenv('APAMA_HOME','') + '/monitors/ManagementImpl.mon') corr.injectEPL(os.getenv('APAMA_HOME','') + '/monitors/Management.mon') corr.injectEPL('../../common/TestHelper.mon') corr.injectEPL('../../../src/Assert.mon') corr.injectEPL('TestAssertIsTrueIsFalse.mon') self.waitForGrep('correlator.log', 'Removed monitor TestAssertIsTrueIsFalse')
class CycleMonitorTest(BaseTest): def setup(self): '''Override BaseTest setup. ''' BaseTest.setup(self) self.stations=[] self.jython_classpath = os.path.join(PROJECT.JYTHON_HOME, 'jython.jar') self.addToJythonClassPath(os.path.join(PROJECT.APAMA_HOME,'lib','ap-util.jar')) self.addToJythonClassPath(os.path.join(PROJECT.APAMA_HOME,'lib','ap-client.jar')) def addToJythonClassPath(self, path): '''Path builder for for jython. ''' self.jython_classpath = '%s%s%s' % (self.jython_classpath, ENVSEPERATOR, path) def addStation(self,id,name,lat,lng): '''Add a station to the list of station, return the station object. ''' station = Station(id,name,lat,lng) self.stations.append(station) return station def dumpStations(self, file): '''Write the current list of stations to file in JSON. ''' with open(os.path.join(self.output, file), 'w') as fp: json.dump([station.__dict__ for station in self.stations], fp, indent=4) def dumpStationsAndPoll(self, file): '''Write the current list of stations to file in JSON, and force a poll on the adapter through the correlator. ''' self.dumpStations(file) with open(os.path.join(self.output, 'poll.mon'),'w') as fp: fp.write('monitor Poll { action onload{ send com.jtech.source.Poll() to "CITY-BIKES"; } }') self.correlator.injectMonitorscript('poll.mon', filedir=self.output) def startCorrelator(self, url=None, city='London', xclock=True): '''Start a correlator and set logging, return correlator object handle. ''' self.correlator = CorrelatorHelper(self) self.log.info('Allocating port %s for correlator'%self.correlator.port) arguments = [] arguments.extend(['--inputLog',os.path.join(self.output,'correlator-input.log')]) if not(url is None): replaceDict = {'${apama.project}': PROJECT.root, '${app.city}': city, '${app.data.url}': url} replace(os.path.join(PROJECT.root, 'config', 'connectors.yaml'), os.path.join(self.output, 'connectors.yaml'), replaceDict) arguments.extend(['--connectivityConfig',os.path.join(self.output, 'connectors.yaml')]) if xclock: arguments.append('-Xclock') self.correlator.start(logfile='correlator.log', arguments=arguments) self.correlator.receive('correlator_input.log', channels=['com.apama.input']) self.correlator.receive('correlator_output.log') self.setApplicationLogFile(self.correlator, 'application.log', 'com.jtech') self.setApplicationLogLevel(self.correlator, 'DEBUG', 'com.jtech') def initialiseApplication(self, correlator): '''Initialise the application. ''' parser=FileListParser(os.path.join(self.project.root, 'build-filelists.xml'), self.project.root, {'${apama.home}':PROJECT.APAMA_HOME}) self.inject(correlator, parser.getFileList('apama.scenarios')) self.inject(correlator, parser.getFileList('apama.adbc')) self.inject(correlator, parser.getFileList('apama.connectivity')) self.inject(correlator, parser.getFileList('utils')) self.inject(correlator, parser.getFileList('configuration')) self.inject(correlator, parser.getFileList('source')) self.inject(correlator, parser.getFileList('strategy')) correlator.send(filenames='adbc.evt',filedir=self.output) self.waitForSignal('correlator_output.log', expr='com.jtech.source.Start', timeout=20) def startADBCAdapter(self, correlator, insert=None): '''Start IAF running the ADBC adapter for sqlite, return process handle. ''' schema = os.path.join(PROJECT.root,'test','utils','scripts','schema.sql') if not insert: insert = os.path.join(PROJECT.root,'test','utils','scripts','insert.sql') else: insert = os.path.join(self.input, insert) self.sqlite(schema) self.sqlite(insert) self.adbcAdapter = IAFHelper(self) database_url = 'jdbc:sqlite:%s' % os.path.join(self.output, 'store.db') replaceDict = {'${basedir}':'%s' % PROJECT.root, '${apama.home}':'%s' % PROJECT.APAMA_HOME, '${correlator.port}':'%d' % correlator.port, '${adbc.database-url}': database_url.replace('\\', '\\\\'), '${adbc.driver}': 'org.sqlite.JDBC', '${adbc.driver-jar}':'sqlite-jdbc-3.7.2.jar', '${adbc.username}':'', '${adbc.password}':''} for include in ['ADBC-static-codecs.xml', 'ADBC-static.xml', 'ADBC-application.xml', 'adbc.evt']: replace(os.path.join(PROJECT.root, 'config', include), os.path.join(self.output, include), replaceDict) return self.adbcAdapter.start(configdir=os.path.join(PROJECT.root, 'config'), configname='adbc.xml', logfile='adbc_adapter.log', replace=replaceDict) def startHTTPServer(self, dir=None): '''Start HTTP server serving files from output directory, setting port as self.httpPort. ''' command = sys.executable displayName = 'http-server' if dir is None: dir=self.output instances = self.getInstanceCount(displayName) dstdout = os.path.join(self.output, 'http-server.out') dstderr = os.path.join(self.output, 'http-server.err') if instances: dstdout = '%s.%d' % (dstdout, instances) if instances: dstderr = '%s.%d' % (dstderr, instances) self.httpPort = allocateTCPPort() self.log.info('Allocating port %s for HTTP server'%self.httpPort) arguments = [] arguments.append(os.path.join(PROJECT.root,'python','com','jtech','httpserver.py')) arguments.append('%s'%dir) arguments.append('%d'%self.httpPort) return self.startProcess(command, arguments, os.environ, self.output, BACKGROUND, 300, dstdout, dstderr, displayName) def startScenarioPrinter(self, correlator, filedir=None): if filedir is None: filedir=os.path.join(PROJECT.root,'test','utils','scripts') self.startJython(script='printer.py', filedir=filedir, scriptArgs=['%d'%correlator.port]) def startScenarioPrinter(self, correlator, dvname='DV_StationAlert', fields=None): if fields is None: fields=['id','ratio','type'] filedir=os.path.join(PROJECT.root,'test','utils','scripts') self.startJython(script='printer.py', filedir=filedir, scriptArgs=['%d'%correlator.port,dvname,','.join(fields)]) def startJython(self, script, filedir=None, scriptArgs=None): command = os.path.join(PROJECT.APAMA_COMMON_JRE, 'bin', 'java') displayName = 'jython' if filedir is None: filedir=self.input # set the default stdout and stderr instances = self.getInstanceCount(displayName) dstdout = "%s/jython.out"%self.output dstderr = "%s/jython.err"%self.output if instances: dstdout = "%s.%d" % (dstdout, instances) if instances: dstderr = "%s.%d" % (dstderr, instances) # setup args args=[] args.extend(['-classpath', self.jython_classpath]) args.append('-Dpython.home=%s' % PROJECT.JYTHON_HOME) args.append('-Dpython.path=%s' % os.path.join(PROJECT.root,'python')) args.append('org.python.util.jython') args.append(os.path.join(self.input, os.path.join(filedir,script))) if scriptArgs is not None: args.extend(scriptArgs) # run the process and return the handle return self.startProcess(command, args, os.environ, self.output, BACKGROUND, 0, dstdout, dstderr, displayName) def setApplicationLogFile(self, correlator, logfile, package): '''Set the correlator application log file. ''' correlator.manage(arguments=['-r', 'setApplicationLogFile %s %s'%(os.path.join(self.output,logfile),package)]) def setApplicationLogLevel(self, correlator, level, package): '''Set the correlator application log level. ''' correlator.manage(arguments=['-r', 'setApplicationLogLevel %s %s'%(level,package)]) def inject(self, correlator, fileList, **xargs): '''Inject a file list. ''' for entry in fileList: filedir,filenames=entry correlator.injectMonitorscript(filenames=filenames, filedir=filedir) def sqlite(self, filename): '''Run sqlite using the input script specified. ''' command = PROJECT.SQLITE3_EXE displayName = 'sqlite3' instances = self.getInstanceCount(displayName) dstdout = os.path.join(self.output, 'sqlite.out') dstderr = os.path.join(self.output, 'sqlite.err') if instances: dstdout = '%s.%d' % (dstdout, instances) if instances: dstderr = '%s.%d' % (dstderr, instances) arguments = [] arguments.append('-echo') arguments.extend(['-init', filename]) arguments.append('store.db') arguments.append('.quit') self.startProcess(command, arguments, os.environ, self.output, FOREGROUND, 300, dstdout, dstderr, displayName) def sendLiteral(self, correlator, literal): with open(os.path.join(self.output,'sendliteral.evt'),'w') as file: file.write(literal) correlator.send(os.path.join(self.output,'sendliteral.evt'))