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

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

The GOAL for this setup is:

CODE client

/**
 *   @file         example/java/testclient.java
 *   @brief        testclient.java - 24 Oct 2022 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      633e552893e541feafe5b2d13a38ce3b4528f05c
 *   @date         Mon Oct 24 23:24:31 2022 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */
package example;

import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import javamsgque.mqmsgque.*;
import javamsgque.mkkernel.*;


class testclient extends MqContextC {

  // my helper
  private StringBuffer Get() {
    StringBuffer RET = new StringBuffer();
    SendSTART();
    SendEND_AND_WAIT("GTCX", -2);
    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;
  }

  public static void main(String[] argv) {
    // setup the clients
    List<String> LIST1 = new ArrayList<>(Arrays.asList("--prefix", "c", "--postfix", "1"));
    LIST1.addAll(Arrays.asList(argv));
    List<String> LIST0 = Arrays.asList("--prefix", "c", "--postfix", "0", "--debug", System.getenv("TS_DEBUG"), "@", "java", "example.testserver", "--prefix", "s");

    // create the objects
    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(new String[0]));
      c00.LinkCreateChild   (c0,  "--postfix", "00"   );
      c01.LinkCreateChild   (c0,  "--postfix", "01"   );
      c000.LinkCreateChild  (c00, "--postfix", "000"  );
      c1.LinkCreate(LIST1.toArray(new String[0]));
      c10.LinkCreateChild   (c1,  "--postfix", "10"   );
      c100.LinkCreateChild  (c10, "--postfix", "100"  );
      c101.LinkCreateChild  (c10, "--postfix", "101"  );

      // do the tests
      System.out.println(c0.Get());
      System.out.println(c00.Get());
      System.out.println(c01.Get());
      System.out.println(c000.Get());
      System.out.println(c1.Get());
      System.out.println(c10.Get());
      System.out.println(c100.Get());
      System.out.println(c101.Get());
    } catch (Throwable e) {
      c0.ErrorCatch(e);
    } finally {
      // do the cleanup
      c1.LinkDelete();
      c0.Exit();
    }
  }
}

CODE server

/**
 *   @file         example/java/testserver.java
 *   @brief        testserver.java - 24 Oct 2022 - aotto1968
 *   @copyright    (C) NHI - #1 - Project - Group
 *                 This software has NO permissions to copy,
 *                 please contact AUTHOR for additional information
 *   @version      633e552893e541feafe5b2d13a38ce3b4528f05c
 *   @date         Mon Oct 24 23:24:31 2022 +0200
 *   @author       aotto1968 <aotto1968@t-online.de>
 */

package example;

import javamsgque.mqmsgque.*;
import javamsgque.mkkernel.*;

final class testserver extends MqContextC implements IServerSetup {

  public testserver(MqContextC tmpl) {
    super(tmpl);
  }

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

  public void ServerSetup() {
    ServiceCreate("GTCX", new GTCX());
  }

  public static void main(String[] argv) {
    MqContextC srv = MqFactoryC.Add(testserver.class).New();
    try {
      srv.LinkCreate(argv);
      srv.ProcessEvent(MqWaitOnEventE.FOREVER);
    } catch (Throwable e) {
      srv.ErrorCatch(e);
    } finally {
      srv.Exit();
    }
  }
}