ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilDatabaseAtomRunTest Class Reference

TestCase for the ilDatabaseAtomBaseTest. More...

+ Inheritance diagram for ilDatabaseAtomRunTest:
+ Collaboration diagram for ilDatabaseAtomRunTest:

Public Member Functions

 tearDown ()
 
 testConnection ()
 
 setupTable ()
 
 testTableExists ()
 
 testWriteWithTransactions ()
 
 testWriteWithLocks ()
 
 testWriteWithLocksAndAlias ()
 
 testWriteWithMultipleLocksAndAlias ()
 
 testWriteWithMultipleLocksWithAndWithoutAlias ()
 
 testNoTables ()
 
 testNoQueries ()
 
 testUpdateDuringTransaction ()
 
 testUpdateDuringLock ()
 

Protected Member Functions

 setUp ()
 
 getInsertQueryCallable ()
 
 getTableLocksForDbInterface ()
 
 getResultFromDB ()
 
 getExpectedResult ()
 

Protected Attributes

 $backupGlobals = false
 
 $ilDBInterfaceGalera
 
 $ilDBInterfaceGaleraSecond
 
 $ilDBInterfaceInnoDB
 
 $ilDBInterfaceInnoDBSecond
 

Detailed Description

TestCase for the ilDatabaseAtomBaseTest.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

needsInstalledILIAS

Definition at line 32 of file ilDatabaseAtomRunTest.php.

Member Function Documentation

◆ getExpectedResult()

ilDatabaseAtomRunTest::getExpectedResult ( )
protected
Returns
array

Definition at line 327 of file ilDatabaseAtomRunTest.php.

Referenced by testWriteWithLocks(), testWriteWithLocksAndAlias(), testWriteWithMultipleLocksAndAlias(), testWriteWithMultipleLocksWithAndWithoutAlias(), and testWriteWithTransactions().

328  {
329  return array(
330  0 => array(
331  'id' => '1',
332  'is_online' => '1',
333  ),
334  1 => array(
335  'id' => '2',
336  'is_online' => '0',
337  ),
338  );
339  }
+ Here is the caller graph for this function:

◆ getInsertQueryCallable()

ilDatabaseAtomRunTest::getInsertQueryCallable ( )
protected
Returns

Definition at line 275 of file ilDatabaseAtomRunTest.php.

References $ilDB, and $query.

Referenced by testNoTables(), testWriteWithLocks(), testWriteWithLocksAndAlias(), testWriteWithMultipleLocksAndAlias(), testWriteWithMultipleLocksWithAndWithoutAlias(), and testWriteWithTransactions().

276  {
277  $query = function (ilDBInterface $ilDB) {
278  $ilDB->insert('il_db_tests_atom', array(
279  'id' => array( 'integer', $ilDB->nextId('il_db_tests_atom') ),
280  'is_online' => array( 'integer', 1 ),
281  ));
282  $ilDB->insert('il_db_tests_atom', array(
283  'id' => array( 'integer', $ilDB->nextId('il_db_tests_atom') ),
284  'is_online' => array( 'integer', 0 ),
285  ));
286  };
287 
288  return $query;
289  }
$query
global $ilDB
+ Here is the caller graph for this function:

◆ getResultFromDB()

ilDatabaseAtomRunTest::getResultFromDB ( )
protected
Returns
array

Definition at line 312 of file ilDatabaseAtomRunTest.php.

References $d, $res, and $results.

Referenced by testWriteWithLocks(), testWriteWithLocksAndAlias(), testWriteWithMultipleLocksAndAlias(), testWriteWithMultipleLocksWithAndWithoutAlias(), and testWriteWithTransactions().

313  {
314  $res = $this->ilDBInterfaceGalera->query('SELECT * FROM il_db_tests_atom');
315  $results = array();
316  while ($d = $this->ilDBInterfaceGalera->fetchAssoc($res)) {
317  $results[] = $d;
318  }
319 
320  return $results;
321  }
foreach($_POST as $key=> $value) $res
$results
Definition: svg-scanner.php:47
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
+ Here is the caller graph for this function:

◆ getTableLocksForDbInterface()

ilDatabaseAtomRunTest::getTableLocksForDbInterface ( )
protected
Returns
array

Definition at line 295 of file ilDatabaseAtomRunTest.php.

References ilAtomQuery\LOCK_WRITE.

296  {
297  $tables = array(
298  array(
299  'name' => 'il_db_tests_atom',
300  'type' => ilAtomQuery::LOCK_WRITE,
301  'sequence' => true,
302  ),
303  );
304 
305  return $tables;
306  }

◆ setUp()

ilDatabaseAtomRunTest::setUp ( )
protected

Definition at line 57 of file ilDatabaseAtomRunTest.php.

References setupTable(), ilDBConstants\TYPE_GALERA, and ilDBConstants\TYPE_PDO_MYSQL_INNODB.

