예제 #1
0
    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)
예제 #2
0
 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()
 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()
예제 #4
0
파일: run.py 프로젝트: sasmitaA/ApamaEPLApp
    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()
예제 #5
0
	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)
		
		# Set the log level to DEBUG so that we can see when the listeners are killed
		correlator.setApplicationLogLevel(verbosity='DEBUG')
				
		# 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'])
예제 #6
0
    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")
예제 #7
0
	def execute(self):
		corr = CorrelatorHelper(self, name='correlator')
		corr.start(logfile='correlator.log')
		corr.injectEPL(filenames=['ManagementImpl.mon', 'Management.mon'], filedir=self.project.APAMA_HOME+'/monitors')
		corr.injectEPL(filenames=['L10N.mon'], filedir=self.input+'/../../../')
		corr.injectEPL(filenames=['Sample.mon'])
		corr.flush()
		corr.shutdown()
예제 #8
0
	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')
예제 #9
0
	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
예제 #10
0
	def execute(self):
		for lang in ['en_GB.utf8', 'es_MX.utf8']:
			corr = CorrelatorHelper(self, name=f'correlator_{lang}')
			corr.start(logfile=f'correlator_{lang}.log', environ={'LANG':lang}, arguments=[f'-DSAMPLE_TRANSLATIONS={self.input}/../../../sample'])
			corr.injectEPL(filenames=['ManagementImpl.mon', 'Management.mon'], filedir=self.project.APAMA_HOME+'/monitors')
			corr.injectEPL(filenames=['L10N.mon'], filedir=self.input+'/../../../')
			corr.injectEPL(filenames=['Sample.mon'])
			corr.flush()
			corr.shutdown()
예제 #11
0
	def execute(self):
		for allocator in ['platform', 'jemalloc']:
			corr = CorrelatorHelper(self, name=f'correlator_{allocator}')
			corr.start(logfile=f'correlator_{allocator}.log', environ={'AP_ALLOCATOR':allocator, 'AP_TRACKMEMORY':'true'})
			corr.injectEPL(filenames=['ManagementImpl.mon', 'Management.mon', 'TimeFormatEvents.mon'], filedir=self.project.APAMA_HOME+'/monitors')
			corr.injectEPL(filenames=['JEMallocPlugin.mon', 'JEMallocStatus.mon'], filedir=self.input+'/../../../')
			corr.flush()
			corr.manage(['-r', 'malloc_stats'])
			self.wait(12)
			corr.shutdown()
예제 #12
0
 def execute(self):
     corr = CorrelatorHelper(self, name='correlator')
     corr.start(logfile='correlator.log')
     corr.injectEPL('../../../CircularBuffer.mon')
     tests = os.listdir(self.input)
     tests.sort()
     for test in tests:
         if test.endswith('.mon'):
             corr.injectEPL(test)
             corr.flush()
     corr.shutdown()
예제 #13
0
    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('../../../src/Assert.mon')

        corr.injectEPL('Demo.mon')
        corr.flush()
        corr.shutdown()
예제 #14
0
    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()
예제 #15
0
    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()
예제 #16
0
	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)
예제 #17
0
    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")
예제 #18
0
	def execute(self):
		correlator = CorrelatorHelper(self, name='testcorrelator')
		correlator.start(logfile='testcorrelator.log', config=self.input+"/config.yaml", arguments=['-DCOMMAND_LINE=commandValue'])
		correlator.injectEPL(filenames=['ConfigurationPlugin.mon'], filedir=PROJECT.APAMA_WORK+"/monitors")
		correlator.injectEPL(filenames=['test.mon'])
		correlator.flush() 
	def execute(self):
		correlator = CorrelatorHelper(self)
		correlator.start(logfile='correlator.log', arguments=['--config', self.input+'/test.yaml'])
		correlator.flush()
예제 #20
0
    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