def test_lock_and_timeout(self): """Test that the lock times out and updates can be seen even though nothing is unlocked""" # first make sure that our writes to the master make it to the replica self._write_data_to_master() self._check_data_on_replica(1, "replica getting the data") # now lock the replica tablet_manager = self.replica.tablet_manager() tablet_manager.LockTables(LockTablesRequest()) # make sure that writing to the master does not show up on the replica while locked self._write_data_to_master() with self.assertRaises(TestError): self._check_data_on_replica( 2, "the replica should not see these updates") # the tests sets the lock timeout to 5 seconds, so sleeping 10 should be safe time.sleep(10) self._check_data_on_replica( 2, "the replica should now see these updates") # finally, trying to unlock should clearly tell us we did not have the lock with self.assertRaises(Exception): tablet_manager.UnlockTables(UnlockTablesRequest())
def test_lock_and_unlock(self): """Test the lock ability by locking a replica and asserting it does not see changes""" # first make sure that our writes to the master make it to the replica self._write_data_to_master() self._check_data_on_replica(1, "replica getting the data") # now lock the replica tablet_manager = self.replica.tablet_manager() tablet_manager.LockTables(LockTablesRequest()) # make sure that writing to the master does not show up on the replica while locked self._write_data_to_master() with self.assertRaises(TestError): self._check_data_on_replica(2, "the replica should not see these updates") # finally, make sure that unlocking the replica leads to the previous write showing up tablet_manager.UnlockTables(UnlockTablesRequest()) self._check_data_on_replica(2, "after unlocking the replica, we should see these updates")