Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace cachestore_redis;
17
namespace cachestore_redis;
18
 
18
 
19
use cache_store;
19
use core_cache\definition;
Línea 20... Línea 20...
20
use cache_definition;
20
use core_cache\store;
Línea 21... Línea 21...
21
use cachestore_redis;
21
use cachestore_redis;
Línea 36... Línea 36...
36
 * @package   cachestore_redis
36
 * @package   cachestore_redis
37
 * @covers    \cachestore_redis
37
 * @covers    \cachestore_redis
38
 * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
38
 * @copyright Copyright (c) 2015 Moodlerooms Inc. (http://www.moodlerooms.com)
39
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 */
40
 */
41
class store_test extends \cachestore_tests {
41
final class store_test extends \cachestore_tests {
42
    /**
42
    /**
43
     * @var cachestore_redis
43
     * @var cachestore_redis
44
     */
44
     */
45
    protected $store;
45
    protected $store;
Línea 74... Línea 74...
74
     * @param bool $ttl True to use a cache definition with TTL enabled
74
     * @param bool $ttl True to use a cache definition with TTL enabled
75
     * @return cachestore_redis
75
     * @return cachestore_redis
76
     */
76
     */
77
    protected function create_cachestore_redis(array $extraconfig = [], bool $ttl = false): cachestore_redis {
77
    protected function create_cachestore_redis(array $extraconfig = [], bool $ttl = false): cachestore_redis {
78
        if ($ttl) {
78
        if ($ttl) {
79
            /** @var cache_definition $definition */
79
            /** @var definition $definition */
80
            $definition = cache_definition::load('core/wibble', [
80
            $definition = definition::load('core/wibble', [
81
                'mode' => 1,
81
                'mode' => 1,
82
                'simplekeys' => true,
82
                'simplekeys' => true,
83
                'simpledata' => true,
83
                'simpledata' => true,
84
                'ttl' => 10,
84
                'ttl' => 10,
85
                'component' => 'core',
85
                'component' => 'core',
Línea 87... Línea 87...
87
                'selectedsharingoption' => 2,
87
                'selectedsharingoption' => 2,
88
                'userinputsharingkey' => '',
88
                'userinputsharingkey' => '',
89
                'sharingoptions' => 15,
89
                'sharingoptions' => 15,
90
            ]);
90
            ]);
91
        } else {
91
        } else {
92
            /** @var cache_definition $definition */
92
            /** @var definition $definition */
93
            $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_redis', 'phpunit_test');
93
            $definition = definition::load_adhoc(store::MODE_APPLICATION, 'cachestore_redis', 'phpunit_test');
94
        }
94
        }
95
        $configuration = array_merge(cachestore_redis::unit_test_configuration(), $extraconfig);
95
        $configuration = array_merge(cachestore_redis::unit_test_configuration(), $extraconfig);
96
        $store = new cachestore_redis('Test', $configuration);
96
        $store = new cachestore_redis('Test', $configuration);
97
        $store->initialise($definition);
97
        $store->initialise($definition);
Línea 153... Línea 153...
153
 
153
 
154
        // User 456 tries to acquire lock - should fail after about 2 seconds.
154
        // User 456 tries to acquire lock - should fail after about 2 seconds.
155
        $before = microtime(true);
155
        $before = microtime(true);
156
        $this->assertFalse($store->acquire_lock('lock', '456'));
156
        $this->assertFalse($store->acquire_lock('lock', '456'));
157
        $after = microtime(true);
157
        $after = microtime(true);
Línea 158... Línea 158...
158
        $this->assertEqualsWithDelta(2, $after - $before, 0.5);
158
        $this->assertEqualsWithDelta(2, $after - $before, 1);
159
 
159
 
160
        // Wait another 2 seconds and then it should be able to get the lock because of timeout.
160
        // Wait another 3 seconds and then it should be able to get the lock because of timeout.
161
        sleep(2);
161
        sleep(3);
Línea 162... Línea 162...
162
        $this->assertTrue($store->acquire_lock('lock', '456'));
162
        $this->assertTrue($store->acquire_lock('lock', '456'));
163
        $this->assertTrue($store->check_lock_state('lock', '456'));
163
        $this->assertTrue($store->check_lock_state('lock', '456'));
Línea 198... Línea 198...
198
     */
198
     */
199
    public function test_get_last_io_bytes(): void {
199
    public function test_get_last_io_bytes(): void {
200
        $store = $this->create_cachestore_redis();
200
        $store = $this->create_cachestore_redis();
Línea 201... Línea 201...
201
 
201
 
202
        $store->set('foo', [1, 2, 3, 4]);
202
        $store->set('foo', [1, 2, 3, 4]);
203
        $this->assertEquals(\cache_store::IO_BYTES_NOT_SUPPORTED, $store->get_last_io_bytes());
203
        $this->assertEquals(store::IO_BYTES_NOT_SUPPORTED, $store->get_last_io_bytes());
204
        $store->get('foo');
204
        $store->get('foo');
205
        $this->assertEquals(\cache_store::IO_BYTES_NOT_SUPPORTED, $store->get_last_io_bytes());
205
        $this->assertEquals(store::IO_BYTES_NOT_SUPPORTED, $store->get_last_io_bytes());
Línea 206... Línea 206...
206
    }
206
    }
207
 
207
 
208
    /**
208
    /**