public function test_should_sharding_table_router_set_and_get_works_fine() { $table = \Myfox\App\Model\Table::instance('numsplit'); try { Router::set('numsplit', array(array('field' => array('thedate' => '20110610'), 'count' => 1201))); $this->assertTrue(false); } catch (\Exception $e) { $this->assertTrue($e instanceof \Myfox\Lib\Exception); $this->assertContains('Column "cid" required for table "numsplit"', $e->getMessage()); } $this->assertEquals(array('cid:1,thedate:20110610' => array(array('rows' => 1000, 'hosts' => '3,1', 'table' => 'numsplit_0.t_' . $table->get('autokid') . '_0'), array('rows' => 201, 'hosts' => '1,2', 'table' => 'numsplit_0.t_' . $table->get('autokid') . '_1')), 'cid:2,thedate:20110610' => array(array('rows' => 998, 'hosts' => '1,2', 'table' => 'numsplit_0.t_' . $table->get('autokid') . '_1'))), Router::set('numsplit', array(array('field' => array('thedate' => '2011-06-10', 'cid' => 1), 'count' => 1201), array('field' => array('thedate' => '2011-06-10', 'cid' => 2), 'count' => 998)))); $this->assertEquals(array(), Router::get('numsplit', array('thedate' => '2011-6-10', 'cid' => 1, 'blablala' => 2))); Router::effect('numsplit', array('thedate' => 20110610, 'cid' => 1), 'numsplit_0.t_' . $table->get('autokid') . '_1', '1,2') && Router::flush(); $routes = Router::get('numsplit', array('thedate' => '2011-6-10', 'cid' => 1, 'blablala' => 2)); $result = array(); foreach ($routes as $item) { unset($item['tabid'], $item['seqid']); $item['mtime'] = $item['mtime'] > 0 ? true : false; $result[] = $item; } $this->assertEquals(array(array('tbidx' => 'test_route_info_c', 'mtime' => true, 'hosts' => '1,2', 'table' => sprintf('numsplit_0.t_%d_1', $table->get('autokid')))), $result); }