csmqmsgque 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 csmqmsgque.

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 csmqmsgque protocoll and build together a flat structure.

The GOAL for this setup is:

CODE client

/**
 *   @file         example/csharp/testclient.cs
 *   @brief        testclient.cs - 25 Dec 2022 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      9dfa375425d5e344c853828f6fe0ccf7c03287d5
 *   @date         Sun Dec 25 13:44:16 2022 +0100
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Reflection;
using csmsgque.mqmsgque;

namespace example {

  sealed class testclient : MqContextC {

    private StringBuilder Get() {
      StringBuilder RET = new StringBuilder();
      SendSTART();
      SendEND_AND_WAIT("GTCX");
      RET.Append(ConfigGetName());
      RET.Append("+");
      RET.Append(ReadC());
      RET.Append(ReadC());
      RET.Append(ReadC());
      RET.Append(ReadC());
      RET.Append(ReadC());
      RET.Append(ReadC());
      return RET;
    }

    static void Main(string[] argv) {

      // setup the clients
      string dirname = new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName;
      string server = Path.Combine(dirname, "testserver.exe");
      List<String> LIST1 = new List<String>() {"--prefix", "c", "--postfix", "1"};
      LIST1.AddRange(argv);
      List<String> LIST0 = new List<String>() {
        "--prefix", "c", "--postfix", "0", "--debug", System.Environment.GetEnvironmentVariable("TS_DEBUG"), "@"
      };
      if(Type.GetType ("Mono.Runtime") != null) LIST0.Add("mono");
      LIST0.Add(server);
      LIST0.Add("--prefix");
      LIST0.Add("s");

      // create the object
      testclient c0 = new testclient();
      testclient c00 = new testclient();
      testclient c01 = new testclient();
      testclient c000 = new testclient();
      testclient c1 = new testclient();
      testclient c10 = new testclient();
      testclient c100 = new testclient();
      testclient c101 = new testclient();
      try {
	// create the link
        c0.LinkCreate(LIST0.ToArray());
	c00.LinkCreateChild   (c0,  "--postfix", "00"   );
	c01.LinkCreateChild   (c0,  "--postfix", "01"   );
	c000.LinkCreateChild  (c00, "--postfix", "000"  );
	c1.LinkCreate(LIST1.ToArray());
	c10.LinkCreateChild   (c1,  "--postfix", "10"   );
	c100.LinkCreateChild  (c10, "--postfix", "100"  );
	c101.LinkCreateChild  (c10, "--postfix", "101"  );
	// do the tests
	Console.WriteLine(c0.Get());
	Console.WriteLine(c00.Get());
	Console.WriteLine(c01.Get());
	Console.WriteLine(c000.Get());
	Console.WriteLine(c1.Get());
	Console.WriteLine(c10.Get());
	Console.WriteLine(c100.Get());
	Console.WriteLine(c101.Get());
      } catch (Exception ex) {
	c0.ErrorCatch(ex);
      } finally {
	// do the cleanup
	c1.LinkDelete();
	c0.Exit();
      }
    }
  }
}

CODE server

/**
 *   @file         example/csharp/testserver.cs
 *   @brief        testserver.cs - 25 Dec 2022 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      9dfa375425d5e344c853828f6fe0ccf7c03287d5
 *   @date         Sun Dec 25 13:44:16 2022 +0100
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

using System;
using csmsgque.mqmsgque;

namespace example {

  sealed class testserver : MqContextC, IServerSetup {

    public testserver(MqContextC tmpl=null) : base(tmpl) {
    }

    public void GTCX () {
      SendSTART();
      SendI(LinkGetCtxId());
      SendC("+");
      if (LinkIsParent()) {
        SendI(-1);
      } else {
        SendI(LinkGetParent().LinkGetCtxId());
      }
      SendC("+");
      SendC(ConfigGetName());
      SendC(":");
      SendRETURN();
    }

    void IServerSetup.ServerSetup() {
      ServiceCreate("GTCX", GTCX);
    }

    static void Main(string[] argv) {
      testserver srv = MqFactoryCT<testserver>.Add().New();
      try {
	srv.LinkCreate(argv);
	srv.ProcessEvent(MqWaitOnEventE.FOREVER);
      } catch (Exception ex) {
        srv.ErrorCatch (ex);
      }
      srv.Exit();
    }
  }
}