gomqmsgque 9.0
Loading...
Searching...
No Matches
Example: Identification-Test

Documentation of the Test-Client-Server tool used for example.test.

INTRODUCTION

The Naming-Test-Tool tool is used to test the name-resolution-feature of gomqmsgque.

To perform the test 2 tools are used, the testclient and the testserver.

testclient

This tool creates multiple parent and child client-context, all using a --postfix argument to identify unique.

testserver This tool listen on the service GTCX and return the unique identification pattern of the server-context in duty.

All context created, 8x client and 8x server, are connected using the gomqmsgque protocoll and build together a flat structure.

The GOAL for this setup is:

CODE client

/**
 *   @file         example/go/testclient.go
 *   @brief        testclient.go - 18 Apr 2023 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      614a1e551abaa613cb635c95181a52afb9f8cf34
 *   @date         Tue Apr 18 23:23:15 2023 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

package main

import (
  . "gomsgque/mqmsgque"
    "os"
    "path"
    "fmt"
)

func Get(ctx *MqContextC) string {
  var RET string
  ctx.SendSTART()
  ctx.SendEND_AND_WAIT_1("GTCX")
  RET += ctx.ConfigGetName()
  RET += "+"
  RET += ctx.ReadC()
  RET += ctx.ReadC()
  RET += ctx.ReadC()
  RET += ctx.ReadC()
  RET += ctx.ReadC()
  RET += ctx.ReadC()
  return RET
}

func main() {
  // create the object
  c0	:= MqContextC_New(nil)
  c00	:= MqContextC_New(nil)
  c01	:= MqContextC_New(nil)
  c000	:= MqContextC_New(nil)
  c1	:= MqContextC_New(nil)
  c10	:= MqContextC_New(nil)
  c100	:= MqContextC_New(nil)
  c101	:= MqContextC_New(nil)

  // get server
  dir, _ := path.Split(os.Args[0])
  server := path.Join(dir, "testserver")
  LIST0 := append([]string{os.Args[0], "--prefix", "c", "--postfix", "0"}, "--debug", os.Getenv("TS_DEBUG"), "@", server, "--prefix", "s")
  LIST1 := append([]string{os.Args[0], "--prefix", "c", "--postfix", "1"}, os.Args[1:]...)

  // catch errors and exit the app
  defer func() {
    if x := recover(); x != nil {
      c0.ErrorCatch_1(x)
    }
    c0.LinkDelete();
    //c1.LinkDelete();
    c0.Exit_0();
  }()

  // create the link
  c0.LinkCreateVC         (LIST0  )
  c00.LinkCreateChildVA   (c0,    "--postfix",  "00"   )
  c01.LinkCreateChildVA   (c0,    "--postfix",  "01"   )
  c000.LinkCreateChildVA  (c00,   "--postfix",  "000"  )
  c1.LinkCreateVC         (LIST1  )
  c10.LinkCreateChildVA   (c1,    "--postfix",  "10"   )
  c100.LinkCreateChildVA  (c10,   "--postfix",  "100"  )
  c101.LinkCreateChildVA  (c10,   "--postfix",  "101"  )

  // do the tests
  fmt.Fprintln(os.Stdout,Get(c0))
  fmt.Fprintln(os.Stdout,Get(c00))
  fmt.Fprintln(os.Stdout,Get(c01))
  fmt.Fprintln(os.Stdout,Get(c000))
  fmt.Fprintln(os.Stdout,Get(c1))
  fmt.Fprintln(os.Stdout,Get(c10))
  fmt.Fprintln(os.Stdout,Get(c100))
  fmt.Fprintln(os.Stdout,Get(c101))
}

CODE server

/**
 *   @file         example/go/testserver.go
 *   @brief        testserver.go - 18 Apr 2023 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      614a1e551abaa613cb635c95181a52afb9f8cf34
 *   @date         Tue Apr 18 23:23:15 2023 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

package main

import (
  . "gomsgque/mqmsgque"
    "os"
)

type TestServer struct {
  MqContextC
  // add server specific data 
}

func TestServer_Factory(tmpl MqContextCI) MqFactoryI {
  srv := new(TestServer)
  srv.Init(tmpl, srv)
  return srv
}

func (this *TestServer) ServerSetup() {
  this.ServiceCreate("GTCX", (*GTCX)(this))
}

type GTCX TestServer
  func (this *GTCX) Call() {
    this.SendSTART()
    this.SendI(this.LinkGetCtxId())
    this.SendC("+")
    if (this.LinkIsParent()) {
      this.SendI(-1)
    } else {
      this.SendI(this.LinkGetParent().LinkGetCtxId())
    }
    this.SendC("+")
    this.SendC(this.ConfigGetName())
    this.SendC(":")
    this.SendRETURN()
  }

func main() {
  srv := MqFactoryAdd(TestServer_Factory, "TestServer").New()
  defer func() {
    if x := recover(); x != nil {
      srv.ErrorCatch_1(x)
    }
    srv.Exit_0()
  }()
  srv.LinkCreateVC(os.Args)
  srv.ProcessEvent_1(MQ_WAIT_FOREVER)
}