Commit efac8d60 authored by Ryan Berkheimer's avatar Ryan Berkheimer

added successful test for native transformation

parent f036e933
Pipeline #5774 failed with stages
in 0 seconds
......@@ -18,8 +18,7 @@
"metadata": "{}/resources/test/metadata/file-reader/container.json",
"collections": "{}/resources/test/file-reader/parameters.json",
"transformations": {
"map": "{}/resources/test/file-reader/parameters.json",
"factory": "gov.noaa.messageapi.test.factories.transformations.FileReaderFactory"
"map": "{}/resources/test/file-reader/parameters.json"
}
}
},
......
{
"plugin": "gov.noaa.messageapi.sessions.DefaultSession",
"constructor": {
"schema": {
"plugin": "gov.noaa.messageapi.schemas.DefaultSchema",
"constructor": {
"fields": "{}/resources/test/native-transformation/parameters.json"
}
},
"container": {
"plugin": "gov.noaa.messageapi.containers.DefaultContainer",
"constructor": {
"collections": "{}/resources/test/native-transformation/parameters.json",
"transformations": {"map": "{}/resources/test/native-transformation/parameters.json"}
}
},
"protocol": {
"plugin": "gov.noaa.messageapi.protocols.DefaultProtocol",
"constructor": {
"endpoints": [{
"plugin": "gov.noaa.messageapi.endpoints.EvaluationEndpoint",
"connections": "{}/resources/test/native-transformation/parameters.json"
}]
}
}
}
}
\ No newline at end of file
{
"fields": [
{
"id": "initial-value",
"type": "integer",
"required": true
},
{
"id": "string-test",
"type": "string",
"required": false
},
{
"id": "null-test",
"type": "string",
"required": false
},
{
"id": "int-list-test",
"type": "list(int)",
"required": true,
"value": [0,1,2,3,4,5,6]
}],
"collections": [{"id": "collection-1",
"fields": ["initial-value", "string-test", "int-list-test", "null-test"]}],
"transformations": [
{
"id": "transform-1",
"operator": "gov.noaa.messageapi.transformations.NativeTransformation",
"constructor": {
"native-library": "/Users/rberkheimer/projects/asos/ingest/libraries/messageapi/lib/test/native/demotransformationlibrary/libDemoTransformationLibrary.jnilib"
},
"records": {"test_key": {"COLLECTION": "collection-1"}}}
],
"connections": [{"id": "connection-1",
"transformations": ["transform-1"],
"constructor": {}}]
}
### This is a Makefile for MessageAPI Native Endpoints.
### This is a Makefile for MessageAPI Native Transformations.
# The majority of this Makefile is standard, with very few user specified things.
# There are a few specific requirements and other notable things to keep in mind when using this Makefile:
## 1. You must have a JDK installed (not JRE). This library requires the jni.h header included in your jdk.
## 2. JAVA_HOME must be set to your JDK home directory. This Makefile references JAVA_HOME in looking for jni.h
## 3. This Makefile assumes a specific project layout when setting the PROJECTPATH. If the Makefile is not working,
## you should look at how it uses PROJECTPATH, ENDPOINT_NAME, and ENDPOINT_TYPE to find required files.
## you should look at how it uses PROJECTPATH, TRANSFORMATION_NAME, and TRANSFORMATION_TYPE to find required files.
## if your project is set up differently, i.e. custom project layout, then path dependent vars will need to be
## looked at and possibly changed.
#The following represents the root project path. DO NOT EDIT
SCRIPTDIR=$(PWD)
PROJECTPATH=$(firstword $(subst /scripts/$(ENDPOINT_TYPE)/, ,$(SCRIPTDIR)))
PROJECTPATH=$(firstword $(subst /scripts/$(TRANSFORMATION_TYPE)/, ,$(SCRIPTDIR)))
#The following is used to determine how native resources are compiled. DO NOT EDIT.
UNAME := $(shell uname)
......@@ -20,13 +20,13 @@ UNAME := $(shell uname)
#The following vars are used to route source code and scripts (from the scripts and src dirs)
#to the library dir as compiled files (the job name should match the name of the directory/job map.)
#the job type is simply a test job or a main job and should either be test or main.
ENDPOINT_NAME=demotransformationlibrary
ENDPOINT_TYPE=test
TRANSFORMATION_NAME=demotransformationlibrary
TRANSFORMATION_TYPE=test
#USER SPECIFIED
#The following var represents the output name of the JniLib that will be created and referenced in the job map.
#Do not specify the extension (.so/.dll/.jnilib) - these are determined automatically on build.
#The full path to the created library must be referenced in the endpoint config.
#The full path to the created library must be referenced in the transformation config.
LIBNAME=DemoTransformationLibrary
#USER SPECIFIED
......@@ -71,16 +71,16 @@ JAVACLASSES:=$(PROJECTPATH)/src/java/main/gov/noaa/messageapi/transformations/Na
JAVAPATH=$(PROJECTPATH)/src/java/main:$(PROJECTPATH)/src/java/main/gov/noaa/messageapi/transformations
#The following contains source code paths derived from the ENDPOINT_NAME and ENDPOINT_TYPE supplied by the user.
#The following contains source code paths derived from the TRANSFORMATION_NAME and TRANSFORMATION_TYPE supplied by the user.
COMMONCPATH=$(PROJECTPATH)/src/c/main/common/structs/
USERCPATH=$(PROJECTPATH)/src/c/$(ENDPOINT_TYPE)/transformations/$(ENDPOINT_NAME)/
USERCPATH=$(PROJECTPATH)/src/c/$(TRANSFORMATION_TYPE)/transformations/$(TRANSFORMATION_NAME)/
COMMONCPPPATH=$(PROJECTPATH)/src/cpp/main/common/
USERCPPPATH=$(PROJECTPATH)/src/cpp/$(ENDPOINT_TYPE)/$(ENDPOINT_NAME)/
USERCPPPATH=$(PROJECTPATH)/src/cpp/$(TRANSFORMATION_TYPE)/$(TRANSFORMATION_NAME)/
COMMONFORTRANPATH=$(PROJECTPATH)/src/fortran/main/common/
USERFORTRANPATH=$(PROJECTPATH)/src/fortran/$(ENDPOINT_TYPE)/$(ENDPOINT_NAME)/
USERFORTRANPATH=$(PROJECTPATH)/src/fortran/$(TRANSFORMATION_TYPE)/$(TRANSFORMATION_NAME)/
#The following var contains the target path for the project code.
TARGETPATH="$(PROJECTPATH)/lib/$(ENDPOINT_TYPE)/native/$(ENDPOINT_NAME)/"
TARGETPATH="$(PROJECTPATH)/lib/$(TRANSFORMATION_TYPE)/native/$(TRANSFORMATION_NAME)/"
#The following is the target library for the native jni library.
ifeq ($(UNAME), Linux)
......@@ -123,7 +123,7 @@ gen-headers:
echo ""
build:
echo "Building " $(ENDPOINT_NAME) " in " $(PROJECTPATH)
echo "Building " $(TRANSFORMATION_NAME) " in " $(PROJECTPATH)
#echo "Compiling Fortran"
#echo ""
#cd $(TARGETPATH) && $(FF) $(FFLAGS) -c $(COMMONFORTRAN1) $(USERFORTRAN1)
......@@ -139,7 +139,7 @@ build:
echo "Creating JNI Library"
echo ""
cd $(TARGETPATH) && $(CXX) $(LNFLAGS) *.o -o $(DYLIB)
echo "Build success for " $(ENDPOINT_NAME)
echo "Build success for " $(TRANSFORMATION_NAME)
clean:
echo "Cleaning up."
......
......@@ -15,6 +15,9 @@ JNIEXPORT jobject JNICALL Java_gov_noaa_messageapi_transformations_NativeTransfo
printf("In our transformation test!\n");
printf("Hello, World\n");
fflush(stdout);
return getRecords(message, "test_key")->jrecords;
struct record_list *records = getRecords(message, "test_key");
printf("Record count: %d\n", records->count);
fflush(stdout);
return records->jrecords;
}
......@@ -21,7 +21,7 @@
/**
* This is the header for the MessageApiTransformation class - this class is the native side facility
* for doing endpoint processing and communicating back with the java side. This class holds
* for doing transformation processing and communicating back with the java side. This class holds
* three private vars - a pointer to the jvm where the call originated from, a pointer to the
* transformation class instance (jobject), and a pointer to the map that holds data for
* this transformation to process as a jobject.
......
......@@ -5,7 +5,7 @@
#include "gov_noaa_messageapi_transformations_NativeTransformation.h"
/**
* Creates a C++ object and returns a pointer to it cast as a long. This allows the NativeEndpoint method
* Creates a C++ object and returns a pointer to it cast as a long. This allows the NativeTransformation method
* to hold onto it and manipulate it during the process method while preventing potential conflicts with
* other threads or transformations using the same native library. This is used inside the Java process method.
* The Native process method should be implemented in a separate User class wrapper.
......
/**
* Tests sessions that use the native transformation. This is an end to end type testing module.
* @author Ryan Berkheimer
*/
import java.util.List
import gov.noaa.messageapi.interfaces.ISession
import gov.noaa.messageapi.interfaces.IRequest
import gov.noaa.messageapi.interfaces.IResponse
import gov.noaa.messageapi.interfaces.IRejection
import gov.noaa.messageapi.interfaces.IRecord
import gov.noaa.messageapi.interfaces.IField
import gov.noaa.messageapi.sessions.DefaultSession
class NativeTransformationTests extends spock.lang.Specification {
def 'Session with one endpoint that calls into C, populates a return record, and checks vals.'() {
given: 'A session created based on a native counter'
ISession session = new DefaultSession('{}/resources/test/native-transformation/manifest.json')
IRequest request = session.createRequest()
IRecord record1 = request.createRecord()
IRecord record2 = request.createRecord()
record1.setField('initial-value', 1000)
record1.setField('string-test', 'hi there!')
record1.setField('null-test', 'null')
record2.setField('string-test', 'cool!')
record2.setField('initial-value', 5000)
//record2.setField('null-test', 'null')
/*for (int i=0; i<500; i++) {
IRecord r = request.createRecord();
r.setField("initial-value", i);
r.setField("string-test", Integer.toString(i));
}*/
when: 'Submit the request, call a transformation in the evaluation endpoint, return all records'
IResponse response = request.submit()
while (!response.isComplete()) { }
then: 'No rejections, two return records, field values match..'
response.getRejections().size() == 0
response.getRecords().size() == 2
//response.getRecords().get(0).getField('test-integer').getValue() == 5
//response.getRecords().get(0).getField('return-list').getValue().get(0) == "first element of our string!"
//response.getRecords().get(0).getField('return-list').getValue().get(1) == "second element of our string!!"
}
}
......@@ -5,6 +5,7 @@ import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import gov.noaa.messageapi.interfaces.IEndpoint;
import gov.noaa.messageapi.interfaces.IField;
import gov.noaa.messageapi.interfaces.IPacket;
import gov.noaa.messageapi.interfaces.IRecord;
......@@ -29,7 +30,7 @@ import gov.noaa.messageapi.utils.general.ListUtils;
*
* @author Ryan Berkheimer
*/
public class EvaluationEndpoint extends BaseEndpoint {
public class EvaluationEndpoint extends BaseEndpoint implements IEndpoint {
public EvaluationEndpoint(Map<String, Object> parameters) {
super(parameters);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment