class ServerReplicationTestCase(unittest.TestCase): def setUp(self): """ Set replication to 2 other navistore http server instances. For simplicity those instances are going to be assumed to be running on the same machine this test runs. However, it should be easy to configure otherwise replacing the hostnames/ports and re-running the test. To run the test, have 2 other instancs running at ports 8889 and 8887. """ self.localstore = HttpStorageBackend(SERVER_HOST) self.localstore.save('/_replication_slaves', "http://localhost:8889,http://localhost:8887") self.remote1 = HttpStorageBackend(REMOTE1) self.remote2 = HttpStorageBackend(REMOTE2) def test_save_and_get_replicated(self): """ Test saving a value by a key to the database, and then make sure the save value by the same key is also available in the target replication instances. """ self.localstore.save("1", "replication testcase inserted value") fvalue = self.localstore.get("1") remote1value = self.remote1.get("1") remote2value = self.remote2.get("1") self.assertTrue(fvalue == remote1value) self.assertTrue(fvalue == remote2value) def test_delete_replicated(self): """ Add a value, then delete it, and make sure the deletion operation was carried on to the replicated instances. """ self.localstore.save('/_replication_slaves', "http://localhost:8889,http://localhost:8887") self.localstore.save("sample_key2", "sample_value2") self.assertTrue(self.localstore.haskey("sample_key2")) self.assertTrue(self.remote1.haskey("sample_key2")) self.assertTrue(self.remote2.haskey("sample_key2")) self.localstore.delete("sample_key2") # no replication is immediate time.sleep(0.1) self.assertRaises(ResourceNotFound, self.remote1.get, ("sample_key2")) self.assertRaises(ResourceNotFound, self.remote2.get, ("sample_key2")) def tearDown(self): self.localstore.reset() self.remote1.reset() self.remote2.reset()
class HttpStorageBackendTestCase(testNavistoreBackend.StorageBackendTestCase): """ HTTP storage backend client test case. This tests the HttpStorageBackend class, according to the interface conformance we defined in StorageBackendTestCase. This test also makes the http server we work against, conforms to the navistore backend interface specification and actually serves to test the http server as well. Since replication support is outside of the defined interface, and is part of the http server implementation we use a different test to test it, testServerReplication.py """ store = None def setUp(self): """ create a backend object that allows us to interact with the key value storage """ self.store = HttpStorageBackend(SERVER_HOST) def tearDown(self): self.store.reset() # cleaning up the store for the nex test def test_delete(self): self.store.save("sample_key2", "sample_value2") self.assertTrue(self.store.haskey("sample_key2")) self.store.delete("sample_key2") self.assertRaises(ResourceNotFound, self.store.get, ("sample_key2")) def test_reset(self): self.store.save("mkey", "value") self.assertTrue(self.store.haskey("mkey")) self.store.reset() self.assertRaises(ResourceNotFound, self.store.get, ("mkey")) def test_loadstore(self): # not relevant here since we cannot # stop and start the service from here pass
class HttpStorageBackendTestCase(testNavistoreBackend.StorageBackendTestCase): """ HTTP storage backend client test case. This tests the HttpStorageBackend class, according to the interface conformance we defined in StorageBackendTestCase. This test also makes the http server we work against, conforms to the navistore backend interface specification and actually serves to test the http server as well. Since replication support is outside of the defined interface, and is part of the http server implementation we use a different test to test it, testServerReplication.py """ store = None def setUp(self): """ create a backend object that allows us to interact with the key value storage """ self.store = HttpStorageBackend(SERVER_HOST) def tearDown(self): self.store.reset() # cleaning up the store for the nex test def test_delete(self): self.store.save("sample_key2","sample_value2") self.assertTrue(self.store.haskey("sample_key2")) self.store.delete("sample_key2") self.assertRaises(ResourceNotFound, self.store.get, ("sample_key2")) def test_reset(self): self.store.save("mkey","value") self.assertTrue(self.store.haskey("mkey")) self.store.reset() self.assertRaises(ResourceNotFound, self.store.get, ("mkey")) def test_loadstore(self): # not relevant here since we cannot # stop and start the service from here pass