Skip to content

Commit

Permalink
HelloWorld and parallelHelloWorld documentation and additional test a…
Browse files Browse the repository at this point in the history
…dded
  • Loading branch information
awicenec committed Oct 25, 2021
1 parent b494768 commit 4b40bb7
Show file tree
Hide file tree
Showing 5 changed files with 3,163 additions and 2,601 deletions.
10 changes: 9 additions & 1 deletion daliuge-engine/dlg/apps/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,15 @@ class HelloWorldApp(BarrierAppDROP):
greet = dlg_string_param('greet', 'World')

def run(self):
self.greeting = 'Hello %s' % self.greet
ins = self.inputs
# if no inputs use the parameter else use the input
if len(ins) == 0:
self.greeting = 'Hello %s' % self.greet
elif len(ins) != 1:
raise Exception(
'Only one input expected for %r' % self)
else: # the input is expected to be a vector. We'll use the first element
self.greeting = 'Hello %s' % str(pickle.loads(droputils.allDropContents(ins[0]))[0])

outs = self.outputs
if len(outs) < 1:
Expand Down
9 changes: 5 additions & 4 deletions daliuge-engine/dlg/droputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DROPWaiterCtx(object):
def __init__(self, test, drops, timeout=1, expected_states=[]):
self._drops = listify(drops)
self._expected_states = expected_states or (DROPStates.COMPLETED, DROPStates.ERROR)
self._test = test
self._test = test if hasattr(test, 'assertTrue') else None
self._timeout = timeout
self._evts = []
def __enter__(self):
Expand All @@ -91,10 +91,11 @@ def __enter__(self):
def __exit__(self, typ, value, tb):
if typ is not None:
traceback.print_tb(tb)
self._test.fail('%r' % (value,))
if self._test: self._test.fail('%r' % (value,))
to = self._timeout
for evt in self._evts:
self._test.assertTrue(evt.wait(to), "Waiting for DROP failed with timeout %d" % to)
if self._test:
for evt in self._evts:
self._test.assertTrue(evt.wait(to), "Waiting for DROP failed with timeout %d" % to)


def allDropContents(drop, bufsize=4096):
Expand Down
24 changes: 24 additions & 0 deletions daliuge-engine/test/apps/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ def test_helloworldapp(self):
h.execute()
self.assertEqual(h.greeting.encode('utf8'), droputils.allDropContents(b))

def test_parallelHelloWorld(self):
m0 = InMemoryDROP('m0','m0')
s = GenericScatterApp('s', 's')
greets = ['World', 'Solar system', 'Galaxy', 'Universe']
m0.write(pickle.dumps(greets))
s.addInput(m0)
m = []
h = []
f = []
for i in range(1, len(greets)+1, 1):
m.append(InMemoryDROP('m%d' % i, 'm%d' % i))
h.append(HelloWorldApp('h%d' % i, 'h%d' % i))
f.append(FileDROP('f%d' % i, 'f%d' % i))
s.addOutput(m[-1])
h[-1].addInput(m[-1])
h[-1].addOutput(f[-1])
ad = [m0, s]
ad.extend(m)
ad.extend(h)
ad.extend(f)
self._test_graph_runs(ad, m0, f)
for i in range(len(f)):
self.assertEqual(('Hello %s' % greets[i]).encode('utf8'), droputils.allDropContents(f[i]))

def test_ngasio(self):
nd_in = NgasDROP('HelloWorld.txt', 'HelloWorld.txt')
nd_in.ngasSrv = 'ngas.ddns.net'
Expand Down
Loading

0 comments on commit 4b40bb7

Please sign in to comment.