Exemple #1
0
def test_AddOnes(grpc_channel):
    from Testing_protos import Add_One_pb2_grpc
    from Testing_protos import AddTypes_pb2
    stub = Add_One_pb2_grpc.AdditionStub(grpc_channel)
    responses = stub.AddOnes(AddTypes_pb2.Addend(number=5))
    for i, response in enumerate(responses):
        assert response.number == 6 + i
    assert i == 4
Exemple #2
0
def test_AddOne(grpc_channel, lazy_cleaner):
    yagrc_importer.add_lazy_packages(["Testing_protos"])
    from Testing_protos import Add_One_pb2_grpc
    from Testing_protos import AddTypes_pb2
    yagrc_importer.resolve_lazy_imports(grpc_channel)
    stub = Add_One_pb2_grpc.AdditionStub(grpc_channel)
    response = stub.AddOne(AddTypes_pb2.Addend(number=5))
    assert response.number == 6
Exemple #3
0
def test_AddsOnes(grpc_channel, grpc_importer):
    from Testing_protos import Add_One_pb2_grpc
    from Testing_protos import AddTypes_pb2
    stub = Add_One_pb2_grpc.AdditionStub(grpc_channel)
    responses = stub.AddsOnes(
        (AddTypes_pb2.Addend(number=x) for x in range(5)))
    for i, response in enumerate(responses):
        assert response.number == i + 1
    assert i == 4
Exemple #4
0
def test_StatusQuery(grpc_channel):
    from Testing_protos import Add_One_pb2_grpc
    from Testing_protos import AddTypes_pb2
    stub = Add_One_pb2_grpc.AdditionStub(grpc_channel)
    response = stub.Status(AddTypes_pb2.StatusQuery(state={}))
    assert response.state.states[
        "sum_engine"].state == AddTypes_pb2.ServiceState.READY
    assert AddTypes_pb2.ServiceState.Name(
        response.state.states["difference_engine"].state
    ) == "BUSY_COMPUTING_ONE"
    assert response.state.states["chaos_engine"].state == AddTypes_pb2._UNKNOWN
Exemple #5
0
def main():
    with grpc.insecure_channel("localhost:19001") as channel:
        stub = Add_One_pb2_grpc.AdditionStub(channel)

        response = stub.AddOne(AddTypes_pb2.Addend(number=5))
        print(response)

        responses = stub.AddOnes(AddTypes_pb2.Addend(number=5))
        print(*responses)

        response = stub.AddsOne(
            (AddTypes_pb2.Addend(number=x) for x in range(5)))
        print(response)

        responses = stub.AddsOnes(
            (AddTypes_pb2.Addend(number=x) for x in range(5)))
        print(*responses)

        response = stub.Status(AddTypes_pb2.StatusQuery(count={}))
        print(response)

        response = stub.Status(AddTypes_pb2.StatusQuery(state={}))
        print(response)
Exemple #6
0
def test_resolve_fail(grpc_channel, lazy_cleaner):
    yagrc_importer.add_lazy_packages(["Testing_protos"])
    from Testing_protos import AddTypes_pb2

    try:
        yagrc_importer.resolve_lazy_imports(None)
        assert False
    except AttributeError:
        pass

    # Test failure again to verify first failure did not lose state.
    try:
        yagrc_importer.resolve_lazy_imports(None)
        assert False
    except AttributeError:
        pass

    # Finally, test success case to make sure prior failures did not break
    # things permanently, including the ability to do more lazy imports.
    from Testing_protos import Add_One_pb2_grpc
    yagrc_importer.resolve_lazy_imports(grpc_channel)
    stub = Add_One_pb2_grpc.AdditionStub(grpc_channel)
    response = stub.AddOne(AddTypes_pb2.Addend(number=5))
    assert response.number == 6
Exemple #7
0
def test_CountQuery(grpc_channel):
    from Testing_protos import Add_One_pb2_grpc
    from Testing_protos import AddTypes_pb2
    stub = Add_One_pb2_grpc.AdditionStub(grpc_channel)
    response = stub.Status(AddTypes_pb2.StatusQuery(count={}))
    assert response.count.number > 0
Exemple #8
0
def test_AddsOne(grpc_channel):
    from Testing_protos import Add_One_pb2_grpc
    from Testing_protos import AddTypes_pb2
    stub = Add_One_pb2_grpc.AdditionStub(grpc_channel)
    response = stub.AddsOne((AddTypes_pb2.Addend(number=x) for x in range(5)))
    assert response.number == 0 + 1 + 2 + 3 + 4 + 1
Exemple #9
0
def test_AddOne(grpc_channel):
    from Testing_protos import Add_One_pb2_grpc
    from Testing_protos import AddTypes_pb2
    stub = Add_One_pb2_grpc.AdditionStub(grpc_channel)
    response = stub.AddOne(AddTypes_pb2.Addend(number=5))
    assert response.number == 6