58  {
59  require_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
60  ilUnitUtil::performInitialisation();
61 
62  global $ilClientIniFile;
63  $this->ilDBInterfaceGalera = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_GALERA);
64  $this->ilDBInterfaceGalera->initFromIniFile($ilClientIniFile);
65  $this->ilDBInterfaceGalera->connect();
66 
67  $this->ilDBInterfaceGaleraSecond = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_GALERA);
68  $this->ilDBInterfaceGaleraSecond->initFromIniFile($ilClientIniFile);
69  $this->ilDBInterfaceGaleraSecond->connect();
70 
71  $this->ilDBInterfaceInnoDB = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_PDO_MYSQL_INNODB);
72  $this->ilDBInterfaceInnoDB->initFromIniFile($ilClientIniFile);
73  $this->ilDBInterfaceInnoDB->connect();
74 
75  $this->ilDBInterfaceInnoDBSecond = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_PDO_MYSQL_INNODB);
76  $this->ilDBInterfaceInnoDBSecond->initFromIniFile($ilClientIniFile);
77  $this->ilDBInterfaceInnoDBSecond->connect();
78 
79  $this->setupTable();
80  }
+ Here is the call graph for this function:

◆ setupTable()

ilDatabaseAtomRunTest::setupTable ( )

Definition at line 98 of file ilDatabaseAtomRunTest.php.

Referenced by setUp().

99  {
100  if ($this->ilDBInterfaceGalera->sequenceExists('il_db_tests_atom')) {
101  $this->ilDBInterfaceGalera->dropSequence('il_db_tests_atom');
102  }
103  $this->ilDBInterfaceGalera->createTable('il_db_tests_atom', $fields = array(
104  'id' => array(
105  'type' => 'integer',
106  'length' => 4,
107  'notnull' => true,
108  ),
109  'is_online' => array(
110  'type' => 'integer',
111  'length' => 1,
112  'notnull' => false,
113  ),
114  ), true);
115  $this->ilDBInterfaceGalera->addPrimaryKey('il_db_tests_atom', array( 'id' ));
116  $this->ilDBInterfaceGalera->createSequence('il_db_tests_atom');
117  }
+ Here is the caller graph for this function:

◆ tearDown()

ilDatabaseAtomRunTest::tearDown ( )

Definition at line 83 of file ilDatabaseAtomRunTest.php.

84  {
85  $this->ilDBInterfaceGalera->dropSequence('il_db_tests_atom');
86  $this->ilDBInterfaceGalera->dropTable('il_db_tests_atom');
87  }

◆ testConnection()

ilDatabaseAtomRunTest::testConnection ( )

Definition at line 90 of file ilDatabaseAtomRunTest.php.

91  {
92  $this->assertTrue($this->ilDBInterfaceGalera->connect(true));
93  $this->assertTrue($this->ilDBInterfaceGaleraSecond->connect(true));
94  $this->assertTrue($this->ilDBInterfaceInnoDB->connect(true));
95  }

◆ testNoQueries()

ilDatabaseAtomRunTest::testNoQueries ( )

Definition at line 198 of file ilDatabaseAtomRunTest.php.

199  {
200  $this->setExpectedException('ilDatabaseException');
201  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
202  $ilAtomQuery->addTableLock('il_db_tests_atom');
203 
204  $ilAtomQuery->run();
205  }

◆ testNoTables()

ilDatabaseAtomRunTest::testNoTables ( )

Definition at line 188 of file ilDatabaseAtomRunTest.php.

References getInsertQueryCallable().

189  {
190  $this->setExpectedException('ilDatabaseException');
191  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
192  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
193 
194  $ilAtomQuery->run();
195  }
+ Here is the call graph for this function:

◆ testTableExists()

ilDatabaseAtomRunTest::testTableExists ( )

Definition at line 120 of file ilDatabaseAtomRunTest.php.

121  {
122  $this->assertTrue($this->ilDBInterfaceGalera->tableExists('il_db_tests_atom'));
123  }

◆ testUpdateDuringLock()

ilDatabaseAtomRunTest::testUpdateDuringLock ( )

Definition at line 238 of file ilDatabaseAtomRunTest.php.

References $d, $query, $res, and ilAtomQuery\LOCK_WRITE.

