<commit_before>#!/bin/sh

if [ "$#" -ne 2 ]; then
  echo "remote_pingpong_test.sh: distributed and decentralized workflow execution test"
  echo "     using the HyperFlow REST API."
  echo
  echo "Usage:"
  echo "- run the 1st HyperFlow server:    node app.js    ( -> runs on port1)"
  echo "- run the 2nd HyperFlow server:    node app.js    ( -> runs on port2)"
  echo "- then run this script:            test/remote_pingpong_test.sh port1 port2"
  exit
fi

# URIs:
# {appfactory1} http://localhost:{port1}/apps 
# {appfactory2} http://localhost:{port2}/apps 
# {app1}        http://localhost:{port1}/apps/{appId1}
# {app2}        http://localhost:{port2}/apps/{appId2}

# REST-based protocol is as follows (<...> denotes the content of message body):
# 1) POST {appfactory1} <Wf_RemotePing.json>   ==> create Pinger instance, returns URI {app1}.
# 2) POST {appfactory2} <Wf_RemotePong.json>   ==> create Ponger instance, returns URI {app2}.
# 3) PUT {app1}/sigs/Ping/remotesinks <{app2}>  ==> connects signal "Ping" from app1 to app2.
# 4) PUT {app2}/sigs/Pong/remotesinks <{app1}>  ==> connects signal "Pong" from app2 to app1.
# 5) POST {app1} <signal data>   ==> sends the initial signal to Pinger to start the Ping-Pong.

appfact1="http://localhost:$1/apps"
appfact2="http://localhost:$2/apps"
echo $appfact1
echo $appfact2

# 1)
app1=`curl -v -X POST -d @workflows/Wf_RemotePing.json $appfact1 --header "Content-Type:application/json" 2>&1 | grep Location | cut -f 3 -d' '`
app1uri="http://localhost:$1"$app1

# 2)
app2=`curl -v -X POST -d @workflows/Wf_RemotePong.json $appfact2 --header "Content-Type:application/json" 2>&1 | grep Location | cut -f 3 -d' '`
app2uri="http://localhost:$2"$app2

# 3)
curl -v -X PUT -d "[{ \"uri\": \"$app2uri\" }]" $app1uri/sigs/Pong/remotesinks --header "Content-Type:application/json"

# 4)
curl -v -X PUT -d "[{ \"uri\": \"$app1uri\" }]" $app2uri/sigs/Ping/remotesinks --header "Content-Type:application/json"

# 5)
curl -X POST -d '{ "name": "Ping", "data": [0] }' $app1uri --header "Content-Type:application/json"
<commit_msg>Corrections in comments<commit_after>#!/bin/sh

if [ "$#" -ne 2 ]; then
  echo "remote_pingpong_test.sh: distributed and decentralized workflow execution test"
  echo "     using the HyperFlow REST API."
  echo
  echo "Usage:"
  echo "- run the 1st HyperFlow server:    node app.js    ( -> runs on port1)"
  echo "- run the 2nd HyperFlow server:    node app.js    ( -> runs on port2)"
  echo "- then run this script:            test/remote_pingpong_test.sh port1 port2"
  exit
fi

# URIs:
# {appfactory1} http://localhost:{port1}/apps 
# {appfactory2} http://localhost:{port2}/apps 
# {app1}        http://localhost:{port1}/apps/{appId1}
# {app2}        http://localhost:{port2}/apps/{appId2}

# REST-based protocol is as follows ('<...>' denotes the content of a message body):
# 1) POST {appfactory1} <Wf_RemotePing.json>   ==> create Pinger instance, returns URI {app1}.
# 2) POST {appfactory2} <Wf_RemotePong.json>   ==> create Ponger instance, returns URI {app2}.
# 3) PUT {app1}/sigs/Pong/remotesinks <{app2}>  ==> connects signal "Pong" from app1 to app2.
# 4) PUT {app2}/sigs/Ping/remotesinks <{app1}>  ==> connects signal "Ping" from app2 to app1.
# 5) POST {app1} <signal data>   ==> sends the initial signal to Pinger to start the Ping-Pong.

appfact1="http://localhost:$1/apps"
appfact2="http://localhost:$2/apps"
echo $appfact1
echo $appfact2

# 1)
app1=`curl -v -X POST -d @workflows/Wf_RemotePing.json $appfact1 --header "Content-Type:application/json" 2>&1 | grep Location | cut -f 3 -d' '`
app1uri="http://localhost:$1"$app1

# 2)
app2=`curl -v -X POST -d @workflows/Wf_RemotePong.json $appfact2 --header "Content-Type:application/json" 2>&1 | grep Location | cut -f 3 -d' '`
app2uri="http://localhost:$2"$app2

# 3)
curl -v -X PUT -d "[{ \"uri\": \"$app2uri\" }]" $app1uri/sigs/Pong/remotesinks --header "Content-Type:application/json"

# 4)
curl -v -X PUT -d "[{ \"uri\": \"$app1uri\" }]" $app2uri/sigs/Ping/remotesinks --header "Content-Type:application/json"

# 5)
curl -X POST -d '{ "name": "Ping", "data": [0] }' $app1uri --header "Content-Type:application/json"

{'fraction_non_alphanumeric': 0.1750841750841751, 'fraction_numerical': 0.03270803270803271, 'mean_word_length': 3.7047511312217196, 'pattern_counts': {'":': 8, '<': 15, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4598971', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1537, 'n_words': 417}