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

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

The GOAL for this setup is:

CODE client

<?php
#+
#:   @file         example/php/testclient.php
#:   @brief        testclient.php - 20 Oct 2022 - aotto1968
#:   @copyright    (C) NHI - #1 - Project - Group
#:                 This software has NO permissions to copy,
#:                 please contact AUTHOR for additional information
#:   @version      eca2a2ee05f368470d4127d36503bd9e26063147
#:   @date         Thu Oct 20 14:18:44 2022 +0200
#:   @author       aotto1968 <aotto1968@t-online.de>
#:

use PhpMsgque\MqMsgque\MqContextC;

$php = explode(' ', getenv('PHP'))[0];

## setup the clients
$server = dirname($argv[0]) . "/testserver.php";
## create object
$c0 = new MqContextC();
$c00 = new MqContextC();
$c01 = new MqContextC();
$c000 = new MqContextC();
$c1 = new MqContextC();
$c10 = new MqContextC();
$c100 = new MqContextC();
$c101 = new MqContextC();
## setup object link

$c0->LinkCreate(              "c0",    "--postfix", "0",      "--prefix", "c", "--debug", getenv('TS_DEBUG'), 
                                                              "@", $php, "-c", getenv('PHPRC'),
                                                              $server, "--prefix", "s");
$c00->LinkCreateChild($c0,    "c00",   "--postfix", "00"  );
$c01->LinkCreateChild($c0,    "c01",   "--postfix", "01"  );
$c000->LinkCreateChild($c00,  "c000",  "--postfix", "000" );

$c1->LinkCreate(              "c1",    "--postfix", "1",      "--prefix", "c", ...array_slice($argv,1));
$c10->LinkCreateChild($c1,    "c10",   "--postfix", "10"  );
$c100->LinkCreateChild($c10,  "c100",  "--postfix", "100" );
$c101->LinkCreateChild($c10,  "c101",  "--postfix", "101" );

## my helper
function Get($ctx) {
  $ret = "";
  $ctx->SendSTART();
  $ctx->SendEND_AND_WAIT("GTCX");
  $ret .= $ctx->ConfigGetName();
  $ret .= "+";
  $ret .= $ctx->ReadC();
  $ret .= $ctx->ReadC();
  $ret .= $ctx->ReadC();
  $ret .= $ctx->ReadC();
  $ret .= $ctx->ReadC();
  $ret .= $ctx->ReadC();
  $ret .= "\n";
  return $ret;
}
## do the tests
print(Get($c0));
print(Get($c00));
print(Get($c01));
print(Get($c000));
print(Get($c1));
print(Get($c10));
print(Get($c100));
print(Get($c101));
flush();

## do the cleanup
$c1->LinkDelete();
$c0->Exit();

?>

CODE server

<?php
#+
#:   @file         example/php/testserver.php
#:   @brief        testserver.php - 20 Oct 2022 - aotto1968
#:   @copyright    (C) NHI - #1 - Project - Group
#:                 This software has NO permissions to copy,
#:                 please contact AUTHOR for additional information
#:   @version      eca2a2ee05f368470d4127d36503bd9e26063147
#:   @date         Thu Oct 20 14:18:44 2022 +0200
#:   @author       aotto1968 <aotto1968@t-online.de>
#:

use PhpMsgque\MqMsgque as mq;

class TestServer extends mq\MqContextC implements mq\iServerSetup {
  public function ServerSetup() {
    $this->ServiceCreate('GTCX', 'GTCX');
  }
  public function GTCX() {
    $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();
  }
}
$srv = mq\MqFactoryC::Add('TestServer')->New();
try {
  $srv->LinkCreate($argv);
  $srv->ProcessEvent(mq\MqWaitOnEventE::FOREVER);
} catch (Throwable $ex) {
  $srv->ErrorCatch($ex);
} finally {
  $srv->Exit();
}

?>