示例#1
0
    def setUp(self):
        Tester.setup_streaming_analytics(self, force_remote_build=True)
        self.sc = StreamingAnalyticsConnection()
        self.test_config[ConfigParams.STREAMS_CONNECTION] = self.sc

        self.is_v2 = False
        if _IAMConstants.V2_REST_URL in self.sc.credentials:
            self.is_v2 = True
示例#2
0
    def setUp(self):
        Tester.setup_streaming_analytics(self, force_remote_build=True)
        self.sc = StreamingAnalyticsConnection()
        self.test_config[ConfigParams.STREAMS_CONNECTION]=self.sc

        self.is_v2 = False
        if _IAMConstants.V2_REST_URL in self.sc.session.auth._credentials:
            self.is_v2 = True
    def test_credentials(self):
        """ Test a connection using a credentials."""
        creds = {}
        for s in self.vcap_services['streaming-analytics']:
            if s['name'] == self.service_name:
               creds = s['credentials']

        sasc = StreamingAnalyticsConnection.of_definition(creds)
        instances = sasc.get_instances()
        self.assertEqual(1, len(instances))
示例#4
0
    def test_credentials(self):
        """ Test a connection using a credentials."""
        creds = {}
        for s in self.vcap_services['streaming-analytics']:
            if s['name'] == self.service_name:
                creds = s['credentials']

        sasc = StreamingAnalyticsConnection.of_definition(creds)
        instances = sasc.get_instances()
        self.assertEqual(1, len(instances))
    def test_service_def(self):
        """ Test a connection using a service definition."""
        creds = {}
        for s in self.vcap_services['streaming-analytics']:
            if s['name'] == self.service_name:
               creds = s['credentials']

        service = {'type':'streaming-analytics', 'name':self.service_name}
        service['credentials'] = creds
        sasc = StreamingAnalyticsConnection.of_definition(service)
        instances = sasc.get_instances()
        self.assertEqual(1, len(instances))
示例#6
0
 def _streaming_analytics_test(self, ctxtype, config):
     sjr = stc.submit(ctxtype, self.topology, config)
     self.submission_result = sjr
     self.streams_connection = config.get(ConfigParams.STREAMS_CONNECTION)
     if self.streams_connection is None:
         vcap_services = config.get(ConfigParams.VCAP_SERVICES)
         service_name = config.get(ConfigParams.SERVICE_NAME)
         self.streams_connection = StreamingAnalyticsConnection(vcap_services, service_name)
     if sjr['return_code'] != 0:
         _logger.error("Failed to submit job to Streaming Analytics instance")
         return False
     return self._distributed_wait_for_result(ctxtype, config)
示例#7
0
    def test_service_def(self):
        """ Test a connection using a service definition."""
        creds = {}
        for s in self.vcap_services['streaming-analytics']:
            if s['name'] == self.service_name:
                creds = s['credentials']

        service = {'type': 'streaming-analytics', 'name': self.service_name}
        service['credentials'] = creds
        sasc = StreamingAnalyticsConnection.of_definition(service)
        instances = sasc.get_instances()
        self.assertEqual(1, len(instances))
示例#8
0
 def _get_sas_conn(config):
     vcap_services = config.get(ConfigParams.VCAP_SERVICES)
     service_name = config.get(ConfigParams.SERVICE_NAME)
     return StreamingAnalyticsConnection(vcap_services, service_name)
示例#9
0
class TestSasRestFeatures(TestDistributedRestFeatures):

    def setUp(self):
        Tester.setup_streaming_analytics(self, force_remote_build=True)
        self.sc = StreamingAnalyticsConnection()
        self.test_config[ConfigParams.STREAMS_CONNECTION]=self.sc

        self.is_v2 = False
        if _IAMConstants.V2_REST_URL in self.sc.session.auth._credentials:
            self.is_v2 = True

    # The underscore in front of this test causes it to be skipped by default
    # This is to prevent the starting and stopping of the instance from 
    # interfering with other tests.
    # The test can be run manually: 
    # python -m unittest test_rest_bluemix.TestRestFeaturesBluemix._test_service_stop_start
    def _test_service_stop_start(self):
        self.logger.debug("Beginning test: test_service_stop_start")
        sas = self.sc.get_streaming_analytics()

        status = sas.get_instance_status()
        self.valid_response(status)        
        self.assertEqual('running', status['status'])

        res = sas.stop_instance()
        self.valid_response(res)
        status = sas.get_instance_status()
        self.assertEqual('stopped', status['status'])
        
        res = sas.start_instance()
        self.valid_response(res)
        status = sas.get_instance_status()
        self.assertEqual('running', status['status'])
        
    def valid_response(self, res):
        for key in instance_response_keys:
            self.assertTrue(key in res)

    # The underscore in front of this test causes it to be skipped by default
    # This is because the test must run on an os version that matches
    # the service and has a local Streams Install.
    # python3 -m unittest test_rest_bluemix.TestRestFeaturesBluemix._test_submit_sab
    def _test_submit_sab(self):
        sab_name = 'Sab_'+uuid.uuid4().hex
        topo = topology.Topology(sab_name, namespace='mynamespace')
        s = topo.source([1,2])
        es = s.for_each(lambda x : None)
        bb = streamsx.topology.context.submit('BUNDLE', topo, {})
        self.assertIn('bundlePath', bb)
        self.assertIn('jobConfigPath', bb)

        sas = self.sc.get_streaming_analytics()

        sr = sas.submit_job(bundle=bb['bundlePath'])
        job_id = sr.get('id', sr.get('jobId'))
        self.assertIsNotNone(job_id)
        self.assertIn('name', sr)
        self.assertIn('application', sr)
        self.assertEqual('mynamespace::' + sab_name, sr['application'])
        cr = sas.cancel_job(job_id=job_id)

        jn = 'SABTEST:' + uuid.uuid4().hex
        jc = streamsx.topology.context.JobConfig(job_name=jn)
        sr = sas.submit_job(bundle=bb['bundlePath'], job_config=jc)
        job_id = sr.get('id', sr.get('jobId'))
        self.assertIsNotNone(job_id)
        self.assertIn('application', sr)
        self.assertEqual('mynamespace::'+sab_name, sr['application'])
        self.assertIn('name', sr)
        self.assertEqual(jn, sr['name'])
        cr = sas.cancel_job(job_id=job_id)
       
        os.remove(bb['bundlePath'])
        os.remove(bb['jobConfigPath'])
示例#10
0
class TestSasRestFeatures(TestDistributedRestFeatures):
    def setUp(self):
        Tester.setup_streaming_analytics(self, force_remote_build=True)
        self.sc = StreamingAnalyticsConnection()
        self.test_config[ConfigParams.STREAMS_CONNECTION] = self.sc

        self.is_v2 = False
        if _IAMConstants.V2_REST_URL in self.sc.credentials:
            self.is_v2 = True

    # The underscore in front of this test causes it to be skipped by default
    # This is to prevent the starting and stopping of the instance from
    # interfering with other tests.
    # The test can be run manually:
    # python -m unittest test_rest_bluemix.TestRestFeaturesBluemix._test_service_stop_start
    def _test_service_stop_start(self):
        self.logger.debug("Beginning test: test_service_stop_start")
        sas = self.sc.get_streaming_analytics()

        status = sas.get_instance_status()
        self.valid_response(status)
        self.assertEqual('running', status['status'])

        res = sas.stop_instance()
        self.valid_response(res)
        status = sas.get_instance_status()
        self.assertEqual('stopped', status['status'])

        res = sas.start_instance()
        self.valid_response(res)
        status = sas.get_instance_status()
        self.assertEqual('running', status['status'])

    def valid_response(self, res):
        for key in instance_response_keys:
            self.assertTrue(key in res)

    # The underscore in front of this test causes it to be skipped by default
    # This is because the test must run on an os version that matches
    # the service and has a local Streams Install.
    # python3 -m unittest test_rest_bluemix.TestRestFeaturesBluemix._test_submit_sab
    def _test_submit_sab(self):
        sab_name = 'Sab_' + uuid.uuid4().hex
        topo = topology.Topology(sab_name, namespace='mynamespace')
        s = topo.source([1, 2])
        es = s.for_each(lambda x: None)
        bb = streamsx.topology.context.submit('BUNDLE', topo, {})
        self.assertIn('bundlePath', bb)
        self.assertIn('jobConfigPath', bb)

        sas = self.sc.get_streaming_analytics()

        sr = sas.submit_job(bundle=bb['bundlePath'])
        job_id = sr.get('id', sr.get('jobId'))
        self.assertIsNotNone(job_id)
        self.assertIn('name', sr)
        self.assertIn('application', sr)
        self.assertEqual('mynamespace::' + sab_name, sr['application'])
        cr = sas.cancel_job(job_id=job_id)

        jn = 'SABTEST:' + uuid.uuid4().hex
        jc = streamsx.topology.context.JobConfig(job_name=jn)
        sr = sas.submit_job(bundle=bb['bundlePath'], job_config=jc)
        job_id = sr.get('id', sr.get('jobId'))
        self.assertIsNotNone(job_id)
        self.assertIn('application', sr)
        self.assertEqual('mynamespace::' + sab_name, sr['application'])
        self.assertIn('name', sr)
        self.assertEqual(jn, sr['name'])
        cr = sas.cancel_job(job_id=job_id)

        os.remove(bb['bundlePath'])
        os.remove(bb['jobConfigPath'])
 def setUp(self):
     Tester.setup_streaming_analytics(self, force_remote_build=True)
     self.sc = StreamingAnalyticsConnection()
     self.test_config[ConfigParams.STREAMS_CONNECTION]=self.sc