<?php require_once 'common.php'; class mock_peer extends redis_peer { } # Benchmark $p = new mock_peer(); bench_mark::start('Setting 10000 entities'); for ($i = 0; $i < 10000; $i++) { $p->insert(array('data' => md5($i))); } bench_mark::stop(); bench_mark::start('Reading 10000 entities'); for ($i = 0; $i < 10000; $i++) { $p->get_by_id($i + 1); } bench_mark::stop(); bench_mark::start('Deleting 10000 entities'); for ($i = 0; $i < 10000; $i++) { $p->delete($i + 1); } bench_mark::stop();
$ts = time(); $data = array('name' => 'Test', 'time' => $ts); $p = new mock_peer(); $id = $p->insert($data); test::assert_true($id > 0, 'Insert tests'); $v = $p->get_by_id($id); test::assert_value($v['id'], $id); test::assert_value($v['time'], $ts); test::assert_value($v['name'], 'Test'); test::assert_value(count($v), 3); $id1 = $p->insert($data); $id2 = $p->insert($data); $id3 = $p->insert($data); test::assert_value($id1, $id2 - 1); test::assert_value($id1, $id3 - 2); $id = $p->insert($data); $p->delete($id); $v = $p->get_by_id($id); test::assert_null($v, 'Delete tests'); $id = $p->insert($data); $p->update($id, array('name' => 'Test updated')); $v = $p->get_by_id($id); test::assert_value($v['name'], 'Test updated', 'Update tests'); test::assert_value($v['id'], $id); test::assert_value($v['time'], $ts); test::assert_value(count($v), 3); $p->update($id, array('country' => 'Ukraine')); $v = $p->get_by_id($id); test::assert_value($v['country'], 'Ukraine'); test::assert_value(count($v), 4); test::summary();