Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     StaticDataLayer::disconnect();
     StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);
     StaticDataLayer::multiQuery(file_get_contents(__DIR__ . '/config/setup.sql'));
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  * 
  */
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     StaticDataLayer::disconnect();
     StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);
     StaticDataLayer::executeNone('alter table `test_data`.`TABLE1` engine=innodb');
 }
Ejemplo n.º 3
0
    /**
     * Test audit table is created correctly.
     */
    public function test01()
    {
        $application = new Application();
        $application->add(new AuditCommand());
        /** @var AuditCommand $command */
        $command = $application->find('audit');
        $command->setRewriteConfigFile(false);
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command' => $command->getName(), 'config file' => __DIR__ . '/config/audit.json']);
        $this->assertSame(0, $commandTester->getStatusCode());
        // Reconnect to DB.
        StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);
        $sql = sprintf('
select COLUMN_NAME        as column_name
,      COLUMN_TYPE        as column_type
,      IS_NULLABLE        as is_nullable
,      CHARACTER_SET_NAME as character_set_name
,      COLLATION_NAME     as collation_name
from   information_schema.COLUMNS
where  TABLE_SCHEMA = %s
and    TABLE_NAME   = %s
order by ORDINAL_POSITION', StaticDataLayer::quoteString(self::$auditSchema), StaticDataLayer::quoteString('AUT_COMPANY'));
        $rows = StaticDataLayer::executeRows($sql);
        $expected = [['column_name' => 'audit_timestamp', 'column_type' => 'timestamp', 'is_nullable' => 'NO', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'audit_statement', 'column_type' => "enum('INSERT','DELETE','UPDATE')", 'is_nullable' => 'NO', 'character_set_name' => 'ascii', 'collation_name' => 'ascii_general_ci'], ['column_name' => 'audit_type', 'column_type' => "enum('OLD','NEW')", 'is_nullable' => 'NO', 'character_set_name' => 'ascii', 'collation_name' => 'ascii_general_ci'], ['column_name' => 'audit_uuid', 'column_type' => 'bigint(20) unsigned', 'is_nullable' => 'NO', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'audit_rownum', 'column_type' => 'int(10) unsigned', 'is_nullable' => 'NO', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'audit_ses_id', 'column_type' => 'int(10) unsigned', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'audit_usr_id', 'column_type' => 'int(10) unsigned', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'cmp_id', 'column_type' => 'smallint(5) unsigned', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null], ['column_name' => 'cmp_abbr', 'column_type' => 'varchar(15)', 'is_nullable' => 'YES', 'character_set_name' => 'utf8', 'collation_name' => 'utf8_general_ci'], ['column_name' => 'cmp_label', 'column_type' => 'varchar(20)', 'is_nullable' => 'YES', 'character_set_name' => 'ascii', 'collation_name' => 'ascii_general_ci']];
        $this->assertEquals($expected, $rows);
    }
Ejemplo n.º 4
0
 private function runAudit()
 {
     $application = new Application();
     $application->add(new AuditCommand());
     /** @var AuditCommand $command */
     $command = $application->find('audit');
     $command->setRewriteConfigFile(false);
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'config file' => __DIR__ . '/config/audit.json']);
     // Reconnect to MySQL.
     StaticDataLayer::disconnect();
     StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);
     return $commandTester->getStatusCode();
 }
Ejemplo n.º 5
0
 /**
  * Test that the table is actually locked.
  */
 public function test02()
 {
     $application = new Application();
     $application->add(new AuditCommand());
     // Start process that inserts rows into TABLE1.
     $pid = pcntl_fork();
     if ($pid == 0) {
         // Child process.
         pcntl_exec(__DIR__ . '/config/generator.php');
     }
     // Parent process.
     sleep(2);
     /** @var AuditCommand $command */
     $command = $application->find('audit');
     $command->setRewriteConfigFile(false);
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'config file' => __DIR__ . '/config/audit.json']);
     // Tell the generator it is time to stop.
     posix_kill($pid, SIGUSR1);
     $status = $commandTester->getStatusCode();
     $this->assertSame(0, $status, 'status code');
     pcntl_waitpid($pid, $status);
     $this->assertEquals(0, $status);
     // Reconnect to DB.
     StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);
     // It can take some time before that all rows generated by $generator are visible by this process.
     $n1 = 0;
     $n2 = 0;
     sleep(5);
     for ($i = 0; $i < 60; $i++) {
         $n1 = StaticDataLayer::executeSingleton1("select AUTO_INCREMENT - 1 \n                                                from information_schema.TABLES\n                                                where TABLE_SCHEMA = 'test_data'\n                                                and   TABLE_NAME   = 'TABLE1'");
         $n2 = StaticDataLayer::executeSingleton1('select count(*) from test_audit.TABLE1');
         if (4 * $n1 == $n2) {
             break;
         }
         sleep(3);
     }
     $this->assertEquals(4 * $n1, $n2, 'count');
 }
Ejemplo n.º 6
0
 /**
  * Connects to a MySQL instance.
  *
  * Wrapper around [mysqli::__construct](http://php.net/manual/mysqli.construct.php), however on failure an exception
  * is thrown.
  *
  * @param string $host     The hostname.
  * @param string $user     The MySQL user name.
  * @param string $passWord The password.
  * @param string $database The default database.
  * @param int    $port     The port number.
  */
 public static function connect($host, $user, $passWord, $database, $port = 3306)
 {
     self::$dl = new StaticDataLayer();
     self::$dl->connect($host, $user, $passWord, $database, $port);
 }
Ejemplo n.º 7
0
 protected function setUp()
 {
     StaticDataLayer::disconnect();
     StaticDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);
 }
Ejemplo n.º 8
0
$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../vendor/autoload.php', __DIR__ . '/../../../vendor/autoload.php', __DIR__ . '/../../../../vendor/autoload.php'];
foreach ($files as $file) {
    if (file_exists($file)) {
        require $file;
        break;
    }
}
declare (ticks=1);
//----------------------------------------------------------------------------------------------------------------------
function signalHandler()
{
    $GLOBALS['exit'] = true;
}
//----------------------------------------------------------------------------------------------------------------------
$GLOBALS['exit'] = false;
pcntl_signal(SIGUSR1, "signalHandler");
// Set error handler.
$handler = new ErrorHandler();
$handler->register();
StaticDataLayer::connect('localhost', 'test', 'test', 'test_data');
while (true) {
    if ($GLOBALS['exit']) {
        break;
    }
    StaticDataLayer::begin();
    StaticDataLayer::executeNone('insert into TABLE1(c) values(1)');
    StaticDataLayer::executeNone('update TABLE1 set c = 2');
    StaticDataLayer::executeNone('delete from TABLE1 where c = 2');
    StaticDataLayer::commit();
}
StaticDataLayer::disconnect();