def __init__(self, methodName='runTest'): txweb2.dav.test.util.TestCase.__init__(self, methodName) while len(self.theStoreBuilders) < self.numberOfStores: self.theStoreBuilders.append( SQLStoreBuilder(count=len(self.theStoreBuilders))) self.theStores = [None] * self.numberOfStores self.activeTransactions = [None] * self.numberOfStores
def __init__(self, methodName='runTest'): super(SQLDump, self).__init__(methodName) if DB_TYPE[0] == POSTGRES_DIALECT: self.testStoreBuilder = theStoreBuilder else: self.testStoreBuilder = SQLStoreBuilder(dsnUser="******", noCleanup=True)
class MultiStoreConduitTest(CommonCommonTests, txweb2.dav.test.util.TestCase): theStoreBuilder2 = SQLStoreBuilder(secondary=True) otherTransaction = None @inlineCallbacks def setUp(self): yield super(MultiStoreConduitTest, self).setUp() # Store 1 serversDB1 = ServersDB() server1a = Server("A", "http://127.0.0.1:8008", "A", True) serversDB1.addServer(server1a) server1b = Server("B", "http://127.0.0.1:8108", "B", False) serversDB1.addServer(server1b) yield self.buildStoreAndDirectory(serversDB=serversDB1) self.store.queryCacher = None # Cannot use query caching self.store.conduit = self.makeConduit(self.store) # Store 2 serversDB2 = ServersDB() server2a = Server("A", "http://127.0.0.1:8008", "A", False) serversDB2.addServer(server2a) server2b = Server("B", "http://127.0.0.1:8108", "B", True) serversDB2.addServer(server2b) self.store2 = yield self.buildStore(self.theStoreBuilder2) directory2 = buildTestDirectory(self.store2, self.mktemp(), serversDB=serversDB2) self.store2.setDirectoryService(directory2) self.store2.queryCacher = None # Cannot use query caching self.store2.conduit = self.makeConduit(self.store2) FakeConduitRequest.addServerStore(server1a, self.store) FakeConduitRequest.addServerStore(server2b, self.store2) def configure(self): super(MultiStoreConduitTest, self).configure() self.config.Servers.Enabled = True def otherStoreUnderTest(self): """ Return a store for testing. """ return self.store2 def newOtherTransaction(self): assert self.otherTransaction is None store2 = self.otherStoreUnderTest() txn = store2.newTransaction() @inlineCallbacks def maybeCommitThis(): try: yield txn.commit() except AlreadyFinishedError: pass self.addCleanup(maybeCommitThis) self.otherTransaction = txn return self.otherTransaction def otherTransactionUnderTest(self): if self.otherTransaction is None: self.newOtherTransaction() return self.otherTransaction @inlineCallbacks def otherCommit(self): assert self.otherTransaction is not None yield self.otherTransaction.commit() self.otherTransaction = None @inlineCallbacks def otherAbort(self): assert self.otherTransaction is not None yield self.otherTransaction.abort() self.otherTransaction = None def makeConduit(self, store): conduit = PoddingConduit(store) conduit.conduitRequestClass = FakeConduitRequest return conduit @inlineCallbacks def createShare(self, ownerGUID="user01", shareeGUID="puser02", name="calendar"): home = yield self.homeUnderTest(name=ownerGUID, create=True) calendar = yield home.calendarWithName(name) yield calendar.inviteUserToShare(shareeGUID, _BIND_MODE_WRITE, "shared", shareName="shared-calendar") yield self.commit() # ACK: home2 is None home2 = yield self.homeUnderTest(txn=self.newOtherTransaction(), name=shareeGUID) yield home2.acceptShare("shared-calendar") yield self.otherCommit() returnValue("shared-calendar") @inlineCallbacks def removeShare(self, ownerGUID="user01", shareeGUID="puser02", name="calendar"): home = yield self.homeUnderTest(name=ownerGUID) calendar = yield home.calendarWithName(name) yield calendar.uninviteUserFromShare(shareeGUID) yield self.commit()