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

Rework testing substantially (and several bugfixes along the way) #118

Merged
merged 9 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ ile:
camel:
gmake -C camel

test:
test: install
gmake -C test

testonly:
gmake -C test runtests

all: ile camel

install:
Expand Down
2 changes: 1 addition & 1 deletion camel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BUILDVERSION:="Development build \(built with Make\)"

JAVA_SRCS := $(shell find src -type f)
target/manzan.jar: ${JAVA_SRCS} /QOpenSys/pkgs/bin/mvn
JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit /QOpenSys/pkgs/bin/mvn -Djava.net.preferIPv4Stack=true "-Dmanzan.version=${BUILDVERSION}" package
JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit /QOpenSys/pkgs/bin/mvn -Djava.net.preferIPv4Stack=true -Dmanzan.version=${BUILDVERSION} package
cp target/manzan-*-with-dependencies.jar target/manzan.jar

mkdirs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void strwch()
public boolean isRunning()
throws AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException,
PropertyVetoException, ObjectDoesNotExistException {
AS400 as400 = IBMiDotEnv.getNewSystemConnection(true);
AS400 as400 = new AS400("localhost","*CURRENT","*CURRENT");//IBMiDotEnv.getNewSystemConnection(true);
ProgramCall pc = new ProgramCall(as400);

final ProgramCall program = new ProgramCall(as400);
Expand Down Expand Up @@ -106,7 +106,7 @@ public boolean isRunning()

private static void runCmd(final String _command)
throws AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException {
AS400 as400 = IBMiDotEnv.getNewSystemConnection(true);
AS400 as400 = new AS400("localhost","*CURRENT","*CURRENT");// IBMiDotEnv.getNewSystemConnection(true);
CommandCall cmd = new CommandCall(as400, _command);
boolean isSuccess = cmd.run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.github.theprez.jcmdutils.StringUtils;
import com.github.theprez.manzan.routes.ManzanRoute;
import com.github.theprez.manzan.routes.dest.DirDestination;
import com.github.theprez.manzan.routes.dest.EmailDestination;
import com.github.theprez.manzan.routes.dest.FileDestination;
import com.github.theprez.manzan.routes.dest.FluentDDestination;
Expand Down Expand Up @@ -69,6 +70,10 @@ public synchronized Map<String, ManzanRoute> getRoutes(CamelContext context) {
final String file = getRequiredString(name, "file");
ret.put(name, new FileDestination(name, file, format, getUriAndHeaderParameters(name, sectionObj, "file")));
break;
case "dir":
final String dir = getRequiredString(name, "dir");
ret.put(name, new DirDestination(name, dir, format, getUriAndHeaderParameters(name, sectionObj, "dir")));
break;
case "sentry":
final String dsn = getRequiredString(name, "dsn");
ret.put(name, new SentryDestination(name, dsn));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void configure() {
}
})
.setBody(simple("${body}\n"))
.wireTap("stream:out")
.process(exchange -> {customPostProcess(exchange);})
.to(getTargetUri());
}
Expand All @@ -61,14 +62,17 @@ private String getTargetUri() {
for (final Entry<String, String> entry : m_uriParams.entrySet()) {
ret += entry.getKey();
ret += "=";
try {
ret += URLEncoder.encode(entry.getValue(), "UTF-8");
} catch (final UnsupportedEncodingException e) {
ret += URLEncoder.encode(entry.getValue());
}
ret += entry.getValue();
//TODO: what's right here? with "file://" targets Camel wants real paths
// try {
// ret += URLEncoder.encode(entry.getValue(), "UTF-8");
// } catch (final UnsupportedEncodingException e) {
// ret += URLEncoder.encode(entry.getValue());
// }
ret += "&";
}
ret = ret.replaceFirst("&$", "");
System.out.println("target URI: "+ret);
return ret;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.theprez.manzan.routes.dest;

import java.util.Map;

import org.apache.camel.Exchange;

import com.github.theprez.manzan.routes.ManzanGenericCamelRoute;

public class DirDestination extends ManzanGenericCamelRoute {
public DirDestination(final String _name, final String _file, final String _format, final Map<String, String> _uriParams) {
super(_name, "file", _file, _format, _uriParams, null);
}

@Override
protected void customPostProcess(Exchange exchange) {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.theprez.manzan.routes.dest;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.camel.Exchange;
Expand All @@ -8,7 +9,13 @@

public class FileDestination extends ManzanGenericCamelRoute {
public FileDestination(final String _name, final String _file, final String _format, final Map<String, String> _uriParams) {
super(_name, "file", _file, _format, _uriParams, null);
super(_name, "stream", "file", _format, addToMap(_uriParams, "fileName", _file), null);
}

private static Map<String, String> addToMap(Map<String, String> _uriParams, String _key, String _val) {
Map<String, String> ret = null == _uriParams ? new LinkedHashMap<String,String>(): _uriParams;
ret.put(_key, _val);
return ret;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public WatchMsgEvent(final String _name, final String _session_id, final String
//@formatter:off
@Override
public void configure() {
from("timer://foo?synchronous=false&period=" + m_interval)
from("timer://foo?synchronous=true&period=" + m_interval)
.routeId("manzan_msg:"+m_name)
.setHeader(EVENT_TYPE, constant(ManzanEventType.WATCH_MSG))
.setBody(constant("SeLeCt * fRoM " + m_schema + ".mAnZaNmSg wHeRe SESSION_ID = '"+m_sessionId+"' limit " + m_numToProcess ))
Expand Down
2 changes: 1 addition & 1 deletion config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ app.ini: app.ini.tpl
cat $< | /QOpenSys/usr/bin/sed 's|library=.*|library=${BUILDLIB}|g' > $@


copyfiles: app.ini data.ini dests.ini
copyfiles: app.ini $(CURDIR)/data.ini dests.ini
install -m 555 -o qsys $^ ${INSTALL_ROOT}/QOpenSys/etc/manzan

install: mkdirs copyfiles
Expand Down
18 changes: 13 additions & 5 deletions ile/src/pub_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <qp0ztrc.h>
#include <qsnddtaq.h>
#include <qtqiconv.h>
#include <bcd.h>

int to_utf8(char *out, size_t out_len, const char *in)
{
Expand Down Expand Up @@ -99,17 +100,24 @@ int json_publish(const char *_session_id, std::string &_json)
DEBUG("Publishing JSON\n");
DEBUG("%s\n", _json.c_str());

char dtaq_key[11];
__attribute__((aligned(16))) char dtaq_key[11];
memset(dtaq_key, ' ', 11);
memcpy(dtaq_key, _session_id, MIN(11, strlen(_session_id)));

_DecimalT<5,0> len2 = __D("0");
len2 += strlen(utf8);
_DecimalT<3,0> keyLen = __D("10.0");

DEBUG("About to call QSNDDTAQ\n");
QSNDDTAQ("MANZANDTAQ",
"*CURLIB ", // TODO: How to properly resolve the library here?
strlen(utf8),
"MANZAN ", // TODO: How to properly resolve the library here?
len2,
utf8,
(_Decimal(3,0))10,
dtaq_key);
keyLen,
&dtaq_key);
DEBUG("About to free up stuff\n");
free(utf8);
DEBUG("Done publishing JSON\n");
return 0;
}

Expand Down
30 changes: 19 additions & 11 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@
ile:
gmake -C ../ile

testing: /qsys.lib/${BUILDLIB}.lib/MANZANQ.msgq watch_start watch_testq watch_end

sndmsg.class: sndmsg.java
javac -cp /QIBM/ProdData/OS400/jt400/lib/jt400.jar sndmsg.java
TESTS:=$(shell find * -type d)
TESTLIB:=MZNTEST

# run before every test case
pretest:
echo "Doing pre-test setup"
system "crtlib ${TESTLIB}" || system "clrlib ${TESTLIB}"

# Run after every test case
posttest:
echo "Doing post-test cleanup"
system -kKv "ENDWCH SSNID(TESTING)" || echo "watch not ended"
system "clrlib ${TESTLIB}"

watch_testq: ./tester/sndmsg.class
java -cp ./tester:/QIBM/ProdData/OS400/jt400/lib/jt400.jar sndmsg
runtests:
echo "Running tests"
exec runTests.sh

testing: /qsys.lib/${BUILDLIB}.lib/MANZANQ.msgq watch_start watch_testq watch_end

watch_start:
# Listens to chosen message queue for all messages
# then calls the handler program
# Check /tmp/manzan_debug.txt for logs
system -kKv "STRWCH SSNID(TESTING) WCHPGM(${BUILDLIB}/HANDLER) CALLWCHPGM(*STRWCH) WCHMSG((*ALL)) WCHMSGQ((${BUILDLIB}/MANZANQ))"

watch_end:
system -kKv "ENDWCH SSNID(TESTING)"
# select rtrim(HANDLED_TIMESTAMP) as TS, rtrim(SESSION_ID) as SESSION, rtrim(MESSAGE_ID) as MSG_ID from ${BUILDLIB}.manzanmsg where SESSION_ID = 'TESTING '

all: ile testing
all: ile runtests
29 changes: 29 additions & 0 deletions test/msg/snd2q/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
TESTLIB:=MZNTEST

/qsys.lib/${TESTLIB}.lib/msgs.msgq:
system "CRTMSGQ ${TESTLIB}/MSGS"


sndmsg.class: sndmsg.java
/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit/bin/javac -cp /QIBM/ProdData/OS400/jt400/lib/jt400.jar sndmsg.java

setup: /qsys.lib/${TESTLIB}.lib/msgs.msgq sndmsg.class
rm -f $(CURDIR)/test.out
touch $(CURDIR)/test.out
echo "strwch=WCHMSG((*ALL)) WCHMSGQ((${TESTLIB}/MSGS))" >> data.ini
echo "file=$(CURDIR)/test.out" >> dests.ini
# echo "[install]" > app.ini
# echo "library=${TESTLIB}" >> app.ini

cleanup:
rm sndmsg.class
rm -f $(CURDIR)/test.out

run:
/opt/manzan/bin/manzan --configdir=$(CURDIR) &
sleep 12
/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit/bin/java -cp $(CURDIR):/QIBM/ProdData/OS400/jt400/lib/jt400.jar sndmsg ${TESTLIB} msgs
sleep 5

checkresult:
grep -i CAE0023 $(CURDIR)/test.out
5 changes: 5 additions & 0 deletions test/msg/snd2q/data.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[watchout]
type=watch
id=TESTING
destinations=stdout,myfile
format=$MESSAGE_ID$ (severity $SEVERITY$): $MESSAGE$
6 changes: 6 additions & 0 deletions test/msg/snd2q/dests.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[stdout]
type=stdout

[myfile]
type=file
21 changes: 12 additions & 9 deletions test/sndmsg.java → test/msg/snd2q/sndmsg.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import com.ibm.as400.access.*;
public class sndmsg
{

public static void main(String[] args) throws Exception{
AS400 as400 = new AS400("localhost", "*CURRENT", "*CURRENT");
MessageQueue mq = new MessageQueue(as400, "/qsys.lib/jesseg.lib/manzanq.msgq");
mq.sendInformational("CAE0023", "/qsys.lib/qcpfmsg.msgf", "TABLE1".getBytes("Cp037"));
}
import com.ibm.as400.access.*;
public class sndmsg
{

public static void main(String[] args) throws Exception{
String lib = args[0];
String q = args[1];
AS400 as400 = new AS400("localhost", "*CURRENT", "*CURRENT");
MessageQueue mq = new MessageQueue(as400, "/qsys.lib/"+lib+".lib/"+q+".msgq");
mq.sendInformational("CAE0023", "/qsys.lib/qcpfmsg.msgf", "TABLE1".getBytes("Cp037"));
System.out.println("msg sent to MSGQ");
}
}
57 changes: 57 additions & 0 deletions test/runTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/QOpenSys/pkgs/bin/bash

TESTS=$(/QOpenSys/pkgs/bin/find * -mindepth 1 -type d)

num_fail=0
num_pass=0
num_error=0

for test in $TESTS
do
echo "Running test $test..."
gmake pretest
echo "Performing test-specific setup for test $test..."
gmake -C $test setup || exit 1
echo "Running test $test..."
gmake -C $test run
if [[ "0" != "$?" ]]
then
((num_error+=1))
fi

echo "Done running test $test. Exit code was $?"

echo "Killing jobs..."
for pid in $(ps | grep jre| awk '{print $1}')
do
echo killing pid $pid
kill -INT $pid
sleep 1
kill -KILL $pid
done
echo "checking result...."
echo "=================================="
gmake -C $test checkresult
echo "result is $?"
if [[ "0" == "$?" ]]
then
((num_pass+=1))
else
((num_fail+=1))
fi
echo "=================================="
echo "output"
echo "=================================="
cat $test/test.out
echo "=================================="

echo "Performing test-specific cleanup for test $test..."
gmake -C $test cleanup || echo "no setup needed"
echo "Performing cleanup..."
gmake posttest
echo "=================================="
echo "Results:"
echo " $num_pass passed"
echo " $num_fail failed"
echo " $num_error errored"
done
Loading