Skip to content

Commit

Permalink
Rebuilding...
Browse files Browse the repository at this point in the history
  • Loading branch information
kohkimakimoto committed Oct 22, 2014
1 parent c236e73 commit 0572610
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 33 deletions.
11 changes: 6 additions & 5 deletions src/Altax/Foundation/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
];
}

$env['server.port'] = 22;
$env['server.key'] = getenv("HOME")."/.ssh/id_rsa";
$env['server.username'] = getenv("USER");
$env['command.shell'] = '/bin/bash -l -c';
$env['script.working'] = sys_get_temp_dir()."/altax";
$env['server.port'] = 22;
$env['server.key'] = getenv("HOME")."/.ssh/id_rsa";
$env['server.username'] = getenv("USER");
$env['command.shell'] = '/bin/bash -l -c';
$env['script.working'] = sys_get_temp_dir()."/altax";
$env['process.parallel'] = true;

$env['aliases'] = [
'App' => 'Altax\Facade\App',
Expand Down
7 changes: 5 additions & 2 deletions src/Altax/Process/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ class Executor

protected $console;

public function __construct($runtime, $servers, $output, $console)
protected $env;

public function __construct($runtime, $servers, $output, $console, $env)
{
$this->runtime = $runtime;
$this->servers = $servers;
$this->output = $output;
$this->console = $console;
$this->env = $env;
}

public function on()
Expand Down Expand Up @@ -58,7 +61,7 @@ public function on()
}
}

$manager = new ProcessManager($this->runtime, $this->output);
$manager = new ProcessManager($this->runtime, $this->output, $this->env);
$manager->execute($closure, $nodes);
}

Expand Down
12 changes: 10 additions & 2 deletions src/Altax/Process/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ class ProcessManager

protected $output;

protected $env;

protected $isParallel;

protected $childPids = array();

public function __construct($runtime, $output)
public function __construct($runtime, $output, $env)
{
$this->runtime = $runtime;
$this->output = $output;
$this->env = $env;

if (!function_exists('pcntl_signal') || !function_exists('pcntl_fork') || !function_exists('pcntl_wait') || !function_exists('posix_kill')) {
if ($this->env->get('process.parallel', true) == false) {
$this->isParallel = false;
if ($this->output->isDebug()) {
$this->output->writeln("Running serial mode.");
}
} elseif (!function_exists('pcntl_signal') || !function_exists('pcntl_fork') || !function_exists('pcntl_wait') || !function_exists('posix_kill')) {
$this->isParallel = false;
if ($this->output->isDebug()) {
$this->output->writeln("Running serial mode.");
Expand Down
4 changes: 3 additions & 1 deletion src/Altax/Process/ProcessServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function register()
$app['process.runtime'],
$app['servers'],
$app['output'],
$app['console']);
$app['console'],
$app['env']
);
});
}
}
19 changes: 19 additions & 0 deletions tests/Altax/RemoteFile/RemoteFileServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Test\Altax\RemoteFile;

use Altax\RemoteFile\RemoteFileBuilder;

class RemoteFileProviderTest extends \PHPUnit_Framework_TestCase
{
public function setup()
{
$this->app = bootAltaxApplication();
}

public function testRemoteFile()
{
$obj = $this->app["remote_file"];
$this->assertTrue($obj instanceof RemoteFileBuilder);
}

}
46 changes: 46 additions & 0 deletions tests/Altax/RemoteFile/RemoteFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace Test\Altax\RemoteFile;

use Symfony\Component\Console\Output\BufferedOutput;

