ILIAS  release_7 Revision v7.30-3-g800a261c036
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

@group needsInstalledILIAS

Definition at line 34 of file ilDatabaseAtomRunTest.php.

Member Function Documentation

◆ getExpectedResult()

ilDatabaseAtomRunTest::getExpectedResult ( )
protected
Returns
array

Definition at line 328 of file ilDatabaseAtomRunTest.php.

329 {
330 return array(
331 0 => array(
332 'id' => '1',
333 'is_online' => '1',
334 ),
335 1 => array(
336 'id' => '2',
337 'is_online' => '0',
338 ),
339 );
340 }

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

+ Here is the caller graph for this function:

◆ getInsertQueryCallable()

ilDatabaseAtomRunTest::getInsertQueryCallable ( )
protected
Returns
\Closure

Definition at line 276 of file ilDatabaseAtomRunTest.php.

277 {
278 $query = function (ilDBInterface $ilDB) {
279 $ilDB->insert('il_db_tests_atom', array(
280 'id' => array( 'integer', $ilDB->nextId('il_db_tests_atom') ),
281 'is_online' => array( 'integer', 1 ),
282 ));
283 $ilDB->insert('il_db_tests_atom', array(
284 'id' => array( 'integer', $ilDB->nextId('il_db_tests_atom') ),
285 'is_online' => array( 'integer', 0 ),
286 ));
287 };
288
289 return $query;
290 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query
global $ilDB

References $ilDB, and $query.

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

+ Here is the caller graph for this function:

◆ getResultFromDB()

ilDatabaseAtomRunTest::getResultFromDB ( )
protected
Returns
array

Definition at line 313 of file ilDatabaseAtomRunTest.php.

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

References $d, $res, and $results.

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

+ Here is the caller graph for this function:

◆ getTableLocksForDbInterface()

ilDatabaseAtomRunTest::getTableLocksForDbInterface ( )
protected
Returns
array

Definition at line 296 of file ilDatabaseAtomRunTest.php.

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

References ilAtomQuery\LOCK_WRITE.

◆ setUp()

ilDatabaseAtomRunTest::setUp ( )
protected

Definition at line 59 of file ilDatabaseAtomRunTest.php.

59 : void
60 {
61 ilUnitUtil::performInitialisation();
62
63 global $ilClientIniFile;
65 $this->ilDBInterfaceGalera->initFromIniFile($ilClientIniFile);
66 $this->ilDBInterfaceGalera->connect();
67
68 $this->ilDBInterfaceGaleraSecond = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_GALERA);
69 $this->ilDBInterfaceGaleraSecond->initFromIniFile($ilClientIniFile);
70 $this->ilDBInterfaceGaleraSecond->connect();
71
73 $this->ilDBInterfaceInnoDB->initFromIniFile($ilClientIniFile);
74 $this->ilDBInterfaceInnoDB->connect();
75
77 $this->ilDBInterfaceInnoDBSecond->initFromIniFile($ilClientIniFile);
78 $this->ilDBInterfaceInnoDBSecond->connect();
79
80 $this->setupTable();
81 }

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

+ Here is the call graph for this function:

◆ setupTable()

ilDatabaseAtomRunTest::setupTable ( )

Definition at line 99 of file ilDatabaseAtomRunTest.php.

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

Referenced by setUp().

+ Here is the caller graph for this function:

◆ tearDown()

ilDatabaseAtomRunTest::tearDown ( )

Definition at line 84 of file ilDatabaseAtomRunTest.php.

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

◆ testConnection()

ilDatabaseAtomRunTest::testConnection ( )

Definition at line 91 of file ilDatabaseAtomRunTest.php.

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

◆ testNoQueries()

ilDatabaseAtomRunTest::testNoQueries ( )

Definition at line 199 of file ilDatabaseAtomRunTest.php.

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

◆ testNoTables()

ilDatabaseAtomRunTest::testNoTables ( )

Definition at line 189 of file ilDatabaseAtomRunTest.php.

190 {
191 $this->setExpectedException('ilDatabaseException');
192 $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
193 $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
194
195 $ilAtomQuery->run();
196 }

References getInsertQueryCallable().

+ Here is the call graph for this function:

◆ testTableExists()

ilDatabaseAtomRunTest::testTableExists ( )

Definition at line 121 of file ilDatabaseAtomRunTest.php.

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

◆ testUpdateDuringLock()

ilDatabaseAtomRunTest::testUpdateDuringLock ( )

Definition at line 239 of file ilDatabaseAtomRunTest.php.

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

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

◆ testUpdateDuringTransaction()

ilDatabaseAtomRunTest::testUpdateDuringTransaction ( )

Definition at line 209 of file ilDatabaseAtomRunTest.php.

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

References $d, $query, and $res.

◆ testWriteWithLocks()

ilDatabaseAtomRunTest::testWriteWithLocks ( )

Definition at line 139 of file ilDatabaseAtomRunTest.php.

140 {
141 $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
142 $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
143 $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
144
145 $ilAtomQuery->run();
146
147 $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
148 }

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

+ Here is the call graph for this function:

◆ testWriteWithLocksAndAlias()

ilDatabaseAtomRunTest::testWriteWithLocksAndAlias ( )

Definition at line 151 of file ilDatabaseAtomRunTest.php.

152 {
153 $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
154 $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
155 $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
156
157 $ilAtomQuery->run();
158
159 $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
160 }

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

+ Here is the call graph for this function:

◆ testWriteWithMultipleLocksAndAlias()

ilDatabaseAtomRunTest::testWriteWithMultipleLocksAndAlias ( )

Definition at line 163 of file ilDatabaseAtomRunTest.php.

164 {
165 $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
166 $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
167 $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_second_alias');
168 $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
169
170 $ilAtomQuery->run();
171
172 $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
173 }

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

+ Here is the call graph for this function:

◆ testWriteWithMultipleLocksWithAndWithoutAlias()

ilDatabaseAtomRunTest::testWriteWithMultipleLocksWithAndWithoutAlias ( )

Definition at line 176 of file ilDatabaseAtomRunTest.php.

177 {
178 $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
179 $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
180 $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
181 $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
182
183 $ilAtomQuery->run();
184
185 $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
186 }

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

+ Here is the call graph for this function:

◆ testWriteWithTransactions()

ilDatabaseAtomRunTest::testWriteWithTransactions ( )

Definition at line 127 of file ilDatabaseAtomRunTest.php.

128 {
129 $ilAtomQuery = $this->ilDBInterfaceGalera->buildAtomQuery();
130 $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
131 $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
132
133 $ilAtomQuery->run();
134
135 $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
136 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $backupGlobals

ilDatabaseAtomRunTest::$backupGlobals = false
protected

Definition at line 40 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceGalera

ilDatabaseAtomRunTest::$ilDBInterfaceGalera
protected

Definition at line 44 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceGaleraSecond

ilDatabaseAtomRunTest::$ilDBInterfaceGaleraSecond
protected

Definition at line 48 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceInnoDB

ilDatabaseAtomRunTest::$ilDBInterfaceInnoDB
protected

Definition at line 52 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceInnoDBSecond

ilDatabaseAtomRunTest::$ilDBInterfaceInnoDBSecond
protected

Definition at line 56 of file ilDatabaseAtomRunTest.php.


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