Esempio n. 1
0
function tryCommand($command)
{
    global $server;
    echo "Sending Command: {$command}\n";
    socket_write($server, $command, 100);
    if ($command == "Sleep") {
        return;
    } else {
        if ($command == "quit") {
            $arrOpt = array('l_onoff' => 1, 'l_linger' => 1);
            socket_set_block($server);
            socket_set_option($server, SOL_SOCKET, SO_LINGER, $arrOpt);
            socket_close($server);
            return;
        }
    }
    $t = time();
    while (true) {
        $res = socket_read($server, 20);
        if ($res == $command) {
            echo "Command Applied {$res}\n";
            break;
        } else {
            if (is_numeric($res)) {
                echo "Replied with leader id {$res}\n";
                connectNode($res);
                tryCommand($command);
                break;
            } else {
                if (time() > $t + 15) {
                    echo "Resending command\n";
                    connectNode(0);
                    tryCommand($command);
                    break;
                }
            }
        }
    }
}
Esempio n. 2
0
function TestCase5()
{
    global $port;
    echo "\n\nTest Case 5 : Multiple Log Test with 2 machines close\nLog : Hello How Are You Today\n\n\n\n";
    setupTest(5);
    connectNode(0);
    tryCommand("Hello");
    sleep(1);
    tryCommand("How");
    sleep(1);
    connectNode(0);
    tryCommand("quit");
    connectNode(1);
    sleep(1);
    tryCommand("Are");
    sleep(1);
    connectNode(2);
    tryCommand("quit");
    connectNode(1);
    sleep(1);
    tryCommand("You");
    sleep(1);
    tryCommand("Today");
    sleep(1);
    CloseAll(5);
    TestResult(5);
    $port += 5;
}