Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamsContainer.datasources #1729

Merged
merged 9 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ansys/dpf/core/streams_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
data_processing_capi,
data_processing_grpcapi,
)
from ansys.dpf.core import errors
from ansys.dpf.core import errors, data_sources


class StreamsContainer:
Expand Down Expand Up @@ -80,6 +80,10 @@ def _server(self, value):
# step3: init environment
self._api.init_streams_environment(self) # creates stub when gRPC

@property
def datasources(self):
return data_sources.DataSources(data_sources=self._api.streams_get_data_sources(self))

def release_handles(self):
"""Release the streams."""
self._api.streams_release_handles(self)
Expand Down
28 changes: 28 additions & 0 deletions tests/test_streams_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,31 @@ def test_create_from_streams_container(server_in_process, simple_bar):
streams_provider = model.metadata.streams_provider
sc = streams_provider.outputs.streams_container()
dpf.core.streams_container.StreamsContainer(streams_container=sc, server=server_in_process)

def test_streams_container_datasources(server_type, simple_bar):
ds = dpf.DataSources(simple_bar)
streams = dpf.operators.metadata.streams_provider(data_sources=ds).eval()
ds2 = streams.datasources
assert ds.result_files[0] == ds2.result_files[0]

def test_retrieve_ip(server_in_process):
start_server = dpf.core.Operator("grpc::stream_provider", server=server_in_process)
in_thread = 1
should_start_server = 3

start_server.connect(2, in_thread)
start_server.connect(3, should_start_server)

streams = start_server.get_output(0, dpf.core.types.streams_container)
ds = streams.datasources

# look for ip
assert len(ds.result_files) == 1
assert ds.result_key == "grpc"

addr = ds.result_files[0]
import re
# can match 999.999.999.999:99999, 0.0.0.0:0
# but not 0.0.0:0, 9999.999.999.999:999, 0.0.0.0
ip_addr_regex = r"([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]{1,5}"
assert re.match(ip_addr_regex, addr) != None
Loading