239  {
240  $this->ilDBInterfaceInnoDB->insert('il_db_tests_atom', array(
241  'id' => array( 'integer', $this->ilDBInterfaceInnoDB->nextId('il_db_tests_atom') ),
242  'is_online' => array( 'integer', 1 ),
243  ));
244  // Start a Transaction with one instance and update the same entry as another instance
245  $this->ilDBInterfaceInnoDB->lockTables(array( array( 'name' => 'il_db_tests_atom', 'type' => ilAtomQuery::LOCK_WRITE ) ));
246  $this->ilDBInterfaceInnoDB->update('il_db_tests_atom', array(
247  'is_online' => array( 'integer', 5 ),
248  ), array( 'id' => array( 'integer', 1 ) ));
249 
250  // Update the same entry with another instance (which currently fails due to missing multi-thread in PHP)
251  // $this->ilDBInterfaceInnoDBSecond->update('il_db_tests_atom', array(
252  // 'is_online' => array( 'integer', 6 ),
253  // ), array( 'id' => array( 'integer', 1 ) ), true);
254 
255  // Unlock Tables
256  $this->ilDBInterfaceInnoDB->unlockTables();
257 
258  // Check
259  $query = 'SELECT is_online FROM il_db_tests_atom WHERE id = ' . $this->ilDBInterfaceInnoDB->quote(1, 'integer');
260  $res = $this->ilDBInterfaceInnoDB->query($query);
261  $d = $this->ilDBInterfaceInnoDB->fetchAssoc($res);
262 
263  $this->assertEquals(5, $d['is_online']);
264  }
foreach($_POST as $key=> $value) $res
$query
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

◆ testUpdateDuringTransaction()

ilDatabaseAtomRunTest::testUpdateDuringTransaction ( )

Definition at line 208 of file ilDatabaseAtomRunTest.php.

References $d, $query, and $res.

209  {
210  $this->ilDBInterfaceGalera->insert('il_db_tests_atom', array(
211  'id' => array( 'integer', $this->ilDBInterfaceGalera->nextId('il_db_tests_atom') ),
212  'is_online' => array( 'integer', 1 ),
213  ));
214 
215  // Start a Transaction with one instance and update the same entry as another instance
216  $this->ilDBInterfaceGalera->beginTransaction();
217  $this->ilDBInterfaceGalera->update('il_db_tests_atom', array(
218  'is_online' => array( 'integer', 5 ),
219  ), array( 'id' => array( 'integer', 1 ) ));
220 
221  // Update the same entry with another instance (which currently fails due to missing multi-thread in PHP)
222  // $this->ilDBInterfaceGaleraSecond->update('il_db_tests_atom', array(
223  // 'is_online' => array( 'integer', 6 ),
224  // ), array( 'id' => array( 'integer', 1 ) ), true);
225 
226  // Commit the other
227  $this->ilDBInterfaceGalera->commit();
228 
229  // Check
230  $query = 'SELECT is_online FROM il_db_tests_atom WHERE id = ' . $this->ilDBInterfaceGalera->quote(1, 'integer');
231  $res = $this->ilDBInterfaceGalera->query($query);
232  $d = $this->ilDBInterfaceGalera->fetchAssoc($res);
233 
234  $this->assertEquals(5, $d['is_online']);
235  }
foreach($_POST as $key=> $value) $res
$query
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

◆ testWriteWithLocks()

ilDatabaseAtomRunTest::testWriteWithLocks ( )

Definition at line 138 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

139  {
140  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
141  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
142  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
143 
144  $ilAtomQuery->run();
145 
146  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
147  }
+ Here is the call graph for this function:

◆ testWriteWithLocksAndAlias()

ilDatabaseAtomRunTest::testWriteWithLocksAndAlias ( )

Definition at line 150 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

151  {
152  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
153  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
154  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
155 
156  $ilAtomQuery->run();
157 
158  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
159  }
+ Here is the call graph for this function:

◆ testWriteWithMultipleLocksAndAlias()

ilDatabaseAtomRunTest::testWriteWithMultipleLocksAndAlias ( )

Definition at line 162 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

163  {
164  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
165  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
166  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_second_alias');
167  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
168 
169  $ilAtomQuery->run();
170 
171  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
172  }
+ Here is the call graph for this function:

◆ testWriteWithMultipleLocksWithAndWithoutAlias()

ilDatabaseAtomRunTest::testWriteWithMultipleLocksWithAndWithoutAlias ( )

Definition at line 175 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

176  {
177  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
178  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
179  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
180  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
181 
182  $ilAtomQuery->run();
183 
184  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
185  }
+ Here is the call graph for this function:

◆ testWriteWithTransactions()

ilDatabaseAtomRunTest::testWriteWithTransactions ( )

Definition at line 126 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

127  {
128  $ilAtomQuery = $this->ilDBInterfaceGalera->buildAtomQuery();
129  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
130  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
131 
132  $ilAtomQuery->run();
133 
134  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
135  }
+ Here is the call graph for this function:

Field Documentation

◆ $backupGlobals

ilDatabaseAtomRunTest::$backupGlobals = false
protected

Definition at line 38 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceGalera

ilDatabaseAtomRunTest::$ilDBInterfaceGalera
protected

Definition at line 42 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceGaleraSecond

ilDatabaseAtomRunTest::$ilDBInterfaceGaleraSecond
protected

Definition at line 46 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceInnoDB

ilDatabaseAtomRunTest::$ilDBInterfaceInnoDB
protected

Definition at line 50 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceInnoDBSecond

ilDatabaseAtomRunTest::$ilDBInterfaceInnoDBSecond
protected

Definition at line 54 of file ilDatabaseAtomRunTest.php.


The documentation for this class was generated from the following file: