Exemplo n.º 1
0
def test_load_algorithm_callbacks():
    algorunner = Algorunner()
    algorunner.loadAlgorithmCallbacks(startCallback, options=config)
    result1 = algorunner._originalAlgorithm['start']({'input': mockdata.initData}, None)
    result2 = startCallback({'input': mockdata.initData})
    assert result1 == result2
    algorunner.close()
Exemplo n.º 2
0
def test_connect_to_worker():
    config.discovery.update({"port": "9021"})
    algorunner = Algorunner()
    algorunner.loadAlgorithmCallbacks(startCallback2, options=config)
    algorunner.connectToWorker(config)
    time.sleep(2)
    assert algorunner._connected == True
    assert algorunner._input == mockdata.initData
    algorunner.close()
Exemplo n.º 3
0
def test_failed_load_algorithm():
    alg = Algorithm()
    alg.algorithm = {
        "path": "no_such_path",
        "entryPoint": "main.py"
    }
    algorunner = Algorunner()
    algorunner.loadAlgorithm(alg)
    assert "No module named" in algorunner._loadAlgorithmError
    assert "no_such_path" in algorunner._loadAlgorithmError
    algorunner.close()
def test_load_algorithm_callbacks(mocker):
    interval = 500
    config.discovery["servingReportInterval"] = interval
    config.discovery["enable"] = True
    algorunner = Algorunner()
    algorunner._job = Job({"kind": "batch"})
    spy = mocker.spy(algorunner, '_reportServingStatus')
    algorunner._initDataServer(config)
    sleep(0.8)
    assert spy.call_count == 2
    algorunner.close()
Exemplo n.º 5
0
def test_load_algorithm_streaming_then_batch():
    algorunner = Algorunner()
    algorunner.loadAlgorithmCallbacks(startCallback, options=config)
    algorunner.streamingManager = StreamingManager()
    algorunner._hkubeApi = HKubeApi(None, algorunner, None, None,algorunner.streamingManager)
    algorunner._init(mockdata.streamingInitData)
    thrd = Thread(target=algorunner._originalAlgorithm['start'], args=[{'input': mockdata.streamingInitData}, algorunner._hkubeApi])
    thrd.start()
    algorunner._stopAlgorithm(mockdata.initData)
    result1 = algorunner._originalAlgorithm['start']({'input': mockdata.initData}, algorunner._hkubeApi)
    result2 = startCallback({'input': mockdata.initData})
    assert result1 == result2
    algorunner.close()
Exemplo n.º 6
0
def test_callback():
    sm = StorageManager(config.storage)
    algorunner = Algorunner()

    algorunner.loadAlgorithmCallbacks(start, options=config)
    algorunner.connectToWorker(config)
    origGet = algorunner._dataAdapter.tryGetDataFromPeerOrStorage
    def mockStorageGet(response):
        return storageMock.get(response.get('storageInfo').get('path'))
    algorunner._dataAdapter.tryGetDataFromPeerOrStorage = mockStorageGet
    time.sleep(3)
    (header, payload) = sm.storage.get({"path": "local-hkube/jobId/taskId"})
    algorunner._dataAdapter.tryGetDataFromPeerOrStorage = origGet
    decoded = encoding.decode(header=header, value=payload)
    assert decoded[0][0] == inp1
    assert decoded[1] == outp2
    time.sleep(2)
    Tracer.instance.close()
    algorunner.close()