Exemplo n.º 1
0
 private function sendGenTestDataBridge()
 {
     $dirName1 = 'testdir_client1_' . date('Ymd_His') . '_' . uniqid('', true);
     $dirName2 = 'testdir_client2_' . date('Ymd_His') . '_' . uniqid('', true);
     $dirName3 = 'testdir_client3_' . date('Ymd_His') . '_' . uniqid('', true);
     $filesystem = new Filesystem();
     $filesystem->mkdir('test_data/' . $dirName1, $mode = 0777);
     $filesystem->mkdir('test_data/' . $dirName2, $mode = 0777);
     $filesystem->mkdir('test_data/' . $dirName3, $mode = 0777);
     file_put_contents('test_data/' . $dirName1 . '/id_rsa.prv', static::NODE_LOCAL_SSL_KEY_PRV1);
     file_put_contents('test_data/' . $dirName1 . '/id_rsa.pub', static::NODE_LOCAL_SSL_KEY_PUB1);
     file_put_contents('test_data/' . $dirName2 . '/id_rsa.prv', static::NODE_LOCAL_SSL_KEY_PRV2);
     file_put_contents('test_data/' . $dirName2 . '/id_rsa.pub', static::NODE_LOCAL_SSL_KEY_PUB2);
     file_put_contents('test_data/' . $dirName3 . '/id_rsa.prv', static::NODE_LOCAL_SSL_KEY_PRV3);
     file_put_contents('test_data/' . $dirName3 . '/id_rsa.pub', static::NODE_LOCAL_SSL_KEY_PUB3);
     $localNode1 = new Node();
     $localNode1->setUri('tcp://127.0.0.1:25000');
     $localNode1->setIdHexStr('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $table1 = new Table('test_data/' . $dirName1 . '/table.yml');
     $table1->setDatadirBasePath('test_data/' . $dirName1);
     $table1->setLocalNode($localNode1);
     $table1->setDataChanged(true);
     $table1->save();
     $localNode2 = new Node();
     $localNode2->setUri('tcp://127.0.0.2:25000');
     $localNode2->setIdHexStr('cafed00d-2131-4159-8e11-0b4dbadb1739');
     $table2 = new Table('test_data/' . $dirName2 . '/table.yml');
     $table2->setDatadirBasePath('test_data/' . $dirName2);
     $table2->setLocalNode($localNode2);
     $table2->setDataChanged(true);
     $table2->save();
     $localNode3 = new Node();
     $localNode3->setUri('tcp://127.0.0.3:25000');
     $localNode3->setIdHexStr('cafed00d-2131-4159-8e11-0b4dbadb1740');
     $table3 = new Table('test_data/' . $dirName3 . '/table.yml');
     $table3->setDatadirBasePath('test_data/' . $dirName3);
     $table3->setLocalNode($localNode3);
     $table3->setDataChanged(true);
     $table3->save();
     $settings1 = new Settings();
     $settings1->data['datadir'] = 'test_data/' . $dirName1;
     $settings1->data['firstRun'] = false;
     $settings1->data['timeCreated'] = time();
     $settings1->data['node']['uriLocal'] = 'tcp://127.0.0.1';
     $settings1->data['node']['id'] = Node::genIdHexStr(static::NODE_LOCAL_SSL_KEY_PUB1);
     $settings1->data['node']['sslKeyPrvPass'] = '******';
     $settings1->data['node']['sslKeyPrvPath'] = 'test_data/' . $dirName1 . '/id_rsa.prv';
     $settings1->data['node']['sslKeyPubPath'] = 'test_data/' . $dirName1 . '/id_rsa.pub';
     $settings1->data['user']['nickname'] = 'user1';
     $settings1->data['node']['bridge']['client']['enabled'] = true;
     $settings2 = new Settings();
     $settings2->data['datadir'] = 'test_data/' . $dirName2;
     $settings2->data['firstRun'] = false;
     $settings2->data['timeCreated'] = time();
     $settings2->data['node']['uriLocal'] = 'tcp://127.0.0.2';
     $settings2->data['node']['id'] = Node::genIdHexStr(static::NODE_LOCAL_SSL_KEY_PUB2);
     $settings2->data['node']['sslKeyPrvPass'] = '******';
     $settings2->data['node']['sslKeyPrvPath'] = 'test_data/' . $dirName2 . '/id_rsa.prv';
     $settings2->data['node']['sslKeyPubPath'] = 'test_data/' . $dirName2 . '/id_rsa.pub';
     $settings2->data['user']['nickname'] = 'user2';
     $settings2->data['node']['bridge']['server']['enabled'] = true;
     $settings3 = new Settings();
     $settings3->data['datadir'] = 'test_data/' . $dirName3;
     $settings3->data['firstRun'] = false;
     $settings3->data['timeCreated'] = time();
     $settings3->data['node']['uriLocal'] = 'tcp://127.0.0.3';
     $settings3->data['node']['id'] = Node::genIdHexStr(static::NODE_LOCAL_SSL_KEY_PUB2);
     $settings3->data['node']['sslKeyPrvPass'] = '******';
     $settings3->data['node']['sslKeyPrvPath'] = 'test_data/' . $dirName3 . '/id_rsa.prv';
     $settings3->data['node']['sslKeyPubPath'] = 'test_data/' . $dirName3 . '/id_rsa.pub';
     $settings3->data['user']['nickname'] = 'user3';
     $settings3->data['node']['bridge']['client']['enabled'] = true;
     $log1 = new Logger('client_1');
     $log1->pushHandler(new LoggerStreamHandler('php://stdout', Logger::DEBUG));
     $log2 = new Logger('client_2');
     $log2->pushHandler(new LoggerStreamHandler('php://stdout', Logger::DEBUG));
     $log3 = new Logger('client_2');
     $log3->pushHandler(new LoggerStreamHandler('php://stdout', Logger::DEBUG));
     $kernel1 = new Kernel();
     $kernel1->setLog($log1);
     $kernel1->setSettings($settings1);
     $kernel1->init();
     $kernel2 = new Kernel();
     $kernel2->setLog($log2);
     $kernel2->setSettings($settings2);
     $kernel2->init();
     $kernel3 = new Kernel();
     $kernel3->setLog($log3);
     $kernel3->setSettings($settings3);
     $kernel3->init();
     $server1 = $kernel1->getServer();
     $server1->setLog($log1);
     $server2 = $kernel2->getServer();
     $server2->setLog($log2);
     $server3 = $kernel3->getServer();
     $server3->setLog($log3);
     $client1 = new Client();
     $client1->debug = true;
     $client1->setSslPrv($settings1->data['node']['sslKeyPrvPath'], $settings1->data['node']['sslKeyPrvPass']);
     $client1->setId(1);
     $client1->setUri($settings1->data['node']['uriLocal']);
     $client1->setServer($server1);
     $this->assertEquals($settings1->data['node']['uriLocal'], 'tcp://' . $client1->getUri()->getHost());
     #fwrite(STDOUT, 'ip1: /'.$client1->getUri()->getHost().'/'."\n");
     $client2 = new Client();
     $client2->debug = true;
     $client2->setSslPrv($settings2->data['node']['sslKeyPrvPath'], $settings2->data['node']['sslKeyPrvPass']);
     $client2->setId(2);
     $client2->setUri($settings2->data['node']['uriLocal']);
     $client2->setServer($server2);
     $this->assertEquals($settings2->data['node']['uriLocal'], 'tcp://' . $client2->getUri()->getHost());
     #fwrite(STDOUT, 'ip2: /'.$client2->getUri()->getHost().'/'."\n");
     $client3 = new Client();
     $client3->debug = true;
     $client3->setSslPrv($settings3->data['node']['sslKeyPrvPath'], $settings3->data['node']['sslKeyPrvPass']);
     $client3->setId(3);
     $client3->setUri($settings3->data['node']['uriLocal']);
     $client3->setServer($server3);
     $this->assertEquals($settings3->data['node']['uriLocal'], 'tcp://' . $client3->getUri()->getHost());
     #fwrite(STDOUT, 'ip3: /'.$client3->getUri()->getHost().'/'."\n");
     return array($client1, $client2, $client3);
 }
Exemplo n.º 2
0
 public function testCreateGuzzleHttpClient()
 {
     $runName = uniqid('', true);
     $prvFileName = 'testfile_cronjob_id_rsa_' . date('Ymd_His') . '_' . $runName . '.prv';
     $pubFileName = 'testfile_cronjob_id_rsa_' . date('Ymd_His') . '_' . $runName . '.pub';
     $settignsFileName = 'testfile_cronjob_settings_' . date('Ymd_His') . '_' . $runName . '.pub';
     file_put_contents('test_data/' . $prvFileName, static::NODE_LOCAL_SSL_KEY_PRV);
     file_put_contents('test_data/' . $pubFileName, static::NODE_LOCAL_SSL_KEY_PUB);
     $settings = new Settings('test_data/' . $settignsFileName);
     $settings->data['datadir'] = 'test_data';
     $settings->data['node']['id'] = Node::genIdHexStr(static::NODE_LOCAL_SSL_KEY_PUB);
     $settings->data['node']['sslKeyPrvPass'] = '******';
     $settings->data['node']['sslKeyPrvPath'] = 'test_data/' . $prvFileName;
     $settings->data['node']['sslKeyPubPath'] = 'test_data/' . $pubFileName;
     $settings->data['node']['bridge']['client']['enabled'] = true;
     $localNode = new Node();
     $localNode->setIdHexStr($settings->data['node']['id']);
     $localNode->setUri($settings->data['node']['uriLocal']);
     $localNode->setSslKeyPub(file_get_contents($settings->data['node']['sslKeyPubPath']));
     $table = new Table();
     $table->setDatadirBasePath($settings->data['datadir']);
     $table->setLocalNode($localNode);
     $nodesNewDb = new NodesNewDb('test_data/testfile_cronjob_nodesnewdb2.yml');
     $nodesNewDb->nodeAddConnect('tcp://192.168.241.21', false);
     $nodesNewDb->nodeAddConnect('tcp://192.168.241.22', true);
     $nodesNewDb->nodeAddFind('cafed00d-2131-4159-8e11-0b4dbadb1742', false);
     $nodesNewDb->nodeAddFind('cafed00d-2131-4159-8e11-0b4dbadb1743', true);
     $cronjobLog = new Logger('cronjob');
     #$cronjobLog->pushHandler(new LoggerStreamHandler('php://stdout', Logger::DEBUG));
     $cronjob = new Cronjob();
     $cronjob->setLog($cronjobLog);
     $cronjob->setSettings($settings);
     $cronjob->setTable($table);
     $cronjob->setNodesNewDb($nodesNewDb);
     $httpClient = $cronjob->createGuzzleHttpClient();
     #fwrite(STDOUT, 'client: '.get_class($httpClient).''.PHP_EOL);
     #\Doctrine\Common\Util\Debug::dump($httpClient);
     $this->assertTrue(is_object($httpClient));
     $url = 'http://www.example.com/';
     $response = null;
     try {
         #fwrite(STDOUT, 'get url: '.$url.''.PHP_EOL);
         $request = $httpClient->get($url);
         #fwrite(STDOUT, 'request: '.get_class($request).''.PHP_EOL);
         $response = $request->send();
         #fwrite(STDOUT, 'response: '.get_class($response).''.PHP_EOL);
     } catch (Exception $e) {
         #fwrite(STDOUT, 'url failed, "'.$url.'": '.$e->getMessage().PHP_EOL);
     }
     /*if($response){
     			fwrite(STDOUT, 'response: '.$response->getStatusCode().PHP_EOL);
     			fwrite(STDOUT, 'content-type: '.$response->getHeader('content-type').PHP_EOL);
     		}
     		else{
     			fwrite(STDOUT, 'response failed'.PHP_EOL);
     		}*/
 }
Exemplo n.º 3
0
 public function testNodeEnclose5()
 {
     $runName = uniqid('', true);
     $fileName = 'testfile_table_nodeenclose5_' . date('Ymd_His') . '_' . $runName . '.yml';
     $localNode = new Node();
     $localNode->setIdHexStr('11000001-2002-4004-8008-100000000006');
     $table = new Table('test_data/' . $fileName);
     $table->setDatadirBasePath('test_data');
     $table->setLocalNode($localNode);
     $node1 = new Node();
     $node1->setIdHexStr('11000001-2002-4004-8008-100000000001');
     $node1->setUri('tcp://192.168.241.1:25000');
     $node2 = new Node();
     $node2->setIdHexStr('11000001-2002-4004-8008-100000000002');
     $node2->setUri('tcp://192.168.241.2:25000');
     $node3 = new Node();
     $node3->setUri('tcp://192.168.241.1:25000');
     $node4 = new Node();
     $node4->setIdHexStr('11000001-2002-4004-8008-100000000003');
     $node4->setUri('tcp://192.168.241.2:25000');
     $table->nodeEnclose($node1);
     $table->nodeEnclose($node2);
     $node = $table->nodeEnclose($node3);
     $this->assertEquals('00000000-0000-4000-8000-000000000000', $node->getIdHexStr());
     $this->assertEquals('tcp://192.168.241.1:25000', (string) $node->getUri());
     $node = $table->nodeEnclose($node4);
     $this->assertEquals('11000001-2002-4004-8008-100000000003', $node->getIdHexStr());
     $this->assertEquals('tcp://192.168.241.2:25000', (string) $node->getUri());
     $this->assertEquals('', (string) $node2->getUri());
     $table->save();
 }