class CommandTest extends \PHPUnit_Framework_TestCase
{
public function setup()
{
$this->app = bootAltaxApplication();
$this->app->instance("output", new BufferedOutput());
}

public function testPutError()
{
$remoteFileBuilder = $this->app["remote_file"];
$remoteFile = $remoteFileBuilder->make();
try {
$remoteFile->put(__DIR__."/files/puttext.txt", "/tmp/puttext.txt");
$this->assertEquals(true, false);
} catch (\Exception $e) {
$this->assertTrue(true);
}
}

public function testPut()
{
$servers = $this->app['servers'];
$servers->node("127.0.0.1");
$env = $this->app['env'];
$env->set('process.parallel', false);

$executor = $this->app['process.executor'];
$executor->on(["127.0.0.1"], function(){

$remoteFileBuilder = $this->app["remote_file"];
$remoteFile = $remoteFileBuilder->make();
$remoteFile->put(__DIR__."/files/puttext.txt", __DIR__."/../../tmp/puttext.txt");

});

$this->assertTrue(file_exists(__DIR__."/../../tmp/puttext.txt"));
unlink(__DIR__."/../../tmp/puttext.txt");
}

}
1 change: 1 addition & 0 deletions tests/Altax/RemoteFile/files/puttext.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
put ok
3 changes: 3 additions & 0 deletions tests/Altax/Server/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function testReplaceTilda()
$serverManager = $this->app["servers"];
$node = $serverManager->makeNode("test_node_name");

$orgHome = getenv("HOME");
putenv("HOME=/home/your");
$node->setKey("~/path/to/private_key");
$this->assertEquals("~/path/to/private_key", $node->getKey());
Expand All @@ -69,5 +70,7 @@ public function testReplaceTilda()
$node->setKey("/path/to/private_key~");
$this->assertEquals("/path/to/private_key~", $node->getKey());
$this->assertEquals("/path/to/private_key~", $node->getKeyOrDefault());

putenv("HOME=$orgHome");
}
}
22 changes: 0 additions & 22 deletions tests/Altax/Shell/CommandBuilderTest.php

This file was deleted.

67 changes: 67 additions & 0 deletions tests/Altax/Shell/CommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
namespace Test\Altax\Shell;

use Symfony\Component\Console\Output\BufferedOutput;

class CommandTest extends \PHPUnit_Framework_TestCase
{
public function setup()
{
$this->app = bootAltaxApplication();
$this->app->instance("output", new BufferedOutput());
}

public function testMakeAndRunOnLoccally()
{
$commandBuilder = $this->app["shell.command"];
$command = $commandBuilder->make("pwd");
$command->run();

$this->assertRegExp("/Run command locally:/", $this->app['output']->fetch());
}

public function testMakeAndRunOnRemotely()
{
$servers = $this->app['servers'];
$servers->node("127.0.0.1");
$env = $this->app['env'];
$env->set('process.parallel', false);

$executor = $this->app['process.executor'];
$executor->on(["127.0.0.1"], function(){

$commandBuilder = $this->app["shell.command"];
$command = $commandBuilder->make("pwd");
$command->run();

});

$this->assertRegExp("/Run command: pwd on 127.0.0.1/", $this->app['output']->fetch());
}

public function testRunOnLoccally()
{
$commandBuilder = $this->app["shell.command"];
$commandBuilder->run("pwd");

$this->assertRegExp("/Run command locally:/", $this->app['output']->fetch());
}

public function testRunOnRemotely()
{
$servers = $this->app['servers'];
$servers->node("127.0.0.1");
$env = $this->app['env'];
$env->set('process.parallel', false);

$executor = $this->app['process.executor'];
$executor->on(["127.0.0.1"], function(){

$commandBuilder = $this->app["shell.command"];
$commandBuilder->run("pwd");

});

$this->assertRegExp("/Run command: pwd on 127.0.0.1/", $this->app['output']->fetch());
}
}
1 change: 0 additions & 1 deletion tests/Altax/Shell/ShellServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
namespace Test\Altax\Shell;

use Altax\Shell\CommandBuilder;
use Altax\Shell\ScriptBuilder;

class ShellServiceProviderTest extends \PHPUnit_Framework_TestCase
{
Expand Down

0 comments on commit 0572610

Please sign in to comment.