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', Xclock=True, 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']) # Inject timestamps correlator.send(filenames=['timestamps.evt']) # 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 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=PROJECT.TEST_SUBJECT_DIR + '/initialization.yaml') receiveProcess = correlator.receive(filename='receive.evt', channels=['output'], logChannels=True) correlator.applicationEventLogging(enable=True) # send in the events contained in the test.evt file (directory defaults # to the testcase input) correlator.send(filenames=['test.evt']) # wait for all events to be processed correlator.flush() # wait until the receiver writes the expected events to disk self.waitForSignal('receive.evt', expr="Msg", condition="==1")
def startAnalyticsBuilderCorrelator(self, blockSourceDir=None, Xclock=True, numWorkers=4, **kwargs): """ Start a correlator with the EPL for Analytics Builder loaded. :param blockSourceDir: A location of blocks to include. :param Xclock: Externally clock correlator (on by default). :param numWorkers: Number of workers for Analytics Builder runtime (4 by default). """ # Build and extract the block extension: if blockSourceDir == None: blockSourceDir = self.input blockOutput = self.output + '/block-output.zip' self.runAnalyticsBuilderScript([ 'build', 'extension', '--input', blockSourceDir, '--output', blockOutput ]) with zipfile.ZipFile(blockOutput, 'r') as zf: blockOutput = Path(self.output + '/block-output/') os.mkdir(blockOutput) zf.extractall(blockOutput) # Start the correlator: corr = CorrelatorHelper(self) arguments = kwargs.get('arguments', []) arguments.append(f'-DanalyticsBuilder.numWorkerThreads={numWorkers}') 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') # inject block files: corr.injectEPL(sorted(list(blockOutput.rglob('*.mon')))) corr.send(sorted(list(blockOutput.rglob('*.evt')))) # now done corr.sendEventStrings( 'com.apama.connectivity.ApplicationInitialized()') corr.flush(10) self.analyticsBuilderCorrelator = corr corr.receive('output.evt', channels=['TestOutput']) corr.injectTestEventLogger(channels=['TestOutput']) return corr