├── .gitignore ├── LICENSE ├── LICENSE_C ├── README.md ├── VERSION ├── atmi.go ├── atmisrv.go ├── doc ├── Makefile ├── class_diagram.dia ├── docupdate.pl ├── endurox-go-book.adoc ├── images │ └── class_diagram.png └── out │ ├── .gitignore │ └── images │ └── .gitignore ├── go.mod ├── tests ├── 01_basic_ubf_call │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── client.go │ │ └── go.mod │ │ ├── runtimeck │ │ ├── Makefile │ │ ├── go.mod │ │ └── runtimeck.go │ │ ├── server │ │ ├── Makefile │ │ ├── go.mod │ │ └── server.go │ │ └── ubftab │ │ ├── Exfields │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd ├── 02_basic_string_call │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── etclient │ │ ├── Makefile │ │ ├── client.go │ │ └── go.mod │ │ └── tserver │ │ ├── Makefile │ │ ├── go.mod │ │ └── server.go ├── 03_basic_carray_call │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── cclient │ │ ├── Makefile │ │ ├── client.go │ │ └── go.mod │ │ └── cserver │ │ ├── Makefile │ │ ├── go.mod │ │ └── server.go ├── 04_distributed_transaction │ ├── BSDmakefile │ ├── Makefile │ ├── README │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── client.go │ │ └── go.mod │ │ ├── oci8.pc │ │ ├── scheme.sql │ │ ├── server │ │ ├── Makefile │ │ ├── go.mod │ │ └── server.go │ │ └── ubftab │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd ├── 05_basic_json_call │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── client.go │ │ └── go.mod │ │ ├── server │ │ ├── Makefile │ │ ├── go.mod │ │ └── server.go │ │ └── ubftab │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd ├── 06_ubf_marshal │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── client.go │ │ ├── go.mod │ │ └── single.go │ │ └── ubftab │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd ├── 07_basic_durable_queue │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ ├── q.conf │ │ └── setndrx │ ├── run.sh │ ├── src │ │ ├── Makefile │ │ ├── atmi │ │ └── etclient │ │ │ ├── Makefile │ │ │ ├── client.go │ │ │ └── go.mod │ └── var │ │ ├── qspace1 │ │ └── README │ │ └── tm │ │ └── README ├── 08_logging │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── client.go │ │ └── go.mod │ │ ├── server │ │ ├── Makefile │ │ ├── go.mod │ │ └── server.go │ │ └── ubftab │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd ├── 09_return_manual_buffer │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── client.go │ │ └── go.mod │ │ ├── server │ │ ├── Makefile │ │ ├── go.mod │ │ └── server.go │ │ └── ubftab │ │ ├── Exfields │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd ├── 10_views │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── client.go │ │ └── go.mod │ │ ├── server │ │ ├── Makefile │ │ ├── go.mod │ │ └── server.go │ │ ├── ubftab │ │ ├── Exfields │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd │ │ └── viewdir │ │ ├── Makefile │ │ └── t40.v_in ├── 11_ubf_tests │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── bprint.go │ │ ├── client.go │ │ └── go.mod │ │ └── ubftab │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd ├── 12_tpimportexp │ ├── BSDmakefile │ ├── Makefile │ ├── conf │ │ ├── debug.conf │ │ ├── ndrxconfig.xml │ │ └── setndrx │ ├── run.sh │ └── src │ │ ├── Makefile │ │ ├── atmi │ │ ├── client │ │ ├── Makefile │ │ ├── client.go │ │ ├── data.go │ │ └── go.mod │ │ └── ubftab │ │ ├── Makefile │ │ ├── go.mod │ │ └── test.fd ├── Makefile ├── README ├── etclient │ ├── Makefile │ └── client.go └── run.sh ├── tplog.go ├── typed_carray.go ├── typed_json.go ├── typed_string.go ├── typed_ubf.go ├── typed_ubf_tag.go └── typed_view.go /.gitignore: -------------------------------------------------------------------------------- 1 | tests/01_basic_ubf_call/bin/ 2 | tests/01_basic_ubf_call/pkg/ 3 | tests/01_basic_ubf_call/src/github.com/ 4 | tests/01_basic_ubf_call/src/golang.org/ 5 | tests/01_basic_ubf_call/src/ubftab/test.fd.go 6 | tests/10_views/bin/ 7 | tests/10_views/pkg/ 8 | tests/10_views/src/github.com/ 9 | tests/10_views/src/golang.org/ 10 | tests/10_views/src/ubftab/test.fd.go 11 | tests/10_views/src/viewdir/t40.V 12 | tests/10_views/src/viewdir/t40.h 13 | 14 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 2.5.14 2 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## @brief Enduro/X Go lang module documentation 3 | ## 4 | ## @file Makefile 5 | ## 6 | ## ----------------------------------------------------------------------------- 7 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 8 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 9 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 10 | ## This software is released under one of the following licenses: 11 | ## LGPL or Mavimax's license for commercial use. 12 | ## See LICENSE file for full text. 13 | ## 14 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 15 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 16 | ## See LICENSE_C file for full text. 17 | ## ----------------------------------------------------------------------------- 18 | ## LGPL license: 19 | ## 20 | ## This program is free software; you can redistribute it and/or modify it under 21 | ## the terms of the GNU Lesser General Public License, version 3 as published 22 | ## by the Free Software Foundation; 23 | ## 24 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 25 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 26 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 27 | ## for more details. 28 | ## 29 | ## You should have received a copy of the Lesser General Public License along 30 | ## with this program; if not, write to the Free Software Foundation, Inc., 31 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32 | ## 33 | ## ----------------------------------------------------------------------------- 34 | ## A commercial use license is available from Mavimax, Ltd 35 | ## contact@mavimax.com 36 | ## ----------------------------------------------------------------------------- 37 | ## 38 | SOURCEDIR:=. 39 | DOCOUT:=./out/ 40 | IMG:=./images/ 41 | 42 | 43 | DOCSOURCES := $(shell ls -1 ../*.go ./docupdate.pl); 44 | SOURCES := $(shell find -name '*.adoc' -printf "%f\n") 45 | HTML := $(addprefix $(DOCOUT), $(patsubst %.adoc, %.html, $(SOURCES))) 46 | 47 | 48 | SOURCES_GRPAHS :=$(shell find -name '*.dia' -printf "%f\n") 49 | GRPAHS := $(addprefix $(IMG), $(patsubst %.dia, %.png, $(SOURCES_GRPAHS))) 50 | #GRPAHS := $(patsubst %.dia, %.png, $(SOURCES_GRPAHS)) 51 | 52 | all: endurox-go-book.adoc $(GRPAHS) $(HTML) 53 | 54 | $(info $$HTML is [${HTML}]) 55 | 56 | $(info $$GRPAHS is [${GRPAHS}]) 57 | 58 | $(info $$DOCSOURCES is [${DOCSOURCES}]) 59 | 60 | # 61 | # Generate the book from javadoc comments 62 | # 63 | endurox-go-book.adoc: $(DOCSOURCES) 64 | ./docupdate.pl ../* 65 | 66 | # 67 | # Build the charts (have to put the images locally so that we see them in 68 | # 69 | $(GRPAHS): $(SOURCES_GRPAHS) 70 | dia --size=1200x --filter=png -e ./images/$(patsubst %.dia,%,$<).png -t png $< 71 | cp ./images/$(patsubst %.dia,%,$<).png ./out/images 72 | 73 | # 74 | # Build the document 75 | # 76 | $(HTML): $(SOURCES) 77 | a2x -D ./out -f xhtml $< 78 | 79 | clean: 80 | rm -f $(HTML) ./out/docbook-xsl.css $(addprefix ./out/images/, $(patsubst %.dia, %.png, $(SOURCES_GRPAHS))) 81 | 82 | .PHONY: clean 83 | 84 | 85 | 86 | # vim: set ts=4 sw=4 et smartindent: 87 | -------------------------------------------------------------------------------- /doc/class_diagram.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/endurox-dev/endurox-go/5324c6f3d3898a779a0080378ce8048ac6cbfdec/doc/class_diagram.dia -------------------------------------------------------------------------------- /doc/images/class_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/endurox-dev/endurox-go/5324c6f3d3898a779a0080378ce8048ac6cbfdec/doc/images/class_diagram.png -------------------------------------------------------------------------------- /doc/out/.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Empty dir for build puproses 3 | # 4 | -------------------------------------------------------------------------------- /doc/out/images/.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Empty dir for build puproses 3 | # 4 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/v2 2 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=3 ubf=0 file= tp=5 4 | client ndrx=3 ubf=0 tp=5 file=/tmp/01_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 1 79 | 2 80 | 2 81 | -e /tmp/01_SERVER.log -r 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | export FIELDTBLS=test.fd,Exfields 91 | 92 | # vim: set ts=4 sw=4 et smartindent: 93 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | rm /tmp/01_CLIENT.log 2>/dev/null 16 | 17 | # should print some hello world 18 | client > /tmp/01_CLIENT.log 19 | 20 | RET=$? 21 | 22 | # Test the logfile for content 23 | OUT=`grep 'Hello World from Enduro/X service' /tmp/01_CLIENT.log` 24 | 25 | if [[ "X$OUT" == "X" ]]; then 26 | echo "TESTERROR: Content not found" 27 | RET=1 28 | fi 29 | 30 | echo "Runtime check (wait 60)" 31 | # Check the runtime.. for intr/SIGURG (shall not pass to C) 32 | # the signal ignoring shall do 33 | 34 | TMP_GODEBUG="$GODEBUG" 35 | unset GODEBUG 36 | runtimeck 37 | 38 | if [ $? -ne 0 ]; then 39 | echo "Runtime check failed (problems with atmi.RuntimeInit() or paly with GODEBUG=\"asyncpreemptoff=...\")" 40 | RET=1 41 | fi 42 | 43 | GODEBUG="$TMP_GODEBUG" 44 | 45 | if [[ "X$RET" == "X0" ]]; then 46 | echo "Test OK" 47 | 48 | else 49 | echo "Test FAIL" 50 | fi 51 | 52 | # shutdown the app server 53 | xadmin stop -c -y 54 | 55 | exit $RET 56 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C ubftab 3 | $(MAKE) -C server 4 | $(MAKE) -C client 5 | $(MAKE) -C runtimeck 6 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/client/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | //"log" 7 | //http "net/http" 8 | //_ "net/http/pprof" 9 | "os" 10 | "runtime" 11 | "ubftab" 12 | ) 13 | 14 | const ( 15 | SUCCEED = 0 16 | FAIL = -1 17 | ) 18 | 19 | //Binary main entry 20 | func main() { 21 | 22 | ret := SUCCEED 23 | 24 | // Run profiler 25 | // go func() { 26 | // log.Println(http.ListenAndServe("localhost:6060", nil)) 27 | //}() 28 | 29 | var tpur2 map[int64]int 30 | 31 | tpur2 = make(map[int64]int) 32 | 33 | for i := 0; i < 10000; i++ { 34 | 35 | ac, err := atmi.NewATMICtx() 36 | 37 | if nil != err { 38 | fmt.Errorf("Failed to allocate cotnext!", err) 39 | os.Exit(atmi.FAIL) 40 | } 41 | 42 | buf, err := ac.NewUBF(1024) 43 | 44 | if err != nil { 45 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 46 | ret = FAIL 47 | goto out 48 | } 49 | 50 | //Set one field for call 51 | if err := buf.BChg(ubftab.T_CARRAY_FLD, 0, "HELLO FROM CLIENT"); nil != err { 52 | fmt.Printf("UBF Error %d:[%s]\n", err.Code(), err.Message()) 53 | ret = FAIL 54 | goto out 55 | } 56 | //test that we can run zero lenght byte arrays 57 | var nulbuf []byte 58 | if err := buf.BChg(ubftab.T_CARRAY_2_FLD, 0, nulbuf); nil != err { 59 | fmt.Printf("UBF Error %d:[%s]\n", err.Code(), err.Message()) 60 | ret = FAIL 61 | goto out 62 | } 63 | 64 | //Get zero len array 65 | nulout, err := buf.BGetByteArr(ubftab.T_CARRAY_2_FLD, 0) 66 | 67 | if nil != err { 68 | fmt.Printf("Failed to get 0len array %d:[%s]\n", err.Code(), err.Message()) 69 | ret = FAIL 70 | goto out 71 | } 72 | 73 | if len(nulout) != 0 { 74 | fmt.Printf("nulout not 0: %d\n", len(nulout)) 75 | ret = FAIL 76 | goto out 77 | } 78 | 79 | //Call the server 80 | if _, err := ac.TpCall("TESTSVC", buf, 0); nil != err { 81 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 82 | ret = FAIL 83 | goto out 84 | } 85 | 86 | 87 | //This is between two servers 88 | //Thus number shall not repeate two times 89 | urcode, _ := ac.TpURCode() 90 | 91 | tpur2[urcode]++ 92 | 93 | if (tpur2[urcode] > 2) { 94 | fmt.Printf("Expected urcode %d only twice, but got: %d\n", 95 | urcode, tpur2[urcode]) 96 | ret = FAIL 97 | goto out 98 | } 99 | 100 | //Print the output buffer 101 | //buf.BPrint() 102 | buf.TpLogPrintUBF(atmi.LOG_DEBUG, "Got response") 103 | ac.TpTerm() 104 | ac.FreeATMICtx() 105 | runtime.GC() 106 | } 107 | 108 | //Run some bigger message tests 109 | fmt.Printf("Message size: %d\n", atmi.ATMIMsgSizeMax()) 110 | if atmi.ATMIMsgSizeMax() > 68000 { 111 | for i := 0; i < 10000; i++ { 112 | testdata := make([]byte, 1024*1024) 113 | ac, err := atmi.NewATMICtx() 114 | 115 | if nil != err { 116 | fmt.Errorf("Failed to allocate cotnext!", err) 117 | os.Exit(atmi.FAIL) 118 | } 119 | 120 | //2MB buffer 121 | buf, err := ac.NewUBF(1024*1024 + 1024) 122 | 123 | if err != nil { 124 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 125 | ret = FAIL 126 | goto out 127 | } 128 | 129 | for i := 0; i < len(testdata); i++ { 130 | testdata[i] = byte((i + 1) % 255) 131 | } 132 | 133 | //Set one field for call 134 | if err := buf.BChg(ubftab.T_CARRAY_FLD, 0, testdata); nil != err { 135 | fmt.Printf("! ATMI Error %d:[%s]\n", err.Code(), err.Message()) 136 | ret = FAIL 137 | goto out 138 | } 139 | 140 | //Call the server 141 | if _, err := ac.TpCall("BIGMSG", buf, 0); nil != err { 142 | //RPI and others, ignore big fails when message size unavailable 143 | if err.Code() == atmi.TPEINVAL { 144 | continue 145 | } 146 | 147 | fmt.Printf("ATMI Error BIGMSG %d:[%s]\n", err.Code(), err.Message()) 148 | 149 | ret = FAIL 150 | goto out 151 | } 152 | 153 | testdata, err = buf.BGetByteArr(ubftab.T_CARRAY_FLD, 0) 154 | 155 | if nil != err { 156 | fmt.Printf("! Failed to get rsp: ATMI Error %d:[%s]\n", err.Code(), err.Message()) 157 | ret = FAIL 158 | goto out 159 | } 160 | 161 | for i := 0; i < len(testdata); i++ { 162 | if testdata[i] != byte((i+2)%255) { 163 | ac.TpLogError("TESTERROR: Error at index %d expected %d got: %d", 164 | i, (i+2)%255, testdata[i]) 165 | ret = FAIL 166 | goto out 167 | } 168 | } 169 | 170 | } 171 | } 172 | 173 | out: 174 | //Close the ATMI session 175 | 176 | os.Exit(ret) 177 | } 178 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/01_basic_ubf_call/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/runtimeck/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/runtimeck: runtimeck.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/runtimeck/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/01_basic_ubf_call/src/runtimeck 2 | 3 | require ( 4 | atmi v1.0.0 5 | ) 6 | 7 | replace atmi v1.0.0 => ../../../../ 8 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/runtimeck/runtimeck.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | #include 5 | #include 6 | #include 7 | #cgo LDFLAGS: 8 | // simple C code 9 | int do_some_c_call(void) 10 | { 11 | 12 | struct timespec timeout; 13 | timeout.tv_sec = 0; 14 | timeout.tv_nsec = 1000; 15 | 16 | if (0!=nanosleep(&timeout, &timeout) && errno == EINTR) 17 | { 18 | printf("INTERRUPTED\n"); 19 | return -1; 20 | } 21 | 22 | return 0; 23 | } 24 | */ 25 | import "C" 26 | 27 | 28 | import ( 29 | "sync" 30 | "os" 31 | "atmi" 32 | "time" 33 | ) 34 | 35 | func main() { 36 | 37 | atmi.RuntimeInit() 38 | var wg sync.WaitGroup 39 | 40 | go func() { 41 | time.Sleep(60 * time.Second) 42 | //OK in this time.. 43 | os.Exit(0) 44 | }() 45 | 46 | for i :=0; i<100000; i++ { 47 | wg.Add(1) 48 | go func() { 49 | defer wg.Done() 50 | for { 51 | if C.do_some_c_call()!=0 { 52 | os.Exit(-1) 53 | } 54 | } 55 | }() 56 | 57 | /* check for run-time */ 58 | } 59 | wg.Wait() 60 | } 61 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/server/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/server: server.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/server/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/01_basic_ubf_call/src/server 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | "ubftab" 8 | ) 9 | 10 | const ( 11 | SUCCEED = 0 12 | FAIL = -1 13 | ) 14 | 15 | var Murcode int64 = 0 16 | 17 | //TESTSVC service 18 | func TESTSVC(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 19 | 20 | ret := SUCCEED 21 | 22 | //Get UBF Handler 23 | ub, _ := ac.CastToUBF(&svc.Data) 24 | 25 | //Print the buffer to stdout 26 | //fmt.Println("Incoming request:") 27 | ub.TpLogPrintUBF(atmi.LOG_DEBUG, "Incoming request:") 28 | 29 | //Resize buffer, to have some more space 30 | if err := ub.TpRealloc(1024); err != nil { 31 | fmt.Printf("TpRealloc() Got error: %d:[%s]\n", err.Code(), err.Message()) 32 | ret = FAIL 33 | goto out 34 | } 35 | 36 | //Set some field 37 | if err := ub.BChg(ubftab.T_STRING_FLD, 0, "Hello World from Enduro/X service"); err != nil { 38 | fmt.Printf("Bchg() Got error: %d:[%s]\n", err.Code(), err.Message()) 39 | ret = FAIL 40 | goto out 41 | } 42 | //Set second occurance too of the T_STRING_FLD field 43 | if err := ub.BChg(ubftab.T_STRING_FLD, 1, "This is line2"); err != nil { 44 | fmt.Printf("Bchg() 2 Got error: %d:[%s]\n", err.Code(), err.Message()) 45 | ret = FAIL 46 | goto out 47 | } 48 | 49 | Murcode++ 50 | 51 | out: 52 | //Return to the caller 53 | if SUCCEED == ret { 54 | ac.TpReturn(atmi.TPSUCCESS, Murcode, ub, 0) 55 | } else { 56 | ac.TpReturn(atmi.TPFAIL, Murcode, ub, 0) 57 | } 58 | return 59 | } 60 | 61 | //BIGMSG service 62 | func BIGMSG(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 63 | 64 | ret := SUCCEED 65 | 66 | //Get UBF Handler 67 | ub, _ := ac.CastToUBF(&svc.Data) 68 | 69 | //Print the buffer to stdout 70 | //fmt.Println("Incoming request:") 71 | //ub.TpLogPrintUBF(atmi.LOG_DEBUG, "Incoming request:") 72 | ac.TpLogInfo("BIGMSG got call!") 73 | 74 | //Set some field 75 | testdata, err := ub.BGetByteArr(ubftab.T_CARRAY_FLD, 0) 76 | 77 | if err != nil { 78 | fmt.Printf("Bchg() Got error: %d:[%s]\n", err.Code(), err.Message()) 79 | ret = FAIL 80 | goto out 81 | } 82 | 83 | for i := 0; i < len(testdata); i++ { 84 | if testdata[i] != byte((i+1)%255) { 85 | ac.TpLogError("TESTERROR: Error at index %d expected %d got: %d", 86 | i, (i+2)%255, testdata[i]) 87 | ret = FAIL 88 | goto out 89 | } 90 | 91 | testdata[i] = byte((i + 2) % 255) 92 | } 93 | 94 | ac.TpLogInfo("About to test test data!") 95 | 96 | if err := ub.BChg(ubftab.T_CARRAY_FLD, 0, testdata); err != nil { 97 | ac.TpLogError("TESTERROR ! Bchg() 2 Got error: %d:[%s]", err.Code(), err.Message()) 98 | ret = FAIL 99 | goto out 100 | } 101 | 102 | out: 103 | //Return to the caller 104 | if SUCCEED == ret { 105 | ac.TpReturn(atmi.TPSUCCESS, 0, ub, 0) 106 | } else { 107 | ac.TpReturn(atmi.TPFAIL, 0, ub, 0) 108 | } 109 | return 110 | } 111 | 112 | //Server init 113 | func Init(ac *atmi.ATMICtx) int { 114 | 115 | //Advertize TESTSVC 116 | if err := ac.TpAdvertise("TESTSVC", "TESTSVC", TESTSVC); err != nil { 117 | fmt.Println(err) 118 | return atmi.FAIL 119 | } 120 | 121 | if err := ac.TpAdvertise("BIGMSG", "BIGMSG", BIGMSG); err != nil { 122 | fmt.Println(err) 123 | return atmi.FAIL 124 | } 125 | 126 | return atmi.SUCCEED 127 | } 128 | 129 | //Server shutdown 130 | func Uninit(ac *atmi.ATMICtx) { 131 | fmt.Println("Server shutting down...") 132 | } 133 | 134 | //Executable main entry point 135 | func main() { 136 | 137 | //Have some context 138 | ac, err := atmi.NewATMICtx() 139 | 140 | if nil != err { 141 | fmt.Errorf("Failed to allocate cotnext!", err) 142 | os.Exit(atmi.FAIL) 143 | } else { 144 | //Run as server 145 | ac.TpRun(Init, Uninit) 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/01_basic_ubf_call/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/01_basic_ubf_call/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CHAR_FLD 11 char - 1 Chart test field 1 46 | T_CHAR_2_FLD 12 char - 1 Chart test field 2 47 | T_SHORT_FLD 21 short - 1 Short test field 1 48 | T_SHORT_2_FLD 22 short - 1 Short test field 2 49 | T_LONG_FLD 31 long - 1 Long test field 1 50 | T_LONG_2_FLD 32 long - 1 Long test field 2 51 | T_FLOAT_FLD 41 float - 1 Float test field 1 52 | T_FLOAT_2_FLD 42 float - 1 Float test field 2 53 | T_FLOAT_3_FLD 43 float - 1 Float test field 3 54 | T_DOUBLE_FLD 51 double - 1 Double test field 1 55 | T_DOUBLE_2_FLD 52 double - 1 Double test field 2 56 | T_DOUBLE_3_FLD 53 double - 1 Double test field 3 57 | T_DOUBLE_4_FLD 54 double - 1 Double test field 4 58 | T_STRING_FLD 61 string - 1 String test field 1 59 | T_STRING_2_FLD 62 string - 1 String test field 2 60 | T_STRING_3_FLD 63 string - 1 String test field 3 61 | T_STRING_4_FLD 64 string - 1 String test field 4 62 | T_STRING_5_FLD 65 string - 1 String test field 5 63 | T_STRING_6_FLD 66 string - 1 String test field 6 64 | T_STRING_7_FLD 67 string - 1 String test field 7 65 | T_STRING_8_FLD 68 string - 1 String test field 8 66 | T_STRING_9_FLD 69 string - 1 String test field 9 67 | T_STRING_10_FLD 10 string - 1 String test field 10 68 | T_CARRAY_FLD 81 carray - 1 Carray test field 1 69 | T_CARRAY_2_FLD 82 carray - 1 Carray test field 2 70 | 71 | 72 | $#endif 73 | 74 | $/* vim: set ts=4 sw=4 et smartindent: */ 75 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=5 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | tserver ndrx=5 ubf=0 file= 4 | etclient ndrx=5 ubf=0 file=/tmp/02_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 1 79 | 2 80 | 2 81 | -e /tmp/02_SERVER.log -r 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | export FIELDTBLS=test.fd 91 | 92 | # vim: set ts=4 sw=4 et smartindent: 93 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | 16 | # should print some hello world 17 | etclient | tee test.out 18 | 19 | # Test the logfile for content 20 | 21 | OUT=`grep 'Hello From TESTSVC. This string is bit longer than receved in req]' test.out` 22 | 23 | if [[ "X$OUT" == "X" ]]; then 24 | echo "TESTERROR: Content not found" 25 | exit 1 26 | fi 27 | 28 | echo "Test OK" 29 | 30 | # shutdown the app server 31 | xadmin stop -c -y 32 | 33 | exit 0 34 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C tserver 3 | $(MAKE) -C etclient 4 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/02_basic_string_call/src/etclient/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/src/etclient/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | const ( 10 | SUCCEED = 0 11 | FAIL = -1 12 | ) 13 | 14 | //Binary main entry 15 | func main() { 16 | 17 | ret := SUCCEED 18 | var ac *atmi.ATMICtx 19 | var err atmi.ATMIError 20 | //Return to the caller (kind of destructor..) 21 | defer func() { 22 | if nil != ac { 23 | ac.TpTerm() 24 | ac.FreeATMICtx() // Kill the context 25 | } 26 | os.Exit(ret) 27 | }() 28 | 29 | ac, err = atmi.NewATMICtx() 30 | 31 | if nil != err { 32 | fmt.Errorf("Failed to allocate cotnext!", err) 33 | ret = FAIL 34 | return 35 | } 36 | 37 | buf, err := ac.NewString("Hello World") 38 | 39 | if err != nil { 40 | ac.TpLogError("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 41 | ret = FAIL 42 | return 43 | } 44 | 45 | //Call the server 46 | if _, err := ac.TpCall("TESTSVC", buf, 0); nil != err { 47 | ac.TpLogError("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 48 | ret = FAIL 49 | return 50 | } 51 | 52 | //Print the output buffer 53 | fmt.Printf("Got response: [%s]\n", buf.GetString()) 54 | } 55 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/src/etclient/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/02_basic_string_call/src/etclient 2 | 3 | require atmi v1.0.0 4 | replace atmi v1.0.0 => ../../../../ 5 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/src/tserver/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/server: server.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/src/tserver/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/02_basic_string_call/src/tserver 2 | 3 | require ( 4 | atmi v1.0.0 5 | ) 6 | 7 | replace atmi v1.0.0 => ../../../../ 8 | -------------------------------------------------------------------------------- /tests/02_basic_string_call/src/tserver/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | const ( 10 | SUCCEED = 0 11 | FAIL = -1 12 | ) 13 | 14 | //TESTSVC service 15 | func TESTSVC(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 16 | 17 | ret := SUCCEED 18 | 19 | //Get Typed String Handler 20 | s, _ := ac.CastToString(&svc.Data) 21 | 22 | //Print the buffer to stdout 23 | fmt.Printf("Incoming request: [%s]\n", s.GetString()) 24 | 25 | //Resize buffer, to have some more space 26 | if err := s.TpRealloc(128); err != nil { 27 | fmt.Printf("Got error: %d:[%s]\n", err.Code(), err.Message()) 28 | ret = FAIL 29 | goto out 30 | } 31 | 32 | //Send string back 33 | s.SetString("Hello From TESTSVC. This string is bit longer than receved in req") 34 | 35 | out: 36 | //Return to the caller 37 | if SUCCEED == ret { 38 | ac.TpReturn(atmi.TPSUCCESS, 0, s, 0) 39 | } else { 40 | ac.TpReturn(atmi.TPFAIL, 0, s, 0) 41 | } 42 | return 43 | } 44 | 45 | //Server init 46 | func Init(ac *atmi.ATMICtx) int { 47 | 48 | //Advertize TESTSVC 49 | if err := ac.TpAdvertise("TESTSVC", "TESTSVC", TESTSVC); err != nil { 50 | fmt.Println(err) 51 | return atmi.FAIL 52 | } 53 | 54 | return atmi.SUCCEED 55 | } 56 | 57 | //Server shutdown 58 | func Uninit(ac *atmi.ATMICtx) { 59 | fmt.Println("Server shutting down...") 60 | } 61 | 62 | //Executable main entry point 63 | func main() { 64 | //Have some context 65 | ac, err := atmi.NewATMICtx() 66 | 67 | if nil != err { 68 | fmt.Errorf("Failed to allocate cotnext!", err) 69 | os.Exit(atmi.FAIL) 70 | } else { 71 | //Run as server 72 | ac.TpRun(Init, Uninit) 73 | ac.FreeATMICtx() 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=5 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | cserver ndrx=5 ubf=0 file= 4 | cclient ndrx=5 ubf=0 file=/tmp/03_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 1 79 | 2 80 | 2 81 | -e /tmp/03_SERVER.log -r 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | export FIELDTBLS=test.fd 91 | 92 | # vim: set ts=4 sw=4 et smartindent: 93 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | 16 | # should print some hello world 17 | cclient | tee test.out 18 | 19 | # Test the logfile for content 20 | 21 | OUT=`grep '0 1 2 3 4 5 6 7 8 9 10' test.out` 22 | 23 | if [[ "X$OUT" == "X" ]]; then 24 | echo "TESTERROR: Content not found" 25 | exit 1 26 | fi 27 | 28 | echo "Test OK" 29 | 30 | # shutdown the app server 31 | xadmin stop -c -y 32 | 33 | exit 0 34 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C cserver 3 | $(MAKE) -C cclient 4 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/03_basic_carray_call/src/cclient/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/src/cclient/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | "runtime" 8 | ) 9 | 10 | const ( 11 | SUCCEED = 0 12 | FAIL = -1 13 | ) 14 | 15 | //Binary main entry 16 | func main() { 17 | 18 | ret := SUCCEED 19 | //Return to the caller (kind of destructor..) 20 | defer func() { 21 | os.Exit(ret) 22 | }() 23 | 24 | for i := 0; i < 10000; i++ { 25 | var ac *atmi.ATMICtx 26 | var err atmi.ATMIError 27 | bytes := []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0} 28 | 29 | //Allocate context 30 | ac, err = atmi.NewATMICtx() 31 | if nil != err { 32 | fmt.Errorf("Failed to allocate cotnext!", err) 33 | ret = FAIL 34 | return 35 | } 36 | 37 | buf, err := ac.NewCarray(bytes) 38 | 39 | if err != nil { 40 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 41 | ret = FAIL 42 | return 43 | } 44 | 45 | fmt.Printf("Sending: [%v]\n", buf.GetBytes()) 46 | 47 | //Call the server 48 | if _, err := ac.TpCall("TESTSVC", buf, 0); nil != err { 49 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 50 | ret = FAIL 51 | return 52 | } 53 | 54 | //Print the output buffer 55 | fmt.Printf("Got response: [%v]\n", buf.GetBytes()) 56 | 57 | runtime.GC() 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/src/cclient/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/03_basic_carray_call/src/cclient 2 | 3 | require ( 4 | atmi v1.0.0 5 | ) 6 | 7 | replace atmi v1.0.0 => ../../../../ 8 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/src/cserver/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/server: server.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/src/cserver/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/03_basic_carray_call/src/cserver 2 | 3 | require ( 4 | atmi v1.0.0 5 | ) 6 | 7 | replace atmi v1.0.0 => ../../../../ 8 | -------------------------------------------------------------------------------- /tests/03_basic_carray_call/src/cserver/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | const ( 10 | SUCCEED = 0 11 | FAIL = -1 12 | ) 13 | 14 | //TESTSVC service 15 | func TESTSVC(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 16 | 17 | ret := SUCCEED 18 | somebytes := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 19 | 20 | //Get Typed String Handler 21 | c, _ := ac.CastToCarray(&svc.Data) 22 | 23 | //Print the buffer to stdout 24 | fmt.Printf("Incoming request: [%v]\n", c.GetBytes()) 25 | 26 | //Resize buffer, to have some more space 27 | if err := c.TpRealloc(128); err != nil { 28 | fmt.Printf("Got error: %d:[%s]\n", err.Code(), err.Message()) 29 | ret = FAIL 30 | goto out 31 | } 32 | 33 | //Send some bytes back... 34 | c.SetBytes(somebytes) 35 | 36 | out: 37 | //Return to the caller 38 | if SUCCEED == ret { 39 | ac.TpReturn(atmi.TPSUCCESS, 0, c, 0) 40 | } else { 41 | ac.TpReturn(atmi.TPFAIL, 0, c, 0) 42 | } 43 | return 44 | } 45 | 46 | //Server init 47 | func Init(ac *atmi.ATMICtx) int { 48 | 49 | //Advertize TESTSVC 50 | if err := ac.TpAdvertise("TESTSVC", "TESTSVC", TESTSVC); err != nil { 51 | fmt.Println(err) 52 | return atmi.FAIL 53 | } 54 | 55 | return atmi.SUCCEED 56 | } 57 | 58 | //Server shutdown 59 | func Uninit(ac *atmi.ATMICtx) { 60 | fmt.Println("Server shutting down...") 61 | } 62 | 63 | //Executable main entry point 64 | func main() { 65 | //Have some context 66 | ac, err := atmi.NewATMICtx() 67 | 68 | if nil != err { 69 | fmt.Errorf("Failed to allocate cotnext!", err) 70 | os.Exit(atmi.FAIL) 71 | } else { 72 | //Run as server 73 | ac.TpRun(Init, Uninit) 74 | ac.FreeATMICtx() 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export CGO_CFLAGS=-DOCI8_ENABLE_XA 3 | export GO111MODULE=auto 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | 14 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/README: -------------------------------------------------------------------------------- 1 | Before try to build & run NOTE: 2 | 3 | ** BUILD ** 4 | 1. Set the oracle install params in: `src/oci8.pc' 5 | 2. export CGO_CFLAGS=-DOCI8_ENABLE_XA 6 | 7 | ** RUN ** 8 | 1. Configure DB SID/username/password in: `conf/setndrx' 9 | 2. Install under the same Oracle user `src/scheme.sql' 10 | 3. call ./run.sh 11 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=5 ubf=0 file= 4 | client ndrx=5 ubf=0 file=/tmp/04_CLIENT.log 5 | tmsrv ndrx=5 file= 6 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 79 | 10 80 | 2 81 | 3 82 | -e /tmp/TM1 -r -- -t10 -l/tmp 83 | 84 | 85 | 150 86 | 3 87 | 3 88 | -e /tmp/04_SERVER.log -r 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | if [ -f ~/ndrx_home ]; then 72 | . ~/ndrx_home 73 | fi 74 | 75 | # Log & levels 76 | export NDRX_DMNLOG=/tmp/ndrxd.log 77 | export NDRX_DMNLEV=5 78 | 79 | export NDRX_LOG=/tmp/ndrx.log 80 | export NDRX_LEV=5 81 | 82 | # Correct the path so that ndrx can find ndrxd 83 | export PATH=$PATH:`pwd`/../bin 84 | 85 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 86 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 87 | # UBFTAB 88 | export FLDTBLDIR=`pwd`/../src/ubftab 89 | export FIELDTBLS=test.fd 90 | 91 | # 92 | # XA SECTION - updated according to your environment! 93 | # here 94 | # SID = ROCKY 95 | # username = endurotest 96 | # password = endurotest1 97 | # 98 | export ORACLE_SID=ROCKY 99 | export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 100 | export PATH=$PATH:ORACLE_HOME/bin 101 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib 102 | export NDRX_XA_RES_ID=1 103 | export NDRX_XA_OPEN_STR="ORACLE_XA+SqlNet=ROCKY+ACC=P/endurotest/endurotest1+SesTM=180+LogDir=/tmp/xa+nolocal=f" 104 | export NDRX_XA_CLOSE_STR=$NDRX_XA_OPEN_STR 105 | ##Static reg: 106 | export NDRX_XA_DRIVERLIB=/usr/lib/libndrxxaoras.so 107 | ## Dynamic reg: 108 | #export NDRX_XA_DRIVERLIB=/usr/lib/libndrxxaorad.so 109 | export NDRX_XA_RMLIB=/u01/app/oracle/product/11.2.0/dbhome_1/lib/libclntsh.so.11.1 110 | export NDRX_XA_LAZY_INIT=1 111 | # XA SECTION, END 112 | 113 | # vim: set ts=4 sw=4 et smartindent: 114 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | 16 | # should print some hello world 17 | client > test.out 2>&1 18 | ret=$? 19 | 20 | # Test the logfile for content 21 | 22 | OUT=`grep -E 'Got customer id: [0-9]+' test.out` 23 | 24 | if [[ "X$OUT" == "X" ]]; then 25 | echo "TESTERROR: Content not found" 26 | exit 1 27 | fi 28 | 29 | if [[ "$ret" == "0" ]]; then 30 | echo "Test OK" 31 | else 32 | echo "Ret $ret -> FAIL" 33 | fi 34 | 35 | # shutdown the app server 36 | xadmin stop -c -y 37 | 38 | exit $ret 39 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/Makefile: -------------------------------------------------------------------------------- 1 | # Env needed for oci build: 2 | export PKG_CONFIG_PATH:=$(PKG_CONFIG_PATH):$(shell pwd)/oci8 3 | export CGO_CFLAGS=$(CFLAGS) 4 | export CGO_LDFLAGS=$(CFLAGS) 5 | 6 | $(info $$PKG_CONFIG_PATH is [${PKG_CONFIG_PATH}]) 7 | 8 | all: oci8 submakes 9 | 10 | # 11 | # Get the Oracle Driver patched for XA 12 | # 13 | oci8: 14 | git clone https://github.com/endurox-dev/go-oci8 oci8 15 | cp oci8.pc oci8 16 | 17 | # 18 | # Run the submakes 19 | # 20 | submakes: 21 | $(MAKE) -C ubftab 22 | $(MAKE) -C client 23 | $(MAKE) -C server 24 | 25 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/client/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // #include 4 | import "C" 5 | 6 | import ( 7 | "atmi" 8 | "fmt" 9 | "os" 10 | "ubftab" 11 | "runtime" 12 | ) 13 | 14 | const ( 15 | SUCCEED = 0 16 | FAIL = -1 17 | ) 18 | 19 | //Binary main entry 20 | func main() { 21 | 22 | ret := SUCCEED 23 | //Return to the caller (kind of destructor..) 24 | defer func() { 25 | os.Exit(ret) 26 | }() 27 | C.signal(11, nil); 28 | 29 | for i:=0; i<1000; i++ { 30 | var ac *atmi.ATMICtx 31 | var err atmi.ATMIError 32 | var cust_id_first int64 33 | 34 | //Allocate context 35 | ac, err = atmi.NewATMICtx() 36 | if nil != err { 37 | fmt.Errorf("Failed to allocate cotnext!", err) 38 | ret = FAIL 39 | return 40 | } 41 | 42 | // Allocate some buffer 43 | buf, err := ac.NewUBF(1024) 44 | 45 | if err != nil { 46 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 47 | ret = FAIL 48 | return 49 | } 50 | 51 | //Open The XA sub-sysitem 52 | if err := ac.TpOpen(); err != nil { 53 | fmt.Printf("ATMI Error: [%s]\n", err.Message()) 54 | ret = FAIL 55 | return 56 | } 57 | 58 | //Begin transaction, timeout 60 sec 59 | if err := ac.TpBegin(60, 0); err != nil { 60 | fmt.Printf("ATMI Error: [%s]\n", err.Message()) 61 | ret = FAIL 62 | return 63 | } 64 | 65 | //Set customer name field 66 | if err := buf.BChg(ubftab.T_CUSTOMER_NAME, 0, "John"); nil != err { 67 | fmt.Printf("UBF Error %d:[%s]\n", err.Code(), err.Message()) 68 | ret = FAIL 69 | return 70 | } 71 | 72 | //Set city field 73 | if err := buf.BChg(ubftab.T_CITY, 0, "Riga"); nil != err { 74 | fmt.Printf("UBF Error %d:[%s]\n", err.Code(), err.Message()) 75 | ret = FAIL 76 | return 77 | } 78 | 79 | //////////////////////////////////////////////////////////////////////// 80 | //First call! 81 | //////////////////////////////////////////////////////////////////////// 82 | //Call the server 83 | //Will use TRANSUSPEND as we run on the same RMID 84 | //On one RMID there can be only one resource client active 85 | //Or otherwise we could use dynamic registration 86 | if _, err := ac.TpCall("MKCUST", buf, atmi.TPTRANSUSPEND); nil != err { 87 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 88 | ret = FAIL 89 | return 90 | } 91 | //////////////////////////////////////////////////////////////////////// 92 | 93 | //Print the output buffer 94 | buf.BPrint() 95 | 96 | //Get the first call customer id. 97 | //After txn abort, must be the same at next call. 98 | 99 | cust_id_first, _ = buf.BGetInt64(ubftab.T_CUSTOMER_ID, 0) 100 | 101 | //Do the abort & call again, the ID must be the same if tran works. 102 | 103 | //Abort the transaction 104 | if err := ac.TpAbort(0); err != nil { 105 | fmt.Printf("Got error: [%s]\n", err.Message()) 106 | ret = FAIL 107 | return 108 | } 109 | 110 | //Begin transaction, timeout 60 sec 111 | if err := ac.TpBegin(60, 0); err != nil { 112 | fmt.Printf("ATMI Error: [%s]\n", err.Message()) 113 | ret = FAIL 114 | return 115 | } 116 | 117 | //////////////////////////////////////////////////////////////////////// 118 | //Second call! 119 | //////////////////////////////////////////////////////////////////////// 120 | //Call the server 121 | //Will use TRANSUSPEND as we run on the same RMID 122 | //On one RMID there can be only one resource client active 123 | //Or otherwise we could use dynamic registration 124 | if _, err := ac.TpCall("MKCUST", buf, atmi.TPTRANSUSPEND); nil != err { 125 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 126 | ret = FAIL 127 | return 128 | } 129 | 130 | //Print the customer id 131 | if cust_id, err := buf.BGetInt64(ubftab.T_CUSTOMER_ID, 0); nil != err { 132 | fmt.Printf("UBF Error %d:[%s]\n", err.Code(), err.Message()) 133 | ret = FAIL 134 | return 135 | } else { 136 | fmt.Printf("Got customer id: %d\n", cust_id) 137 | 138 | if cust_id_first != cust_id { 139 | fmt.Printf("XA transaction fail, first call id: %d, second %d\n", 140 | cust_id_first, cust_id) 141 | ret = FAIL 142 | return 143 | } 144 | } 145 | 146 | //Commit the transaction 147 | if err := ac.TpCommit(0); err != nil { 148 | fmt.Printf("Got error: [%s]\n", err.Message()) 149 | ret = FAIL 150 | return 151 | } 152 | 153 | //Abort transaction, if we failed. 154 | if SUCCEED != ret { 155 | if err := ac.TpAbort(0); err != nil { 156 | fmt.Printf("Got error: [%s]\n", err.Message()) 157 | } 158 | } 159 | 160 | //Close the XA sub-system 161 | ac.TpClose() 162 | 163 | //Close the ATMI session 164 | ac.TpTerm() 165 | 166 | runtime.GC() 167 | } 168 | 169 | os.Exit(ret) 170 | } 171 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/04_distributed_transaction/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/oci8.pc: -------------------------------------------------------------------------------- 1 | prefix=/devel/target/XXXXXXXXXXXXXXXXXXXXXXXXXX 2 | exec_prefix=${prefix} 3 | libdir=/u01/app/oracle/product/11.2.0/dbhome_1/lib 4 | includedir=/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/public 5 | 6 | glib_genmarshal=glib-genmarshal 7 | gobject_query=gobject-query 8 | glib_mkenums=glib-mkenums 9 | 10 | Name: oci8 11 | Description: oci8 library 12 | Version: 11.1 13 | Cflags: -I${includedir} 14 | Libs: -L${libdir} -lclntsh 15 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/scheme.sql: -------------------------------------------------------------------------------- 1 | create table customers 2 | ( 3 | customer_id number(10) not null, 4 | customer_name varchar2(50) not null, 5 | city varchar2(50) 6 | ) 7 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/server/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/server: server.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/server/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/04_distributed_transaction/src/server 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | oci8 v1.0.0 7 | ) 8 | 9 | replace atmi v1.0.0 => ../../../../ 10 | replace ubftab v1.0.0 => ../ubftab 11 | replace oci8 v1.0.0 => ../oci8 12 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "database/sql" 6 | "fmt" 7 | _ "oci8" 8 | "os" 9 | "runtime" 10 | "ubftab" 11 | ) 12 | 13 | const ( 14 | SUCCEED = 0 15 | FAIL = -1 16 | ) 17 | 18 | //Connection to DB 19 | var M_db *sql.DB 20 | 21 | //MKCUST service 22 | func MKCUST(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 23 | 24 | //Run in single thread (this will include further connection to db) 25 | runtime.LockOSThread() 26 | 27 | //////////////////////////////////////////////////////////////////////// 28 | //DB must run in global transaction... 29 | //////////////////////////////////////////////////////////////////////// 30 | ac.AssocThreadWithCtx() 31 | 32 | ret := SUCCEED 33 | 34 | var id, city, cust_name string 35 | var uerr atmi.UBFError 36 | 37 | //Get UBF Handler 38 | ub, _ := ac.CastToUBF(&svc.Data) 39 | 40 | //Print the buffer to stdout 41 | fmt.Println("Incoming request:") 42 | ub.BPrint() 43 | 44 | //Ensure that we have space for answer... 45 | if err := ub.TpRealloc(64); err != nil { 46 | fmt.Printf("Got error: %d:[%s]\n", err.Code(), err.Message()) 47 | ret = FAIL 48 | goto out 49 | } 50 | 51 | // Get the next customer id 52 | if rows, err := M_db.Query("select nvl(max(CUSTOMER_ID),0)+1 from customers"); err != nil { 53 | fmt.Println("Query error: ", err) 54 | } else { 55 | // defer rows.Close() 56 | for rows.Next() { 57 | if err := rows.Scan(&id); err != nil { 58 | ret = FAIL 59 | goto out 60 | } 61 | fmt.Printf("Got new ID: [%d]", id) 62 | } 63 | } 64 | 65 | //Return ID back to caller. 66 | if err := ub.BChg(ubftab.T_CUSTOMER_ID, 0, id); err != nil { 67 | fmt.Printf("Failed to set T_CUSTOMER_ID: %d:[%s]\n", err.Code(), err.Message()) 68 | ret = FAIL 69 | goto out 70 | } 71 | 72 | //Read the other fields 73 | cust_name, uerr = ub.BGetString(ubftab.T_CUSTOMER_NAME, 0) 74 | if uerr != nil { 75 | fmt.Printf("Failed to get T_CUSTOMER_NAME: %d:[%s]\n", uerr.Code(), uerr.Message()) 76 | ret = FAIL 77 | goto out 78 | } 79 | 80 | city, uerr = ub.BGetString(ubftab.T_CITY, 0) 81 | if uerr != nil { 82 | fmt.Printf("Failed to get T_CITY: %d:[%s]\n", uerr.Code(), uerr.Message()) 83 | ret = FAIL 84 | goto out 85 | } 86 | 87 | //Now insert the record 88 | if _, err := M_db.Exec("INSERT INTO customers (customer_id, customer_name, city) " + 89 | " VALUES (" + id + ", '" + cust_name + "', '" + city + "')"); err != nil { 90 | fmt.Printf("Failed to create customer: %s\n", err) 91 | ret = FAIL 92 | goto out 93 | } 94 | 95 | out: 96 | //////////////////////////////////////////////////////////////////////// 97 | // Disassoc thread from Ctx 98 | //////////////////////////////////////////////////////////////////////// 99 | ac.DisassocThreadFromCtx() 100 | // Might want to unlock the thread. 101 | 102 | //Return to the caller 103 | if SUCCEED == ret { 104 | ac.TpReturn(atmi.TPSUCCESS, 0, ub, 0) 105 | } else { 106 | ac.TpReturn(atmi.TPFAIL, 0, ub, 0) 107 | } 108 | return 109 | } 110 | 111 | //Server init 112 | func Init(ac *atmi.ATMICtx) int { 113 | 114 | if err := ac.TpOpen(); err != nil { 115 | fmt.Println(err) 116 | return atmi.FAIL 117 | } 118 | 119 | //Advertize MKCUST 120 | if err := ac.TpAdvertise("MKCUST", "MKCUST", MKCUST); err != nil { 121 | fmt.Println(err) 122 | return atmi.FAIL 123 | } 124 | 125 | //Connect to XA driver (empty conn string...) & get the SQL handler. 126 | if db, err := sql.Open("oci8", "dummy_user:dummy_pass@localhost:1111/SID?enable_xa=YES"); err != nil { 127 | // if db, err := sql.Open("oci8", "endurotest:endurotest1@localhost:1521/ROCKY"); err != nil { 128 | fmt.Printf("Failed to get SQL handler: %s\n", err) 129 | return atmi.FAIL 130 | } else { 131 | M_db = db 132 | } 133 | 134 | return atmi.SUCCEED 135 | } 136 | 137 | //Server shutdown 138 | func Uninit(ac *atmi.ATMICtx) { 139 | fmt.Println("Server shutting down...") 140 | 141 | ac.TpClose() 142 | } 143 | 144 | //Executable main entry point 145 | func main() { 146 | 147 | //Have some context 148 | ac, err := atmi.NewATMICtx() 149 | 150 | if nil != err { 151 | fmt.Errorf("Failed to allocate cotnext!", err) 152 | os.Exit(atmi.FAIL) 153 | } else { 154 | //Run as server 155 | ac.TpRun(Init, Uninit) 156 | ac.FreeATMICtx() 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | go install 7 | 8 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/04_distributed_transaction/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/04_distributed_transaction/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CUSTOMER_ID 1 long - 1 Customer ID 46 | T_CUSTOMER_NAME 2 string - 1 Customer Name 47 | T_CITY 3 string - 1 City 48 | 49 | $#endif 50 | 51 | $/* vim: set ts=4 sw=4 et smartindent: */ 52 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=5 ubf=0 file= 4 | client ndrx=5 ubf=0 file=/tmp/01_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 1 79 | 2 80 | 2 81 | -e /tmp/01_SERVER.log -r -xTESTSVC:JSON2UBF 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | export FIELDTBLS=test.fd 91 | 92 | # vim: set ts=4 sw=4 et smartindent: 93 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | 16 | # should print some hello world 17 | client 18 | 19 | ret=$? 20 | 21 | echo "Test OK" 22 | 23 | # shutdown the app server 24 | xadmin stop -c -y 25 | 26 | exit $? 27 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C ubftab 3 | $(MAKE) -C server 4 | $(MAKE) -C client 5 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/client/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // #include 4 | import "C" 5 | 6 | import ( 7 | "atmi" 8 | "bytes" 9 | "encoding/json" 10 | "fmt" 11 | "os" 12 | "runtime" 13 | "sync" 14 | "ubftab" 15 | ) 16 | 17 | const ( 18 | SUCCEED = 0 19 | FAIL = -1 20 | ) 21 | 22 | type Message struct { 23 | T_CHAR_FLD byte 24 | T_SHORT_FLD int16 25 | T_LONG_FLD int64 26 | T_FLOAT_FLD float32 27 | T_DOUBLE_FLD float64 28 | T_STRING_FLD string 29 | T_CARRAY_FLD []byte 30 | } 31 | 32 | var M_ret chan int 33 | var M_wg sync.WaitGroup 34 | 35 | //Binary main entry 36 | func async_main() { 37 | 38 | ret := SUCCEED 39 | 40 | defer func() { 41 | M_wg.Done() 42 | M_ret <- ret 43 | }() 44 | //Have some loop for memory leak checks... 45 | for i := 0; i < 100; i++ { 46 | var ac *atmi.ATMICtx 47 | var err atmi.ATMIError 48 | //Allocate context 49 | ac, err = atmi.NewATMICtx() 50 | if nil != err { 51 | fmt.Errorf("Failed to allocate cotnext!", err) 52 | ret = FAIL 53 | return 54 | } 55 | 56 | m := Message{65, 100, 1294706395881547000, 66.77, 11111111222.77, "Hello Wolrd", []byte{0, 1, 2, 3}} 57 | 58 | b, _ := json.Marshal(m) 59 | 60 | bb := []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0} 61 | 62 | fmt.Printf("Got JSON [%s]\n", string(b)) 63 | 64 | buf, err := ac.NewJSON(b) 65 | 66 | if err != nil { 67 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 68 | ret = FAIL 69 | return 70 | } 71 | 72 | //Call the server 73 | if _, err := ac.TpCall("TESTSVC", buf, 0); nil != err { 74 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 75 | ret = FAIL 76 | return 77 | } 78 | 79 | json.Unmarshal(buf.GetJSON(), &m) 80 | 81 | if m.T_STRING_FLD != "Hello World from Enduro/X service" { 82 | fmt.Printf("Invalid message recieved: [%s]\n", m.T_STRING_FLD) 83 | ret = FAIL 84 | return 85 | } 86 | 87 | if 0 != bytes.Compare(bb, m.T_CARRAY_FLD) { 88 | fmt.Printf("Invalid c array received...") 89 | ret = FAIL 90 | return 91 | } 92 | 93 | fmt.Println(m) 94 | //Close the ATMI session 95 | runtime.GC() 96 | } 97 | 98 | } 99 | 100 | //Do some tests with UBF convert to/from JSON 101 | func test_buffer_convert() int { 102 | 103 | var ac *atmi.ATMICtx 104 | var err atmi.ATMIError 105 | //Allocate context 106 | ac, err = atmi.NewATMICtx() 107 | if nil != err { 108 | fmt.Errorf("Failed to allocate contex [%s]t!\n", err) 109 | return atmi.FAIL 110 | 111 | } 112 | //Create UBF buffer 113 | u, err := ac.NewUBF(1024) 114 | if err != nil { 115 | fmt.Errorf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 116 | return atmi.FAIL 117 | } 118 | 119 | //Set some fields to buffer 120 | u.BChg(ubftab.T_CHAR_FLD, 0, "A") 121 | u.BChg(ubftab.T_DOUBLE_2_FLD, 0, 12.9999) 122 | u.BChg(ubftab.T_STRING_FLD, 0, "Hello World") 123 | u.BChg(ubftab.T_STRING_FLD, 2, "Yes...") 124 | 125 | u.TpLogPrintUBF(atmi.LOG_WARN, "Original UBF") 126 | 127 | //Conver to JSON... 128 | str, err := u.TpUBFToJSON() 129 | 130 | if err != nil { 131 | fmt.Printf("TpUBFToJSON() fail - ATMI Error %d:[%s]\n", 132 | err.Code(), err.Message()) 133 | return atmi.FAIL 134 | } 135 | 136 | fmt.Printf("Got json string from UBF: [%s]\n", str) 137 | 138 | //Convert the JSON back to buffer... 139 | u.BProj([]int{0}) //Reset the the buffer (0 - bad field id...) 140 | 141 | //Check that reset was ok 142 | if u.BPres(ubftab.T_CHAR_FLD, 0) { 143 | fmt.Printf("ubftab.T_CHAR_FLD must not exist!\n") 144 | return atmi.FAIL 145 | } 146 | 147 | u.TpLogPrintUBF(atmi.LOG_WARN, "Cleared UBF") 148 | 149 | //Convert build UBF from json 150 | err = u.TpJSONToUBF(str) 151 | if err != nil { 152 | fmt.Printf("TpUBFToJSON() fail - ATMI Error %d:[%s]\n", 153 | err.Code(), err.Message()) 154 | return atmi.FAIL 155 | } 156 | 157 | //Check the buffer for values... 158 | if res, err := u.BQBoolEv("T_CHAR_FLD=='A' && T_STRING_FLD[2]=='Yes...'"); !res || nil != err { 159 | if nil != err { 160 | fmt.Printf("long: Expression failed: %s\n", err.Error()) 161 | return atmi.FAIL 162 | } else { 163 | fmt.Printf("long: Expression is false\n") 164 | return atmi.FAIL 165 | } 166 | } 167 | 168 | u.TpLogPrintUBF(atmi.LOG_WARN, "Restored UBF") 169 | 170 | return atmi.SUCCEED 171 | } 172 | 173 | func main() { 174 | 175 | // you can also add these one at 176 | // a time if you need to 177 | M_ret = make(chan int, 10) 178 | M_wg.Add(10) 179 | // Have some core dumps... 180 | C.signal(11, nil) 181 | 182 | for i := 0; i < 10; i++ { 183 | go async_main() 184 | } 185 | 186 | M_wg.Wait() 187 | 188 | i := 0 189 | for ret := range M_ret { 190 | fmt.Println(ret) 191 | if ret == FAIL { 192 | os.Exit(FAIL) 193 | } 194 | i++ 195 | //For some reason the for loop does not terminate by it self.. 196 | if i >= 10 { 197 | break 198 | } 199 | } 200 | 201 | ret2 := test_buffer_convert() 202 | 203 | if atmi.SUCCEED != ret2 { 204 | os.Exit(FAIL) 205 | } 206 | 207 | os.Exit(SUCCEED) 208 | } 209 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/05_basic_json_call/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/server/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/server: server.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/server/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/05_basic_json_call/src/server 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | "ubftab" 8 | ) 9 | 10 | const ( 11 | SUCCEED = 0 12 | FAIL = -1 13 | ) 14 | 15 | //TESTSVC service 16 | func TESTSVC(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 17 | 18 | ret := SUCCEED 19 | 20 | //Get UBF Handler 21 | ub, _ := ac.CastToUBF(&svc.Data) 22 | 23 | //Print the buffer to stdout 24 | fmt.Println("Incoming request:") 25 | ub.BPrint() 26 | 27 | //Return to the caller 28 | defer func() { 29 | if SUCCEED == ret { 30 | ac.TpReturn(atmi.TPSUCCESS, 0, ub, 0) 31 | } else { 32 | ac.TpReturn(atmi.TPFAIL, 0, ub, 0) 33 | } 34 | }() 35 | 36 | //Resize buffer, to have some more space 37 | if err := ub.TpRealloc(1024); err != nil { 38 | fmt.Printf("Got error: %d:[%s]\n", err.Code(), err.Message()) 39 | ret = FAIL 40 | return 41 | } 42 | 43 | s_val, _ := ub.BGetInt16(ubftab.T_SHORT_FLD, 0) 44 | 45 | if s_val != 100 { 46 | fmt.Printf("Got error, T_SHORT_FLD not 100!") 47 | ret = FAIL 48 | return 49 | } 50 | 51 | //Set some field 52 | if err := ub.BChg(ubftab.T_STRING_FLD, 0, 53 | "Hello World from Enduro/X service"); err != nil { 54 | fmt.Printf("Got error: %d:[%s]\n", err.Code(), err.Message()) 55 | ret = FAIL 56 | return 57 | } 58 | 59 | b := []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0} 60 | if err := ub.BChg(ubftab.T_CARRAY_FLD, 0, b); err != nil { 61 | fmt.Printf("Got error: %d:[%s]\n", err.Code(), err.Message()) 62 | ret = FAIL 63 | return 64 | } 65 | } 66 | 67 | //Server init 68 | func Init(ac *atmi.ATMICtx) int { 69 | 70 | //Advertize TESTSVC 71 | if err := ac.TpAdvertise("TESTSVC", "TESTSVC", TESTSVC); err != nil { 72 | fmt.Println(err) 73 | return atmi.FAIL 74 | } 75 | 76 | return atmi.SUCCEED 77 | } 78 | 79 | //Server shutdown 80 | func Uninit(ac *atmi.ATMICtx) { 81 | fmt.Println("Server shutting down...") 82 | } 83 | 84 | //Executable main entry point 85 | func main() { 86 | //Have some context 87 | ac, err := atmi.NewATMICtx() 88 | 89 | if nil != err { 90 | fmt.Errorf("Failed to allocate cotnext!", err) 91 | os.Exit(atmi.FAIL) 92 | } else { 93 | //Run as server 94 | ac.TpRun(Init, Uninit) 95 | ac.FreeATMICtx() 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | go install 7 | 8 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/05_basic_json_call/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/05_basic_json_call/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CHAR_FLD 11 char - 1 Chart test field 1 46 | T_CHAR_2_FLD 12 char - 1 Chart test field 2 47 | T_SHORT_FLD 21 short - 1 Short test field 1 48 | T_SHORT_2_FLD 22 short - 1 Short test field 2 49 | T_LONG_FLD 31 long - 1 Long test field 1 50 | T_LONG_2_FLD 32 long - 1 Long test field 2 51 | T_FLOAT_FLD 41 float - 1 Float test field 1 52 | T_FLOAT_2_FLD 42 float - 1 Float test field 2 53 | T_FLOAT_3_FLD 43 float - 1 Float test field 3 54 | T_DOUBLE_FLD 51 double - 1 Double test field 1 55 | T_DOUBLE_2_FLD 52 double - 1 Double test field 2 56 | T_DOUBLE_3_FLD 53 double - 1 Double test field 3 57 | T_DOUBLE_4_FLD 54 double - 1 Double test field 4 58 | T_STRING_FLD 61 string - 1 String test field 1 59 | T_STRING_2_FLD 62 string - 1 String test field 2 60 | T_STRING_3_FLD 63 string - 1 String test field 3 61 | T_STRING_4_FLD 64 string - 1 String test field 4 62 | T_STRING_5_FLD 65 string - 1 String test field 5 63 | T_STRING_6_FLD 66 string - 1 String test field 6 64 | T_STRING_7_FLD 67 string - 1 String test field 7 65 | T_STRING_8_FLD 68 string - 1 String test field 8 66 | T_STRING_9_FLD 69 string - 1 String test field 9 67 | T_STRING_10_FLD 10 string - 1 String test field 10 68 | T_CARRAY_FLD 81 carray - 1 Carray test field 1 69 | T_CARRAY_2_FLD 82 carray - 1 Carray test field 2 70 | 71 | 72 | $#endif 73 | 74 | $/* vim: set ts=4 sw=4 et smartindent: */ 75 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=5 ubf=0 file= 4 | client ndrx=5 ubf=0 file=/tmp/06_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | #export FIELDTBLS=test.fd,Exfields 91 | export FIELDTBLS=test.fd 92 | 93 | # vim: set ts=4 sw=4 et smartindent: 94 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | 16 | # should print some hello world 17 | client 18 | 19 | ret=$? 20 | 21 | if [[ $ret -eq 0 ]]; then 22 | echo "Test OK" 23 | else 24 | echo "Test failed" 25 | fi 26 | 27 | # shutdown the app server 28 | xadmin stop -c -y 29 | 30 | exit $ret 31 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C ubftab 3 | $(MAKE) -C client 4 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/06_ubf_marshal/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go single.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/06_ubf_marshal/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | go install 7 | 8 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/06_ubf_marshal/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/06_ubf_marshal/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CHAR_FLD 11 char - 1 Chart test field 1 46 | T_CHAR_2_FLD 12 char - 1 Chart test field 2 47 | T_SHORT_FLD 21 short - 1 Short test field 1 48 | T_SHORT_2_FLD 22 short - 1 Short test field 2 49 | T_LONG_FLD 31 long - 1 Long test field 1 50 | T_LONG_2_FLD 32 long - 1 Long test field 2 51 | T_FLOAT_FLD 41 float - 1 Float test field 1 52 | T_FLOAT_2_FLD 42 float - 1 Float test field 2 53 | T_FLOAT_3_FLD 43 float - 1 Float test field 3 54 | T_DOUBLE_FLD 51 double - 1 Double test field 1 55 | T_DOUBLE_2_FLD 52 double - 1 Double test field 2 56 | T_DOUBLE_3_FLD 53 double - 1 Double test field 3 57 | T_DOUBLE_4_FLD 54 double - 1 Double test field 4 58 | T_STRING_FLD 61 string - 1 String test field 1 59 | T_STRING_2_FLD 62 string - 1 String test field 2 60 | T_STRING_3_FLD 63 string - 1 String test field 3 61 | T_STRING_4_FLD 64 string - 1 String test field 4 62 | T_STRING_5_FLD 65 string - 1 String test field 5 63 | T_STRING_6_FLD 66 string - 1 String test field 6 64 | T_STRING_7_FLD 67 string - 1 String test field 7 65 | T_STRING_8_FLD 68 string - 1 String test field 8 66 | T_STRING_9_FLD 69 string - 1 String test field 9 67 | T_STRING_10_FLD 10 string - 1 String test field 10 68 | T_CARRAY_FLD 81 carray - 1 Carray test field 1 69 | T_CARRAY_2_FLD 82 carray - 1 Carray test field 2 70 | 71 | 72 | $#endif 73 | 74 | $/* vim: set ts=4 sw=4 et smartindent: */ 75 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=5 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | etclient ndrx=5 ubf=0 file=/tmp/07_CLIENT.log 4 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 1 79 | 1 80 | -e /tmp/tmsrv.log -r -- -t1 -l${NDRX_APPHOME}/var/tm 81 | 82 | 83 | 1 84 | 20 85 | 86 | 2 87 | libndrxxanulls.${NDRX_LIBEXT} 88 | 89 | -e /tmp/tmsrv2.log -r -- -t1 -l${NDRX_APPHOME}/var/tm2 90 | 91 | 92 | 1 93 | 100 94 | -e /tmp/tmqueue.log -r -- -q ${NDRX_APPHOME}/conf/q.conf -s1 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/conf/q.conf: -------------------------------------------------------------------------------- 1 | # 2 | # Queue defintions 3 | # @ - default Q 4 | # 5 | @,svcnm=-,autoq=n,tries=0,waitinit=0,waitretry=0,waitretryinc=0,waitretrymax=0,memonly=n,mode=fifo 6 | MYQ1,svcnm=-,autoq=n,tries=0,waitinit=0,waitretry=0,waitretryinc=0,waitretrymax=0,memonly=n,mode=fifo 7 | 8 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # Log & levels 71 | export NDRX_DMNLOG=/tmp/ndrxd.log 72 | export NDRX_DMNLEV=5 73 | 74 | export NDRX_LOG=/tmp/ndrx.log 75 | export NDRX_LEV=5 76 | 77 | 78 | # load the config if have one from tests 79 | 80 | if [ -f ~/ndrx_home ]; then 81 | . ~/ndrx_home 82 | fi 83 | 84 | 85 | # Correct the path so that ndrx can find ndrxd 86 | export PATH=$PATH:`pwd`/../bin 87 | 88 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 89 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 90 | # UBFTAB 91 | export FLDTBLDIR=`pwd`/../src/ubftab 92 | export FIELDTBLS=test.fd 93 | 94 | # 95 | # Exports for test case 96 | # 97 | export NDRX_APPHOME=`pwd`/.. 98 | 99 | # 100 | # XA Config for queues, according to manual: http://www.endurox.org/dokuwiki/doku.php?id=v2.5.x:guides:persistent_message_queues_overview 101 | # 102 | export NDRX_XA_RES_ID=1 103 | export NDRX_XA_OPEN_STR="datadir='$NDRX_APPHOME/var/qspace1',qspace='QSPACE1'" 104 | export NDRX_XA_CLOSE_STR=$NDRX_XA_OPEN_STR 105 | # Static registration: 106 | if [ "$(uname)" == "Darwin" ]; then 107 | export NDRX_XA_DRIVERLIB=libndrxxaqdisks.dylib 108 | export NDRX_XA_RMLIB=libndrxxaqdisk.dylib 109 | export NDRX_LIBEXT=dylib 110 | else 111 | 112 | export NDRX_XA_DRIVERLIB=libndrxxaqdisks.so 113 | export NDRX_XA_RMLIB=libndrxxaqdisk.so 114 | export NDRX_LIBEXT=so 115 | fi 116 | export NDRX_XA_LAZY_INIT=1 117 | 118 | echo "Using extensio: [$NDRX_LIBEXT]" 119 | 120 | # vim: set ts=4 sw=4 et smartindent: 121 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | 8 | # 9 | # cleanup any leftovers from previous cases 10 | # 11 | rm -rf var/qspace1/prepared 2>/dev/null 12 | rm -rf var/qspace1/committed 2>/dev/null 13 | rm -rf var/qspace1/active 2>/dev/null 14 | rm -rf var/tm2 2>/dev/null 15 | mkdir var/tm2 16 | 17 | pushd . 18 | cd conf 19 | . setndrx 20 | popd 21 | 22 | # Seems on freebsd we have an issue with stack sizes, as cgo limit is 2M 23 | # Support #251 24 | export NDRX_MSGSIZEMAX=100000 25 | 26 | # Start the enduro/x app server (which will boot the our server executable) 27 | 28 | xadmin down -y 29 | xadmin start -y 30 | 31 | # 32 | # Move process to RM2/NULL switch 33 | # 34 | export NDRX_XA_RES_ID=2 35 | export NDRX_XA_DRIVERLIB=libndrxxanulls.${NDRX_LIBEXT} 36 | 37 | # should print some hello world 38 | etclient 39 | 40 | RET=$? 41 | 42 | 43 | echo "Exit $RET" 44 | 45 | # shutdown the app server 46 | xadmin stop -c -y 47 | 48 | exit $RET 49 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C etclient 3 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/src/etclient/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/etclient: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/src/etclient/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/07_basic_durable_queue/src/etclient 2 | 3 | require ( 4 | atmi v1.0.0 5 | ) 6 | 7 | replace atmi v1.0.0 => ../../../../ 8 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/var/qspace1/README: -------------------------------------------------------------------------------- 1 | Here goes Persisted queue files 2 | -------------------------------------------------------------------------------- /tests/07_basic_durable_queue/var/tm/README: -------------------------------------------------------------------------------- 1 | Here goes Transaction Manager logs 2 | -------------------------------------------------------------------------------- /tests/08_logging/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/08_logging/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/08_logging/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=5 ubf=0 file= 4 | client ndrx=5 ubf=0 file=/tmp/08_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/08_logging/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 1 79 | 1 80 | 1 81 | -e /tmp/08_SERVER.log -r 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /tests/08_logging/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | 84 | # Correct the path so that ndrx can find ndrxd 85 | export PATH=$PATH:`pwd`/../bin 86 | 87 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 88 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 89 | # UBFTAB 90 | export FLDTBLDIR=`pwd`/../src/ubftab 91 | export FIELDTBLS=test.fd 92 | 93 | # vim: set ts=4 sw=4 et smartindent: 94 | -------------------------------------------------------------------------------- /tests/08_logging/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | 16 | # Run the client 17 | client 18 | 19 | RET=$? 20 | 21 | if [ "X$RET" != "X0" ]; then 22 | echo "Invalid exit code $RET" 23 | exit $RET 24 | fi 25 | 26 | # Test the logfile for content 27 | OUT=`grep '00 01 02 03 04 05 06 08 09' /tmp/08_client_process.log` 28 | if [[ "X$OUT" == "X" ]]; then 29 | echo "TESTERROR: [00 01 02 03 04 05 06 08 09] not found in /tmp/08_client_process.log" 30 | exit 1 31 | fi 32 | 33 | # Test the logfile for content 34 | OUT=`grep '02 03 04 05 06 07 08 09 0a' /tmp/08_client_process.log` 35 | if [[ "X$OUT" == "X" ]]; then 36 | echo "TESTERROR: [02 03 04 05 06 07 08 09 0a] not found in /tmp/08_client_process.log" 37 | exit 1 38 | fi 39 | 40 | # test Th1 41 | OUT=`grep 'Hello from TH1' /tmp/08_th1.log` 42 | if [[ "X$OUT" == "X" ]]; then 43 | echo "TESTERROR: [Hello from TH1] not found in /tmp/08_th1.log" 44 | exit 1 45 | fi 46 | 47 | # test Th2 48 | OUT=`grep 'Hello from TH2' /tmp/08_th2.log` 49 | if [[ "X$OUT" == "X" ]]; then 50 | echo "TESTERROR: [Hello from TH2] not found in /tmp/08_th2.log" 51 | exit 1 52 | fi 53 | 54 | # Test reqeust logging 55 | OUT=`grep 'HELLO FROM CLIENT' /tmp/08_request95.log` 56 | if [[ "X$OUT" == "X" ]]; then 57 | echo "TESTERROR: [HELLO FROM CLIENT] not found in /tmp/08_request95.log" 58 | exit 1 59 | fi 60 | 61 | 62 | OUT=`grep 'Hello World from userlog' /tmp/ULOG*` 63 | if [[ "X$OUT" == "X" ]]; then 64 | echo "TESTERROR: [Hello World from userlog] not found in /tmp/ULOG*" 65 | exit 2 66 | fi 67 | 68 | echo "Test OK" 69 | 70 | # shutdown the app server 71 | xadmin stop -c -y 72 | 73 | exit 0 74 | -------------------------------------------------------------------------------- /tests/08_logging/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C ubftab 3 | $(MAKE) -C server 4 | $(MAKE) -C client 5 | -------------------------------------------------------------------------------- /tests/08_logging/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/08_logging/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/08_logging/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/08_logging/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/08_logging/src/server/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/server: server.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/08_logging/src/server/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/08_logging/src/server 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/08_logging/src/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | "runtime" 8 | "ubftab" 9 | ) 10 | 11 | const ( 12 | SUCCEED = 0 13 | FAIL = -1 14 | ) 15 | 16 | var M_counter = 0 17 | 18 | //Set the request file 19 | func GETLOGFILE(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 20 | runtime.LockOSThread() 21 | ret := SUCCEED 22 | 23 | //Get UBF Handler 24 | ub, _ := ac.CastToUBF(&svc.Data) 25 | 26 | //Return to the caller 27 | defer func() { 28 | 29 | ac.TpLogCloseReqFile() 30 | if SUCCEED == ret { 31 | ac.TpReturn(atmi.TPSUCCESS, 0, ub, 0) 32 | } else { 33 | ac.TpReturn(atmi.TPFAIL, 0, ub, 0) 34 | } 35 | }() 36 | 37 | M_counter++ 38 | ac.TpLog(atmi.LOG_DEBUG, "Current counter = %d", M_counter) 39 | 40 | ac.TpLogSetReqFile(&svc.Data, fmt.Sprintf("/tmp/08_request%d.log", M_counter), "") 41 | 42 | ac.TpLog(atmi.LOG_WARN, "Hello from GETLOGFILE!") 43 | 44 | } 45 | 46 | //TESTSVC service 47 | func TESTSVC(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 48 | ret := SUCCEED 49 | 50 | //Get UBF Handler 51 | ub, _ := ac.CastToUBF(&svc.Data) 52 | 53 | ac.TpLogSetReqFile(&svc.Data, "", "") 54 | //Print the buffer to stdout 55 | 56 | ub.TpLogPrintUBF(atmi.LOG_ERROR, "Got call") 57 | 58 | //Resize buffer, to have some more space 59 | size, _ := ub.BSizeof() 60 | if err := ub.TpRealloc(size + 1024); err != nil { 61 | ac.TpLog(atmi.LOG_ERROR, "Got error: %d:[%s]\n", err.Code(), err.Message()) 62 | ret = FAIL 63 | goto out 64 | } 65 | 66 | //Set some field 67 | if err := ub.BAdd(ubftab.T_STRING_FLD, "Hello World from Enduro/X service"); err != nil { 68 | ac.TpLog(atmi.LOG_ERROR, "Got error: %d:[%s]\n", err.Code(), err.Message()) 69 | ret = FAIL 70 | goto out 71 | } 72 | //Set second occurance too of the T_STRING_FLD field 73 | if err := ub.BAdd(ubftab.T_STRING_FLD, "This is line2"); err != nil { 74 | ac.TpLog(atmi.LOG_ERROR, "Got error: %d:[%s]\n", err.Code(), err.Message()) 75 | ret = FAIL 76 | goto out 77 | } 78 | 79 | out: 80 | ac.TpLog(atmi.LOG_ERROR, "Returning... %d", ret) 81 | 82 | ac.TpLogCloseReqFile() 83 | 84 | ac.TpLog(atmi.LOG_DEBUG, "bank to main") 85 | 86 | //Return to the caller 87 | if SUCCEED == ret { 88 | ac.TpReturn(atmi.TPSUCCESS, 0, ub, 0) 89 | } else { 90 | ac.TpReturn(atmi.TPFAIL, 0, ub, 0) 91 | } 92 | return 93 | } 94 | 95 | //Server init 96 | func Init(ac *atmi.ATMICtx) int { 97 | 98 | //Configure logger 99 | ac.TpLogConfig(atmi.LOG_FACILITY_NDRX|atmi.LOG_FACILITY_UBF|atmi.LOG_FACILITY_TP, 100 | -1, "file=/tmp/08_server.log ndrx=5 ubf=0 tp=5", "SRV", "") 101 | 102 | //Advertize TESTSVC 103 | if err := ac.TpAdvertise("TESTSVC", "TESTSVC", TESTSVC); err != nil { 104 | ac.TpLog(atmi.LOG_ERROR, fmt.Sprint(err)) 105 | return atmi.FAIL 106 | } 107 | 108 | if err := ac.TpAdvertise("GETLOGFILE", "GETLOGFILE", GETLOGFILE); err != nil { 109 | ac.TpLog(atmi.LOG_ERROR, fmt.Sprint(err)) 110 | return atmi.FAIL 111 | } 112 | 113 | return atmi.SUCCEED 114 | } 115 | 116 | //Server shutdown 117 | func Uninit(ac *atmi.ATMICtx) { 118 | fmt.Println("Server shutting down...") 119 | } 120 | 121 | //Executable main entry point 122 | func main() { 123 | //Have some context 124 | ac, err := atmi.NewATMICtx() 125 | 126 | if nil != err { 127 | fmt.Errorf("Failed to allocate cotnext!", err) 128 | os.Exit(atmi.FAIL) 129 | } else { 130 | //Run as server 131 | ac.TpRun(Init, Uninit) 132 | ac.FreeATMICtx() 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /tests/08_logging/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | go install 7 | 8 | -------------------------------------------------------------------------------- /tests/08_logging/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/01_basic_ubf_call/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/08_logging/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CHAR_FLD 11 char - 1 Chart test field 1 46 | T_CHAR_2_FLD 12 char - 1 Chart test field 2 47 | T_SHORT_FLD 21 short - 1 Short test field 1 48 | T_SHORT_2_FLD 22 short - 1 Short test field 2 49 | T_LONG_FLD 31 long - 1 Long test field 1 50 | T_LONG_2_FLD 32 long - 1 Long test field 2 51 | T_FLOAT_FLD 41 float - 1 Float test field 1 52 | T_FLOAT_2_FLD 42 float - 1 Float test field 2 53 | T_FLOAT_3_FLD 43 float - 1 Float test field 3 54 | T_DOUBLE_FLD 51 double - 1 Double test field 1 55 | T_DOUBLE_2_FLD 52 double - 1 Double test field 2 56 | T_DOUBLE_3_FLD 53 double - 1 Double test field 3 57 | T_DOUBLE_4_FLD 54 double - 1 Double test field 4 58 | T_STRING_FLD 61 string - 1 String test field 1 59 | T_STRING_2_FLD 62 string - 1 String test field 2 60 | T_STRING_3_FLD 63 string - 1 String test field 3 61 | T_STRING_4_FLD 64 string - 1 String test field 4 62 | T_STRING_5_FLD 65 string - 1 String test field 5 63 | T_STRING_6_FLD 66 string - 1 String test field 6 64 | T_STRING_7_FLD 67 string - 1 String test field 7 65 | T_STRING_8_FLD 68 string - 1 String test field 8 66 | T_STRING_9_FLD 69 string - 1 String test field 9 67 | T_STRING_10_FLD 10 string - 1 String test field 10 68 | T_CARRAY_FLD 81 carray - 1 Carray test field 1 69 | T_CARRAY_2_FLD 82 carray - 1 Carray test field 2 70 | 71 | 72 | $#endif 73 | 74 | $/* vim: set ts=4 sw=4 et smartindent: */ 75 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=3 ubf=0 tp=3 file=/tmp/09_SERVER.log 4 | client ndrx=3 ubf=0 tp=3 file=/tmp/09_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 5 | 6 6 | 1 7 | 1 8 | 5 9 | 20 10 | Y 11 | 12 | 13 | 1 14 | 2 15 | 1 16 | 2 17 | 10 18 | 40 19 | 30 20 | 1 21 | 22 | 23 | 24 | 1 25 | 1 26 | 1 27 | -e /tmp/09_SERVER.log -r 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | export FIELDTBLS=test.fd,Exfields 91 | 92 | # vim: set ts=4 sw=4 et smartindent: 93 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | rm /tmp/09_CLIENT.log 2>/dev/null 16 | 17 | # should print some hello world 18 | client 19 | 20 | RET=$? 21 | 22 | # shutdown the app server 23 | xadmin stop -c -y 24 | 25 | exit $? 26 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C ubftab 3 | $(MAKE) -C server 4 | $(MAKE) -C client 5 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/client/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | //"log" 7 | //http "net/http" 8 | //_ "net/http/pprof" 9 | "os" 10 | "strconv" 11 | "ubftab" 12 | ) 13 | 14 | const ( 15 | SUCCEED = 0 16 | FAIL = -1 17 | ) 18 | 19 | //Binary main entry 20 | func main() { 21 | 22 | ret := SUCCEED 23 | 24 | // Run profiler 25 | // go func() { 26 | // log.Println(http.ListenAndServe("localhost:6060", nil)) 27 | //}() 28 | 29 | for i := 0; i < 100000; i++ { 30 | 31 | ac, err := atmi.NewATMICtx() 32 | 33 | if nil != err { 34 | fmt.Errorf("Failed to allocate cotnext!", err) 35 | os.Exit(atmi.FAIL) 36 | } 37 | 38 | buf, err := ac.NewUBF(1024) 39 | 40 | if err != nil { 41 | ac.TpLogError("ATMI Error %s", err.Error()) 42 | ret = FAIL 43 | goto out 44 | } 45 | 46 | s := strconv.Itoa(i) 47 | 48 | //Set one field for call 49 | if errB := buf.BChg(ubftab.T_STRING_FLD, 0, s); nil != errB { 50 | ac.TpLogError("UBF Error: %s", errB.Error()) 51 | ret = FAIL 52 | goto out 53 | } 54 | 55 | //Call the server 56 | if _, err := ac.TpCall("TEST1", buf, 0); nil != err { 57 | ac.TpLogError("ATMI Error: %s", err.Error()) 58 | ret = FAIL 59 | goto out 60 | } 61 | 62 | res, errB := buf.BGetString(ubftab.T_STRING_3_FLD, 0) 63 | 64 | if nil!=errB { 65 | ac.TpLogError("UBF Error: %s", errB.Error()) 66 | ret = FAIL 67 | goto out 68 | } 69 | 70 | if res!=s { 71 | ac.TpLogError("Sent %s, but got [%s]") 72 | } 73 | 74 | ac.TpTerm() 75 | ac.FreeATMICtx() 76 | } 77 | 78 | out: 79 | //Close the ATMI session 80 | 81 | os.Exit(ret) 82 | } 83 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/09_return_manual_buffer/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/server/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/server: server.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/server/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/09_return_manual_buffer/src/server 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | "ubftab" 8 | ) 9 | 10 | const ( 11 | SUCCEED = 0 12 | FAIL = -1 13 | ) 14 | 15 | //TEST1 service 16 | //Read the value of the T_STRING_FLD, alloc new buffer and set T_STRING2_FLD 17 | //Forward to TEST2 service 18 | func TEST1(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 19 | 20 | ret := SUCCEED 21 | 22 | //Get UBF Handler 23 | ub, _ := ac.CastToUBF(&svc.Data) 24 | 25 | //Return to the caller 26 | defer func() { 27 | 28 | ac.TpLogCloseReqFile() 29 | if SUCCEED == ret { 30 | ac.TpForward("TEST2", ub, 0) 31 | } else { 32 | ac.TpReturn(atmi.TPFAIL, 0, ub, 0) 33 | } 34 | }() 35 | 36 | //Set some field 37 | f, errB := ub.BGetString(ubftab.T_STRING_FLD, 0) 38 | 39 | if errB != nil { 40 | ac.TpLogError("Bget() Got error: %s", errB.Error()) 41 | ret = FAIL 42 | return 43 | } 44 | 45 | //Alloc new buffer 46 | ub, errA := ac.NewUBF(1024) 47 | 48 | if errA != nil { 49 | ac.TpLogError("ATMI Error: %s", errA.Error()) 50 | ret=FAIL 51 | return 52 | } 53 | 54 | //Set one field for call 55 | if errB = ub.BChg(ubftab.T_STRING_2_FLD, 0, f); nil != errB { 56 | fmt.Printf("UBF Error: %s", errB.Error()) 57 | ret = FAIL 58 | return 59 | } 60 | } 61 | 62 | //TEST2 service 63 | //Read the value of the T_STRING2_FLD, alloc new buffer and set T_STRING3_FLD 64 | //And return 65 | func TEST2(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 66 | 67 | ret := SUCCEED 68 | 69 | //Get UBF Handler 70 | ub, _ := ac.CastToUBF(&svc.Data) 71 | 72 | //Return to the caller 73 | defer func() { 74 | 75 | ac.TpLogCloseReqFile() 76 | if SUCCEED == ret { 77 | ac.TpReturn(atmi.TPSUCCESS, 0, ub, 0) 78 | } else { 79 | ac.TpReturn(atmi.TPFAIL, 0, ub, 0) 80 | } 81 | }() 82 | 83 | //Set some field 84 | f, errB := ub.BGetString(ubftab.T_STRING_2_FLD, 0) 85 | 86 | if errB != nil { 87 | ac.TpLogError("Bget() Got error: %s", errB.Error()) 88 | ret = FAIL 89 | return 90 | } 91 | 92 | //Alloc new buffer 93 | ub, errA := ac.NewUBF(1024) 94 | 95 | if errA != nil { 96 | ac.TpLogError("ATMI Error: %s", errA.Error()) 97 | ret=FAIL 98 | return 99 | } 100 | 101 | //Set one field for call 102 | if errB = ub.BChg(ubftab.T_STRING_3_FLD, 0, f); nil != errB { 103 | fmt.Printf("UBF Error: %s", errB.Error()) 104 | ret = FAIL 105 | return 106 | } 107 | } 108 | 109 | 110 | //Server init 111 | func Init(ac *atmi.ATMICtx) int { 112 | 113 | //Advertize TEST1 114 | if err := ac.TpAdvertise("TEST1", "TEST1", TEST1); err != nil { 115 | ac.TpLogError("TpAdvertise fail: %s", err.Error()) 116 | return atmi.FAIL 117 | } 118 | 119 | //Advertize TEST2 120 | if err := ac.TpAdvertise("TEST2", "TEST2", TEST2); err != nil { 121 | ac.TpLogError("TpAdvertise fail: %s", err.Error()) 122 | return atmi.FAIL 123 | } 124 | 125 | return atmi.SUCCEED 126 | } 127 | 128 | //Server shutdown 129 | func Uninit(ac *atmi.ATMICtx) { 130 | fmt.Println("Server shutting down...") 131 | } 132 | 133 | //Executable main entry point 134 | func main() { 135 | //Have some context 136 | ac, err := atmi.NewATMICtx() 137 | 138 | if nil != err { 139 | fmt.Errorf("Failed to allocate cotnext!", err) 140 | os.Exit(atmi.FAIL) 141 | } else { 142 | //Run as server 143 | ac.TpRun(Init, Uninit) 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | go install 7 | 8 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/09_return_manual_buffer/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/09_return_manual_buffer/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CHAR_FLD 11 char - 1 Chart test field 1 46 | T_CHAR_2_FLD 12 char - 1 Chart test field 2 47 | T_SHORT_FLD 21 short - 1 Short test field 1 48 | T_SHORT_2_FLD 22 short - 1 Short test field 2 49 | T_LONG_FLD 31 long - 1 Long test field 1 50 | T_LONG_2_FLD 32 long - 1 Long test field 2 51 | T_FLOAT_FLD 41 float - 1 Float test field 1 52 | T_FLOAT_2_FLD 42 float - 1 Float test field 2 53 | T_FLOAT_3_FLD 43 float - 1 Float test field 3 54 | T_DOUBLE_FLD 51 double - 1 Double test field 1 55 | T_DOUBLE_2_FLD 52 double - 1 Double test field 2 56 | T_DOUBLE_3_FLD 53 double - 1 Double test field 3 57 | T_DOUBLE_4_FLD 54 double - 1 Double test field 4 58 | T_STRING_FLD 61 string - 1 String test field 1 59 | T_STRING_2_FLD 62 string - 1 String test field 2 60 | T_STRING_3_FLD 63 string - 1 String test field 3 61 | T_STRING_4_FLD 64 string - 1 String test field 4 62 | T_STRING_5_FLD 65 string - 1 String test field 5 63 | T_STRING_6_FLD 66 string - 1 String test field 6 64 | T_STRING_7_FLD 67 string - 1 String test field 7 65 | T_STRING_8_FLD 68 string - 1 String test field 8 66 | T_STRING_9_FLD 69 string - 1 String test field 9 67 | T_STRING_10_FLD 10 string - 1 String test field 10 68 | T_CARRAY_FLD 81 carray - 1 Carray test field 1 69 | T_CARRAY_2_FLD 82 carray - 1 Carray test field 2 70 | 71 | 72 | $#endif 73 | 74 | $/* vim: set ts=4 sw=4 et smartindent: */ 75 | -------------------------------------------------------------------------------- /tests/10_views/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/10_views/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/10_views/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= iflags=detailed 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=2 ubf=0 tp=2 file=/tmp/10_SERVER.log 4 | client ndrx=2 ubf=3 tp=2 file=/tmp/10_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/10_views/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 5 | 6 6 | 1 7 | 1 8 | 5 9 | 20 10 | Y 11 | 12 | 13 | 1 14 | 2 15 | 1 16 | 2 17 | 10 18 | 40 19 | 30 20 | 1 21 | 22 | 23 | 24 | 1 25 | 1 26 | 1 27 | -e /tmp/10_SERVER.log -r 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/10_views/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | export FIELDTBLS=test.fd,Exfields 91 | export VIEWDIR=`pwd`/../src/viewdir 92 | export VIEWFILES=t40.V 93 | 94 | # vim: set ts=4 sw=4 et smartindent: 95 | -------------------------------------------------------------------------------- /tests/10_views/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin down -y 15 | xadmin start -y 16 | rm /tmp/09_CLIENT.log 2>/dev/null 17 | 18 | # should print some hello world 19 | client 20 | 21 | RET=$? 22 | 23 | # shutdown the app server 24 | xadmin stop -c -y 25 | 26 | exit $? 27 | -------------------------------------------------------------------------------- /tests/10_views/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C viewdir 3 | $(MAKE) -C ubftab 4 | $(MAKE) -C server 5 | $(MAKE) -C client 6 | -------------------------------------------------------------------------------- /tests/10_views/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/10_views/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/10_views/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/10_views/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/10_views/src/server/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/server: server.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/10_views/src/server/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/10_views/src/server 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/10_views/src/server/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "atmi" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | const ( 10 | SUCCEED = 0 11 | FAIL = -1 12 | ) 13 | 14 | var M_prev int16 = -1 15 | var M_ret int 16 | var M_ac *atmi.ATMICtx 17 | 18 | func assertEqual(a interface{}, b interface{}, message string) { 19 | aa := fmt.Sprintf("%v", a) 20 | bb := fmt.Sprintf("%v", b) 21 | 22 | if aa == bb { 23 | return 24 | } 25 | msg2 := fmt.Sprintf("%v != %v", a, b) 26 | M_ac.TpLogError("%s: %s", message, msg2) 27 | M_ret = FAIL 28 | } 29 | 30 | //TEST1 service 31 | //Read the value of the T_STRING_FLD, alloc new buffer and set T_STRING2_FLD 32 | //Forward to TEST2 service 33 | func TEST1(ac *atmi.ATMICtx, svc *atmi.TPSVCINFO) { 34 | 35 | M_ret = SUCCEED 36 | M_ac = ac 37 | 38 | //Get UBF Handler 39 | v, err := ac.CastToVIEW(&svc.Data) 40 | if err != nil { 41 | ac.TpLogError("Failed to cast to view: %s", err.Error()) 42 | M_ret = FAIL 43 | return //drop the message... 44 | } 45 | 46 | //Return to the caller 47 | defer func() { 48 | if SUCCEED == M_ret { 49 | ac.TpReturn(atmi.TPSUCCESS, 0, v, 0) 50 | } else { 51 | ac.TpReturn(atmi.TPFAIL, 0, v, 0) 52 | } 53 | }() 54 | 55 | //////////////////////////////////////////////////////////////////////// 56 | //Test the values received 57 | //////////////////////////////////////////////////////////////////////// 58 | tshort1, errV := v.BVGetInt16("tshort1", 0, 0) 59 | assertEqual(errV, nil, "tshort1 -> errV") 60 | 61 | if M_prev == tshort1 { 62 | ac.TpLogError("Short match prev: %d vs %d", M_prev, 63 | tshort1) 64 | M_ret = FAIL 65 | return 66 | } 67 | 68 | tint2, errV := v.BVGetInt("tint2", 1, 0) 69 | assertEqual(tint2, 123456789, "tint2") 70 | assertEqual(errV, nil, "tint2 -> errV") 71 | 72 | tchar2, errV := v.BVGetString("tchar2", 4, 0) 73 | assertEqual(tchar2, "C", "tchar2") 74 | assertEqual(errV, nil, "tchar2 -> errV") 75 | 76 | tfloat2, errV := v.BVGetFloat32("tfloat2", 0, 0) 77 | assertEqual(tfloat2, 0.11, "tfloat2") 78 | assertEqual(errV, nil, "tfloat2 -> errV") 79 | 80 | tdouble2, errV := v.BVGetFloat64("tdouble2", 0, 0) 81 | assertEqual(tdouble2, 110.099, "tdouble2") 82 | assertEqual(errV, nil, "tdouble2 -> errV") 83 | 84 | tstring0, errV := v.BVGetString("tstring0", 2, 0) 85 | assertEqual(tstring0, "HELLO ENDURO", "tstring0") 86 | assertEqual(errV, nil, "tstring0 -> errV") 87 | 88 | b := []byte{0, 1, 2, 3, 4, 5} 89 | 90 | tcarray2, errV := v.BVGetByteArr("tcarray2", 0, 0) 91 | for i := 0; i < 5; i++ { 92 | assertEqual(tcarray2[i], b[i], "tcarray2") 93 | } 94 | //assertEqual(tcarray2, b, "tcarray2") 95 | assertEqual(errV, nil, "tcarray2 -> errV") 96 | //////////////////////////////////////////////////////////////////////// 97 | //Test BVACCESS_NOTNULL functionality... 98 | //////////////////////////////////////////////////////////////////////// 99 | 100 | tshort2, errV := v.BVGetInt16("tshort2", 1, 0) 101 | assertEqual(tshort2, 2001, "tshort2") 102 | assertEqual(errV, nil, "tshort2 -> errV") 103 | 104 | tshort2_2, errV := v.BVGetInt16("tshort2", 1, atmi.BVACCESS_NOTNULL) 105 | assertEqual(tshort2_2, 0, "tshort2") 106 | assertEqual(errV.Code(), atmi.BNOTPRES, "tshort2_2 -> must not be present"+ 107 | " with atmi.BVACCESS_NOTNULL") 108 | 109 | _, errV = v.BVGetInt16("tshortX", 1, atmi.BVACCESS_NOTNULL) 110 | assertEqual(errV.Code(), atmi.BNOCNAME, "tshortX") 111 | 112 | v, err = ac.NewVIEW("MYVIEW2", 0) 113 | if err != nil { 114 | ac.TpLogError("Failed to cast to view: %s", err.Error()) 115 | M_ret = FAIL 116 | return 117 | } 118 | 119 | if errB := v.BVChg("ttshort1", 0, 2233); nil != errB { 120 | ac.TpLogError("VIEW Error: %s", errB.Error()) 121 | M_ret = FAIL 122 | return 123 | } 124 | 125 | if errB := v.BVChg("ttstring1", 0, "HELLO ENDURO"); nil != errB { 126 | ac.TpLogError("VIEW Error: %s", errB.Error()) 127 | M_ret = FAIL 128 | return 129 | } 130 | } 131 | 132 | //Server init 133 | func Init(ac *atmi.ATMICtx) int { 134 | 135 | //Advertize TEST1 136 | if err := ac.TpAdvertise("TEST1", "TEST1", TEST1); err != nil { 137 | ac.TpLogError("TpAdvertise fail: %s", err.Error()) 138 | return atmi.FAIL 139 | } 140 | 141 | return atmi.SUCCEED 142 | } 143 | 144 | //Server shutdown 145 | func Uninit(ac *atmi.ATMICtx) { 146 | fmt.Println("Server shutting down...") 147 | } 148 | 149 | //Executable main entry point 150 | func main() { 151 | //Have some context 152 | ac, err := atmi.NewATMICtx() 153 | 154 | if nil != err { 155 | fmt.Errorf("Failed to allocate cotnext: %s!", err.Message()) 156 | os.Exit(atmi.FAIL) 157 | } else { 158 | //Run as server 159 | ac.TpRun(Init, Uninit) 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /tests/10_views/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | go install 7 | 8 | -------------------------------------------------------------------------------- /tests/10_views/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/10_views/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/10_views/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CHAR_FLD 11 char - 1 Chart test field 1 46 | T_CHAR_2_FLD 12 char - 1 Chart test field 2 47 | T_CHAR_3_FLD 13 char - 1 Chart test field 3 48 | T_SHORT_FLD 21 short - 1 Short test field 1 49 | T_SHORT_2_FLD 22 short - 1 Short test field 2 50 | T_SHORT_3_FLD 23 short - 1 Short test field 3 51 | T_LONG_FLD 31 long - 1 Long test field 1 52 | T_LONG_2_FLD 32 long - 1 Long test field 2 53 | T_LONG_3_FLD 33 long - 1 Long test field 3 54 | T_FLOAT_FLD 41 float - 1 Float test field 1 55 | T_FLOAT_2_FLD 42 float - 1 Float test field 2 56 | T_FLOAT_3_FLD 43 float - 1 Float test field 3 57 | T_DOUBLE_FLD 51 double - 1 Double test field 1 58 | T_DOUBLE_2_FLD 52 double - 1 Double test field 2 59 | T_DOUBLE_3_FLD 53 double - 1 Double test field 3 60 | T_DOUBLE_4_FLD 54 double - 1 Double test field 4 61 | T_STRING_FLD 61 string - 1 String test field 1 62 | T_STRING_2_FLD 62 string - 1 String test field 2 63 | T_STRING_3_FLD 63 string - 1 String test field 3 64 | T_STRING_4_FLD 64 string - 1 String test field 4 65 | T_STRING_5_FLD 65 string - 1 String test field 5 66 | T_STRING_6_FLD 66 string - 1 String test field 6 67 | T_STRING_7_FLD 67 string - 1 String test field 7 68 | T_STRING_8_FLD 68 string - 1 String test field 8 69 | T_STRING_9_FLD 69 string - 1 String test field 9 70 | T_STRING_10_FLD 10 string - 1 String test field 10 71 | T_CARRAY_FLD 81 carray - 1 Carray test field 1 72 | T_CARRAY_2_FLD 82 carray - 1 Carray test field 2 73 | T_CARRAY_3_FLD 83 carray - 1 Carray test field 3 74 | 75 | 76 | $#endif 77 | 78 | $/* vim: set ts=4 sw=4 et smartindent: */ 79 | -------------------------------------------------------------------------------- /tests/10_views/src/viewdir/Makefile: -------------------------------------------------------------------------------- 1 | 2 | unexport VIEWDIR 3 | unexport VIEWFILES 4 | # 5 | # This for AIX, we always run in 64bit mode 6 | # 7 | export OBJECT_MODE=64 8 | 9 | .DEFAULT_GOAL := t40.V 10 | 11 | t40.V: t40.v_in 12 | viewc -n t40.v_in 13 | 14 | 15 | clean: 16 | rm *.V 17 | -------------------------------------------------------------------------------- /tests/10_views/src/viewdir/t40.v_in: -------------------------------------------------------------------------------- 1 | VIEW MYVIEW1 2 | #type cname fbname count flag size null 3 | 4 | short tshort1 T_SHORT_FLD 1 FS - 2000 5 | short tshort2 T_SHORT_2_FLD 2 FSC - 2001 6 | short tshort3 T_SHORT_3_FLD 3 FSC - - 7 | short tshort4 - 1 N - NONE 8 | 9 | long tlong1 T_LONG_FLD 1 FS - 0 10 | int tint2 T_LONG_2_FLD 2 FS - 0 11 | int tint3 - 1 - - -1 12 | int tint4 - 2 - - -1 13 | 14 | char tchar1 T_CHAR_FLD 1 F - '\n' 15 | char tchar2 T_CHAR_2_FLD 5 SC - 'A' 16 | char tchar3 T_CHAR_3_FLD 2 CN - - 17 | 18 | float tfloat1 T_FLOAT_FLD 4 FS - 1.1 19 | float tfloat2 T_FLOAT_2_FLD 2 S - - 20 | float tfloat3 - 1 N - 9999.99 21 | 22 | double tdouble1 T_DOUBLE_FLD 2 FS - 55555.99 23 | double tdouble2 T_DOUBLE_2_FLD 1 F - -999.123 24 | 25 | string tstring0 - 3 - 18 '\n\t\f\\\'\"\vHELLOWORLD' 26 | string tstring1 T_STRING_FLD 3 FSP 20 'HELLO WORLDB' 27 | string tstring2 T_STRING_2_FLD 3 FCL 20 - 28 | string tstring3 T_STRING_3_FLD 4 FSCL 20 'TESTEST' 29 | string tstring4 - 1 P 15 'HELLO TEST' 30 | string tstring5 - 1 - 15 'MEGA TEST' 31 | 32 | carray tcarray1 T_CARRAY_FLD 1 FS 30 '\0\n\t\f\\\'\"\vHELLOWORLD' 33 | carray tcarray2 T_CARRAY_2_FLD 1 LFSP 25 '\0\n\t\f\\\'\"\vHELLOWORL\n' 34 | carray tcarray3 T_CARRAY_3_FLD 10 FSCLP 30 '\0\\\nABC\t\f\'\vHELLO' 35 | carray tcarray4 - 1 - 5 'ABC' 36 | carray tcarray5 - 1 - 5 - 37 | 38 | END 39 | 40 | 41 | VIEW MYVIEW2 42 | #type cname fbname count flag size null 43 | short ttshort1 - 1 - - 2000 44 | long ttlong1 - 1 - - 5 45 | char ttchar1 - 1 - - '\0' 46 | float ttfloat1 - 1 - - 1.1 47 | double ttdouble1 - 1 - - 0.0 48 | string ttstring1 - 1 P 15 'HELLO WORLDB' 49 | carray ttcarray1 - 1 - 10 '-' 50 | END 51 | 52 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=5 ubf=0 file= 4 | client ndrx=5 ubf=0 file=/tmp/01_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | #export FIELDTBLS=test.fd,Exfields 91 | export FIELDTBLS=test.fd 92 | 93 | # vim: set ts=4 sw=4 et smartindent: 94 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | 16 | # should print some hello world 17 | client 18 | 19 | ret=$? 20 | 21 | if [[ $ret -eq 0 ]]; then 22 | echo "Test OK" 23 | else 24 | echo "Test failed" 25 | fi 26 | 27 | # shutdown the app server 28 | xadmin stop -c -y 29 | 30 | exit $ret 31 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C ubftab 3 | $(MAKE) -C client 4 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/11_ubf_tests/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/11_ubf_tests/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | go install 7 | 8 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/11_ubf_tests/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/11_ubf_tests/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CHAR_FLD 11 char - 1 Chart test field 1 46 | T_CHAR_2_FLD 12 char - 1 Chart test field 2 47 | T_SHORT_FLD 21 short - 1 Short test field 1 48 | T_SHORT_2_FLD 22 short - 1 Short test field 2 49 | T_LONG_FLD 31 long - 1 Long test field 1 50 | T_LONG_2_FLD 32 long - 1 Long test field 2 51 | T_FLOAT_FLD 41 float - 1 Float test field 1 52 | T_FLOAT_2_FLD 42 float - 1 Float test field 2 53 | T_FLOAT_3_FLD 43 float - 1 Float test field 3 54 | T_DOUBLE_FLD 51 double - 1 Double test field 1 55 | T_DOUBLE_2_FLD 52 double - 1 Double test field 2 56 | T_DOUBLE_3_FLD 53 double - 1 Double test field 3 57 | T_DOUBLE_4_FLD 54 double - 1 Double test field 4 58 | T_STRING_FLD 61 string - 1 String test field 1 59 | T_STRING_2_FLD 62 string - 1 String test field 2 60 | T_STRING_3_FLD 63 string - 1 String test field 3 61 | T_STRING_4_FLD 64 string - 1 String test field 4 62 | T_STRING_5_FLD 65 string - 1 String test field 5 63 | T_STRING_6_FLD 66 string - 1 String test field 6 64 | T_STRING_7_FLD 67 string - 1 String test field 7 65 | T_STRING_8_FLD 68 string - 1 String test field 8 66 | T_STRING_9_FLD 69 string - 1 String test field 9 67 | T_STRING_10_FLD 10 string - 1 String test field 10 68 | T_CARRAY_FLD 81 carray - 1 Carray test field 1 69 | T_CARRAY_2_FLD 82 carray - 1 Carray test field 2 70 | 71 | 72 | $#endif 73 | 74 | $/* vim: set ts=4 sw=4 et smartindent: */ 75 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/BSDmakefile: -------------------------------------------------------------------------------- 1 | all clean: 2 | gmake $@ 3 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/Makefile: -------------------------------------------------------------------------------- 1 | export GOPATH=$(shell pwd) 2 | export GO111MODULE=auto 3 | 4 | all: 5 | $(MAKE) -C src 6 | 7 | clean: 8 | rm -rf pkg bin 9 | 10 | 11 | 12 | .PHONY: clean all 13 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/conf/debug.conf: -------------------------------------------------------------------------------- 1 | * ndrx=0 ubf=0 lines=1 bufsz=1000 file= 2 | xadmin file=/tmp/xadmin.log ubf=0 3 | server ndrx=5 ubf=0 file= 4 | client ndrx=5 ubf=0 file=/tmp/01_CLIENT.log 5 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/conf/ndrxconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 5 7 | 10 | 6 11 | 12 | 13 | 14 | 15 | 19 | 20 | 1 21 | 22 | 1 23 | 24 | 5 25 | 26 | 27 | 29 | 20 30 | 31 | 36 | Y 37 | 38 | 39 | 40 | 1 41 | 2 42 | 43 | 1 44 | 47 | 50 | 54 | 2 55 | 58 | 10 59 | 64 | 40 65 | 69 | 30 70 | 72 | 1 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/conf/setndrx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## 3 | ## @brief Enduro X Configuration File 4 | ## 5 | ## @file setndrx 6 | ## 7 | ## ----------------------------------------------------------------------------- 8 | ## Enduro/X Middleware Platform for Distributed Transaction Processing 9 | ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | ## Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | ## This software is released under one of the following licenses: 12 | ## LGPL or Mavimax's license for commercial use. 13 | ## See LICENSE file for full text. 14 | ## 15 | ## C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | ## under Enduro/X Modified GNU Affero General Public License, version 3. 17 | ## See LICENSE_C file for full text. 18 | ## ----------------------------------------------------------------------------- 19 | ## LGPL license: 20 | ## 21 | ## This program is free software; you can redistribute it and/or modify it under 22 | ## the terms of the GNU Lesser General Public License, version 3 as published 23 | ## by the Free Software Foundation; 24 | ## 25 | ## This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | ## PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | ## for more details. 29 | ## 30 | ## You should have received a copy of the Lesser General Public License along 31 | ## with this program; if not, write to the Free Software Foundation, Inc., 32 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | ## 34 | ## ----------------------------------------------------------------------------- 35 | ## A commercial use license is available from Mavimax, Ltd 36 | ## contact@mavimax.com 37 | ## ----------------------------------------------------------------------------- 38 | ## 39 | 40 | export NDRX_NODEID=1 41 | # If 1 - then yes, if 0 - then not clusterised. 42 | export NDRX_CLUSTERISED=1 43 | # Load balance, 0 = process all locally, 100 = process all on remote servers 44 | export NDRX_LDBAL=0 45 | export NDRX_TOUT=60 46 | export NDRX_ULOG=/tmp 47 | export NDRX_QPREFIX=/n00b 48 | export NDRX_SVCMAX=20000 49 | export NDRX_SRVMAX=10000 50 | export NDRX_QPATH=/dev/mqueue 51 | export NDRX_SHMPATH=/dev/shm 52 | # Milli seconds to wait for command 53 | export NDRX_CMDWAIT=1 54 | export NDRX_DPID=/tmp/ndrxd.pid 55 | # Random key to indentify the processes beloning to this session (i.e. used in ps ef) 56 | export NDRX_RNDK="0myWI5nu" 57 | # System V Semaphores... 58 | export NDRX_IPCKEY=44000 59 | 60 | # Posix queue config (attribs..) 61 | # Max number of messages that can be put in one queue 62 | export NDRX_MSGMAX=1000 63 | # Daemon Q size... 64 | export NDRX_DQMAX=100 65 | # Max message size (in bytes) 66 | export NDRX_MSGSIZEMAX=10000 67 | # Max fields for hashing UBF 68 | export NDRX_UBFMAXFLDS=16000 69 | 70 | # load the config if have one from tests 71 | 72 | if [ -f ~/ndrx_home ]; then 73 | . ~/ndrx_home 74 | fi 75 | 76 | # Log & levels 77 | export NDRX_DMNLOG=/tmp/ndrxd.log 78 | export NDRX_DMNLEV=5 79 | 80 | export NDRX_LOG=/tmp/ndrx.log 81 | export NDRX_LEV=5 82 | 83 | # Correct the path so that ndrx can find ndrxd 84 | export PATH=$PATH:`pwd`/../bin 85 | 86 | export NDRX_CONFIG=`pwd`/ndrxconfig.xml 87 | export NDRX_DEBUG_CONF=`pwd`/debug.conf 88 | # UBFTAB 89 | export FLDTBLDIR=`pwd`/../src/ubftab 90 | #export FIELDTBLS=test.fd,Exfields 91 | export FIELDTBLS=test.fd 92 | 93 | # vim: set ts=4 sw=4 et smartindent: 94 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Run the test case 5 | # 6 | 7 | pushd . 8 | cd conf 9 | . setndrx 10 | popd 11 | 12 | # Start the enduro/x app server (which will boot the our server executable) 13 | 14 | xadmin start -y 15 | 16 | # should print some hello world 17 | #valgrind --tool=memcheck --leak-check=yes client 18 | client 19 | 20 | ret=$? 21 | 22 | if [[ $ret -eq 0 ]]; then 23 | echo "Test OK" 24 | else 25 | echo "Test failed" 26 | fi 27 | 28 | # shutdown the app server 29 | xadmin stop -c -y 30 | 31 | exit $ret 32 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/src/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C ubftab 3 | $(MAKE) -C client 4 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/src/atmi: -------------------------------------------------------------------------------- 1 | ../../.. -------------------------------------------------------------------------------- /tests/12_tpimportexp/src/client/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build 3 | GOBIN=$(dir $(abspath $@)) go install 4 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/src/client/data.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | #include 5 | */ 6 | import "C" 7 | 8 | import ( 9 | "atmi" 10 | "fmt" 11 | "ubftab" 12 | ) 13 | 14 | var M_b1 []byte 15 | var M_b2 []byte 16 | 17 | // 18 | //Load test data into buffer 19 | // 20 | func loadbufferdata(buf *atmi.TypedUBF) atmi.ATMIError { 21 | if err := buf.BChg(ubftab.T_CHAR_FLD, 0, 65); nil != err { 22 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 23 | return err 24 | } 25 | 26 | if err := buf.BChg(ubftab.T_CHAR_FLD, 1, 66); nil != err { 27 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 28 | return err 29 | } 30 | 31 | if err := buf.BChg(ubftab.T_SHORT_FLD, 0, 32000); nil != err { 32 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 33 | return err 34 | } 35 | 36 | if err := buf.BChg(ubftab.T_SHORT_FLD, 1, 32001); nil != err { 37 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 38 | return err 39 | } 40 | 41 | if err := buf.BChg(ubftab.T_LONG_FLD, 0, 199101); nil != err { 42 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 43 | return err 44 | } 45 | 46 | if err := buf.BChg(ubftab.T_LONG_FLD, 1, 199102); nil != err { 47 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 48 | return err 49 | } 50 | 51 | if err := buf.BChg(ubftab.T_FLOAT_FLD, 0, 9.11); nil != err { 52 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 53 | return err 54 | } 55 | 56 | if err := buf.BChg(ubftab.T_FLOAT_FLD, 1, 9.22); nil != err { 57 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 58 | return err 59 | } 60 | 61 | if err := buf.BChg(ubftab.T_DOUBLE_FLD, 0, 19910.888); nil != err { 62 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 63 | return err 64 | } 65 | 66 | if err := buf.BChg(ubftab.T_DOUBLE_FLD, 1, 19910.999); nil != err { 67 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 68 | return err 69 | } 70 | 71 | if err := buf.BChg(ubftab.T_STRING_FLD, 0, "HELLO STRING 1"); nil != err { 72 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 73 | return err 74 | } 75 | 76 | if err := buf.BChg(ubftab.T_STRING_FLD, 1, "HELLO STRING 2"); nil != err { 77 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 78 | return err 79 | } 80 | 81 | if err := buf.BChg(ubftab.T_CARRAY_FLD, 0, M_b1); nil != err { 82 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 83 | return err 84 | } 85 | 86 | if err := buf.BChg(ubftab.T_CARRAY_FLD, 1, M_b2); nil != err { 87 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 88 | return err 89 | } 90 | 91 | return nil 92 | } 93 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/src/client/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/12_tpimportexp/src/client 2 | 3 | require ( 4 | atmi v1.0.0 5 | ubftab v1.0.0 6 | ) 7 | 8 | replace atmi v1.0.0 => ../../../../ 9 | replace ubftab v1.0.0 => ../ubftab 10 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/src/ubftab/Makefile: -------------------------------------------------------------------------------- 1 | export FIELDTBLS=test.fd 2 | export FLDTBLDIR=$(shell pwd) 3 | 4 | test.go: test.fd 5 | mkfldhdr -m1 -pubftab 6 | go install 7 | 8 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/src/ubftab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/endurox-dev/endurox-go/tests/12_tpimportexp/src/ubftab 2 | 3 | -------------------------------------------------------------------------------- /tests/12_tpimportexp/src/ubftab/test.fd: -------------------------------------------------------------------------------- 1 | $/** 2 | $ * @brief Test UD file 3 | $ * Using values from here for test UBF library. 4 | $ * 5 | $ * @file test.fd.h 6 | $ */ 7 | $/* ----------------------------------------------------------------------------- 8 | $ * Enduro/X Middleware Platform for Distributed Transaction Processing 9 | $ * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 10 | $ * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 11 | $ * This software is released under one of the following licenses: 12 | $ * LGPL or Mavimax's license for commercial use. 13 | $ * See LICENSE file for full text. 14 | $ * 15 | $ * C (as designed by Dennis Ritchie and later authors) language code is licensed 16 | $ * under Enduro/X Modified GNU Affero General Public License, version 3. 17 | $ * See LICENSE_C file for full text. 18 | $ * ----------------------------------------------------------------------------- 19 | $ * LGPL license: 20 | $ * 21 | $ * This program is free software; you can redistribute it and/or modify it under 22 | $ * the terms of the GNU Lesser General Public License, version 3 as published 23 | $ * by the Free Software Foundation; 24 | $ * 25 | $ * This program is distributed in the hope that it will be useful, but WITHOUT ANY 26 | $ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 27 | $ * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 28 | $ * for more details. 29 | $ * 30 | $ * You should have received a copy of the Lesser General Public License along 31 | $ * with this program; if not, write to the Free Software Foundation, Inc., 32 | $ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 33 | $ * 34 | $ * ----------------------------------------------------------------------------- 35 | $ * A commercial use license is available from Mavimax, Ltd 36 | $ * contact@mavimax.com 37 | $ * ----------------------------------------------------------------------------- 38 | $ */ 39 | 40 | $#ifndef __TEST_FD 41 | $#define __TEST_FD 42 | 43 | *base 1000 44 | 45 | T_CHAR_FLD 11 char - 1 Chart test field 1 46 | T_CHAR_2_FLD 12 char - 1 Chart test field 2 47 | T_SHORT_FLD 21 short - 1 Short test field 1 48 | T_SHORT_2_FLD 22 short - 1 Short test field 2 49 | T_LONG_FLD 31 long - 1 Long test field 1 50 | T_LONG_2_FLD 32 long - 1 Long test field 2 51 | T_FLOAT_FLD 41 float - 1 Float test field 1 52 | T_FLOAT_2_FLD 42 float - 1 Float test field 2 53 | T_FLOAT_3_FLD 43 float - 1 Float test field 3 54 | T_DOUBLE_FLD 51 double - 1 Double test field 1 55 | T_DOUBLE_2_FLD 52 double - 1 Double test field 2 56 | T_DOUBLE_3_FLD 53 double - 1 Double test field 3 57 | T_DOUBLE_4_FLD 54 double - 1 Double test field 4 58 | T_STRING_FLD 61 string - 1 String test field 1 59 | T_STRING_2_FLD 62 string - 1 String test field 2 60 | T_STRING_3_FLD 63 string - 1 String test field 3 61 | T_STRING_4_FLD 64 string - 1 String test field 4 62 | T_STRING_5_FLD 65 string - 1 String test field 5 63 | T_STRING_6_FLD 66 string - 1 String test field 6 64 | T_STRING_7_FLD 67 string - 1 String test field 7 65 | T_STRING_8_FLD 68 string - 1 String test field 8 66 | T_STRING_9_FLD 69 string - 1 String test field 9 67 | T_STRING_10_FLD 10 string - 1 String test field 10 68 | T_CARRAY_FLD 81 carray - 1 Carray test field 1 69 | T_CARRAY_2_FLD 82 carray - 1 Carray test field 2 70 | 71 | 72 | $#endif 73 | 74 | $/* vim: set ts=4 sw=4 et smartindent: */ 75 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | # Do recursive builds 2 | all: 3 | $(MAKE) -C 01_basic_ubf_call 4 | $(MAKE) -C 02_basic_string_call 5 | $(MAKE) -C 03_basic_carray_call 6 | $(MAKE) -C 05_basic_json_call 7 | $(MAKE) -C 06_ubf_marshal 8 | $(MAKE) -C 07_basic_durable_queue 9 | $(MAKE) -C 08_logging 10 | $(MAKE) -C 09_return_manual_buffer 11 | $(MAKE) -C 10_views 12 | $(MAKE) -C 11_ubf_tests 13 | $(MAKE) -C 12_tpimportexp 14 | 15 | clean: 16 | $(MAKE) -C 01_basic_ubf_call clean 17 | $(MAKE) -C 02_basic_string_call clean 18 | $(MAKE) -C 03_basic_carray_call clean 19 | $(MAKE) -C 05_basic_json_call clean 20 | $(MAKE) -C 06_ubf_marshal clean 21 | $(MAKE) -C 07_basic_durable_queue clean 22 | $(MAKE) -C 08_logging clean 23 | $(MAKE) -C 09_return_manual_buffer clean 24 | $(MAKE) -C 10_views clean 25 | $(MAKE) -C 11_ubf_tests clean 26 | $(MAKE) -C 12_tpimportexp clean 27 | 28 | -------------------------------------------------------------------------------- /tests/README: -------------------------------------------------------------------------------- 1 | 04_distributed_transaction - this should be built manually. See readme in folder. 2 | -------------------------------------------------------------------------------- /tests/etclient/Makefile: -------------------------------------------------------------------------------- 1 | ../../bin/client: client.go 2 | go build && go install 3 | -------------------------------------------------------------------------------- /tests/etclient/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | #include 5 | */ 6 | import "C" 7 | 8 | import ( 9 | "atmi" 10 | "fmt" 11 | "os" 12 | "runtime" 13 | ) 14 | 15 | const ( 16 | SUCCEED = 0 17 | FAIL = -1 18 | ) 19 | 20 | //Binary main entry 21 | // So this is very simple queue use 22 | // We will enqueue one message and dequeue it. 23 | func main() { 24 | 25 | ret := SUCCEED 26 | defer func() { os.Exit(ret) }() 27 | 28 | // Have some core dumps... 29 | C.signal(11, nil); 30 | 31 | //Have some loop for memory leak checks... 32 | for i := 0; i < 1000; i++ { 33 | 34 | var ac *atmi.ATMICtx 35 | var err atmi.ATMIError 36 | //Allocate context 37 | ac, err = atmi.NewATMICtx() 38 | if nil != err { 39 | fmt.Errorf("Failed to allocate cotnext!", err) 40 | ret = FAIL 41 | return 42 | } 43 | 44 | var qctl atmi.TPQCTL 45 | 46 | testMessage := "Hello World from queue" 47 | 48 | buf, err := ac.NewString(testMessage) 49 | 50 | if err != nil { 51 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 52 | ret = FAIL 53 | return 54 | } 55 | 56 | //Enqueue the string 57 | if err := ac.TpEnqueue("QSPACE1", "MYQ1", &qctl, buf, 0); nil != err { 58 | fmt.Printf("TpEnqueue() failed: ATMI Error %d:[%s]\n", err.Code(), err.Message()) 59 | ret = FAIL 60 | return 61 | } 62 | 63 | fmt.Printf("Enqueue OK\n") 64 | 65 | //Allocate new return buffer, to ensure that this is different one..! 66 | buf2, err := ac.NewString("") 67 | 68 | if err != nil { 69 | fmt.Printf("ATMI Error %d:[%s]\n", err.Code(), err.Message()) 70 | ret = FAIL 71 | return 72 | } 73 | 74 | if err := ac.TpDequeue("QSPACE1", "MYQ1", &qctl, buf2, 0); nil != err { 75 | fmt.Printf("TpDequeue() failed: ATMI Error %d:[%s]\n", err.Code(), err.Message()) 76 | ret = FAIL 77 | return 78 | } 79 | 80 | //Print the output buffer 81 | fmt.Printf("Dequeued message: [%s]\n", buf2.GetString()) 82 | 83 | if buf2.GetString() != testMessage { 84 | fmt.Printf("ERROR ! Enqueued [%s] but dequeued [%s]", 85 | testMessage, buf2.GetString()) 86 | ret = FAIL 87 | return 88 | } 89 | fmt.Printf("Message machged ok!\n") 90 | 91 | runtime.GC() 92 | } 93 | 94 | return 95 | } 96 | -------------------------------------------------------------------------------- /tests/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # @(#) Integration tests 5 | # 6 | 7 | > ./test.out 8 | # Have some terminal output... 9 | tail -f test.out & 10 | 11 | ( 12 | 13 | M_tests=0 14 | M_ok=0 15 | M_fail=0 16 | 17 | run_test () { 18 | 19 | test=$1 20 | M_tests=$((M_tests + 1)) 21 | echo "*** RUNNING [$test]" 22 | 23 | pushd . 24 | cd $test 25 | ./run.sh 26 | ret=$? 27 | popd 28 | 29 | echo "*** RESULT [$test] $ret" 30 | 31 | if [[ $ret -eq 0 ]]; then 32 | M_ok=$((M_ok + 1)) 33 | else 34 | M_fail=$((M_fail + 1)) 35 | fi 36 | } 37 | 38 | UNAME=`uname` 39 | 40 | # Not for freebsd - bigmsg test issues - stack size only 2M for threads 41 | # wait for 7.1 Enduro/X for dynamic buffer - currently ignore TPEINVAL when BIGMSG call fails 42 | # allocation 43 | run_test "01_basic_ubf_call" 44 | run_test "02_basic_string_call" 45 | run_test "03_basic_carray_call" 46 | run_test "05_basic_json_call" 47 | run_test "06_ubf_marshal" 48 | run_test "07_basic_durable_queue" 49 | run_test "08_logging" 50 | run_test "09_return_manual_buffer" 51 | run_test "10_views" 52 | run_test "11_ubf_tests" 53 | run_test "12_tpimportexp" 54 | 55 | ################################################################################ 56 | # Print results in out file 57 | # use temp file to avoid plotting to the same file which are are grepping... 58 | ################################################################################ 59 | grep RESULT test.out >test.out.tmp 60 | cat test.out.tmp 61 | rm test.out.tmp 62 | ################################################################################ 63 | 64 | echo "*** SUMMARY $M_tests tests executed. $M_ok passes, $M_fail failures" 65 | 66 | # wait for tail to pick the change 67 | sleep 5 68 | xadmin killall tail 69 | 70 | exit $M_fail 71 | 72 | ) > test.out 2>&1 73 | 74 | -------------------------------------------------------------------------------- /typed_json.go: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief JSON IPC Buffer support 3 | * 4 | * @file typed_json.go 5 | */ 6 | /* ----------------------------------------------------------------------------- 7 | * Enduro/X Middleware Platform for Distributed Transaction Processing 8 | * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 9 | * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 10 | * This software is released under one of the following licenses: 11 | * LGPL or Mavimax's license for commercial use. 12 | * See LICENSE file for full text. 13 | * 14 | * C (as designed by Dennis Ritchie and later authors) language code is licensed 15 | * under Enduro/X Modified GNU Affero General Public License, version 3. 16 | * See LICENSE_C file for full text. 17 | * ----------------------------------------------------------------------------- 18 | * LGPL license: 19 | * 20 | * This program is free software; you can redistribute it and/or modify it under 21 | * the terms of the GNU Lesser General Public License, version 3 as published 22 | * by the Free Software Foundation; 23 | * 24 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 25 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 26 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 27 | * for more details. 28 | * 29 | * You should have received a copy of the Lesser General Public License along 30 | * with this program; if not, write to the Free Software Foundation, Inc., 31 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32 | * 33 | * ----------------------------------------------------------------------------- 34 | * A commercial use license is available from Mavimax, Ltd 35 | * contact@mavimax.com 36 | * ----------------------------------------------------------------------------- 37 | */ 38 | package atmi 39 | 40 | /* 41 | #cgo pkg-config: atmisrvinteg 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | */ 49 | import "C" 50 | import "unsafe" 51 | 52 | //UBF Buffer 53 | type TypedJSON struct { 54 | Buf *ATMIBuf 55 | } 56 | 57 | //Return The ATMI buffer to caller 58 | func (u *TypedJSON) GetBuf() *ATMIBuf { 59 | return u.Buf 60 | } 61 | 62 | //Allocate new JSON buffer 63 | //@param s - source string 64 | func (ac *ATMICtx) NewJSON(b []byte) (*TypedJSON, ATMIError) { 65 | var buf TypedJSON 66 | 67 | c_val := C.CString(string(b)) 68 | defer C.free(unsafe.Pointer(c_val)) 69 | 70 | size := int64(C.strlen(c_val) + 1) /* 1 for EOS. */ 71 | 72 | if ptr, err := ac.TpAlloc("JSON", "", size); nil != err { 73 | return nil, err 74 | } else { 75 | buf.Buf = ptr 76 | C.strcpy(buf.Buf.C_ptr, c_val) 77 | 78 | buf.Buf.TpSetCtxt(ac) 79 | 80 | return &buf, nil 81 | } 82 | } 83 | 84 | //Get the JSON Handler from ATMI Buffer 85 | func (ac *ATMICtx) CastToJSON(abuf *ATMIBuf) (*TypedJSON, ATMIError) { 86 | var buf TypedJSON 87 | 88 | buf.Buf = abuf 89 | 90 | return &buf, nil 91 | } 92 | 93 | //Get the string value out from buffer 94 | //@return JSON value 95 | func (j *TypedJSON) GetJSONText() string { 96 | ret := C.GoString(j.Buf.C_ptr) 97 | j.Buf.nop() 98 | return ret 99 | } 100 | 101 | //Get JSON bytes.. 102 | func (j *TypedJSON) GetJSON() []byte { 103 | 104 | ret := []byte(C.GoString(j.Buf.C_ptr)) 105 | j.Buf.nop() 106 | return ret 107 | } 108 | 109 | //Set JSON bytes 110 | func (j *TypedJSON) SetJSON(b []byte) ATMIError { 111 | return j.SetJSONText(string(b)) 112 | } 113 | 114 | //Set the string to the buffer 115 | //@param str JSON value 116 | func (j *TypedJSON) SetJSONText(gs string) ATMIError { 117 | 118 | c_val := C.CString(gs) 119 | defer C.free(unsafe.Pointer(c_val)) 120 | 121 | new_size := int64(C.strlen(c_val) + 1) /* 1 for EOS. */ 122 | 123 | if cur_size, err := j.Buf.Ctx.TpTypes(j.Buf, nil, nil); nil != err { 124 | return err 125 | } else { 126 | if cur_size >= new_size { 127 | C.strcpy(j.Buf.C_ptr, c_val) 128 | } else if err := j.Buf.TpRealloc(new_size); nil != err { 129 | return err 130 | } else { 131 | C.strcpy(j.Buf.C_ptr, c_val) 132 | } 133 | } 134 | 135 | j.Buf.nop() 136 | 137 | return nil 138 | } 139 | 140 | /////////////////////////////////////////////////////////////////////////////////// 141 | // Wrappers for memory management 142 | /////////////////////////////////////////////////////////////////////////////////// 143 | 144 | func (u *TypedJSON) TpRealloc(size int64) ATMIError { 145 | return u.Buf.TpRealloc(size) 146 | } 147 | 148 | /* vim: set ts=4 sw=4 et smartindent: */ 149 | -------------------------------------------------------------------------------- /typed_string.go: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief Plain text IPC buffer support 3 | * 4 | * @file typed_string.go 5 | */ 6 | /* ----------------------------------------------------------------------------- 7 | * Enduro/X Middleware Platform for Distributed Transaction Processing 8 | * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 9 | * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved. 10 | * This software is released under one of the following licenses: 11 | * LGPL or Mavimax's license for commercial use. 12 | * See LICENSE file for full text. 13 | * 14 | * C (as designed by Dennis Ritchie and later authors) language code is licensed 15 | * under Enduro/X Modified GNU Affero General Public License, version 3. 16 | * See LICENSE_C file for full text. 17 | * ----------------------------------------------------------------------------- 18 | * LGPL license: 19 | * 20 | * This program is free software; you can redistribute it and/or modify it under 21 | * the terms of the GNU Lesser General Public License, version 3 as published 22 | * by the Free Software Foundation; 23 | * 24 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY 25 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 26 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License, version 3 27 | * for more details. 28 | * 29 | * You should have received a copy of the Lesser General Public License along 30 | * with this program; if not, write to the Free Software Foundation, Inc., 31 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32 | * 33 | * ----------------------------------------------------------------------------- 34 | * A commercial use license is available from Mavimax, Ltd 35 | * contact@mavimax.com 36 | * ----------------------------------------------------------------------------- 37 | */ 38 | package atmi 39 | 40 | /* 41 | #cgo pkg-config: atmisrvinteg 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | */ 49 | import "C" 50 | import "unsafe" 51 | 52 | //UBF Buffer 53 | type TypedString struct { 54 | Buf *ATMIBuf 55 | } 56 | 57 | //Return The ATMI buffer to caller 58 | func (u *TypedString) GetBuf() *ATMIBuf { 59 | return u.Buf 60 | } 61 | 62 | //Allocate new string buffer 63 | //@param s - source string 64 | func (ac *ATMICtx) NewString(gs string) (*TypedString, ATMIError) { 65 | var buf TypedString 66 | 67 | c_val := C.CString(gs) 68 | defer C.free(unsafe.Pointer(c_val)) 69 | 70 | size := int64(C.strlen(c_val) + 1) /* 1 for EOS. */ 71 | 72 | if ptr, err := ac.TpAlloc("STRING", "", size); nil != err { 73 | return nil, err 74 | } else { 75 | buf.Buf = ptr 76 | C.strcpy(buf.Buf.C_ptr, c_val) 77 | buf.Buf.TpSetCtxt(ac) 78 | 79 | return &buf, nil 80 | } 81 | } 82 | 83 | //Get the String Handler from ATMI Buffer 84 | func (ac *ATMICtx) CastToString(abuf *ATMIBuf) (*TypedString, ATMIError) { 85 | var buf TypedString 86 | 87 | buf.Buf = abuf 88 | 89 | return &buf, nil 90 | } 91 | 92 | //Get the string value out from buffer 93 | //@return String value 94 | func (s *TypedString) GetString() string { 95 | ret := C.GoString(s.Buf.C_ptr) 96 | 97 | s.Buf.nop() 98 | return ret 99 | 100 | } 101 | 102 | //Set the string to the buffer 103 | //@param str String value 104 | func (s *TypedString) SetString(gs string) ATMIError { 105 | 106 | c_val := C.CString(gs) 107 | defer C.free(unsafe.Pointer(c_val)) 108 | 109 | new_size := int64(C.strlen(c_val) + 1) /* 1 for EOS. */ 110 | 111 | if cur_size, err := s.Buf.Ctx.TpTypes(s.Buf, nil, nil); nil != err { 112 | return err 113 | } else { 114 | if cur_size >= new_size { 115 | C.strcpy(s.Buf.C_ptr, c_val) 116 | } else if err := s.Buf.TpRealloc(new_size); nil != err { 117 | return err 118 | } else { 119 | C.strcpy(s.Buf.C_ptr, c_val) 120 | } 121 | } 122 | 123 | s.Buf.nop() 124 | 125 | return nil 126 | } 127 | 128 | /////////////////////////////////////////////////////////////////////////////////// 129 | // Wrappers for memory management 130 | /////////////////////////////////////////////////////////////////////////////////// 131 | 132 | func (u *TypedString) TpRealloc(size int64) ATMIError { 133 | return u.Buf.TpRealloc(size) 134 | } 135 | 136 | /* vim: set ts=4 sw=4 et smartindent: */ 137 | --------------------------------------------------------------------------------